blob: b09bab6422b846dd2275cc6307acee9558fe5c1b [file] [log] [blame]
Alex0989ecf2022-03-29 13:43:21 -05001# Author: Alex Savatieiev (osavatieiev@mirantis.com; a.savex@gmail.com)
2# Copyright 2019-2022 Mirantis, Inc.
Alex9a4ad212020-10-01 18:04:25 -05003import os
4
Alex3bc95f62020-03-05 17:00:04 -06005from tests.test_base import CfgCheckerTestBase
Alex265f45e2019-04-23 18:51:23 -05006
7
8class TestEntrypoints(CfgCheckerTestBase):
Alex9a4ad212020-10-01 18:04:25 -05009 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
Alex265f45e2019-04-23 18:51:23 -050016 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()
Alexcf91b182019-05-31 11:57:07 -050033 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050034 self.assertEqual(
35 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050036 1,
37 "mcp-checker has unexpected exit code: {}".format(
38 ep.exception.code
39 )
Alex265f45e2019-04-23 18:51:23 -050040 )
41
42 def test_entry_packages(self):
Alexbab1efe2019-04-23 18:51:23 -050043 _module_name = 'cfg_checker.cli.packages'
Alex265f45e2019-04-23 18:51:23 -050044 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:
Alexbab1efe2019-04-23 18:51:23 -050058 _m.cli.packages.entrypoint()
Alexcf91b182019-05-31 11:57:07 -050059 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050060 self.assertEqual(
61 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050062 1,
63 "packages has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -050064 )
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:
Alexbab1efe2019-04-23 18:51:23 -050082 _m.cli.network.entrypoint()
Alexcf91b182019-05-31 11:57:07 -050083 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050084 self.assertEqual(
85 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050086 1,
87 "network has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -050088 )
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:
Alexbab1efe2019-04-23 18:51:23 -0500106 _m.cli.reclass.entrypoint()
Alexcf91b182019-05-31 11:57:07 -0500107 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -0500108 self.assertEqual(
109 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -0500110 1,
111 "reclass has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -0500112 )