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
This commit is contained in:
@@ -239,7 +239,7 @@ def getfilehash(files):
|
|||||||
return m.hexdigest()
|
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)
|
signal.signal(signal.SIGHUP, reexec_self)
|
||||||
# NOTE(bnemec): We need to exit on SIGPIPEs so systemd can restart us.
|
# NOTE(bnemec): We need to exit on SIGPIPEs so systemd can restart us.
|
||||||
# See lp 1795030
|
# See lp 1795030
|
||||||
@@ -316,7 +316,3 @@ def __main__(args=sys.argv, collector_kwargs_map=None):
|
|||||||
print(json.dumps(content, indent=1))
|
print(json.dumps(content, indent=1))
|
||||||
break
|
break
|
||||||
return exitval
|
return exitval
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(__main__())
|
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ class TestCollect(testtools.TestCase):
|
|||||||
}
|
}
|
||||||
with mock.patch.object(config_drive, 'get_metadata') as gm:
|
with mock.patch.object(config_drive, 'get_metadata') as gm:
|
||||||
gm.return_value = {}
|
gm.return_value = {}
|
||||||
return collect.__main__(args=fake_args,
|
return collect.main(args=fake_args,
|
||||||
collector_kwargs_map=collector_kwargs_map)
|
collector_kwargs_map=collector_kwargs_map)
|
||||||
|
|
||||||
def _fake_popen_call_main(self, occ_args):
|
def _fake_popen_call_main(self, occ_args):
|
||||||
calls = []
|
calls = []
|
||||||
@@ -318,8 +318,8 @@ class TestCollect(testtools.TestCase):
|
|||||||
|
|
||||||
self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep))
|
self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep))
|
||||||
try:
|
try:
|
||||||
collect.__main__(['os-collect-config', 'heat_local', '-i', '10',
|
collect.main(['os-collect-config', 'heat_local', '-i', '10',
|
||||||
'-c', 'true'])
|
'-c', 'true'])
|
||||||
except ExpectedException:
|
except ExpectedException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -328,8 +328,8 @@ class TestCollect(testtools.TestCase):
|
|||||||
raise Exception(cfg.CONF.command)
|
raise Exception(cfg.CONF.command)
|
||||||
|
|
||||||
self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep))
|
self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep))
|
||||||
collect.__main__(['os-collect-config', 'heat_local', '--config-file',
|
collect.main(['os-collect-config', 'heat_local', '--config-file',
|
||||||
'/dev/null', '-i', '10'])
|
'/dev/null', '-i', '10'])
|
||||||
|
|
||||||
def test_main_min_polling_interval(self):
|
def test_main_min_polling_interval(self):
|
||||||
class ExpectedException(Exception):
|
class ExpectedException(Exception):
|
||||||
@@ -340,7 +340,7 @@ class TestCollect(testtools.TestCase):
|
|||||||
raise ExpectedException
|
raise ExpectedException
|
||||||
|
|
||||||
self.useFixture(fixtures.MonkeyPatch('time.sleep', fake_sleep))
|
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',
|
['os-collect-config', 'heat_local', '-i', '10',
|
||||||
'--min-polling-interval', '20', '-c', 'true'])
|
'--min-polling-interval', '20', '-c', 'true'])
|
||||||
|
|
||||||
@@ -348,9 +348,9 @@ class TestCollect(testtools.TestCase):
|
|||||||
@mock.patch('random.randrange')
|
@mock.patch('random.randrange')
|
||||||
def test_main_with_splay(self, randrange_mock, sleep_mock):
|
def test_main_with_splay(self, randrange_mock, sleep_mock):
|
||||||
randrange_mock.return_value = 4
|
randrange_mock.return_value = 4
|
||||||
collect.__main__(args=['os-collect-config', 'heat_local', '-i', '10',
|
collect.main(args=['os-collect-config', 'heat_local', '-i', '10',
|
||||||
'--min-polling-interval', '20', '-c', 'true',
|
'--min-polling-interval', '20', '-c', 'true',
|
||||||
'--print', '--splay', '29'])
|
'--print', '--splay', '29'])
|
||||||
randrange_mock.assert_called_with(0, 29)
|
randrange_mock.assert_called_with(0, 29)
|
||||||
sleep_mock.assert_called_with(4)
|
sleep_mock.assert_called_with(4)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user