X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Ftests%2Funit%2Fbenchmark%2Fcontexts%2Ftest_node.py;h=b67be375848e15d351842429c4ba3783f59ee778;hb=1160225135e429ba8581ad162b08d710db4e96a2;hp=9761f6d538c64bcfd091bcd2816d6914b533fce2;hpb=8b2b6806d73e3b4e377cb8afe5ff98152567438f;p=yardstick.git diff --git a/yardstick/tests/unit/benchmark/contexts/test_node.py b/yardstick/tests/unit/benchmark/contexts/test_node.py index 9761f6d53..b67be3758 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_node.py +++ b/yardstick/tests/unit/benchmark/contexts/test_node.py @@ -13,6 +13,7 @@ import errno import mock from yardstick.common import constants as consts +from yardstick.benchmark.contexts import base from yardstick.benchmark.contexts import node @@ -33,9 +34,11 @@ class NodeContextTestCase(unittest.TestCase): 'file': self._get_file_abspath(self.NODES_SAMPLE) } - def _remove_contexts(self): - if self.test_context in self.test_context.list: - self.test_context._delete_context() + @staticmethod + def _remove_contexts(): + for context in base.Context.list: + context._delete_context() + base.Context.list = [] def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -176,7 +179,7 @@ class NodeContextTestCase(unittest.TestCase): 'type': 'script' } obj.deploy() - self.assertTrue(dispatch_script_mock.called) + dispatch_script_mock.assert_called_once() @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX)) def test_deploy_anisible(self, dispatch_ansible_mock): @@ -186,7 +189,7 @@ class NodeContextTestCase(unittest.TestCase): 'type': 'ansible' } obj.deploy() - self.assertTrue(dispatch_ansible_mock.called) + dispatch_ansible_mock.assert_called_once() @mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX)) def test_undeploy(self, dispatch_script_mock): @@ -195,7 +198,7 @@ class NodeContextTestCase(unittest.TestCase): 'type': 'script' } obj.undeploy() - self.assertTrue(dispatch_script_mock.called) + dispatch_script_mock.assert_called_once() @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX)) def test_undeploy_anisble(self, dispatch_ansible_mock): @@ -204,7 +207,7 @@ class NodeContextTestCase(unittest.TestCase): 'type': 'ansible' } obj.undeploy() - self.assertTrue(dispatch_ansible_mock.called) + dispatch_ansible_mock.assert_called_once() @mock.patch('{}.ssh.SSH._put_file_shell'.format(PREFIX)) @mock.patch('{}.ssh.SSH.execute'.format(PREFIX)) @@ -224,8 +227,8 @@ class NodeContextTestCase(unittest.TestCase): execute_mock.return_value = (0, '', '') obj._execute_remote_script('node5', info) - self.assertTrue(put_file_mock.called) - self.assertTrue(execute_mock.called) + put_file_mock.assert_called_once() + execute_mock.assert_called() @mock.patch('{}.NodeContext._execute_local_script'.format(PREFIX)) def test_execute_script_local(self, local_execute_mock): @@ -234,7 +237,7 @@ class NodeContextTestCase(unittest.TestCase): obj = node.NodeContext() self.addCleanup(obj._delete_context) obj._execute_script(node_name, info) - self.assertTrue(local_execute_mock.called) + local_execute_mock.assert_called_once() @mock.patch('{}.NodeContext._execute_remote_script'.format(PREFIX)) def test_execute_script_remote(self, remote_execute_mock): @@ -243,7 +246,7 @@ class NodeContextTestCase(unittest.TestCase): obj = node.NodeContext() self.addCleanup(obj._delete_context) obj._execute_script(node_name, info) - self.assertTrue(remote_execute_mock.called) + remote_execute_mock.assert_called_once() def test_get_script(self): script_args = 'hello.bash' @@ -276,7 +279,7 @@ class NodeContextTestCase(unittest.TestCase): 'pwd': 'ubuntu', }] obj._get_client(node_name_args) - self.assertTrue(wait_mock.called) + wait_mock.assert_called_once() def test_get_server(self): self.test_context.init(self.attrs)