Merge "Create API to get SUT information"
[yardstick.git] / yardstick / benchmark / contexts / node.py
index 35c6433..fa619a9 100644 (file)
@@ -17,12 +17,12 @@ import tempfile
 
 import six
 import pkg_resources
-import yaml
 
 from yardstick import ssh
 from yardstick.benchmark.contexts.base import Context
 from yardstick.common.constants import ANSIBLE_DIR, YARDSTICK_ROOT_PATH
 from yardstick.common.ansible_common import AnsibleCommon
+from yardstick.common.yaml_loader import yaml_load
 
 LOG = logging.getLogger(__name__)
 
@@ -35,7 +35,6 @@ class NodeContext(Context):
     __context_type__ = "Node"
 
     def __init__(self):
-        self.name = None
         self.file_path = None
         self.nodes = []
         self.networks = {}
@@ -55,12 +54,13 @@ class NodeContext(Context):
 
         with open(self.file_path) as stream:
             LOG.info("Parsing pod file: %s", self.file_path)
-            cfg = yaml.safe_load(stream)
+            cfg = yaml_load(stream)
         return cfg
 
     def init(self, attrs):
         """initializes itself from the supplied arguments"""
-        self.name = attrs["name"]
+        super(NodeContext, self).init(attrs)
+
         self.file_path = file_path = attrs.get("file", "pod.yaml")
 
         try:
@@ -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)
@@ -157,7 +157,7 @@ class NodeContext(Context):
         except StopIteration:
             pass
         else:
-            raise ValueError("Duplicate nodes!!! Nodes: %s %s",
+            raise ValueError("Duplicate nodes!!! Nodes: %s %s" %
                              (node, duplicate))
 
         node["name"] = attr_name
@@ -204,7 +204,7 @@ class NodeContext(Context):
         self.client._put_file_shell(script_file, '~/{}'.format(script))
 
         cmd = 'sudo bash {} {}'.format(script, options)
-        status, stdout, stderr = self.client.execute(cmd)
+        status, _, stderr = self.client.execute(cmd)
         if status:
             raise RuntimeError(stderr)