aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-09-12 09:41:45 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-09-15 15:32:11 -0700
commitbe06e38960cea8a54c85418948e8453861012d2d (patch)
tree03847348fc74492f4e298d023bbbbb8b76388185
parent3016786696b9e5a26b364cb5bd4cb5676420fe58 (diff)
Generate pod.yaml from current context
We want to generate pod.yaml from Heat contexts so we can re-use the context without destroying it. But we don't have node role information and it doesn't make sense in this case, so make the role optional. Since we changed Heat to use pkey instead of key_filename, we can embed the pkey into the pod.yaml, but we have to make sure to convert the pkey to string, in case it is a RSAKey object Change-Id: Ibefcfbd8236e68013a704c39964cb870da825da8 Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
-rw-r--r--yardstick/benchmark/contexts/heat.py2
-rw-r--r--yardstick/benchmark/contexts/node.py6
-rw-r--r--yardstick/benchmark/core/task.py1
-rw-r--r--yardstick/benchmark/scenarios/networking/vnf_generic.py34
-rw-r--r--yardstick/ssh.py9
5 files changed, 49 insertions, 3 deletions
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py
index c7586abf4..2f3cc5a30 100644
--- a/yardstick/benchmark/contexts/heat.py
+++ b/yardstick/benchmark/contexts/heat.py
@@ -442,6 +442,8 @@ class HeatContext(Context):
"routing_table": self.generate_routing_table(server),
# empty IPv6 routing table
"nd_route_tbl": [],
+ # we want to save the contex name so we can generate pod.yaml
+ "name": server.name,
}
# Target server may only have private_ip
if server.public_ip:
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
index 250032efc..ffc82c8ed 100644
--- a/yardstick/benchmark/contexts/node.py
+++ b/yardstick/benchmark/contexts/node.py
@@ -74,11 +74,11 @@ class NodeContext(Context):
self.nodes.extend(cfg["nodes"])
self.controllers.extend([node for node in cfg["nodes"]
- if node["role"] == "Controller"])
+ if node.get("role") == "Controller"])
self.computes.extend([node for node in cfg["nodes"]
- if node["role"] == "Compute"])
+ if node.get("role") == "Compute"])
self.baremetals.extend([node for node in cfg["nodes"]
- if node["role"] == "Baremetal"])
+ if node.get("role") == "Baremetal"])
LOG.debug("Nodes: %r", self.nodes)
LOG.debug("Controllers: %r", self.controllers)
LOG.debug("Computes: %r", self.computes)
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index a8447e2cf..75703cf50 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -362,6 +362,7 @@ class Task(object): # pragma: no cover
context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
context_cfg["networks"] = get_networks_from_nodes(
context_cfg["nodes"])
+
runner = base_runner.Runner.get(runner_cfg)
LOG.info("Starting runner of type '%s'", runner_cfg["type"])
diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py
index ada92121b..18ff40422 100644
--- a/yardstick/benchmark/scenarios/networking/vnf_generic.py
+++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py
@@ -25,9 +25,11 @@ import re
from itertools import chain
import six
+import yaml
from collections import defaultdict
from yardstick.benchmark.scenarios import base
+from yardstick.common.constants import LOG_DIR
from yardstick.common.utils import import_modules_from_package, itersubclasses
from yardstick.common.yaml_loader import yaml_load
from yardstick.network_services.collector.subscriber import Collector
@@ -364,6 +366,36 @@ class NetworkServiceTestCase(base.Scenario):
'ifindex': netdev['ifindex'],
})
+ def _generate_pod_yaml(self):
+ context_yaml = os.path.join(LOG_DIR, "pod-{}.yaml".format(self.scenario_cfg['task_id']))
+ # convert OrderedDict to a list
+ # pod.yaml nodes is a list
+ nodes = []
+ for node in self.context_cfg["nodes"].values():
+ # name field is required
+ # remove context suffix
+ node['name'] = node['name'].split('.')[0]
+ nodes.append(node)
+ nodes = self._convert_pkeys_to_string(nodes)
+ pod_dict = {
+ "nodes": nodes,
+ "networks": self.context_cfg["networks"]
+ }
+ with open(context_yaml, "w") as context_out:
+ yaml.safe_dump(pod_dict, context_out, default_flow_style=False,
+ explicit_start=True)
+
+ @staticmethod
+ def _convert_pkeys_to_string(nodes):
+ # make copy because we are mutating
+ nodes = nodes[:]
+ for i, node in enumerate(nodes):
+ try:
+ nodes[i] = dict(node, pkey=ssh.convert_key_to_str(node["pkey"]))
+ except KeyError:
+ pass
+ return nodes
+
TOPOLOGY_REQUIRED_KEYS = frozenset({
"vpci", "local_ip", "netmask", "local_mac", "driver"})
@@ -400,6 +432,8 @@ class NetworkServiceTestCase(base.Scenario):
"Require interface fields '%s' not found, topology file "
"corrupted" % ', '.join(missing))
+ # we have to generate pod.yaml here so we have vpci and driver
+ self._generate_pod_yaml()
# 3. Use topology file to find connections & resolve dest address
self._resolve_topology()
self._update_context_with_topology()
diff --git a/yardstick/ssh.py b/yardstick/ssh.py
index bb715e4b4..e98ee98b7 100644
--- a/yardstick/ssh.py
+++ b/yardstick/ssh.py
@@ -64,6 +64,7 @@ Eventlet:
"""
from __future__ import absolute_import
import os
+import io
import select
import socket
import time
@@ -81,6 +82,14 @@ from yardstick.common.utils import try_int
from yardstick.network_services.utils import provision_tool
+def convert_key_to_str(key):
+ if not isinstance(key, (paramiko.RSAKey, paramiko.DSSKey)):
+ return key
+ k = io.StringIO()
+ key.write_private_key(k)
+ return k.getvalue()
+
+
class SSHError(Exception):
pass