diff options
author | Edward MacGillivray <edward.s.macgillivray@intel.com> | 2017-06-12 11:06:45 -0700 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-06-20 13:19:25 +0000 |
commit | 653902770572c780777d1dc7a371794b670585b1 (patch) | |
tree | 6fcb520a711836eb10c2dd4759666d3b39858150 /yardstick/orchestrator/heat.py | |
parent | 37921fcd232cd2fbba9f45ef9fa5d8c912f54af6 (diff) |
Acquire NSB specific data from Heat.
First we add mac_address, subnet_cidr to Heat template outputs
Then we convert those into a form for NSB and add vld_id.
NSB also requires PCI Bus ID, kernel driver
and dpdk_port_num. We get this by ssh-ing
into instance and dumping sysfs
We also need to fix allow for ssh key auth,
and implement relative path file loading
so NSB can find all its YAML files
JIRA: YARDSTICK-580
Change history:
don't hide heat create tracebacks we need tracebacks for debug
vnf_generic: add task_path to scenario so we can load relative paths
for vnf_generic we want to be able to load yaml relative to the
task path
For example:
traffic_profile: ../../traffic_profiles/fixed.yaml
topology: ping_tg_topology.yaml # TODO: look in relative path where the tc.yaml is found
These need to be relative to samples/vnf_samples/nsut/ping/tc_ping_heat_context.yaml
Add a scenario["task_path"] entry
heat: log actual exception
vnf_generic: replace list with set and iterate over values()
some general refactors to remove redundact lookups and
type conversions
heat: provide mac_address, device_id and network_id from outputs
We may need more information to dynamically
determine test topology.
Towards this end return more info in the heat template.
We can return mac_address, device_id and network_id.
Once we have this info we can add it to the context_cfg
as an interfaces dict.
add sample vnf ping multi-network test
this test requires 3 network, one for mgmt
and the other two for NSB traffic tests
We have to make sure we don't use DPDK
on mgmt interface because DPDK unbinds
the driver
heat: convert networks to OrderedDict
so we can lookups networks as well as
iterate over them in consisitent order
heat: and vld_id to networks for vnf_generic
vnf_generic uses vld_id Virtual Link Descriptor ID
to identify interfaces
Add the key to the networks dict
and store in Networks object
implement relative path file loading in vnf_generic
in multiple places we need to load a file
relative to the task path, so add
open_relative_file_path
and modify load_vnf_model to include the scenario_cfg
parameter so we have access to task_path
DRAFT: heat timeout support
Heat stack in CI job failed due to some Nova issue.
But then apparently yardstick kept running and took 180mins to timeout
https://build.opnfv.org/ci/view/bottlenecks/job/bottlenecks-compass-posca_stress_ping-baremetal-daily-master/16/console
We can add a Heat create timeout and fail faster if there is an error.
The question is how long should we wait for a Heat stack to deploy. We
can set a default and allow override in the heat context config, if
users make complicated stacks
heat: get netmask and gateway from heat outputs
we have do some tricky business with finding
the subnet cidr and converting it into netmask
vnf_generic: get vpci, driver and dpdk_port_num
use a big old find command to dump all the sysfs
netdev info nicely. This was re-used from autotest FCoE tests.
r"""find /sys/devices/pci* -type d -name net -exec sh -c '{ grep -sH ^ \
+$1/ifindex $1/address $1/operstate $1/device/vendor $1/device/device \
+$1/device/subsystem_vendor $1/device/subsystem_device ; \
+printf "%s/driver:" $1 ; basename $(readlink -s $1/device/driver); } \
+' sh \{\}/* \;
This finds all PCI devices that are network devices, then
dumps all the relevant info using /bin/sh.
Then we parse this into a 'netdevs' dict inside the node_dict
and also convert into VNF fields we need.
vnf_generic: set node name for kpis
node is a dict, so we have to use node_name
vnfdgen: we CANNOT use TaskTemplate.render
because it does not allow for missing variables, we need to allow
password for key_filename to be undefined
remove default ssh password hack, once rendering is fixed
add new example tc_external_ping_heat_context
Change-Id: If1fe0c1a2ab0a5be17e40790a66f28f706fa44d6
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Signed-off-by: Edward MacGillivray <edward.s.macgillivray@intel.com>
Diffstat (limited to 'yardstick/orchestrator/heat.py')
-rw-r--r-- | yardstick/orchestrator/heat.py | 122 |
1 files changed, 80 insertions, 42 deletions
diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py index ea9bd1b08..a99d4631d 100644 --- a/yardstick/orchestrator/heat.py +++ b/yardstick/orchestrator/heat.py @@ -1,5 +1,5 @@ ############################################################################## -# Copyright (c) 2015 Ericsson AB and others. +# Copyright (c) 2015-2017 Ericsson AB and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -11,6 +11,7 @@ from __future__ import absolute_import from __future__ import print_function +from six.moves import range import collections import datetime @@ -47,7 +48,8 @@ class HeatObject(object): self._heat_client = None self.uuid = None - def _get_heat_client(self): + @property + def heat_client(self): """returns a heat client instance""" if self._heat_client is None: @@ -61,9 +63,9 @@ class HeatObject(object): def status(self): """returns stack state as a string""" - heat = self._get_heat_client() - stack = heat.stacks.get(self.uuid) - return getattr(stack, 'stack_status') + heat_client = self.heat_client + stack = heat_client.stacks.get(self.uuid) + return stack.stack_status class HeatStack(HeatObject): @@ -88,20 +90,18 @@ class HeatStack(HeatObject): return log.info("Deleting stack '%s', uuid:%s", self.name, self.uuid) - heat = self._get_heat_client() + heat = self.heat_client template = heat.stacks.get(self.uuid) start_time = time.time() template.delete() - status = self.status() - while status != u'DELETE_COMPLETE': + for status in iter(self.status, u'DELETE_COMPLETE'): log.debug("stack state %s", status) if status == u'DELETE_FAILED': raise RuntimeError( heat.stacks.get(self.uuid).stack_status_reason) time.sleep(2) - status = self.status() end_time = time.time() log.info("Deleted stack '%s' in %d secs", self.name, @@ -120,15 +120,13 @@ class HeatStack(HeatObject): self._delete() return - i = 0 - while i < retries: + for _ in range(retries): try: self._delete() break except RuntimeError as err: log.warning(err.args) time.sleep(2) - i += 1 # if still not deleted try once more and let it fail everything if self.uuid is not None: @@ -149,28 +147,34 @@ class HeatStack(HeatObject): class HeatTemplate(HeatObject): """Describes a Heat template and a method to deploy template to a stack""" - def _init_template(self): - self._template = {} - self._template['heat_template_version'] = '2013-05-23' + DESCRIPTION_TEMPLATE = """\ +Stack built by the yardstick framework for %s on host %s %s. +All referred generated resources are prefixed with the template +name (i.e. %s).\ +""" + def _init_template(self): timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - self._template['description'] = \ - """Stack built by the yardstick framework for %s on host %s %s. - All referred generated resources are prefixed with the template - name (i.e. %s).""" % (getpass.getuser(), socket.gethostname(), - timestamp, self.name) + self._template = { + 'heat_template_version': '2013-05-23', + 'description': self.DESCRIPTION_TEMPLATE % ( + getpass.getuser(), + socket.gethostname(), + timestamp, + self.name + ), + 'resources': {}, + 'outputs': {} + } # short hand for resources part of template - self.resources = self._template['resources'] = {} - - self._template['outputs'] = {} + self.resources = self._template['resources'] def __init__(self, name, template_file=None, heat_parameters=None): super(HeatTemplate, self).__init__() self.name = name self.state = "NOT_CREATED" self.keystone_client = None - self.heat_client = None self.heat_parameters = {} # heat_parameters is passed to heat in stack create, empty dict when @@ -272,6 +276,14 @@ class HeatTemplate(HeatObject): 'description': 'subnet %s ID' % name, 'value': {'get_resource': name} } + self._template['outputs'][name + "-cidr"] = { + 'description': 'subnet %s cidr' % name, + 'value': {'get_attr': [name, 'cidr']} + } + self._template['outputs'][name + "-gateway_ip"] = { + 'description': 'subnet %s gateway_ip' % name, + 'value': {'get_attr': [name, 'gateway_ip']} + } def add_router(self, name, ext_gw_net, subnet_name): """add to the template a Neutron Router and interface""" @@ -329,6 +341,22 @@ class HeatTemplate(HeatObject): 'description': 'Address for interface %s' % name, 'value': {'get_attr': [name, 'fixed_ips', 0, 'ip_address']} } + self._template['outputs'][name + "-subnet_id"] = { + 'description': 'Address for interface %s' % name, + 'value': {'get_attr': [name, 'fixed_ips', 0, 'subnet_id']} + } + self._template['outputs'][name + "-mac_address"] = { + 'description': 'MAC Address for interface %s' % name, + 'value': {'get_attr': [name, 'mac_address']} + } + self._template['outputs'][name + "-device_id"] = { + 'description': 'Device ID for interface %s' % name, + 'value': {'get_attr': [name, 'device_id']} + } + self._template['outputs'][name + "-network_id"] = { + 'description': 'Network ID for interface %s' % name, + 'value': {'get_attr': [name, 'network_id']} + } def add_floating_ip(self, name, network_name, port_name, router_if_name, secgroup_name=None): @@ -501,38 +529,48 @@ class HeatTemplate(HeatObject): 'value': {'get_resource': name} } - def create(self, block=True): - """creates a template in the target cloud using heat + HEAT_WAIT_LOOP_INTERVAL = 2 + + def create(self, block=True, timeout=3600): + """ + creates a template in the target cloud using heat returns a dict with the requested output values from the template + + :param block: Wait for Heat create to finish + :type block: bool + :param: timeout: timeout in seconds for Heat create, default 3600s + :type timeout: int """ log.info("Creating stack '%s'", self.name) # create stack early to support cleanup, e.g. ctrl-c while waiting stack = HeatStack(self.name) - heat = self._get_heat_client() + heat_client = self.heat_client start_time = time.time() - stack.uuid = self.uuid = heat.stacks.create( + stack.uuid = self.uuid = heat_client.stacks.create( stack_name=self.name, template=self._template, parameters=self.heat_parameters)['stack']['id'] - status = self.status() - outputs = [] + if not block: + self.outputs = stack.outputs = {} + return stack - if block: - while status != u'CREATE_COMPLETE': - log.debug("stack state %s", status) - if status == u'CREATE_FAILED': - raise RuntimeError(getattr(heat.stacks.get(self.uuid), - 'stack_status_reason')) + time_limit = start_time + timeout + for status in iter(self.status, u'CREATE_COMPLETE'): + log.debug("stack state %s", status) + if status == u'CREATE_FAILED': + raise RuntimeError( + heat_client.stacks.get(self.uuid).stack_status_reason) + if time.time() > time_limit: + raise RuntimeError("Heat stack create timeout") - time.sleep(2) - status = self.status() + time.sleep(self.HEAT_WAIT_LOOP_INTERVAL) - end_time = time.time() - outputs = getattr(heat.stacks.get(self.uuid), 'outputs') - log.info("Created stack '%s' in %d secs", - self.name, end_time - start_time) + end_time = time.time() + outputs = heat_client.stacks.get(self.uuid).outputs + log.info("Created stack '%s' in %d secs", + self.name, end_time - start_time) # keep outputs as unicode self.outputs = {output["output_key"]: output["output_value"] for output |