summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/benchmark/contexts/heat.py16
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py4
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')