summaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorQiLiang <liangqi1@huawei.com>2015-10-25 14:47:37 +0000
committerQiLiang <liangqi1@huawei.com>2015-11-01 12:12:31 +0000
commitb1eb58006197c7a41aa5f1e2c2db465bb2f0dbc3 (patch)
tree8b62695e6c2323990c74a803d0ae9b2a2b2e08e1 /yardstick
parent05d5ac8d6d5e9bd1e6b69afbd764000aeb4a030e (diff)
Support NodeContext type
Initial NodeContext implementation to support BareMetal, Controller, Compute scenarios. Usage: 0) install yardstick 1) mkdir -p /etc/yardstick/nodes 2) cp <yardstick_repo>/etc/yardstick/nodes/pod.yaml.sample \ /etc/yardstick/nodes/pod.yaml 3) edit /etc/yardstick/nodes/pod.yaml (make show ip, username, ssh key are configured correctly) 4) yardstick -d task start \ <yardstick_repo>/samples/ping-node-context.yaml 5) cat /tmp/yardstick.out Design etherpad link: https://etherpad.opnfv.org/p/yardstick_framework JIRA: YARDSTICK-169 Change-Id: I3f6ade8243e68d88326f23ed213edb32c638ed32 Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/contexts/node.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
new file mode 100644
index 000000000..04c8e7ca3
--- /dev/null
+++ b/yardstick/benchmark/contexts/node.py
@@ -0,0 +1,94 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import sys
+import yaml
+import logging
+
+from yardstick.benchmark.contexts.base import Context
+
+LOG = logging.getLogger(__name__)
+
+
+class NodeContext(Context):
+ '''Class that handle nodes info'''
+
+ __context_type__ = "Node"
+
+ def __init__(self):
+ self.name = None
+ self.file_path = None
+ self.nodes = []
+ self.controllers = []
+ self.computes = []
+ self.baremetals = []
+ super(self.__class__, self).__init__()
+
+ def init(self, attrs):
+ '''initializes itself from the supplied arguments'''
+ self.name = attrs["name"]
+ self.file_path = attrs.get("file", "/etc/yardstick/nodes/pod.yaml")
+
+ LOG.info("Parsing pod file: %s", self.file_path)
+
+ try:
+ with open(self.file_path) as stream:
+ cfg = yaml.load(stream)
+ except IOError as ioerror:
+ sys.exit(ioerror)
+
+ self.nodes.extend(cfg["nodes"])
+ self.controllers.extend([node for node in cfg["nodes"]
+ if node["role"] == "Controller"])
+ self.computes.extend([node for node in cfg["nodes"]
+ if node["role"] == "Compute"])
+ self.baremetals.extend([node for node in cfg["nodes"]
+ if node["role"] == "Baremetal"])
+ LOG.debug("Nodes: %r", self.nodes)
+ LOG.debug("Controllers: %r", self.controllers)
+ LOG.debug("Computes: %r", self.computes)
+ LOG.debug("BareMetals: %r", self.baremetals)
+
+ def deploy(self):
+ '''don't need to deploy'''
+ pass
+
+ def undeploy(self):
+ '''don't need to undeploy'''
+ pass
+
+ def _get_server(self, attr_name):
+ '''lookup server info by name from context
+ attr_name: a name for a server listed in nodes config file
+ '''
+ if type(attr_name) is dict:
+ return None
+
+ if self.name != attr_name.split(".")[1]:
+ return None
+ node_name = attr_name.split(".")[0]
+ nodes = [n for n in self.nodes
+ if n["name"] == node_name]
+ if len(nodes) == 0:
+ return None
+ elif len(nodes) > 1:
+ LOG.error("Duplicate nodes!!!")
+ LOG.error("Nodes: %r" % nodes)
+ sys.exit(-1)
+
+ node = nodes[0]
+
+ server = {
+ "name": attr_name,
+ "ip": node["ip"],
+ "user": node["user"],
+ "key_filename": node["key_filename"]
+ }
+
+ return server