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"
41 super(StandaloneContext, self).__init__()
43 def read_config_file(self):
44 """Read from config file"""
46 with open(self.file_path) as stream:
47 LOG.info("Parsing pod file: %s", self.file_path)
48 cfg = yaml.load(stream)
51 def init(self, attrs):
52 """initializes itself from the supplied arguments"""
54 self.name = attrs["name"]
55 self.file_path = attrs.get("file", "pod.yaml")
56 LOG.info("Parsing pod file: %s", self.file_path)
59 cfg = self.read_config_file()
60 except IOError as ioerror:
61 if ioerror.errno == errno.ENOENT:
62 self.file_path = YARDSTICK_ROOT_PATH + self.file_path
63 cfg = self.read_config_file()
67 self.nodes.extend(cfg["nodes"])
68 self.nfvi_node.extend([node for node in cfg["nodes"]
69 if node["role"] == "nfvi_node"])
70 # add optional static network definition
71 self.networks.update(cfg.get("networks", {}))
72 LOG.debug("Nodes: %r", self.nodes)
73 LOG.debug("NFVi Node: %r", self.nfvi_node)
74 LOG.debug("Networks: %r", self.networks)
77 """don't need to deploy"""
79 # Todo: NFVi deploy (sriov, vswitch, ovs etc) based on the config.
83 """don't need to undeploy"""
85 # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config.
86 super(StandaloneContext, self).undeploy()
88 def _get_server(self, attr_name):
89 """lookup server info by name from context
92 attr_name -- A name for a server listed in nodes config file
95 if isinstance(attr_name, collections.Mapping):
98 if self.name.split("-")[0] != attr_name.split(".")[1]:
101 node_name = attr_name.split(".")[0]
102 matching_nodes = (n for n in self.nodes if n["name"] == node_name)
105 # A clone is created in order to avoid affecting the
107 node = dict(next(matching_nodes))
108 except StopIteration:
112 duplicate = next(matching_nodes)
113 except StopIteration:
116 raise ValueError("Duplicate nodes!!! Nodes: %s %s",
117 (matching_nodes, duplicate))
119 node["name"] = attr_name
122 def _get_network(self, attr_name):
123 if not isinstance(attr_name, collections.Mapping):
124 network = self.networks.get(attr_name)
127 # Don't generalize too much Just support vld_id
128 vld_id = attr_name.get('vld_id')
132 network = next(n for n in self.networks.values() if
133 n.get("vld_id") == vld_id)
134 except StopIteration:
142 "name": network["name"],
143 "vld_id": network.get("vld_id"),
144 "segmentation_id": network.get("segmentation_id"),
145 "network_type": network.get("network_type"),
146 "physical_network": network.get("physical_network"),