diff options
author | Emma Foley <emma.l.foley@intel.com> | 2018-02-19 16:06:50 +0000 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-03-02 19:08:37 +0000 |
commit | 24a8c6d89f150666a37a3f8daba0fce7c17a436a (patch) | |
tree | 888e25fc09d65bda2bdfacbf8c24f4c19143f9ef | |
parent | a74ad5a1ec1a73389c5983440b2031b0bc72cea1 (diff) |
Add yardstick.benchmark.contexts.heat.HeatContext._delete_key_file()
* Move logic for removing key file into its own method
* Update the log message to be more useful
JIRA: YARDSTICK-1026
Change-Id: I8c131720ed91c939698c41ad63d586396fcce1fe
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
-rw-r--r-- | yardstick/benchmark/contexts/heat.py | 16 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/contexts/test_heat.py | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 75e26e06f..77ac24899 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -29,6 +29,7 @@ from yardstick.common.openstack_utils import get_neutron_client from yardstick.orchestrator.heat import HeatStack from yardstick.orchestrator.heat import HeatTemplate from yardstick.common import constants as consts +from yardstick.common import utils from yardstick.common.utils import source_env from yardstick.ssh import SSH @@ -402,6 +403,14 @@ class HeatContext(Context): "local_ip": private_ip, } + def _delete_key_file(self): + try: + utils.remove_file(self.key_filename) + utils.remove_file(self.key_filename + ".pub") + except OSError: + LOG.exception("There was an error removing the key file %s", + self.key_filename) + def undeploy(self): """undeploys stack from cloud""" if self._flags.no_teardown: @@ -414,12 +423,7 @@ class HeatContext(Context): self.stack = None LOG.info("Undeploying context '%s' DONE", self.name) - if os.path.exists(self.key_filename): - try: - os.remove(self.key_filename) - os.remove(self.key_filename + ".pub") - except OSError: - LOG.exception("Key filename %s", self.key_filename) + self._delete_key_file() super(HeatContext, self).undeploy() diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py index c449b2a28..f66133b2c 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_heat.py +++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py @@ -355,8 +355,9 @@ class HeatContextTestCase(unittest.TestCase): self.assertDictEqual(server.interfaces['port_a'], expected) @mock.patch('yardstick.benchmark.contexts.heat.os') + @mock.patch.object(heat.HeatContext, '_delete_key_file') @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_undeploy(self, mock_template, *args): + def test_undeploy(self, mock_template, mock_delete_key, *args): self.test_context.stack = mock_template self.test_context._name = 'foo' self.test_context._task_id = '1234567890' @@ -365,6 +366,7 @@ class HeatContextTestCase(unittest.TestCase): # mock_os.path.exists.return_value = True self.test_context.key_filename = 'foo/bar/foobar' self.test_context.undeploy() + mock_delete_key.assert_called() self.assertTrue(mock_template.delete.called) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') |