Merge "HA testcase containerized Compass support"
[yardstick.git] / yardstick / benchmark / contexts / node.py
index a4a2cfc..b3f0aca 100644 (file)
@@ -33,6 +33,7 @@ class NodeContext(Context):
         self.name = None
         self.file_path = None
         self.nodes = []
+        self.networks = {}
         self.controllers = []
         self.computes = []
         self.baremetals = []
@@ -77,6 +78,9 @@ class NodeContext(Context):
         self.env = attrs.get('env', {})
         LOG.debug("Env: %r", self.env)
 
+        # add optional static network definition
+        self.networks.update(cfg.get("networks", {}))
+
     def deploy(self):
         config_type = self.env.get('type', '')
         if config_type == 'ansible':
@@ -141,6 +145,32 @@ class NodeContext(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
+
+            network = next((n for n in self.networks.values() if
+                           n.get("vld_id") == vld_id), 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
+
     def _execute_script(self, node_name, info):
         if node_name == 'local':
             self._execute_local_script(info)
@@ -178,21 +208,7 @@ class NodeContext(Context):
         if node is None:
             raise SystemExit('No such node')
 
-        user = node.get('user', 'ubuntu')
-        ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT)
-        ip = node.get('ip')
-        pwd = node.get('password')
-        key_fname = node.get('key_filename', '/root/.ssh/id_rsa')
-
-        if pwd is not None:
-            LOG.debug("Log in via pw, user:%s, host:%s, password:%s",
-                      user, ip, pwd)
-            self.client = ssh.SSH(user, ip, password=pwd, port=ssh_port)
-        else:
-            LOG.debug("Log in via key, user:%s, host:%s, key_filename:%s",
-                      user, ip, key_fname)
-            self.client = ssh.SSH(user, ip, key_filename=key_fname,
-                                  port=ssh_port)
+        self.client = ssh.SSH.from_node(node, defaults={'user': 'ubuntu'})
 
         self.client.wait(timeout=600)