Merge "HA testcase containerized Compass support"
[yardstick.git] / yardstick / benchmark / contexts / standalone.py
index c1d963f..8614f0c 100644 (file)
@@ -20,7 +20,7 @@ import collections
 import yaml
 
 from yardstick.benchmark.contexts.base import Context
-from yardstick.definitions import YARDSTICK_ROOT_PATH
+from yardstick.common.constants import YARDSTICK_ROOT_PATH
 
 LOG = logging.getLogger(__name__)
 
@@ -36,8 +36,9 @@ class StandaloneContext(Context):
         self.name = None
         self.file_path = None
         self.nodes = []
+        self.networks = {}
         self.nfvi_node = []
-        super(self.__class__, self).__init__()
+        super(StandaloneContext, self).__init__()
 
     def read_config_file(self):
         """Read from config file"""
@@ -66,8 +67,11 @@ class StandaloneContext(Context):
         self.nodes.extend(cfg["nodes"])
         self.nfvi_node.extend([node for node in cfg["nodes"]
                                if node["role"] == "nfvi_node"])
+        # add optional static network definition
+        self.networks.update(cfg.get("networks", {}))
         LOG.debug("Nodes: %r", self.nodes)
         LOG.debug("NFVi Node: %r", self.nfvi_node)
+        LOG.debug("Networks: %r", self.networks)
 
     def deploy(self):
         """don't need to deploy"""
@@ -79,7 +83,7 @@ class StandaloneContext(Context):
         """don't need to undeploy"""
 
         # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config.
-        pass
+        super(StandaloneContext, self).undeploy()
 
     def _get_server(self, attr_name):
         """lookup server info by name from context
@@ -114,3 +118,31 @@ class StandaloneContext(Context):
 
         node["name"] = attr_name
         return node
+
+    def _get_network(self, attr_name):
+        if not isinstance(attr_name, collections.Mapping):
+            network = self.networks.get(attr_name)
+
+        else:
+            # Don't generalize too much  Just support vld_id
+            vld_id = attr_name.get('vld_id')
+            if vld_id is None:
+                return None
+            try:
+                network = next(n for n in self.networks.values() if
+                               n.get("vld_id") == vld_id)
+            except StopIteration:
+                return None
+
+        if network is None:
+            return None
+
+        result = {
+            # name is required
+            "name": network["name"],
+            "vld_id": network.get("vld_id"),
+            "segmentation_id": network.get("segmentation_id"),
+            "network_type": network.get("network_type"),
+            "physical_network": network.get("physical_network"),
+        }
+        return result