1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 from yardstick.benchmark.contexts.base import Context
16 LOG = logging.getLogger(__name__)
19 class NodeContext(Context):
20 '''Class that handle nodes info'''
22 __context_type__ = "Node"
31 super(self.__class__, self).__init__()
33 def init(self, attrs):
34 '''initializes itself from the supplied arguments'''
35 self.name = attrs["name"]
36 self.file_path = attrs.get("file", "/etc/yardstick/nodes/pod.yaml")
38 LOG.info("Parsing pod file: %s", self.file_path)
41 with open(self.file_path) as stream:
42 cfg = yaml.load(stream)
43 except IOError as ioerror:
46 self.nodes.extend(cfg["nodes"])
47 self.controllers.extend([node for node in cfg["nodes"]
48 if node["role"] == "Controller"])
49 self.computes.extend([node for node in cfg["nodes"]
50 if node["role"] == "Compute"])
51 self.baremetals.extend([node for node in cfg["nodes"]
52 if node["role"] == "Baremetal"])
53 LOG.debug("Nodes: %r", self.nodes)
54 LOG.debug("Controllers: %r", self.controllers)
55 LOG.debug("Computes: %r", self.computes)
56 LOG.debug("BareMetals: %r", self.baremetals)
59 '''don't need to deploy'''
63 '''don't need to undeploy'''
66 def _get_server(self, attr_name):
67 '''lookup server info by name from context
68 attr_name: a name for a server listed in nodes config file
70 if type(attr_name) is dict:
73 if self.name != attr_name.split(".")[1]:
75 node_name = attr_name.split(".")[0]
76 nodes = [n for n in self.nodes
77 if n["name"] == node_name]
81 LOG.error("Duplicate nodes!!!")
82 LOG.error("Nodes: %r" % nodes)
86 node["name"] = attr_name