diff options
Diffstat (limited to 'tests/unit/benchmark/contexts')
12 files changed, 114 insertions, 73 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/__init__.py b/tests/unit/benchmark/contexts/standalone/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/unit/benchmark/contexts/standalone/__init__.py diff --git a/tests/unit/benchmark/contexts/ovs_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml index b1da1ea9f..b1da1ea9f 100644 --- a/tests/unit/benchmark/contexts/ovs_sample_password.yaml +++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml diff --git a/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml index 896ec33bb..896ec33bb 100644 --- a/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml +++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml diff --git a/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt index f0eec86f6..f0eec86f6 100644 --- a/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt +++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt diff --git a/tests/unit/benchmark/contexts/sriov_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml index 4f60e46d5..4f60e46d5 100644 --- a/tests/unit/benchmark/contexts/sriov_sample_password.yaml +++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml diff --git a/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml index faa496771..faa496771 100644 --- a/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml +++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml diff --git a/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt index f0eec86f6..f0eec86f6 100644 --- a/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt +++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt diff --git a/tests/unit/benchmark/contexts/test_ovsdpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py index ac25ec877..1d68384c9 100644 --- a/tests/unit/benchmark/contexts/test_ovsdpdk.py +++ b/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py @@ -13,11 +13,13 @@ # limitations under the License. from __future__ import absolute_import + import os -import mock import unittest -from yardstick.benchmark.contexts import ovsdpdk +import mock + +from yardstick.benchmark.contexts.standalone import ovsdpdk NIC_INPUT = { 'interface': {}, @@ -226,11 +228,11 @@ class OvsdpdkTestCase(unittest.TestCase): mock_ovs = mock.Mock() ssh_mock.put = mock.Mock() ovs_obj.check_output = mock.Mock(return_value=(0, "vm1")) - with mock.patch("yardstick.benchmark.contexts.ovsdpdk.time"): + with mock.patch("yardstick.benchmark.contexts.standalone.ovsdpdk.time"): self.assertIsNone(ovs_obj.setup_ovs_context(PCIS, NIC_DETAILS, DRIVER)) @mock.patch( - 'yardstick.benchmark.contexts.ovsdpdk', + 'yardstick.benchmark.contexts.standalone.ovsdpdk', return_value="Domain vm1 created from /tmp/vm_ovs.xml") def test_is_vm_created(self, NIC_INPUT): with mock.patch("yardstick.ssh.SSH") as ssh: diff --git a/tests/unit/benchmark/contexts/test_sriov.py b/tests/unit/benchmark/contexts/standalone/test_sriov.py index a8641a2eb..ea72e1bab 100644 --- a/tests/unit/benchmark/contexts/test_sriov.py +++ b/tests/unit/benchmark/contexts/standalone/test_sriov.py @@ -13,11 +13,13 @@ # limitations under the License. from __future__ import absolute_import + import os -import mock import unittest -from yardstick.benchmark.contexts import sriov +import mock + +from yardstick.benchmark.contexts.standalone import sriov NIC_INPUT = { 'interface': {}, @@ -185,7 +187,7 @@ class SriovTestCase(unittest.TestCase): nic_details['vf_pci'][i] = sriov_obj.get_vf_datas.return_value vf_pci = [[], []] vf_pci[i] = sriov_obj.get_vf_datas.return_value - with mock.patch("yardstick.benchmark.contexts.sriov.time"): + with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"): self.assertIsNotNone(sriov_obj.configure_nics_for_sriov(DRIVER, NIC_DETAILS)) def test_setup_sriov_context(self): @@ -224,7 +226,7 @@ class SriovTestCase(unittest.TestCase): mock.Mock(return_value=(0, {}, "")) ssh_mock.put = mock.Mock() sriov_obj.check_output = mock.Mock(return_value=(1, {})) - with mock.patch("yardstick.benchmark.contexts.sriov.time"): + with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"): self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER)) def test_setup_sriov_context_vm_already_present(self): @@ -263,11 +265,11 @@ class SriovTestCase(unittest.TestCase): mock.Mock(return_value=(0, {}, "")) ssh_mock.put = mock.Mock() sriov_obj.check_output = mock.Mock(return_value=(0, "vm1")) - with mock.patch("yardstick.benchmark.contexts.sriov.time"): + with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"): self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER)) @mock.patch( - 'yardstick.benchmark.contexts.sriov', + 'yardstick.benchmark.contexts.standalone.sriov', return_value="Domain vm1 created from /tmp/vm_sriov.xml") def test_is_vm_created(self, NIC_INPUT): with mock.patch("yardstick.ssh.SSH") as ssh: diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index 658a8e580..2e546805d 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -13,7 +13,6 @@ from __future__ import absolute_import -import ipaddress import logging import os import unittest @@ -147,30 +146,6 @@ class HeatContextTestCase(unittest.TestCase): self.test_context.user = 'foo' @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - @mock.patch('yardstick.benchmark.contexts.heat.get_neutron_client') - def test_attrs_get(self, mock_neutron, mock_template): - image, flavor, user = expected_tuple = 'foo1', 'foo2', 'foo3' - self.assertNotEqual(self.test_context.image, image) - self.assertNotEqual(self.test_context.flavor, flavor) - self.assertNotEqual(self.test_context.user, user) - self.test_context._image = image - self.test_context._flavor = flavor - self.test_context._user = user - attr_tuple = self.test_context.image, self.test_context.flavor, self.test_context.user - self.assertEqual(attr_tuple, expected_tuple) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_attrs_set_negative(self, mock_template): - with self.assertRaises(AttributeError): - self.test_context.image = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.flavor = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.user = 'foo' - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_deploy(self, mock_template): self.test_context.name = 'foo' self.test_context.template_file = '/bar/baz/some-heat-file' @@ -185,9 +160,7 @@ class HeatContextTestCase(unittest.TestCase): def test_add_server_port(self): network1 = mock.MagicMock() - network1.vld_id = 'vld111' network2 = mock.MagicMock() - network2.vld_id = 'vld777' self.test_context.name = 'foo' self.test_context.stack = mock.MagicMock() self.test_context.networks = { @@ -209,11 +182,17 @@ class HeatContextTestCase(unittest.TestCase): u'd-mac_address': u'00:10', u'd-device_id': u'dev43', u'd-network_id': u'net987', + u'e': u'40.30.20.15', + u'e-subnet_id': 2, + u'e-mac_address': u'00:10', + u'e-device_id': u'dev43', + u'e-network_id': u'net987', } server = mock.MagicMock() server.ports = OrderedDict([ - ('a', {'stack_name': 'b'}), - ('c', {'stack_name': 'd'}), + ('a', [{'stack_name': 'b', 'port': 'port_a'}]), + ('c', [{'stack_name': 'd', 'port': 'port_c'}, + {'stack_name': 'e', 'port': 'port_f'}]), ]) expected = { @@ -229,12 +208,11 @@ class HeatContextTestCase(unittest.TestCase): "network_name": 'a', "local_mac": '00:01', "local_ip": '10.20.30.45', - "vld_id": 'vld111', } self.test_context.add_server_port(server) self.assertEqual(server.private_ip, '10.20.30.45') - self.assertEqual(len(server.interfaces), 2) - self.assertDictEqual(server.interfaces['a'], expected) + self.assertEqual(len(server.interfaces), 3) + self.assertDictEqual(server.interfaces['port_a'], expected) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_undeploy(self, mock_template): @@ -249,19 +227,20 @@ class HeatContextTestCase(unittest.TestCase): mock_os.path.exists.return_value = True self.assertIsNone(self.test_context.undeploy()) - def test__get_server_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. """ foo2_server = mock.Mock() - foo2_server.key_filename = 'key_file' + foo2_server.key_filename = None foo2_server.private_ip = '10.0.0.2' foo2_server.public_ip = '127.0.0.2' foo2_server.context.user = 'oof' baz3_server = mock.Mock() - baz3_server.key_filename = 'key_filename' + baz3_server.key_filename = None baz3_server.private_ip = '10.0.0.3' baz3_server.public_ip = '127.0.0.3' baz3_server.context.user = 'zab' @@ -286,11 +265,11 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['ip'], '127.0.0.1') self.assertEqual(result['private_ip'], '10.0.0.1') - def test__get_server_found_dict_no_attrs(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict_no_attrs(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. @@ -323,13 +302,13 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) # no private ip attr mapping in the map results in None value in the result self.assertIsNone(result['private_ip']) # no public ip attr mapping in the map results in no value in the result self.assertNotIn('ip', result) - def test__get_server_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a non-dictionary input @@ -361,12 +340,12 @@ class HeatContextTestCase(unittest.TestCase): attr_name = 'baz3' result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'zab') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['private_ip'], '10.0.0.3') # no public_ip on the server results in no value in the result self.assertNotIn('public_ip', result) - def test__get_server_none_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_none_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server due to None value associated with the match to a non-dictionary @@ -399,7 +378,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a dictionary input @@ -434,7 +414,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a non-dictionary input @@ -475,7 +456,6 @@ class HeatContextTestCase(unittest.TestCase): network2 = mock.MagicMock() network2.name = 'net_2' - network2.vld_id = 'vld999' network2.segmentation_id = 'seg45' network2.network_type = 'type_b' network2.physical_network = 'virt' @@ -491,16 +471,15 @@ class HeatContextTestCase(unittest.TestCase): attr_name = {} self.assertIsNone(self.test_context._get_network(attr_name)) - attr_name = {'vld_id': 'vld777'} + attr_name = {'network_type': 'nosuch'} self.assertIsNone(self.test_context._get_network(attr_name)) attr_name = 'vld777' self.assertIsNone(self.test_context._get_network(attr_name)) - attr_name = {'vld_id': 'vld999'} + attr_name = {'segmentation_id': 'seg45'} expected = { "name": 'net_2', - "vld_id": 'vld999', "segmentation_id": 'seg45', "network_type": 'type_b', "physical_network": 'virt', @@ -511,7 +490,6 @@ class HeatContextTestCase(unittest.TestCase): attr_name = 'a' expected = { "name": 'net_1', - "vld_id": 'vld111', "segmentation_id": 'seg54', "network_type": 'type_a', "physical_network": 'phys', diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py index b0ee792db..3a926f85c 100644 --- a/tests/unit/benchmark/contexts/test_kubernetes.py +++ b/tests/unit/benchmark/contexts/test_kubernetes.py @@ -47,13 +47,15 @@ class KubernetesTestCase(unittest.TestCase): # clear kubernetes contexts from global list so we don't break other tests Context.list = [] + @mock.patch('{}.KubernetesContext._delete_services'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_ssh_key'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_rcs'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_pods'.format(prefix)) def test_undeploy(self, mock_delete_pods, mock_delete_rcs, - mock_delete_ssh): + mock_delete_ssh, + mock_delete_services): k8s_context = KubernetesContext() k8s_context.init(context_cfg) @@ -61,7 +63,9 @@ class KubernetesTestCase(unittest.TestCase): self.assertTrue(mock_delete_ssh.called) self.assertTrue(mock_delete_rcs.called) self.assertTrue(mock_delete_pods.called) + self.assertTrue(mock_delete_services.called) + @mock.patch('{}.KubernetesContext._create_services'.format(prefix)) @mock.patch('{}.KubernetesContext._wait_until_running'.format(prefix)) @mock.patch('{}.KubernetesTemplate.get_rc_pods'.format(prefix)) @mock.patch('{}.KubernetesContext._create_rcs'.format(prefix)) @@ -70,7 +74,8 @@ class KubernetesTestCase(unittest.TestCase): mock_set_ssh_key, mock_create_rcs, mock_get_rc_pods, - mock_wait_until_running): + mock_wait_until_running, + mock_create_services): k8s_context = KubernetesContext() k8s_context.init(context_cfg) @@ -78,12 +83,18 @@ class KubernetesTestCase(unittest.TestCase): k8s_context.deploy() self.assertTrue(mock_set_ssh_key.called) self.assertTrue(mock_create_rcs.called) + self.assertTrue(mock_create_services.called) self.assertTrue(mock_get_rc_pods.called) self.assertTrue(mock_wait_until_running.called) + @mock.patch('{}.paramiko'.format(prefix), **{"resource_filename.return_value": ""}) + @mock.patch('{}.pkg_resources'.format(prefix), **{"resource_filename.return_value": ""}) + @mock.patch('{}.utils'.format(prefix)) + @mock.patch('{}.open'.format(prefix), create=True) @mock.patch('{}.k8s_utils.delete_config_map'.format(prefix)) @mock.patch('{}.k8s_utils.create_config_map'.format(prefix)) - def test_ssh_key(self, mock_create, mock_delete): + def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils, mock_resources, + mock_paramiko): k8s_context = KubernetesContext() k8s_context.init(context_cfg) @@ -101,14 +112,39 @@ class KubernetesTestCase(unittest.TestCase): mock_read_pod_status.return_value = 'Running' k8s_context._wait_until_running() - @mock.patch('{}.k8s_utils.get_pod_list'.format(prefix)) - def test_get_server(self, mock_get_pod_list): + @mock.patch('{}.k8s_utils.get_pod_by_name'.format(prefix)) + @mock.patch('{}.KubernetesContext._get_node_ip'.format(prefix)) + @mock.patch('{}.k8s_utils.get_service_by_name'.format(prefix)) + def test_get_server(self, + mock_get_service_by_name, + mock_get_node_ip, + mock_get_pod_by_name): + class Service(object): + def __init__(self): + self.name = 'yardstick' + self.node_port = 30000 + + class Services(object): + def __init__(self): + self.ports = [Service()] + + class Status(object): + def __init__(self): + self.pod_ip = '172.16.10.131' + + class Pod(object): + def __init__(self): + self.status = Status() + k8s_context = KubernetesContext() k8s_context.init(context_cfg) - mock_get_pod_list.return_value.items = [] + mock_get_service_by_name.return_value = Services() + mock_get_pod_by_name.return_value = Pod() + mock_get_node_ip.return_value = '172.16.10.131' + server = k8s_context._get_server('server') - self.assertIsNone(server) + self.assertIsNotNone(server) @mock.patch('{}.KubernetesContext._create_rc'.format(prefix)) def test_create_rcs(self, mock_create_rc): @@ -138,6 +174,28 @@ class KubernetesTestCase(unittest.TestCase): k8s_context._delete_rc({}) self.assertTrue(mock_delete_replication_controller.called) + @mock.patch('{}.k8s_utils.get_node_list'.format(prefix)) + def test_get_node_ip(self, mock_get_node_list): + + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._get_node_ip() + self.assertTrue(mock_get_node_list.called) + + @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create') + def test_create_services(self, mock_create): + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._create_services() + self.assertTrue(mock_create.called) + + @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete') + def test_delete_services(self, mock_delete): + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._delete_services() + self.assertTrue(mock_delete.called) + def main(): unittest.main() diff --git a/tests/unit/benchmark/contexts/test_standalone.py b/tests/unit/benchmark/contexts/test_standalone.py index d13e28470..b1402a1c9 100644 --- a/tests/unit/benchmark/contexts/test_standalone.py +++ b/tests/unit/benchmark/contexts/test_standalone.py @@ -18,25 +18,26 @@ # Unittest for yardstick.benchmark.contexts.standalone from __future__ import absolute_import + import os import unittest + import mock from yardstick.benchmark.contexts import standalone -from yardstick.benchmark.contexts import sriov -from yardstick.benchmark.contexts import ovsdpdk +from yardstick.benchmark.contexts.standalone import ovsdpdk, sriov MOCKS = { 'yardstick.benchmark.contexts': mock.MagicMock(), - 'yardstick.benchmark.contexts.sriov': mock.MagicMock(), - 'yardstick.benchmark.contexts.ovsdpdk': mock.MagicMock(), + 'yardstick.benchmark.contexts.standalone.sriov': mock.MagicMock(), + 'yardstick.benchmark.contexts.standalone.ovsdpdk': mock.MagicMock(), 'yardstick.benchmark.contexts.standalone': mock.MagicMock(), } -@mock.patch('yardstick.benchmark.contexts.ovsdpdk.time') +@mock.patch('yardstick.benchmark.contexts.standalone.ovsdpdk.time') @mock.patch('yardstick.benchmark.contexts.standalone.time') -@mock.patch('yardstick.benchmark.contexts.sriov.time') +@mock.patch('yardstick.benchmark.contexts.standalone.sriov.time') class StandaloneContextTestCase(unittest.TestCase): NODES_SAMPLE = "nodes_sample_new.yaml" NODES_SAMPLE_SRIOV = "nodes_sample_new_sriov.yaml" @@ -564,7 +565,7 @@ class StandaloneContextTestCase(unittest.TestCase): self.assertIsNone(self.test_context.undeploy()) def test_get_nfvi_obj_sriov(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): - with mock.patch('yardstick.benchmark.contexts.sriov'): + with mock.patch('yardstick.benchmark.contexts.standalone.sriov'): attrs = { 'name': 'sriov', 'file': self._get_file_abspath(self.NODES_SAMPLE) @@ -589,7 +590,7 @@ class StandaloneContextTestCase(unittest.TestCase): self.assertIsNotNone(self.test_context.get_nfvi_obj()) def test_get_nfvi_obj_ovs(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): - with mock.patch('yardstick.benchmark.contexts.ovsdpdk'): + with mock.patch('yardstick.benchmark.contexts.standalone.ovsdpdk'): attrs = { 'name': 'ovs', 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) |