diff options
Diffstat (limited to 'tests/unit/benchmark/contexts')
-rw-r--r-- | tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml | 8 | ||||
-rw-r--r-- | tests/unit/benchmark/contexts/nodes_sample.yaml | 8 | ||||
-rw-r--r-- | tests/unit/benchmark/contexts/test_heat.py | 9 | ||||
-rw-r--r-- | tests/unit/benchmark/contexts/test_model.py | 10 | ||||
-rw-r--r-- | tests/unit/benchmark/contexts/test_node.py | 96 |
5 files changed, 130 insertions, 1 deletions
diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml index cdb5138c2..dbdd3700d 100644 --- a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml +++ b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## nodes: - name: node1 diff --git a/tests/unit/benchmark/contexts/nodes_sample.yaml b/tests/unit/benchmark/contexts/nodes_sample.yaml index 59b5bb9fe..8d50c3aea 100644 --- a/tests/unit/benchmark/contexts/nodes_sample.yaml +++ b/tests/unit/benchmark/contexts/nodes_sample.yaml @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## nodes: - name: node1 diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index f8f349205..8f4852ca8 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -39,6 +39,7 @@ class HeatContextTestCase(unittest.TestCase): self.assertEqual(self.test_context.networks, []) self.assertEqual(self.test_context.servers, []) self.assertEqual(self.test_context.placement_groups, []) + self.assertEqual(self.test_context.server_groups, []) self.assertIsNone(self.test_context.keypair_name) self.assertIsNone(self.test_context.secgroup_name) self.assertEqual(self.test_context._server_map, {}) @@ -51,15 +52,18 @@ class HeatContextTestCase(unittest.TestCase): self.assertIsNotNone(self.test_context.key_filename) @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup') + @mock.patch('yardstick.benchmark.contexts.heat.ServerGroup') @mock.patch('yardstick.benchmark.contexts.heat.Network') @mock.patch('yardstick.benchmark.contexts.heat.Server') - def test_init(self, mock_server, mock_network, mock_pg): + def test_init(self, mock_server, mock_network, mock_sg, mock_pg): pgs = {'pgrp1': {'policy': 'availability'}} + sgs = {'servergroup1': {'policy': 'affinity'}} networks = {'bar': {'cidr': '10.0.1.0/24'}} servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}} attrs = {'name': 'foo', 'placement_groups': pgs, + 'server_groups': sgs, 'networks': networks, 'servers': servers} @@ -71,7 +75,10 @@ class HeatContextTestCase(unittest.TestCase): mock_pg.assert_called_with('pgrp1', self.test_context, pgs['pgrp1']['policy']) + mock_sg.assert_called_with('servergroup1', self.test_context, + sgs['servergroup1']['policy']) self.assertTrue(len(self.test_context.placement_groups) == 1) + self.assertTrue(len(self.test_context.server_groups) == 1) mock_network.assert_called_with( 'bar', self.test_context, networks['bar']) diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py index 537a8c008..a4b7d81ef 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -180,6 +180,7 @@ class ServerTestCase(unittest.TestCase): self.assertEqual(test_server.keypair_name, 'some-keys') self.assertEqual(test_server.secgroup_name, 'some-secgroup') self.assertEqual(test_server.placement_groups, []) + self.assertIsNone(test_server.server_group) self.assertEqual(test_server.instances, 1) self.assertIsNone(test_server.floating_ip) self.assertIsNone(test_server._image) @@ -195,6 +196,15 @@ class ServerTestCase(unittest.TestCase): self.assertRaises(ValueError, model.Server, 'foo', self.mock_context, attrs) + @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup') + def test_construct_get_wrong_server_group(self, mock_sg): + + attrs = {'server_group': 'baz'} + mock_sg.get.return_value = None + + self.assertRaises(ValueError, model.Server, 'foo', + self.mock_context, attrs) + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance(self, mock_template): diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py index 64fe4a566..53a8ffa93 100644 --- a/tests/unit/benchmark/contexts/test_node.py +++ b/tests/unit/benchmark/contexts/test_node.py @@ -14,6 +14,7 @@ from __future__ import absolute_import import os import unittest +import mock from yardstick.benchmark.contexts import node @@ -123,3 +124,98 @@ class NodeContextTestCase(unittest.TestCase): curr_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(curr_path, filename) return file_path + + prefix = 'yardstick.benchmark.contexts.node' + + @mock.patch('{}.NodeContext._execute_script'.format(prefix)) + def test_deploy(self, execute_script_mock): + obj = node.NodeContext() + obj.env = { + 'setup': [ + {'node5': {}} + ] + } + obj.deploy() + self.assertTrue(execute_script_mock.called) + + @mock.patch('{}.NodeContext._execute_script'.format(prefix)) + def test_undeploy(self, execute_script_mock): + obj = node.NodeContext() + obj.env = { + 'teardown': [ + {'node5': {}} + ] + } + obj.undeploy() + self.assertTrue(execute_script_mock.called) + + @mock.patch('{}.ssh.SSH._put_file_shell'.format(prefix)) + @mock.patch('{}.ssh.SSH.execute'.format(prefix)) + def test_execute_remote_script(self, execute_mock, put_file_mock): + obj = node.NodeContext() + obj.env = {'prefix': 'yardstick.benchmark.scenarios.compute'} + node_name_args = 'node5' + obj.nodes = [{ + 'name': node_name_args, + 'user': 'ubuntu', + 'ip': '10.10.10.10', + 'pwd': 'ubuntu', + }] + + info = {'script': 'computecapacity.bash'} + execute_mock.return_value = (0, '', '') + obj._execute_remote_script('node5', info) + + self.assertTrue(put_file_mock.called) + self.assertTrue(execute_mock.called) + + @mock.patch('{}.NodeContext._execute_local_script'.format(prefix)) + def test_execute_script_local(self, local_execute_mock): + node_name = 'local' + info = {} + node.NodeContext()._execute_script(node_name, info) + self.assertTrue(local_execute_mock.called) + + @mock.patch('{}.NodeContext._execute_remote_script'.format(prefix)) + def test_execute_script_remote(self, remote_execute_mock): + node_name = 'node5' + info = {} + node.NodeContext()._execute_script(node_name, info) + self.assertTrue(remote_execute_mock.called) + + def test_get_script(self): + script_args = 'hello.bash' + info_args = { + 'script': script_args + } + script, options = node.NodeContext()._get_script(info_args) + self.assertEqual(script_args, script) + self.assertEqual('', options) + + def test_node_info(self): + node_name_args = 'node5' + obj = node.NodeContext() + obj.nodes = [{'name': node_name_args, 'check': node_name_args}] + node_info = obj._get_node_info(node_name_args) + self.assertEqual(node_info.get('check'), node_name_args) + + @mock.patch('{}.ssh.SSH.wait'.format(prefix)) + def test_get_client(self, wait_mock): + node_name_args = 'node5' + obj = node.NodeContext() + obj.nodes = [{ + 'name': node_name_args, + 'user': 'ubuntu', + 'ip': '10.10.10.10', + 'pwd': 'ubuntu', + }] + obj._get_client(node_name_args) + self.assertTrue(wait_mock.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() |