From 249b795c8cd2c1fea8cf0cb1cc8fafe75680d179 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 29 Jan 2024 23:40:45 +0900 Subject: [PATCH] Drop direct execution of collect.py Now we generate the console script using setuptools, and we don't expect users may directly execute the *.py file. Change-Id: Ida036f138d8e7ef64ea0f8f7c83deeeb71dc4f5b --- os_collect_config/collect.py | 6 +----- os_collect_config/tests/test_collect.py | 20 ++++++++++---------- setup.cfg | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/os_collect_config/collect.py b/os_collect_config/collect.py index 8fec7ad..222e34c 100644 --- a/os_collect_config/collect.py +++ b/os_collect_config/collect.py @@ -239,7 +239,7 @@ def getfilehash(files): return m.hexdigest() -def __main__(args=sys.argv, collector_kwargs_map=None): +def main(args=sys.argv, collector_kwargs_map=None): signal.signal(signal.SIGHUP, reexec_self) # NOTE(bnemec): We need to exit on SIGPIPEs so systemd can restart us. # See lp 1795030 @@ -316,7 +316,3 @@ def __main__(args=sys.argv, collector_kwargs_map=None): print(json.dumps(content, indent=1)) break return exitval - - -if __name__ == '__main__': - sys.exit(__main__()) diff --git a/os_collect_config/tests/test_collect.py b/os_collect_config/tests/test_collect.py index 9c87ec8..3120984 100644 --- a/os_collect_config/tests/test_collect.py +++ b/os_collect_config/tests/test_collect.py @@ -86,8 +86,8 @@ class TestCollect(testtools.TestCase): } with mock.patch.object(config_drive, 'get_metadata') as gm: gm.return_value = {} - return collect.__main__(args=fake_args, - collector_kwargs_map=collector_kwargs_map) + return collect.main(args=fake_args, + collector_kwargs_map=collector_kwargs_map) def _fake_popen_call_main(self, occ_args): calls = [] @@ -318,8 +318,8 @@ class TestCollect(testtools.TestCase): self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep)) try: - collect.__main__(['os-collect-config', 'heat_local', '-i', '10', - '-c', 'true']) + collect.main(['os-collect-config', 'heat_local', '-i', '10', + '-c', 'true']) except ExpectedException: pass @@ -328,8 +328,8 @@ class TestCollect(testtools.TestCase): raise Exception(cfg.CONF.command) self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep)) - collect.__main__(['os-collect-config', 'heat_local', '--config-file', - '/dev/null', '-i', '10']) + collect.main(['os-collect-config', 'heat_local', '--config-file', + '/dev/null', '-i', '10']) def test_main_min_polling_interval(self): class ExpectedException(Exception): @@ -340,7 +340,7 @@ class TestCollect(testtools.TestCase): raise ExpectedException self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep)) - self.assertRaises(ExpectedException, collect.__main__, + self.assertRaises(ExpectedException, collect.main, ['os-collect-config', 'heat_local', '-i', '10', '--min-polling-interval', '20', '-c', 'true']) @@ -348,9 +348,9 @@ class TestCollect(testtools.TestCase): @mock.patch('random.randrange') def test_main_with_splay(self, randrange_mock, sleep_mock): randrange_mock.return_value = 4 - collect.__main__(args=['os-collect-config', 'heat_local', '-i', '10', - '--min-polling-interval', '20', '-c', 'true', - '--print', '--splay', '29']) + collect.main(args=['os-collect-config', 'heat_local', '-i', '10', + '--min-polling-interval', '20', '-c', 'true', + '--print', '--splay', '29']) randrange_mock.assert_called_with(0, 29) sleep_mock.assert_called_with(4) diff --git a/setup.cfg b/setup.cfg index 798f42b..2b5d025 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,4 +29,4 @@ packages = [entry_points] console_scripts = - os-collect-config = os_collect_config.collect:__main__ + os-collect-config = os_collect_config.collect:main