diff options
-rwxr-xr-x | ci/exec_test.sh | 8 | ||||
-rwxr-xr-x | ci/run_tests.py | 14 | ||||
-rw-r--r-- | docs/configguide/configguide.rst | 58 | ||||
-rw-r--r-- | docs/configguide/index.rst | 32 | ||||
-rwxr-xr-x | testcases/Controllers/ODL/OpenDaylightTesting.py | 45 | ||||
-rw-r--r-- | testcases/Controllers/ODL/__init__.py | 0 | ||||
-rw-r--r-- | testcases/Controllers/__init__.py | 0 | ||||
-rwxr-xr-x | testcases/OpenStack/rally/run_rally-cert.py | 46 | ||||
-rw-r--r-- | testcases/OpenStack/tempest/custom_tests/blacklist.txt | 14 | ||||
-rwxr-xr-x | testcases/OpenStack/tempest/run_tempest.py | 45 | ||||
-rw-r--r-- | testcases/OpenStack/vPing/vping_util.py | 23 | ||||
-rwxr-xr-x | testcases/features/sfc/set-up-tacker.sh | 2 | ||||
-rwxr-xr-x | utils/openstack_utils.py | 42 |
13 files changed, 187 insertions, 142 deletions
diff --git a/ci/exec_test.sh b/ci/exec_test.sh index 03eb2c87..20f7c2d4 100755 --- a/ci/exec_test.sh +++ b/ci/exec_test.sh @@ -44,20 +44,18 @@ function odl_tests(){ keystone_ip=$(openstack catalog show identity |grep publicURL| cut -f3 -d"/" | cut -f1 -d":") neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":") odl_ip=${neutron_ip} - odl_port=8181 + odl_port=8080 if [ "$INSTALLER_TYPE" == "fuel" ]; then odl_port=8282 elif [ "$INSTALLER_TYPE" == "apex" ]; then odl_ip=$SDN_CONTROLLER_IP + odl_port=8181 elif [ "$INSTALLER_TYPE" == "joid" ]; then odl_ip=$SDN_CONTROLLER - odl_port=8080 - : elif [ "$INSTALLER_TYPE" == "compass" ]; then - : + odl_port=8181 else odl_ip=$SDN_CONTROLLER_IP - odl_port=8080 fi } diff --git a/ci/run_tests.py b/ci/run_tests.py index 98256721..17481780 100755 --- a/ci/run_tests.py +++ b/ci/run_tests.py @@ -13,8 +13,10 @@ import datetime import os import re import sys + import functest.ci.generate_report as generate_report import functest.ci.tier_builder as tb +from functest.testcases.Controllers.ODL.OpenDaylightTesting import ODLTestCases import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_clean as os_clean @@ -100,9 +102,15 @@ def run_test(test, tier_name): if REPORT_FLAG: flags += " -r" - cmd = ("%s%s" % (EXEC_SCRIPT, flags)) - logger.debug("Executing command '%s'" % cmd) - result = ft_utils.execute_command(cmd, exit_on_error=False) + if test_name == 'odl': + result = ODLTestCases.functest_run() + if result and REPORT_FLAG: + result = ODLTestCases.push_to_db() + result = not result + else: + cmd = ("%s%s" % (EXEC_SCRIPT, flags)) + logger.debug("Executing command '%s'" % cmd) + result = ft_utils.execute_command(cmd, exit_on_error=False) if CLEAN_FLAG: cleanup() diff --git a/docs/configguide/configguide.rst b/docs/configguide/configguide.rst index 6448d2c9..4d0d35b7 100644 --- a/docs/configguide/configguide.rst +++ b/docs/configguide/configguide.rst @@ -18,8 +18,10 @@ release installed in your environment. All available tagged images can be seen from location [FunctestDockerTags_]. For example, when running on the first official release of the OPNFV Colorado system platform, tag "colorado.1.0" is needed. Pulling other tags might cause some -problems while running the tests. If you need to specifically pull the -latest Functest docker image, then omit the tag argument:: +problems while running the tests. +Docker images pulled without a tag specifier bear the implicitly +assigned label "latest". If you need to specifically pull the latest +Functest docker image, then omit the tag argument:: docker pull opnfv/functest @@ -32,9 +34,6 @@ following docker command:: opnfv/functest brahmaputra.3.0 94b78faa94f7 4 weeks ago 874.9 MB hello-world latest 94df4f0ce8a4 7 weeks ago 967 B -Docker images pulled without a tag specifier bear the implicitly -assigned label "latest", as seen above. - The Functest docker container environment can -in principle- be also used with non-OPNFV official installers (e.g. 'devstack'), with the **disclaimer** that support for such environments is outside of the @@ -121,8 +120,9 @@ recommended parameters for invoking docker container under the path: '/home/opnfv/functest/conf/openstack.creds'. WARNING: If you are using the Joid installer, you must pass the - credentials using the **-v** option. See the section - `Accessing the Openstack credentials`_ above. + credentials using the **-v** option: + -v /var/lib/jenkins/admin-openrc:/home/opnfv/functest/conf/openstack.creds. + See the section `Accessing the Openstack credentials`_ above. #. Passing deployment scenario When running Functest against any of the supported OPNFV scenarios, @@ -133,7 +133,7 @@ recommended parameters for invoking docker container -e "DEPLOY_SCENARIO=os-<controller>-<nfv_feature>-<ha_mode>" where: os = OpenStack (No other VIM choices currently available) - controller is one of ( nosdn | odl_l2 | odl_l3 | onos ) + controller is one of ( nosdn | odl_l2 | odl_l3 | onos | ocl) nfv_feature is one or more of ( ovs | kvm | sfc | bgpvpn | nofeature ) If several features are pertinent then use the underscore character '_' to separate each feature (e.g. ovs_kvm) @@ -143,7 +143,7 @@ recommended parameters for invoking docker container **NOTE:** Not all possible combinations of "DEPLOY_SCENARIO" are supported. The name passed in to the Functest Docker container must match the scenario used when the actual OPNFV platform was - deployed. + deployed. See release note to see the list of supported scenarios. Putting all above together, when using installer 'fuel' and an invented INSTALLER_IP of '10.20.0.2', the recommended command to create the @@ -243,19 +243,20 @@ illustration purposes:: Compass installer local development env usage Tips -------------------------------------------------- -In the compass-functest local test case check and development environment, in order -to get openstack service inside the functest container, some parameters should be -configured during container creation, which are hard to guess for freshman. This -section will provide the guideline, the parameters values are defaults here, which should -be adjusted according to the settings, the complete steps are given here so as -not to appear too abruptly. +In the compass-functest local test case check and development environment, +in order to get openstack service inside the functest container, some +parameters should be configured during container creation, which are +hard to guess for freshman. This section will provide the guideline, the +parameters values are defaults here, which should be adjusted according +to the settings, the complete steps are given here so as not to appear +too abruptly. 1, Pull Functest docker image from public dockerhub:: docker pull opnfv/functest:<Tag> -<Tag> here can be "brahmaputra.1.0", "colorado.1.0", etc. Tag omitted means the -latest docker image:: +<Tag> here can be "brahmaputra.1.0", "colorado.1.0", etc. +Tag omitted means the latest docker image:: docker pull opnfv/functest @@ -273,8 +274,8 @@ To make a file used for the environment, such as 'functest-docker-env':: INSTALLER_IP=192.168.200.2 EXTERNAL_NETWORK=ext-net -Note: please adjust the content according to the environment, such as 'TENANT_ID' -maybe used for some special cases. +Note: please adjust the content according to the environment, such as +'TENANT_ID' maybe used for some special cases. Then to create the Functest docker:: @@ -283,8 +284,6 @@ Then to create the Functest docker:: --name <Functest_Container_Name> \ opnfv/functest:<Tag> /bin/bash -Note: it is recommended to be run on jumpserver. - 3, To attach Functest container Before trying to attach the Functest container, the status can be checked by:: @@ -345,6 +344,7 @@ follows:: | |-- __init__.py | |-- check_os.sh | |-- config_functest.yaml + | |-- generate_report.py | |-- exec_test.sh | |-- prepare_env.py | |-- run_tests.py @@ -374,12 +374,12 @@ follows:: | |-- results | `--userguide |-- testcases + | |-- __init__.py | |-- Controllers | |-- OpenStack - | |-- __init__.py | |-- features | |-- security_scan - | `-- vIMS + | `-- vnf `-- utils |-- __init__.py |-- functest_logger.py @@ -694,22 +694,22 @@ docker container. For example, try to use the **nc** command from inside the functest docker container:: - nc -v google.com 80 - Connection to google.com 80 port [tcp/http] succeeded! + nc -v opnfv.org 80 + Connection to opnfv.org 80 port [tcp/http] succeeded! - nc -v google.com 443 - Connection to google.com 443 port [tcp/https] succeeded! + nc -v opnfv.org 443 + Connection to opnfv.org 443 port [tcp/https] succeeded! Note: In a Jumphost node based on the CentOS family OS, the **nc** commands might not work. You can use the **curl** command instead. - curl http://www.google.com:80 + curl http://www.opnfv.org:80 <HTML><HEAD><meta http-equiv="content-type" . . </BODY></HTML> - curl https://www.google.com:443 + curl https://www.opnfv.org:443 <HTML><HEAD><meta http-equiv="content-type" . . diff --git a/docs/configguide/index.rst b/docs/configguide/index.rst index 6b6c62a1..b61bf8ff 100644 --- a/docs/configguide/index.rst +++ b/docs/configguide/index.rst @@ -40,16 +40,20 @@ follows:: | | | | | | | | | | | | Testcases | | | | | | | | | - VIM | | | | | | - | | | -- vPing | | | | | | + | | | -- healthcheck | | | | | | + | | | -- vPing_ssh | | | | | | | | | -- vPing_userdata | | | | | | - | | | -- Tempest | | | | | | - | | | -- Rally | | | | | | - | | | - Controller | | | | | | + | | | -- Tempest_smoke | | | | | | + | | | -- Rally_sanity | | | | | | + | | | -- Tempest_full | | | | | | + | | | -- Rally_full | | | | | | + | | | | | | | | | + | | | - SDN Controller | | | | | | | | | -- odl | | | | | | | | | -- onos | | | | | | | | | | | | | | | - | | | Features | | | | | | - | | | - vIMS | | | | | | + | | | - VNF | | | | | | + | | | -- vIMS | | | | | | | | | | | | | | | | | +--------------------+ | | | | | | | +-------------------------+ | @@ -85,10 +89,10 @@ on any platform on any Operating System. The automated mechanisms inside the Functest Docker container will: - * retrieve OpenStack credentials - * prepare the environment according to the SUT - * perform the appropriate functional tests - * push the test results into the OPNFV test result database + * Retrieve OpenStack credentials + * Prepare the environment according to the SUT + * Perform the appropriate functional tests + * Push the test results into the OPNFV test result database This Docker image can be integrated into CI or deployed independently. @@ -99,11 +103,13 @@ communities. The functional test cases are described in the Functest User Guide `[2]`_ + Prerequisites ============= The OPNFV deployment is out of the scope of this document but it can be -found in `[4]`_. The OPNFV platform is considered as the System Under -Test (SUT) in this document. +found in http://artifacts.opnfv.org/opnfvdocs/colorado/docs/configguide/index.html. +The OPNFV platform is considered as the System Under Test (SUT) in this +document. Several prerequisites are needed for Functest: @@ -273,7 +279,7 @@ References .. _`[1]`: https://ask.openstack.org/en/question/68144/keystone-unable-to-use-the-public-endpoint/ .. _`[2]`: http://artifacts.opnfv.org/functest/docs/userguide/index.html .. _`[3]`: https://git.opnfv.org/cgit/releng/tree/jjb/functest/functest-ci-jobs.yml -.. _`[4]`: http://artifacts.opnfv.org/opnfvdocs/brahmaputra/docs/configguide/index.html +.. _`[4]`: http://artifacts.opnfv.org/opnfvdocs/colorado/docs/configguide/index.html OPNFV main site: opnfvmain_. diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py index d3bc0978..22df9f66 100755 --- a/testcases/Controllers/ODL/OpenDaylightTesting.py +++ b/testcases/Controllers/ODL/OpenDaylightTesting.py @@ -6,6 +6,7 @@ import os import re import shutil import sys +import urlparse from robot import run from robot.api import ExecutionResult, ResultVisitor @@ -14,6 +15,7 @@ from robot.utils.robottime import timestamp_to_secs import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_utils as op_utils class ODLResultVisitor(ResultVisitor): @@ -60,7 +62,7 @@ class ODLTestCases: except IOError as e: cls.logger.error( "Cannot copy OPNFV's testcases to ODL directory: " - "%s" % e.strerror) + "%s" % str(e)) return False return True @@ -76,7 +78,7 @@ class ODLTestCases: line.rstrip()) return True except Exception as e: - cls.logger.error("Cannot set ODL creds: %s" % e.strerror) + cls.logger.error("Cannot set ODL creds: %s" % str(e)) return False @classmethod @@ -95,7 +97,7 @@ class ODLTestCases: 'RESTCONFPORT:' + kwargs['odlrestconfport']] except KeyError as e: cls.logger.error("Cannot run ODL testcases. Please check " - "%s" % e.strerror) + "%s" % str(e)) return False if (cls.copy_opnf_testcases() and cls.set_robotframework_vars(odlusername, odlpassword)): @@ -122,6 +124,43 @@ class ODLTestCases: return False @classmethod + def functest_run(cls): + kclient = op_utils.get_keystone_client() + keystone_url = kclient.service_catalog.url_for( + service_type='identity', endpoint_type='publicURL') + neutron_url = kclient.service_catalog.url_for( + service_type='network', endpoint_type='publicURL') + kwargs = {'keystoneip': urlparse.urlparse(keystone_url).hostname} + kwargs['neutronip'] = urlparse.urlparse(neutron_url).hostname + kwargs['odlip'] = kwargs['neutronip'] + kwargs['odlwebport'] = '8080' + kwargs['odlrestconfport'] = '8181' + kwargs['odlusername'] = 'admin' + kwargs['odlpassword'] = 'admin' + try: + installer_type = os.environ['INSTALLER_TYPE'] + kwargs['osusername'] = os.environ['OS_USERNAME'] + kwargs['ostenantname'] = os.environ['OS_TENANT_NAME'] + kwargs['ospassword'] = os.environ['OS_PASSWORD'] + if installer_type == 'fuel': + kwargs['odlwebport'] = '8282' + elif installer_type == 'apex': + kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP'] + kwargs['odlwebport'] = '8181' + elif installer_type == 'joid': + kwargs['odlip'] = os.environ['SDN_CONTROLLER'] + elif installer_type == 'compass': + kwargs['odlwebport'] = '8181' + else: + kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP'] + except KeyError as e: + cls.logger.error("Cannot run ODL testcases. Please check env var: " + "%s" % str(e)) + return False + + return cls.run(**kwargs) + + @classmethod def push_to_db(cls): try: result = ExecutionResult(cls.res_dir + 'output.xml') diff --git a/testcases/Controllers/ODL/__init__.py b/testcases/Controllers/ODL/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/testcases/Controllers/ODL/__init__.py diff --git a/testcases/Controllers/__init__.py b/testcases/Controllers/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/testcases/Controllers/__init__.py diff --git a/testcases/OpenStack/rally/run_rally-cert.py b/testcases/OpenStack/rally/run_rally-cert.py index 92dbddff..f3eb79d2 100755 --- a/testcases/OpenStack/rally/run_rally-cert.py +++ b/testcases/OpenStack/rally/run_rally-cert.py @@ -376,7 +376,6 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() cinder_client = os_utils.get_cinder_client() start_time = time.time() @@ -402,44 +401,19 @@ def main(): else: logger.debug("Using existing volume type(s)...") - image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) - image_exists = False - - if image_id == '': - logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH)) - image_id = os_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH, - GLANCE_IMAGE_FORMAT) - if not image_id: - logger.error("Failed to create the Glance image...") - exit(-1) - else: - logger.debug("Image '%s' with ID '%s' created succesfully ." - % (GLANCE_IMAGE_NAME, image_id)) - else: - logger.debug("Using existing image '%s' with ID '%s'..." - % (GLANCE_IMAGE_NAME, image_id)) - image_exists = True + image_exists, image_id = os_utils.get_or_create_image(GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH, + GLANCE_IMAGE_FORMAT) + if not image_id: + exit(-1) logger.debug("Creating network '%s'..." % PRIVATE_NET_NAME) - network_dict = os_utils.create_network_full(neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) + network_dict = os_utils.create_shared_network_full(PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) if not network_dict: - logger.error("Failed to create network...") - exit(-1) - else: - if not os_utils.update_neutron_net(neutron_client, - network_dict['net_id'], - shared=True): - logger.error("Failed to update network...") - exit(-1) - else: - logger.debug("Network '%s' available..." % PRIVATE_NET_NAME) + exit(1) if args.test_name == "all": for test_name in tests: diff --git a/testcases/OpenStack/tempest/custom_tests/blacklist.txt b/testcases/OpenStack/tempest/custom_tests/blacklist.txt index 6dd7fad5..e26223b0 100644 --- a/testcases/OpenStack/tempest/custom_tests/blacklist.txt +++ b/testcases/OpenStack/tempest/custom_tests/blacklist.txt @@ -61,3 +61,17 @@ - tempest.scenario.test_server_basic_ops.TestServerBasicOps.test_server_basic_ops - tempest.scenario.test_volume_boot_pattern.TestVolumeBootPattern.test_volume_boot_pattern - tempest.scenario.test_volume_boot_pattern.TestVolumeBootPatternV2.test_volume_boot_pattern + +- + # https://bugs.launchpad.net/tempest/+bug/1586931 + scenarios: + - os-odl_l2-nofeature-ha + - os-odl_l2-sfc-ha + - os-odl_l3-nofeature-ha + - os-nosdn-kvm-ha + - os-nosdn-nofeature-ha + - os-nosdn-ovs-ha + installers: + - fuel + tests: + - tempest.scenario.test_server_basic_ops.TestServerBasicOps.test_server_basic_ops diff --git a/testcases/OpenStack/tempest/run_tempest.py b/testcases/OpenStack/tempest/run_tempest.py index 64a5ed77..306664fe 100755 --- a/testcases/OpenStack/tempest/run_tempest.py +++ b/testcases/OpenStack/tempest/run_tempest.py @@ -125,8 +125,6 @@ def get_info(file_result): def create_tempest_resources(): keystone_client = os_utils.get_keystone_client() - neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() logger.debug("Creating tenant and user for Tempest suite") tenant_id = os_utils.create_tenant(keystone_client, @@ -141,40 +139,19 @@ def create_tempest_resources(): logger.error("Error : Failed to create %s user" % USER_NAME) logger.debug("Creating private network for Tempest suite") - network_dic = os_utils.create_network_full(neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) - if network_dic: - if not os_utils.update_neutron_net(neutron_client, - network_dic['net_id'], - shared=True): - logger.error("Failed to update private network...") - exit(-1) - else: - logger.debug("Network '%s' is available..." % PRIVATE_NET_NAME) - else: - logger.error("Private network creation failed") - exit(-1) + network_dic = os_utils.create_shared_network_full(PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) + if not network_dic: + exit(1) logger.debug("Creating image for Tempest suite") - # Check if the given image exists - image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) - if image_id != '': - logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) - else: - logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH)) - image_id = os_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH, - GLANCE_IMAGE_FORMAT) - if not image_id: - logger.error("Failed to create a Glance image...") - exit(-1) - logger.debug("Image '%s' with ID=%s created successfully." - % (GLANCE_IMAGE_NAME, image_id)) + _, image_id = os_utils.get_or_create_image(GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH, + GLANCE_IMAGE_FORMAT) + if not image_id: + exit(-1) def configure_tempest(deployment_dir): diff --git a/testcases/OpenStack/vPing/vping_util.py b/testcases/OpenStack/vPing/vping_util.py index c16c5d65..3f4adae7 100644 --- a/testcases/OpenStack/vPing/vping_util.py +++ b/testcases/OpenStack/vPing/vping_util.py @@ -147,24 +147,11 @@ def create_security_group(): def create_image(): - EXIT_CODE = -1 - - # Check if the given image exists - image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) - if image_id != '': - logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) - else: - logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH)) - image_id = os_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH, - GLANCE_IMAGE_FORMAT) - if not image_id: - logger.error("Failed to create a Glance image...") - exit(EXIT_CODE) - logger.debug("Image '%s' with ID=%s created successfully." - % (GLANCE_IMAGE_NAME, image_id)) + _, image_id = os_utils.get_or_create_image(GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH, + GLANCE_IMAGE_FORMAT) + if not image_id: + exit(-1) return image_id diff --git a/testcases/features/sfc/set-up-tacker.sh b/testcases/features/sfc/set-up-tacker.sh index 3c21cc58..8098ad99 100755 --- a/testcases/features/sfc/set-up-tacker.sh +++ b/testcases/features/sfc/set-up-tacker.sh @@ -1,4 +1,4 @@ -apt-get -y git-core +apt-get install -y git-core git clone https://gerrit.opnfv.org/gerrit/fuel fuel pushd fuel git checkout e7f7abc89161441548545f79f0299610c6e5b203 diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index d30ca629..bc718bb2 100755 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -671,6 +671,28 @@ def create_network_full(neutron_client, return network_dic +def create_shared_network_full(net_name, subnt_name, router_name, subnet_cidr): + neutron_client = get_neutron_client() + + network_dic = create_network_full(neutron_client, + net_name, + subnt_name, + router_name, + subnet_cidr) + if network_dic: + if not update_neutron_net(neutron_client, + network_dic['net_id'], + shared=True): + logger.error("Failed to update network %s..." % net_name) + return None + else: + logger.debug("Network '%s' is available..." % net_name) + else: + logger.error("Network %s creation failed" % net_name) + return None + return network_dic + + def create_bgpvpn(neutron_client, **kwargs): # route_distinguishers # route_targets @@ -889,6 +911,26 @@ def create_glance_image(glance_client, image_name, file_path, disk="qcow2", return None +def get_or_create_image(name, path, format): + image_exists = False + glance_client = get_glance_client() + + image_id = get_image_id(glance_client, name) + if image_id != '': + logger.info("Using existing image '%s'..." % name) + image_exists = True + else: + logger.info("Creating image '%s' from '%s'..." % (name, path)) + image_id = create_glance_image(glance_client, name, path, format) + if not image_id: + logger.error("Failed to create a Glance image...") + else: + logger.debug("Image '%s' with ID=%s created successfully." + % (name, image_id)) + + return image_exists, image_id + + def delete_glance_image(nova_client, image_id): try: nova_client.images.delete(image_id) |