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 ##############################################################################
15 from yardstick.benchmark.contexts.base import Context
16 from yardstick.definitions import YARDSTICK_ROOT_PATH
18 LOG = logging.getLogger(__name__)
21 class NodeContext(Context):
22 '''Class that handle nodes info'''
24 __context_type__ = "Node"
33 super(self.__class__, self).__init__()
35 def init(self, attrs):
36 '''initializes itself from the supplied arguments'''
37 self.name = attrs["name"]
38 self.file_path = attrs.get("file", "pod.yaml")
39 if not os.path.exists(self.file_path):
40 self.file_path = os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
42 LOG.info("Parsing pod file: %s", self.file_path)
45 with open(self.file_path) as stream:
46 cfg = yaml.load(stream)
47 except IOError as ioerror:
50 self.nodes.extend(cfg["nodes"])
51 self.controllers.extend([node for node in cfg["nodes"]
52 if node["role"] == "Controller"])
53 self.computes.extend([node for node in cfg["nodes"]
54 if node["role"] == "Compute"])
55 self.baremetals.extend([node for node in cfg["nodes"]
56 if node["role"] == "Baremetal"])
57 LOG.debug("Nodes: %r", self.nodes)
58 LOG.debug("Controllers: %r", self.controllers)
59 LOG.debug("Computes: %r", self.computes)
60 LOG.debug("BareMetals: %r", self.baremetals)
63 '''don't need to deploy'''
67 '''don't need to undeploy'''
70 def _get_server(self, attr_name):
71 '''lookup server info by name from context
72 attr_name: a name for a server listed in nodes config file
74 if type(attr_name) is dict:
77 if self.name != attr_name.split(".")[1]:
79 node_name = attr_name.split(".")[0]
80 nodes = [n for n in self.nodes
81 if n["name"] == node_name]
85 LOG.error("Duplicate nodes!!!")
86 LOG.error("Nodes: %r" % nodes)
89 # A clone is created in order to avoid affecting the
92 node["name"] = attr_name