summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorjuraj.linkes <jlinkes@cisco.com>2016-09-15 16:27:06 +0200
committerjuraj.linkes <jlinkes@cisco.com>2016-09-15 16:28:59 +0200
commit0fa8de695dd6b50b7b01131376aefef9c13c21c1 (patch)
tree0c45b1962db6c3fd51afe619d0c3b937643fdf53 /utils
parent758ef5ddb78f8b5a948189f398daa7d4457b9f1d (diff)
Added support for custom images and flavors in tempest
Change-Id: I9335ed1517097e83175a265b603a6707adf476b6 Signed-off-by: juraj.linkes <jlinkes@cisco.com>
Diffstat (limited to 'utils')
-rwxr-xr-xutils/openstack_utils.py57
1 files changed, 39 insertions, 18 deletions
diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py
index d528549a1..e61d06434 100755
--- a/utils/openstack_utils.py
+++ b/utils/openstack_utils.py
@@ -211,6 +211,45 @@ def get_flavor_id_by_ram_range(nova_client, min_ram, max_ram):
return id
+def create_flavor(nova_client, flavor_name, ram, disk, vcpus):
+ try:
+ flavor = nova_client.flavors.create(flavor_name, ram, vcpus, disk)
+ try:
+ extra_specs = ft_utils.get_functest_config(
+ 'general.flavor_extra_specs')
+ flavor.set_keys(extra_specs)
+ except ValueError:
+ # flavor extra specs are not configured, therefore skip the update
+ pass
+
+ except Exception, e:
+ logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', "
+ "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e))
+ return None
+ return flavor.id
+
+
+def get_or_create_flavor(flavor_name, ram, disk, vcpus):
+ flavor_exists = False
+ nova_client = get_nova_client()
+
+ flavor_id = get_flavor_id(nova_client, flavor_name)
+ if flavor_id != '':
+ logger.info("Using existing flavor '%s'..." % flavor_name)
+ flavor_exists = True
+ else:
+ logger.info("Creating flavor '%s' with '%s' RAM, '%s' disk size, "
+ "'%s' vcpus..." % (flavor_name, ram, disk, vcpus))
+ flavor_id = create_flavor(nova_client, flavor_name, ram, disk, vcpus)
+ if not flavor_id:
+ logger.error("Failed to create flavor '%s'..." % (flavor_name))
+ else:
+ logger.debug("Flavor '%s' with ID=%s created successfully."
+ % (flavor_name, flavor_id))
+
+ return flavor_exists, flavor_id
+
+
def get_floating_ips(nova_client):
try:
floating_ips = nova_client.floating_ips.list()
@@ -233,24 +272,6 @@ def get_hypervisors(nova_client):
return None
-def create_flavor(nova_client, flavor_name, ram, disk, vcpus):
- try:
- flavor = nova_client.flavors.create(flavor_name, ram, vcpus, disk)
- try:
- extra_specs = ft_utils.get_functest_config(
- 'general.flavor_extra_specs')
- flavor.set_keys(extra_specs)
- except ValueError:
- # flavor extra specs are not configured, therefore skip the update
- pass
-
- except Exception, e:
- logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', "
- "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e))
- return None
- return flavor.id
-
-
def create_instance(flavor_name,
image_id,
network_id,