aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolodymyr Mytnyk <volodymyrx.mytnyk@intel.com>2019-04-08 09:26:31 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-04-08 09:26:31 +0000
commit1a6f868947011bf3ed4af87555bf2da55aadeac2 (patch)
tree82491b9bb93a5175acc2b1931f3952508c90b750
parentff2093ffa0279e91cf09c1f6843c473a0a1ff129 (diff)
parent489a6064839920121866f8fb3d3a86ab86e5e663 (diff)
Merge "Update to support using external heat template"
-rw-r--r--yardstick/benchmark/contexts/heat.py8
-rw-r--r--yardstick/benchmark/core/task.py20
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py45
-rw-r--r--yardstick/tests/unit/benchmark/core/test_task.py37
4 files changed, 109 insertions, 1 deletions
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py
index 403562c46..917aa9c39 100644
--- a/yardstick/benchmark/contexts/heat.py
+++ b/yardstick/benchmark/contexts/heat.py
@@ -509,6 +509,14 @@ class HeatContext(Context):
server.private_ip = self.stack.outputs.get(
attr_name.get("private_ip_attr", object()), None)
+
+ # Try to find interfaces
+ for key, value in attr_name.get("interfaces", {}).items():
+ value["local_ip"] = server.private_ip
+ for k in ["local_mac", "netmask", "gateway_ip"]:
+ # Keep explicit None or missing entry as is
+ value[k] = self.stack.outputs.get(value[k])
+ server.interfaces.update({key: value})
else:
try:
server = self._server_map[attr_name]
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index afd805f94..bcca3558f 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -624,6 +624,16 @@ class TaskParser(object): # pragma: no cover
tg__0: trafficgen_0.yardstick
vnf__0: vnf_0.yardstick
+ scenario:
+ nodes:
+ tg__0:
+ name: trafficgen_0.yardstick
+ public_ip_attr: "server1_public_ip"
+ private_ip_attr: "server1_private_ip"
+ vnf__0:
+ name: vnf_0.yardstick
+ public_ip_attr: "server2_public_ip"
+ private_ip_attr: "server2_private_ip"
NOTE: in Kubernetes context, the separator character between the server
name and the context name is "-":
scenario:
@@ -655,7 +665,15 @@ class TaskParser(object): # pragma: no cover
scenario['targets'][idx] = qualified_name(target)
if 'nodes' in scenario:
for scenario_node, target in scenario['nodes'].items():
- scenario['nodes'][scenario_node] = qualified_name(target)
+ if isinstance(target, collections.Mapping):
+ # Update node info on scenario with context info
+ # Just update the node name with context
+ # Append context information
+ target['name'] = qualified_name(target['name'])
+ # Then update node
+ scenario['nodes'][scenario_node] = target
+ else:
+ scenario['nodes'][scenario_node] = qualified_name(target)
def _check_schema(self, cfg_schema, schema_type):
"""Check if config file is using the correct schema type"""
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index fbc6fd26d..96946cded 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -13,6 +13,7 @@ import os
import mock
import unittest
+import collections
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import heat
@@ -742,6 +743,50 @@ class HeatContextTestCase(unittest.TestCase):
result = self.test_context._get_server(attr_name)
self.assertIsNone(result)
+ @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources")
+ def test__get_server_found_dict_found_interfaces_dict(self, *args):
+ """
+ Use HeatContext._get_server to get a server that matches
+ based on a dictionary input.
+ """
+ self.test_context._name = 'bar'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
+ self.test_context._user = 'bot'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ 'local_mac_addr': '64:00:6a:18:0f:d6',
+ 'private_netmask': '255.255.255.0',
+ 'private_net_name': 'private_network',
+ 'private_net_gateway': '127.0.0.254'
+ }
+
+ attr_name = {
+ 'name': 'foo.bar-12345678',
+ 'private_ip_attr': 'private_ip',
+ 'public_ip_attr': 'public_ip',
+ 'interfaces': {
+ 'data_net': {
+ 'local_ip': 'private_ip',
+ 'local_mac': 'local_mac_addr',
+ 'netmask': 'private_netmask',
+ 'network': 'private_net_name',
+ 'gateway_ip': 'private_net_gateway'
+ }
+ }
+ }
+ self.test_context.key_uuid = 'foo-42'
+ result = self.test_context._get_server(attr_name)
+ self.assertIsInstance(result['interfaces'], collections.Mapping)
+ for key in attr_name.get("interfaces").keys():
+ self.assertEqual(result['interfaces'][key]['local_ip'], '10.0.0.1')
+ self.assertEqual(result['interfaces'][key]['local_mac'], '64:00:6a:18:0f:d6')
+ self.assertEqual(result['interfaces'][key]['netmask'], '255.255.255.0')
+ self.assertEqual(result['interfaces'][key]['gateway_ip'], '127.0.0.254')
+
# TODO: Split this into more granular tests
def test__get_network(self):
network1 = mock.MagicMock()
diff --git a/yardstick/tests/unit/benchmark/core/test_task.py b/yardstick/tests/unit/benchmark/core/test_task.py
index e1414c2ae..1903babf9 100644
--- a/yardstick/tests/unit/benchmark/core/test_task.py
+++ b/yardstick/tests/unit/benchmark/core/test_task.py
@@ -18,6 +18,7 @@ import six
from six.moves import builtins
import unittest
import uuid
+import collections
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import dummy
@@ -487,6 +488,42 @@ key2:
self.parser._change_node_names(scenario, [my_context])
self.assertIsNone(scenario['options']['server_name'])
+ def test__change_node_names_target_map(self):
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890'
+ }
+ my_context = dummy.DummyContext()
+ self.addCleanup(self._remove_contexts)
+ my_context.init(ctx_attrs)
+ scenario = copy.deepcopy(self.scenario)
+ scenario['nodes'] = {
+ 'tg__0': {
+ 'name': 'tg__0.demo',
+ 'public_ip_attr': "1.1.1.1",
+ },
+ 'vnf__0': {
+ 'name': 'vnf__0.demo',
+ 'public_ip_attr': "2.2.2.2",
+ }
+ }
+ self.parser._change_node_names(scenario, [my_context])
+ for target in scenario['nodes'].values():
+ self.assertIsInstance(target, collections.Mapping)
+
+ def test__change_node_names_not_target_map(self):
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890'
+ }
+ my_context = dummy.DummyContext()
+ self.addCleanup(self._remove_contexts)
+ my_context.init(ctx_attrs)
+ scenario = copy.deepcopy(self.scenario)
+ self.parser._change_node_names(scenario, [my_context])
+ for target in scenario['nodes'].values():
+ self.assertNotIsInstance(target, collections.Mapping)
+
def test__parse_tasks(self):
task_obj = task.Task()
_uuid = uuid.uuid4()