aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests')
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_model.py5
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py16
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py18
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_base.py84
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_dummy.py8
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py108
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_kubernetes.py24
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_node.py45
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py6
9 files changed, 280 insertions, 34 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
index 5ed199a6c..3137821c3 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
@@ -315,11 +315,6 @@ class StandaloneContextHelperTestCase(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
- def test_read_config_file(self):
- self.helper.file_path = self._get_file_abspath(self.NODE_SAMPLE)
- status = self.helper.read_config_file()
- self.assertIsNotNone(status)
-
def test_parse_pod_file(self):
self.helper.file_path = self._get_file_abspath("dummy")
self.assertRaises(IOError, self.helper.parse_pod_file,
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
index 6eb438cb1..5be22a034 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -290,6 +290,22 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
+ def test__get_physical_node_for_server(self):
+ attrs = self.attrs
+ attrs.update({'servers': {'server1': {}}})
+ self.ovs_dpdk.init(attrs)
+
+ # When server is not from this context
+ result = self.ovs_dpdk._get_physical_node_for_server('server1.another-context')
+ self.assertIsNone(result)
+
+ # When node_name is not from this context
+ result = self.ovs_dpdk._get_physical_node_for_server('fake.foo-12345678')
+ self.assertIsNone(result)
+
+ result = self.ovs_dpdk._get_physical_node_for_server('server1.foo-12345678')
+ self.assertEqual(result, 'node5.foo')
+
# TODO(elfoley): Split this test for networks that exist and networks that
# don't
def test__get_network(self):
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
index de748e285..169084607 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -62,7 +62,7 @@ class SriovContextTestCase(unittest.TestCase):
self.attrs = {
'name': 'foo',
'task_id': '1234567890',
- 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
+ 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE),
}
self.sriov = sriov.SriovContext()
self.addCleanup(self._remove_contexts)
@@ -171,6 +171,22 @@ class SriovContextTestCase(unittest.TestCase):
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
+ def test__get_physical_node_for_server(self):
+ attrs = self.attrs
+ attrs.update({'servers': {'server1': {}}})
+ self.sriov.init(attrs)
+
+ # When server is not from this context
+ result = self.sriov._get_physical_node_for_server('server1.another-context')
+ self.assertIsNone(result)
+
+ # When node_name is not from this context
+ result = self.sriov._get_physical_node_for_server('fake.foo-12345678')
+ self.assertIsNone(result)
+
+ result = self.sriov._get_physical_node_for_server('server1.foo-12345678')
+ self.assertEqual(result, 'node5.foo')
+
def test__get_server_no_task_id(self):
self.attrs['flags'] = {'no_setup': True}
self.sriov.init(self.attrs)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py
index 81267cf98..8f1cbcc55 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_base.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_base.py
@@ -12,11 +12,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+import errno
+
+import mock
+
from yardstick.benchmark.contexts import base
+from yardstick.benchmark.contexts.base import Context
from yardstick.tests.unit import base as ut_base
+from yardstick.common.constants import YARDSTICK_ROOT_PATH
+
+class DummyContextClass(Context):
-class DummyContextClass(base.Context):
+ def __init__(self, host_name_separator='.'):
+ super(DummyContextClass, self).__init__\
+ (host_name_separator=host_name_separator)
+ self.nodes = []
+ self.controllers = []
+ self.computes = []
+ self.baremetals = []
def _get_network(self, *args):
pass
@@ -30,6 +45,12 @@ class DummyContextClass(base.Context):
def undeploy(self):
pass
+ def _get_physical_nodes(self):
+ pass
+
+ def _get_physical_node_for_server(self, server_name):
+ pass
+
class FlagsTestCase(ut_base.BaseUnitTestCase):
@@ -87,3 +108,64 @@ class ContextTestCase(ut_base.BaseUnitTestCase):
config_name = 'host_name-ctx_name'
self.assertEqual(('host_name', 'ctx_name'),
ctx_obj.split_host_name(config_name))
+
+ def test_get_physical_nodes(self):
+ ctx_obj = DummyContextClass()
+ self.addCleanup(self._remove_ctx, ctx_obj)
+
+ result = Context.get_physical_nodes()
+
+ self.assertEqual(result, {None: None})
+
+ @mock.patch.object(Context, 'get_context_from_server')
+ def test_get_physical_node_from_server(self, mock_get_ctx):
+ ctx_obj = DummyContextClass()
+ self.addCleanup(self._remove_ctx, ctx_obj)
+
+ mock_get_ctx.return_value = ctx_obj
+
+ result = Context.get_physical_node_from_server("mock_server")
+
+ mock_get_ctx.assert_called_once()
+ self.assertIsNone(result)
+
+ @mock.patch('yardstick.common.utils.read_yaml_file')
+ def test_read_pod_file(self, mock_read_yaml_file):
+ attrs = {'name': 'foo',
+ 'task_id': '12345678',
+ 'file': 'pod.yaml'
+ }
+
+ ctx_obj = DummyContextClass()
+ cfg = {"nodes": [
+ {
+ "name": "node1",
+ "role": "Controller",
+ "ip": "10.229.47.137",
+ "user": "root",
+ "key_filename": "/root/.yardstick_key"
+ },
+ {
+ "name": "node2",
+ "role": "Compute",
+ "ip": "10.229.47.139",
+ "user": "root",
+ "key_filename": "/root/.yardstick_key"
+ }
+ ]
+ }
+
+ mock_read_yaml_file.return_value = cfg
+ result = ctx_obj.read_pod_file(attrs)
+ self.assertEqual(result, cfg)
+
+ mock_read_yaml_file.side_effect = IOError(errno.EPERM, '')
+ with self.assertRaises(IOError):
+ ctx_obj.read_pod_file(attrs)
+
+ mock_read_yaml_file.side_effect = IOError(errno.ENOENT, '')
+ with self.assertRaises(IOError):
+ ctx_obj.read_pod_file(attrs)
+
+ file_path = os.path.join(YARDSTICK_ROOT_PATH, 'pod.yaml')
+ self.assertEqual(ctx_obj.file_path, file_path)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_dummy.py b/yardstick/tests/unit/benchmark/contexts/test_dummy.py
index c4113be41..33832375f 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_dummy.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_dummy.py
@@ -76,3 +76,11 @@ class DummyContextTestCase(unittest.TestCase):
self.assertEqual(result, None)
self.test_context.undeploy()
+
+ def test__get_physical_nodes(self):
+ result = self.test_context._get_physical_nodes()
+ self.assertIsNone(result)
+
+ def test__get_physical_node_for_server(self):
+ result = self.test_context._get_physical_node_for_server("fake")
+ self.assertIsNone(result)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index bcc35902b..df57ca4b3 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -12,30 +12,53 @@ import logging
import os
import mock
+import unittest
-from yardstick import ssh
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import heat
from yardstick.benchmark.contexts import model
from yardstick.common import constants as consts
from yardstick.common import exceptions as y_exc
-from yardstick.tests.unit import base as ut_base
+from yardstick.common import openstack_utils
+from yardstick import ssh
LOG = logging.getLogger(__name__)
-class HeatContextTestCase(ut_base.BaseUnitTestCase):
+class HeatContextTestCase(unittest.TestCase):
+
+ HEAT_POD_SAMPLE = {
+ "nodes": [
+ {
+ "name": "node1",
+ "role": "Controller",
+ "ip": "10.229.47.137",
+ "user": "root",
+ "key_filename": "/root/.yardstick_key"
+ },
+ {
+ "name": "node2",
+ "role": "Compute",
+ "ip": "10.229.47.139",
+ "user": "root",
+ "key_filename": "/root/.yardstick_key"
+ }
+ ]
+ }
+
+ def __init__(self, *args, **kwargs):
+
+ super(HeatContextTestCase, self).__init__(*args, **kwargs)
def setUp(self):
self.test_context = heat.HeatContext()
self.addCleanup(self._remove_contexts)
+ self.mock_context = mock.Mock(spec=heat.HeatContext())
- @staticmethod
- def _remove_contexts():
- for context in base.Context.list:
- context._delete_context()
- base.Context.list = []
+ def _remove_contexts(self):
+ if self.test_context in self.test_context.list:
+ self.test_context._delete_context()
def test___init__(self):
self.assertIsNone(self.test_context._name)
@@ -57,24 +80,29 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
self.assertIsNone(self.test_context.heat_parameters)
self.assertIsNone(self.test_context.key_filename)
+ @mock.patch('yardstick.common.utils.read_yaml_file')
@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_sg, mock_pg):
+ def test_init(self, mock_server, mock_network, mock_sg, mock_pg, mock_read_yaml):
+ mock_read_yaml.return_value = self.HEAT_POD_SAMPLE
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',
+ 'file': 'pod.yaml',
'task_id': '1234567890',
'placement_groups': pgs,
'server_groups': sgs,
'networks': networks,
'servers': servers}
- self.test_context.init(attrs)
+ with mock.patch.object(openstack_utils, 'get_shade_client'), \
+ mock.patch.object(openstack_utils, 'get_shade_operator_client'):
+ self.test_context.init(attrs)
self.assertFalse(self.test_context._flags.no_setup)
self.assertFalse(self.test_context._flags.no_teardown)
@@ -128,13 +156,17 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
'server_groups': {},
'networks': {},
'servers': {},
+ 'file': "pod.yaml",
'flags': {
'no_setup': True,
'no_teardown': True,
},
}
- self.test_context.init(attrs)
+ with mock.patch.object(openstack_utils, 'get_shade_client'), \
+ mock.patch.object(openstack_utils, 'get_shade_operator_client'):
+ self.test_context.init(attrs)
+
self.assertTrue(self.test_context._flags.no_setup)
self.assertTrue(self.test_context._flags.no_teardown)
@@ -654,7 +686,6 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
baz3_server.public_ip = None
baz3_server.context.user = 'zab'
- self.mock_context = mock.Mock(spec=heat.HeatContext())
self.mock_context._name = 'bar1'
self.test_context.stack = mock.Mock()
self.mock_context.stack.outputs = {
@@ -722,3 +753,56 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
}
result = self.test_context._get_network(attr_name)
self.assertDictEqual(result, expected)
+
+ def _get_file_abspath(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ file_path = os.path.join(curr_path, filename)
+ return file_path
+
+ def test__get_physical_nodes(self):
+ self.test_context.nodes = {}
+ nodes = self.test_context._get_physical_nodes()
+ self.assertEquals(nodes, {})
+
+ @mock.patch('yardstick.common.utils.read_yaml_file')
+ def test__get_physical_node_for_server(self, mock_read_yaml):
+ attrs = {'name': 'foo',
+ 'task_id': '12345678',
+ 'file': "pod.yaml",
+ 'servers': {'vnf': {}},
+ 'networks': {'mgmt': {'cidr': '10.0.1.0/24'}}
+ }
+
+ with mock.patch.object(openstack_utils, 'get_shade_client'), \
+ mock.patch.object(openstack_utils, 'get_shade_operator_client'):
+ mock_read_yaml.return_value = self.HEAT_POD_SAMPLE
+ self.test_context.init(attrs)
+
+ with mock.patch('yardstick.common.openstack_utils.get_server') as mock_get_server:
+ mock_get_server.return_value = {'vnf': {}}
+
+ # When server is not from this context
+ result = self.test_context._get_physical_node_for_server('node1.foo-context')
+ self.assertIsNone(result)
+
+ # When node_name is not from this context
+ result = self.test_context._get_physical_node_for_server('fake.foo-12345678')
+ self.assertIsNone(result)
+
+ mock_munch = mock.Mock()
+ mock_munch.toDict = mock.Mock(return_value={
+ 'OS-EXT-SRV-ATTR:hypervisor_hostname': 'hypervisor_hostname'
+ })
+ mock_get_server.return_value = mock_munch
+
+ hypervisor = mock.Mock()
+ hypervisor.hypervisor_hostname = 'hypervisor_hostname'
+ hypervisor.host_ip = '10.229.47.137'
+
+ self.test_context.operator_client.list_hypervisors = mock.Mock(
+ return_value=[hypervisor])
+
+ mock_get_server.return_value = mock_munch
+
+ result = self.test_context._get_physical_node_for_server('vnf.foo-12345678')
+ self.assertEqual(result, 'node1.foo')
diff --git a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
index 0e11a53e1..b33be033c 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
@@ -12,9 +12,10 @@ import unittest
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import kubernetes
+from yardstick.orchestrator import kubernetes as orchestrator_kubernetes
-context_cfg = {
+CONTEXT_CFG = {
'type': 'Kubernetes',
'name': 'k8s',
'task_id': '1234567890',
@@ -22,14 +23,14 @@ context_cfg = {
'host': {
'image': 'openretriever/yardstick',
'command': '/bin/bash',
- 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done']
+ 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; '
+ 'service ssh restart;while true ; do sleep 10000; done']
},
'target': {
'image': 'openretriever/yardstick',
'command': '/bin/bash',
- 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done']
+ 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; '
+ 'service ssh restart;while true ; do sleep 10000; done']
}
}
}
@@ -42,7 +43,7 @@ class KubernetesTestCase(unittest.TestCase):
def setUp(self):
self.k8s_context = kubernetes.KubernetesContext()
self.addCleanup(self._remove_contexts)
- self.k8s_context.init(context_cfg)
+ self.k8s_context.init(CONTEXT_CFG)
@staticmethod
def _remove_contexts():
@@ -68,7 +69,8 @@ class KubernetesTestCase(unittest.TestCase):
@mock.patch.object(kubernetes.KubernetesContext, '_create_services')
@mock.patch.object(kubernetes.KubernetesContext, '_wait_until_running')
- @mock.patch.object(kubernetes.KubernetesTemplate, 'get_rc_pods')
+ @mock.patch.object(orchestrator_kubernetes.KubernetesTemplate,
+ 'get_rc_pods')
@mock.patch.object(kubernetes.KubernetesContext, '_create_rcs')
@mock.patch.object(kubernetes.KubernetesContext, '_set_ssh_key')
def test_deploy(self,
@@ -170,3 +172,11 @@ class KubernetesTestCase(unittest.TestCase):
def test_delete_services(self, mock_delete):
self.k8s_context._delete_services()
mock_delete.assert_called()
+
+ def test__get_physical_nodes(self):
+ result = self.k8s_context._get_physical_nodes()
+ self.assertIsNone(result)
+
+ def test__get_physical_node_for_server(self):
+ result = self.k8s_context._get_physical_node_for_server("fake")
+ self.assertIsNone(result)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_node.py b/yardstick/tests/unit/benchmark/contexts/test_node.py
index b67be3758..5d7b24c3d 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_node.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_node.py
@@ -15,6 +15,7 @@ import mock
from yardstick.common import constants as consts
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import node
+from yardstick.common import exceptions
class NodeContextTestCase(unittest.TestCase):
@@ -55,8 +56,9 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(self.test_context.env, {})
self.assertEqual(self.test_context.attrs, {})
+ @mock.patch('yardstick.common.utils.read_yaml_file')
@mock.patch('{}.os.path.join'.format(PREFIX))
- def test_init_negative(self, mock_path_join):
+ def test_init_negative(self, mock_path_join, read_mock):
special_path = '/foo/bar/error_file'
error_path = self._get_file_abspath("error_file")
@@ -68,7 +70,6 @@ class NodeContextTestCase(unittest.TestCase):
# we can't count mock_path_join calls because
# it can catch join calls for .pyc files.
mock_path_join.side_effect = path_join
- self.test_context.read_config_file = read_mock = mock.Mock()
read_calls = 0
with self.assertRaises(KeyError):
@@ -86,7 +87,7 @@ class NodeContextTestCase(unittest.TestCase):
self.test_context.init(attrs)
read_calls += 1
- self.assertEqual(read_mock.called, read_calls)
+ self.assertEqual(read_mock.call_count, read_calls)
self.assertIn(attrs['file'], self.test_context.file_path)
self.assertEqual(raised.exception.errno, errno.EBUSY)
self.assertEqual(str(raised.exception), str(read_mock.side_effect))
@@ -101,11 +102,6 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(raised.exception.errno, errno.ENOENT)
self.assertEqual(str(raised.exception), str(read_mock.side_effect))
- def test_read_config_file(self):
- self.test_context.init(self.attrs)
-
- self.assertIsNotNone(self.test_context.read_config_file())
-
def test__dispatch_script(self):
self.test_context.init(self.attrs)
@@ -171,6 +167,39 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
+ def test__get_physical_nodes(self):
+ self.test_context.init(self.attrs)
+ nodes = self.test_context._get_physical_nodes()
+ self.assertEquals(nodes, self.test_context.nodes)
+
+ def test__get_physical_node_for_server(self):
+ self.test_context.init(self.attrs)
+
+ # When server is not from this context
+ result = self.test_context._get_physical_node_for_server('node1.another-context')
+ self.assertIsNone(result)
+
+ # When node_name is not from this context
+ result = self.test_context._get_physical_node_for_server('fake.foo-12345678')
+ self.assertIsNone(result)
+
+ result = self.test_context._get_physical_node_for_server('node1.foo-12345678')
+ self.assertEqual(result, 'node1.foo')
+
+ def test_update_collectd_options_for_node(self):
+ self.test_context.init(self.attrs)
+ options = {'collectd': {'interval': 5}}
+
+ with self.assertRaises(exceptions.ContextUpdateCollectdForNodeError):
+ self.test_context.update_collectd_options_for_node(options, 'fake.foo-12345678')
+
+ self.test_context.update_collectd_options_for_node(options, 'node1.foo-12345678')
+
+ node_collectd_options = [node for node in self.test_context.nodes
+ if node['name'] == 'node1'][0]['collectd']
+
+ self.assertEquals(node_collectd_options, options)
+
@mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX))
def test_deploy(self, dispatch_script_mock):
obj = node.NodeContext()
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index 9361a97f2..d02a34d24 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -59,6 +59,12 @@ class GetShadeClientTestCase(unittest.TestCase):
mock_openstack_cloud.assert_called_once_with(
**constants.OS_CLOUD_DEFAULT_CONFIG)
+ @mock.patch.object(shade, 'operator_cloud', return_value='os_client')
+ def test_get_shade_operator_client(self, mock_operator_cloud):
+ self.assertEqual('os_client', openstack_utils.get_shade_operator_client())
+ mock_operator_cloud.assert_called_once_with(
+ **constants.OS_CLOUD_DEFAULT_CONFIG)
+
class DeleteNeutronNetTestCase(unittest.TestCase):