Add custom flavor in config file
Change-Id: I511ff3a50d8f4b937f8240ef143bce4d62a9a6f6
This commit is contained in:
parent
e2148c6c09
commit
3d5769f7c0
@ -22,7 +22,20 @@ ssh_vm_username: 'ubuntu'
|
|||||||
# Name of the flavor to use for the test VMs
|
# Name of the flavor to use for the test VMs
|
||||||
# This name must be an exact match to a flavor name known by the target
|
# This name must be an exact match to a flavor name known by the target
|
||||||
# OpenStack deployment (as shown from 'nova flavor-list')
|
# OpenStack deployment (as shown from 'nova flavor-list')
|
||||||
flavor_type: 'm1.small'
|
flavor_type: 'vmtp'
|
||||||
|
|
||||||
|
# Custom flavor attributes
|
||||||
|
flavor:
|
||||||
|
# Number of vCPUs for the flavor
|
||||||
|
vcpus: 1
|
||||||
|
# Memory for the flavor in MB
|
||||||
|
ram: 2048
|
||||||
|
# Size of local disk in GB
|
||||||
|
disk: 0
|
||||||
|
# metadata are supported and can be added if needed, optional
|
||||||
|
# extra_specs:
|
||||||
|
# "hw:cpu_policy": dedicated
|
||||||
|
# "hw:mem_page_size": 2048
|
||||||
|
|
||||||
# Name of the availability zone to use for the test VMs
|
# Name of the availability zone to use for the test VMs
|
||||||
# Must be one of the zones listed by 'nova availability-zone-list'
|
# Must be one of the zones listed by 'nova availability-zone-list'
|
||||||
|
@ -231,9 +231,29 @@ class Compute(object):
|
|||||||
self.novaclient.servers.delete(server)
|
self.novaclient.servers.delete(server)
|
||||||
|
|
||||||
def find_flavor(self, flavor_type):
|
def find_flavor(self, flavor_type):
|
||||||
flavor = self.novaclient.flavors.find(name=flavor_type)
|
try:
|
||||||
|
flavor = self.novaclient.flavors.find(name=flavor_type)
|
||||||
|
return flavor
|
||||||
|
except exceptions.NotFound:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def create_flavor(self, flavor_type, vcpus, ram, disk, ephemeral=0, extra_specs=None):
|
||||||
|
flavor = self.novaclient.flavors.create(name=flavor_type, vcpus=vcpus, ram=ram, disk=disk,
|
||||||
|
ephemeral=ephemeral)
|
||||||
|
if extra_specs:
|
||||||
|
flavor.set_keys(extra_specs)
|
||||||
|
LOG.info('Flavor %s created.' % flavor_type)
|
||||||
return flavor
|
return flavor
|
||||||
|
|
||||||
|
def delete_flavor(self, flavor):
|
||||||
|
try:
|
||||||
|
flavor.delete()
|
||||||
|
LOG.info('Flavor %s deleted.' % flavor.name)
|
||||||
|
return True
|
||||||
|
except novaclient.exceptions:
|
||||||
|
LOG.error('Failed deleting flavor %s.' % flavor.name)
|
||||||
|
return False
|
||||||
|
|
||||||
def normalize_az_host(self, az, host):
|
def normalize_az_host(self, az, host):
|
||||||
if not az:
|
if not az:
|
||||||
az = self.config.availability_zone
|
az = self.config.availability_zone
|
||||||
|
10
vmtp/vmtp.py
10
vmtp/vmtp.py
@ -146,6 +146,7 @@ class VmtpTest(object):
|
|||||||
self.instance_access = None
|
self.instance_access = None
|
||||||
self.glance_client = None
|
self.glance_client = None
|
||||||
self.image_uploaded = False
|
self.image_uploaded = False
|
||||||
|
self.flavor_created = False
|
||||||
self.rescol = rescol
|
self.rescol = rescol
|
||||||
self.config = config
|
self.config = config
|
||||||
self.cred = cred
|
self.cred = cred
|
||||||
@ -235,7 +236,14 @@ class VmtpTest(object):
|
|||||||
|
|
||||||
self.assert_true(self.image_instance)
|
self.assert_true(self.image_instance)
|
||||||
LOG.info('Found image %s to launch VM, will continue', self.config.image_name)
|
LOG.info('Found image %s to launch VM, will continue', self.config.image_name)
|
||||||
|
|
||||||
self.flavor_type = self.comp.find_flavor(self.config.flavor_type)
|
self.flavor_type = self.comp.find_flavor(self.config.flavor_type)
|
||||||
|
if self.flavor_type is None:
|
||||||
|
LOG.info('Flavor %s not found. Creating custom flavor...', self.config.flavor_type)
|
||||||
|
self.flavor_type = self.comp.create_flavor(self.config.flavor_type,
|
||||||
|
**dict(self.config.flavor))
|
||||||
|
self.flavor_created = True
|
||||||
|
|
||||||
self.net = network.Network(neutron, self.config)
|
self.net = network.Network(neutron, self.config)
|
||||||
|
|
||||||
self.rescol.add_property('l2agent_type', self.net.l2agent_type)
|
self.rescol.add_property('l2agent_type', self.net.l2agent_type)
|
||||||
@ -429,6 +437,8 @@ class VmtpTest(object):
|
|||||||
LOG.warning('Security group in use: not deleted')
|
LOG.warning('Security group in use: not deleted')
|
||||||
if self.image_uploaded and self.config.delete_image_after_run:
|
if self.image_uploaded and self.config.delete_image_after_run:
|
||||||
self.comp.delete_image(self.glance_client, self.config.image_name)
|
self.comp.delete_image(self.glance_client, self.config.image_name)
|
||||||
|
if self.flavor_created:
|
||||||
|
self.comp.delete_flavor(self.flavor_type)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
error_flag = False
|
error_flag = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user