from neutronclient.neutron import client as neutronclient
from novaclient.client import Client
import os
+import re
import time
def __init__(self, config, cred):
self.comp = None
self.image_instance = None
+ self.image_name = None
self.config = config
self.cred = cred
self.nets = []
self.host_ips = None
def _ensure_vms_active(self):
- for _ in range(self.config.generic_retry_count):
+ retry_count = (self.config.check_traffic_time_sec +
+ self.config.generic_poll_sec - 1) / self.config.generic_poll_sec
+ for _ in range(retry_count):
for i, instance in enumerate(self.vms):
if instance.status == 'ACTIVE':
continue
networks = self.neutron.list_networks(name=network_name)
return networks['networks'][0] if networks['networks'] else None
- def _create_net(self, name, subnet, cidr, network_type=None, segmentation_id=None, physical_network=None):
+ def _create_net(self, name, subnet, cidr, network_type=None,
+ segmentation_id=None, physical_network=None):
network = self._lookup_network(name)
if network:
# a network of same name already exists, we need to verify it has the same
return server
def _setup_resources(self):
- if not self.image_instance:
- self.image_instance = self.comp.find_image(self.config.image_name)
- if self.image_instance is None:
+ # To avoid reuploading image in server mode, check whether image_name is set or not
+ if self.image_name:
+ self.image_instance = self.comp.find_image(self.image_name)
+ if self.image_instance:
+ LOG.info("Reusing image %s" % self.image_name)
+ else:
+ image_name_search_pattern = '(nfvbenchvm-\d+(\.\d+)*).qcow2'
if self.config.vm_image_file:
- LOG.info('%s: image for VM not found, trying to upload it ...'
- % self.config.image_name)
- res = self.comp.upload_image_via_url(self.config.image_name,
+ match = re.search(image_name_search_pattern, self.config.vm_image_file)
+ if match:
+ self.image_name = match.group(1)
+ LOG.info('Using provided VM image file %s' % self.config.vm_image_file)
+ else:
+ raise StageClientException('Provided VM image file name %s must start with '
+ '"nfvbenchvm-<version>"' % self.config.vm_image_file)
+ else:
+ pkg_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ for f in os.listdir(pkg_root):
+ if re.search(image_name_search_pattern, f):
+ self.config.vm_image_file = pkg_root + '/' + f
+ self.image_name = f.replace('.qcow2', '')
+ LOG.info('Found built-in VM image file %s' % f)
+ break
+ else:
+ raise StageClientException('Cannot find any built-in VM image file.')
+ if self.image_name:
+ self.image_instance = self.comp.find_image(self.image_name)
+ if not self.image_instance:
+ LOG.info('Uploading %s'
+ % self.image_name)
+ res = self.comp.upload_image_via_url(self.image_name,
self.config.vm_image_file)
if not res:
raise StageClientException('Error uploading image %s from %s. ABORTING.'
- % (self.config.image_name,
+ % (self.image_name,
self.config.vm_image_file))
- self.image_instance = self.comp.find_image(self.config.image_name)
- else:
- raise StageClientException('%s: image to launch VM not found. ABORTING.'
- % self.config.image_name)
-
- LOG.info('Found image %s to launch VM' % self.config.image_name)
+ LOG.info('Image %s successfully uploaded.' % self.image_name)
+ self.image_instance = self.comp.find_image(self.image_name)
self.__setup_flavor()
"""
vlans = []
for net in self.nets:
- assert(net['provider:network_type'] == 'vlan')
+ assert (net['provider:network_type'] == 'vlan')
vlans.append(net['provider:segmentation_id'])
return vlans
class EXTStageClient(BasicStageClient):
-
def __init__(self, config, cred):
super(EXTStageClient, self).__init__(config, cred)
class PVPStageClient(BasicStageClient):
-
def __init__(self, config, cred):
super(PVPStageClient, self).__init__(config, cred)
class PVVPStageClient(BasicStageClient):
-
def __init__(self, config, cred):
super(PVVPStageClient, self).__init__(config, cred)