Merge "Bugfix: yardstick env grafana return http error"
[yardstick.git] / yardstick / benchmark / contexts / standalone / ovs_dpdk.py
index ee0eb9e..88ad598 100644 (file)
@@ -20,10 +20,12 @@ import re
 import time
 
 from yardstick import ssh
-from yardstick.benchmark.contexts.base import Context
+from yardstick.benchmark import contexts
+from yardstick.benchmark.contexts import base
 from yardstick.benchmark.contexts.standalone import model
 from yardstick.common import exceptions
 from yardstick.network_services import utils
+from yardstick.network_services.utils import get_nsb_option
 
 
 LOG = logging.getLogger(__name__)
@@ -31,12 +33,12 @@ LOG = logging.getLogger(__name__)
 MAIN_BRIDGE = 'br0'
 
 
-class OvsDpdkContext(Context):
+class OvsDpdkContext(base.Context):
     """ This class handles OVS standalone nodes - VM running on Non-Managed NFVi
     Configuration: ovs_dpdk
     """
 
-    __context_type__ = "StandaloneOvsDpdk"
+    __context_type__ = contexts.CONTEXT_STANDALONEOVSDPDK
 
     SUPPORTED_OVS_TO_DPDK_MAP = {
         '2.6.0': '16.07.1',
@@ -55,7 +57,8 @@ class OvsDpdkContext(Context):
         self.file_path = None
         self.sriov = []
         self.first_run = True
-        self.dpdk_devbind = ''
+        self.dpdk_devbind = os.path.join(get_nsb_option('bin_path'),
+                                         'dpdk-devbind.py')
         self.vm_names = []
         self.nfvi_host = []
         self.nodes = []
@@ -260,9 +263,6 @@ class OvsDpdkContext(Context):
             return
 
         self.connection = ssh.SSH.from_node(self.host_mgmt)
-        self.dpdk_devbind = utils.provision_tool(
-            self.connection,
-            os.path.join(utils.get_nsb_option('bin_path'), 'dpdk-devbind.py'))
 
         # Check dpdk/ovs version, if not present install
         self.check_ovs_dpdk_env()
@@ -299,13 +299,28 @@ class OvsDpdkContext(Context):
         for vm in self.vm_names:
             model.Libvirt.check_if_vm_exists_and_delete(vm, self.connection)
 
+    def _get_physical_nodes(self):
+        return self.nfvi_host
+
+    def _get_physical_node_for_server(self, server_name):
+        node_name, ctx_name = self.split_host_name(server_name)
+        if ctx_name is None or self.name != ctx_name:
+            return None
+
+        matching_nodes = [s for s in self.servers if s == node_name]
+        if len(matching_nodes) == 0:
+            return None
+
+        # self.nfvi_host always contain only one host
+        return "{}.{}".format(self.nfvi_host[0]["name"], self._name)
+
     def _get_server(self, attr_name):
         """lookup server info by name from context
 
         Keyword arguments:
         attr_name -- A name for a server listed in nodes config file
         """
-        node_name, name = self.split_name(attr_name)
+        node_name, name = self.split_host_name(attr_name)
         if name is None or self.name != name:
             return None
 
@@ -359,7 +374,7 @@ class OvsDpdkContext(Context):
         self.networks = portlist
         LOG.info("Ports %s", self.networks)
 
-    def _enable_interfaces(self, index, vfs, cfg):
+    def _enable_interfaces(self, index, vfs, xml_str):
         vpath = self.ovs_properties.get("vpath", "/usr/local")
         vf = self.networks[vfs[0]]
         port_num = vf.get('port_num', 0)
@@ -368,8 +383,8 @@ class OvsDpdkContext(Context):
         slot = index + port_num + 10
         vf['vpci'] = \
             "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function)
-        model.Libvirt.add_ovs_interface(
-            vpath, port_num, vf['vpci'], vf['mac'], str(cfg))
+        return model.Libvirt.add_ovs_interface(
+            vpath, port_num, vf['vpci'], vf['mac'], xml_str)
 
     def setup_ovs_dpdk_context(self):
         nodes = []
@@ -384,17 +399,16 @@ class OvsDpdkContext(Context):
             # 1. Check and delete VM if already exists
             model.Libvirt.check_if_vm_exists_and_delete(vm_name,
                                                         self.connection)
+            xml_str, mac = model.Libvirt.build_vm_xml(
+                self.connection, self.vm_flavor, vm_name, index)
 
-            _, mac = model.Libvirt.build_vm_xml(
-                self.connection, self.vm_flavor, cfg, vm_name, index)
             # 2: Cleanup already available VMs
-            for vkey, vfs in collections.OrderedDict(
-                    vnf["network_ports"]).items():
-                if vkey == "mgmt":
-                    continue
-                self._enable_interfaces(index, vfs, cfg)
+            for vfs in [vfs for vfs_name, vfs in vnf["network_ports"].items()
+                        if vfs_name != 'mgmt']:
+                xml_str = self._enable_interfaces(index, vfs, xml_str)
 
             # copy xml to target...
+            model.Libvirt.write_file(cfg, xml_str)
             self.connection.put(cfg, cfg)
 
             # NOTE: launch through libvirt