Add a --force option

This is a useful debugging and/or system fixer tool for instances where
metadata has not changed but one needs to re-run the configuration.

Fixes bug #1223693

Change-Id: I62b097bafa339fefcf6e03d11636f5ab622fb71a
This commit is contained in:
Clint Byrum 2013-09-12 15:00:52 -07:00
parent 6eb8eb9af3
commit c1e60159f5
2 changed files with 34 additions and 8 deletions

View File

@ -58,6 +58,10 @@ opts = [
cfg.BoolOpt('print-cachedir',
default=False,
help='Print out the value of cachedir and exit immediately.'),
cfg.BoolOpt('force',
default=False,
help='Pass this to force running the command even if nothing'
' has changed.'),
]
CONF = cfg.CONF
@ -184,7 +188,7 @@ def __main__(args=sys.argv, requests_impl_map=None):
store=bool(CONF.command),
requests_impl_map=requests_impl_map)
if CONF.command:
if any_changed:
if any_changed or cfg.CONF.force:
# ignore HUP now since we will reexec after commit anyway
signal.signal(signal.SIGHUP, signal.SIG_IGN)
try:

View File

@ -56,6 +56,16 @@ class TestCollect(testtools.TestCase):
'cfn': test_cfn.FakeRequests(self)}
collect.__main__(args=fake_args, requests_impl_map=requests_impl_map)
def _fake_popen_call_main(self, occ_args):
calls = []
def capture_popen(proc_args):
calls.append(proc_args)
return dict(returncode=0)
self.useFixture(fixtures.FakePopen(capture_popen))
self._call_main(occ_args)
return calls
def test_main(self):
expected_cmd = self.getUniqueString()
cache_dir = self.useFixture(fixtures.TempDir())
@ -81,13 +91,7 @@ class TestCollect(testtools.TestCase):
'--heat_local-path',
fake_metadata,
]
calls = []
def capture_popen(proc_args):
calls.append(proc_args)
return dict(returncode=0)
self.useFixture(fixtures.FakePopen(capture_popen))
self._call_main(occ_args)
calls = self._fake_popen_call_main(occ_args)
proc_args = calls[0]
self.assertEqual(expected_cmd, proc_args['args'])
list_path = os.path.join(cache_dir.path, 'os_config_files.json')
@ -109,6 +113,24 @@ class TestCollect(testtools.TestCase):
self.assertIn("int1", keys_found)
self.assertIn("map_ab", keys_found)
def test_main_force_command(self):
cache_dir = self.useFixture(fixtures.TempDir())
fake_metadata = _setup_local_metadata(self)
occ_args = [
'os-collect-config',
'--command', 'foo',
'--cachedir', cache_dir.path,
'--config-file', '/dev/null',
'--heat_local-path', fake_metadata,
'--force',
]
calls = self._fake_popen_call_main(occ_args)
self.assertIn('OS_CONFIG_FILES', calls[0]['env'])
cfg.CONF.reset()
# First time caches data, run again, make sure we run command again
calls = self._fake_popen_call_main(occ_args)
self.assertIn('OS_CONFIG_FILES', calls[0]['env'])
def test_main_command_failed_no_caching(self):
cache_dir = self.useFixture(fixtures.TempDir())
fake_metadata = _setup_local_metadata(self)