Alex | 0989ecf | 2022-03-29 13:43:21 -0500 | [diff] [blame] | 1 | # Author: Alex Savatieiev (osavatieiev@mirantis.com; a.savex@gmail.com) |
| 2 | # Copyright 2019-2022 Mirantis, Inc. |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 3 | import os |
| 4 | |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 5 | from tests.test_base import CfgCheckerTestBase |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 6 | |
| 7 | |
| 8 | class TestEntrypoints(CfgCheckerTestBase): |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 9 | def setUp(self): |
| 10 | # force env type to salt |
| 11 | os.environ['MCP_TYPE_FORCE'] = 'SALT' |
| 12 | |
| 13 | def tearDown(self): |
| 14 | del os.environ['MCP_TYPE_FORCE'] |
| 15 | |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 16 | def test_entry_mcp_checker(self): |
| 17 | _module_name = 'cfg_checker.cfg_check' |
| 18 | with self.redirect_output(): |
| 19 | _msg, _m = self._safe_import_module(_module_name) |
| 20 | |
| 21 | self.assertEqual( |
| 22 | len(_msg), |
| 23 | 0, |
| 24 | "Error importing '{}': {}".format( |
| 25 | _module_name, |
| 26 | _msg |
| 27 | ) |
| 28 | ) |
| 29 | |
| 30 | with self.redirect_output(): |
| 31 | with self.assertRaises(SystemExit) as ep: |
| 32 | _m.cfg_check.config_check_entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 33 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 34 | self.assertEqual( |
| 35 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 36 | 1, |
| 37 | "mcp-checker has unexpected exit code: {}".format( |
| 38 | ep.exception.code |
| 39 | ) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | def test_entry_packages(self): |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 43 | _module_name = 'cfg_checker.cli.packages' |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 44 | with self.redirect_output(): |
| 45 | _msg, _m = self._safe_import_module(_module_name) |
| 46 | |
| 47 | self.assertEqual( |
| 48 | len(_msg), |
| 49 | 0, |
| 50 | "Error importing '{}': {}".format( |
| 51 | _module_name, |
| 52 | _msg |
| 53 | ) |
| 54 | ) |
| 55 | |
| 56 | with self.redirect_output(): |
| 57 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 58 | _m.cli.packages.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 59 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 60 | self.assertEqual( |
| 61 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 62 | 1, |
| 63 | "packages has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 64 | ) |
| 65 | |
| 66 | def test_entry_network(self): |
| 67 | _module_name = 'cfg_checker.cli.network' |
| 68 | with self.redirect_output(): |
| 69 | _msg, _m = self._safe_import_module(_module_name) |
| 70 | |
| 71 | self.assertEqual( |
| 72 | len(_msg), |
| 73 | 0, |
| 74 | "Error importing '{}': {}".format( |
| 75 | _module_name, |
| 76 | _msg |
| 77 | ) |
| 78 | ) |
| 79 | |
| 80 | with self.redirect_output(): |
| 81 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 82 | _m.cli.network.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 83 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 84 | self.assertEqual( |
| 85 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 86 | 1, |
| 87 | "network has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 88 | ) |
| 89 | |
| 90 | def test_entry_reclass(self): |
| 91 | _module_name = 'cfg_checker.cli.reclass' |
| 92 | with self.redirect_output(): |
| 93 | _msg, _m = self._safe_import_module(_module_name) |
| 94 | |
| 95 | self.assertEqual( |
| 96 | len(_msg), |
| 97 | 0, |
| 98 | "Error importing '{}': {}".format( |
| 99 | _module_name, |
| 100 | _msg |
| 101 | ) |
| 102 | ) |
| 103 | |
| 104 | with self.redirect_output(): |
| 105 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 106 | _m.cli.reclass.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 107 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 108 | self.assertEqual( |
| 109 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 110 | 1, |
| 111 | "reclass has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 112 | ) |