1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """This module handle non managed standalone virtualization node."""
16 from __future__ import absolute_import
22 from yardstick.benchmark.contexts.base import Context
23 from yardstick.common.constants import YARDSTICK_ROOT_PATH
25 LOG = logging.getLogger(__name__)
28 class StandaloneContext(Context):
29 """ This class handles standalone nodes - VM running on Non-Managed NFVi
30 Configuration: vswitch, ovs, ovs-dpdk, sr-iov, linuxbridge
33 __context_type__ = "Standalone"
40 super(StandaloneContext, self).__init__()
42 def read_config_file(self):
43 """Read from config file"""
45 with open(self.file_path) as stream:
46 LOG.info("Parsing pod file: %s", self.file_path)
47 cfg = yaml.load(stream)
50 def init(self, attrs):
51 """initializes itself from the supplied arguments"""
53 self.name = attrs["name"]
54 self.file_path = attrs.get("file", "pod.yaml")
55 LOG.info("Parsing pod file: %s", self.file_path)
58 cfg = self.read_config_file()
59 except IOError as ioerror:
60 if ioerror.errno == errno.ENOENT:
61 self.file_path = YARDSTICK_ROOT_PATH + self.file_path
62 cfg = self.read_config_file()
66 self.nodes.extend(cfg["nodes"])
67 self.nfvi_node.extend([node for node in cfg["nodes"]
68 if node["role"] == "nfvi_node"])
69 LOG.debug("Nodes: %r", self.nodes)
70 LOG.debug("NFVi Node: %r", self.nfvi_node)
73 """don't need to deploy"""
75 # Todo: NFVi deploy (sriov, vswitch, ovs etc) based on the config.
79 """don't need to undeploy"""
81 # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config.
82 super(StandaloneContext, self).undeploy()
84 def _get_server(self, attr_name):
85 """lookup server info by name from context
88 attr_name -- A name for a server listed in nodes config file
91 if isinstance(attr_name, collections.Mapping):
94 if self.name.split("-")[0] != attr_name.split(".")[1]:
97 node_name = attr_name.split(".")[0]
98 matching_nodes = (n for n in self.nodes if n["name"] == node_name)
101 # A clone is created in order to avoid affecting the
103 node = dict(next(matching_nodes))
104 except StopIteration:
108 duplicate = next(matching_nodes)
109 except StopIteration:
112 raise ValueError("Duplicate nodes!!! Nodes: %s %s",
113 (matching_nodes, duplicate))
115 node["name"] = attr_name