+ def _provide_config_file(self, config_file_path, nfvi_cfg, template_kwargs):
+ template = pkg_resources.resource_string("yardstick.network_services.nfvi",
+ nfvi_cfg).decode('utf-8')
+ cfg_content = jinja2.Template(template, trim_blocks=True, lstrip_blocks=True,
+ finalize=finalize_for_yaml).render(
+ **template_kwargs)
+ # cfg_content = io.StringIO(template.format(**template_kwargs))
+ cfg_file = os.path.join(config_file_path, nfvi_cfg)
+ # must write as root, so use sudo
+ self.connection.execute("cat | sudo tee {}".format(cfg_file), stdin=cfg_content)
+
+ def _prepare_collectd_conf(self, config_file_path):
+ """ Prepare collectd conf """
+
+ kwargs = {
+ "interval": self.interval,
+ "loadplugins": set(chain(LIST_PLUGINS_ENABLED, self.plugins.keys())),
+ # Optional fields PortName is descriptive only, use whatever is present
+ "port_names": self.port_names,
+ # "ovs_bridge_interfaces": ["br-int"],
+ "plugins": self.plugins,
+ }
+ self._provide_config_file(config_file_path, self.COLLECTD_CONF, kwargs)
+
+ def _setup_intel_pmu(self, connection, bin_path):
+ pmu_event_path = os.path.join(bin_path, "pmu_event.json")
+ try:
+ self.plugins["intel_pmu"]["pmu_event_path"] = pmu_event_path
+ except KeyError:
+ # if intel_pmu is not a dict, force it into a dict
+ self.plugins["intel_pmu"] = {"pmu_event_path": pmu_event_path}
+ LOG.debug("Downloading event list for pmu_stats plugin")
+ cmd = 'cd {0}; PMU_EVENTS_PATH={1} python event_download_local.py'.format(
+ bin_path, pmu_event_path)
+ cmd = "sudo bash -c '{}'".format(cmd)
+ connection.execute(cmd)
+
+ def _setup_ovs_stats(self, connection):
+ try:
+ socket_path = self.plugins["ovs_stats"].get("ovs_socket_path", self.OVS_SOCKET_PATH)
+ except KeyError:
+ # ovs_stats is not a dict
+ socket_path = self.OVS_SOCKET_PATH
+ status = connection.execute("test -S {}".format(socket_path))[0]
+ if status != 0:
+ LOG.error("cannot find OVS socket %s", socket_path)
+
+ def _start_collectd(self, connection, bin_path):
+ LOG.debug("Starting collectd to collect NFVi stats")
+ connection.execute('sudo pkill -x -9 collectd')
+ collectd_path = os.path.join(bin_path, "collectd", "sbin", "collectd")
+ config_file_path = os.path.join(bin_path, "collectd", "etc")
+ exit_status = connection.execute("which %s > /dev/null 2>&1" % collectd_path)[0]
+ if exit_status != 0:
+ LOG.warning("%s is not present disabling", collectd_path)
+ # disable auto-provisioning because it requires Internet access
+ # collectd_installer = os.path.join(bin_path, "collectd.sh")
+ # provision_tool(connection, collectd)
+ # http_proxy = os.environ.get('http_proxy', '')
+ # https_proxy = os.environ.get('https_proxy', '')
+ # connection.execute("sudo %s '%s' '%s'" % (
+ # collectd_installer, http_proxy, https_proxy))
+ return
+ if "intel_pmu" in self.plugins:
+ self._setup_intel_pmu(connection, bin_path)
+ if "ovs_stats" in self.plugins:
+ self._setup_ovs_stats(connection)
+
+ LOG.debug("Starting collectd to collect NFVi stats")
+ # ensure collectd.conf.d exists to avoid error/warning
+ connection.execute("sudo mkdir -p /etc/collectd/collectd.conf.d")
+ self._prepare_collectd_conf(config_file_path)