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 ##############################################################################
10 from __future__ import absolute_import
16 from yardstick.benchmark.contexts.base import Context
17 from yardstick.definitions import YARDSTICK_ROOT_PATH
19 LOG = logging.getLogger(__name__)
22 class NodeContext(Context):
23 """Class that handle nodes info"""
25 __context_type__ = "Node"
34 super(self.__class__, self).__init__()
36 def init(self, attrs):
37 """initializes itself from the supplied arguments"""
38 self.name = attrs["name"]
39 self.file_path = attrs.get("file", "pod.yaml")
40 if not os.path.exists(self.file_path):
41 self.file_path = os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
43 LOG.info("Parsing pod file: %s", self.file_path)
46 with open(self.file_path) as stream:
47 cfg = yaml.load(stream)
48 except IOError as ioerror:
51 self.nodes.extend(cfg["nodes"])
52 self.controllers.extend([node for node in cfg["nodes"]
53 if node["role"] == "Controller"])
54 self.computes.extend([node for node in cfg["nodes"]
55 if node["role"] == "Compute"])
56 self.baremetals.extend([node for node in cfg["nodes"]
57 if node["role"] == "Baremetal"])
58 LOG.debug("Nodes: %r", self.nodes)
59 LOG.debug("Controllers: %r", self.controllers)
60 LOG.debug("Computes: %r", self.computes)
61 LOG.debug("BareMetals: %r", self.baremetals)
64 """don't need to deploy"""
68 """don't need to undeploy"""
71 def _get_server(self, attr_name):
72 """lookup server info by name from context
73 attr_name: a name for a server listed in nodes config file
75 if type(attr_name) is dict:
78 if self.name != attr_name.split(".")[1]:
80 node_name = attr_name.split(".")[0]
81 nodes = [n for n in self.nodes
82 if n["name"] == node_name]
86 LOG.error("Duplicate nodes!!!")
87 LOG.error("Nodes: %r", nodes)
90 # A clone is created in order to avoid affecting the
93 node["name"] = attr_name