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
17 from yardstick.benchmark.contexts.base import Context
18 from yardstick.definitions import YARDSTICK_ROOT_PATH
20 LOG = logging.getLogger(__name__)
23 class NodeContext(Context):
24 """Class that handle nodes info"""
26 __context_type__ = "Node"
35 super(self.__class__, self).__init__()
37 def read_config_file(self):
38 """Read from config file"""
40 with open(self.file_path) as stream:
41 LOG.info("Parsing pod file: %s", self.file_path)
42 cfg = yaml.load(stream)
45 def init(self, attrs):
46 """initializes itself from the supplied arguments"""
47 self.name = attrs["name"]
48 self.file_path = attrs.get("file", "pod.yaml")
51 cfg = self.read_config_file()
52 except IOError as ioerror:
53 if ioerror.errno == errno.ENOENT:
55 os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
56 cfg = self.read_config_file()
60 self.nodes.extend(cfg["nodes"])
61 self.controllers.extend([node for node in cfg["nodes"]
62 if node["role"] == "Controller"])
63 self.computes.extend([node for node in cfg["nodes"]
64 if node["role"] == "Compute"])
65 self.baremetals.extend([node for node in cfg["nodes"]
66 if node["role"] == "Baremetal"])
67 LOG.debug("Nodes: %r", self.nodes)
68 LOG.debug("Controllers: %r", self.controllers)
69 LOG.debug("Computes: %r", self.computes)
70 LOG.debug("BareMetals: %r", self.baremetals)
73 """don't need to deploy"""
77 """don't need to undeploy"""
80 def _get_server(self, attr_name):
81 """lookup server info by name from context
82 attr_name: a name for a server listed in nodes config file
84 if isinstance(attr_name, collections.Mapping):
87 if self.name != attr_name.split(".")[1]:
89 node_name = attr_name.split(".")[0]
90 matching_nodes = (n for n in self.nodes if n["name"] == node_name)
93 # A clone is created in order to avoid affecting the
95 node = dict(next(matching_nodes))
100 duplicate = next(matching_nodes)
101 except StopIteration:
104 raise ValueError("Duplicate nodes!!! Nodes: %s %s",
105 (matching_nodes, duplicate))
107 node["name"] = attr_name