#!/usr/bin/env python # # Description: # Cleans possible leftovers after running functest tests: # - Nova instances # - Glance images # - Cinder volumes # - Floating IPs # - Neutron networks, subnets and ports # - Routers # - Users and tenants # # Author: # jose.lausuch@ericsson.com # # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # import os import time import yaml from novaclient import client as novaclient from neutronclient.v2_0 import client as neutronclient from keystoneclient.v2_0 import client as keystoneclient from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils """ logging configuration """ logger = ft_logger.Logger("clean_openstack").getLogger() REPO_PATH = os.environ['repos_dir'] + '/functest/' DEFAULTS_FILE = '/home/opnfv/functest/conf/os_defaults.yaml' def separator(): logger.info("-------------------------------------------") def remove_instances(nova_client, default_instances): logger.info("Removing Nova instances...") instances = os_utils.get_instances(nova_client) if instances is None or len(instances) == 0: logger.debug("No instances found.") return for instance in instances: instance_name = getattr(instance, 'name') instance_id = getattr(instance, 'id') logger.debug("Removing instance '%s', ID=%s ..." % (instance_name, instance_id)) if os_utils.delete_instance(nova_client, instance_id): logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "instance %s..." % instance_id) timeout = 50 while timeout > 0: instances = os_utils.get_instances(nova_client) if instances is None or len(instances) == 0: break else: logger.debug("Waiting for instances to be terminated...") timeout -= 1 time.sleep(1) def remove_images(nova_client, default_images): logger.info("Removing Glance images...") images = os_utils.get_images(nova_client) if images is None or len(images) == 0: logger.debug("No images found.") return for image in images: image_name = getattr(image, 'name') image_id = getattr(image, 'id') logger.debug("'%s', ID=%s " % (image_name, image_id)) if image_id not in default_images: logger.debug("Removing image '%s', ID=%s ..." % (image_name, image_id)) if os_utils.delete_glance_image(nova_client, image_id): logger.debug(" > Done!") else: logger.error("There has been a problem removing the" "image %s..." % image_id) else: logger.debug(" > this is a default image and will " "NOT be deleted.") def remove_volumes(cinder_client, default_volumes): logger.info("Removing Cinder volumes...") volumes = os_utils.get_volumes(cinder_client) if volumes is None or len(volumes) == 0: logger.debug("No volumes found.") return for volume in volumes: volume_id = getattr(volume, 'id') volume_name = getattr(volume, 'display_name') logger.debug("'%s', ID=%s " % (volume_name, volume_id)) if volume_id not in default_volumes: logger.debug("Removing cinder volume %s ..." % volume_id) if os_utils.delete_volume(cinder_client, volume_id): logger.debug(" > Done!") else: logger.debug("Trying forced removal...") if os_utils.delete_volume(cinder_client, volume_id, forced=True): logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "
# Specifies hooks/breakpoints where overcloud deployment should stop
# Allows operator validation between steps, and/or more granular control.
# Note: the wildcards relate to naming convention for some resource suffixes,
# e.g see puppet/*-post.yaml, enabling this will mean we wait for
# a user signal on every *Deployment_StepN resource defined in those files.
resource_registry:
resources:
"*NodesPostDeployment":
"*Deployment_Step*":
hooks: [pre-create, pre-update]