X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Futils%2Fopenstack_snapshot.py;h=3dc6f80c72b73772907084e2b75fc2bc3105420a;hb=3900d3c3efa75e0a382183154c534e67b199152c;hp=d6e7fe0069feedd344101fe43fc04d640b8d161f;hpb=1001f3f7adff734ae80d17ce65914f60c6cce18d;p=functest.git diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py old mode 100755 new mode 100644 index d6e7fe006..3dc6f80c7 --- a/functest/utils/openstack_snapshot.py +++ b/functest/utils/openstack_snapshot.py @@ -9,8 +9,6 @@ # - Neutron networks, subnets and ports # - Routers # - Users and tenants -# - Tacker VNFDs and VNFs -# - Tacker SFCs and SFC classifiers # # Author: # jose.lausuch@ericsson.com @@ -22,16 +20,16 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -import functest.utils.functest_logger as ft_logger -import functest.utils.openstack_utils as os_utils -import functest.utils.openstack_tacker as os_tacker +import logging import yaml -import functest.utils.functest_constants as ft_constants -logger = ft_logger.Logger("openstack_snapshot").getLogger() +import functest.utils.openstack_utils as os_utils +from functest.utils.constants import CONST + +logger = logging.getLogger(__name__) -OS_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE +OS_SNAPSHOT_FILE = CONST.openstack_snapshot_file def separator(): @@ -49,13 +47,13 @@ def get_instances(nova_client): return {'instances': dic_instances} -def get_images(nova_client): +def get_images(glance_client): logger.debug("Getting images...") dic_images = {} - images = os_utils.get_images(nova_client) - if not (images is None or len(images) == 0): - for image in images: - dic_images.update({getattr(image, 'id'): getattr(image, 'name')}) + images = os_utils.get_images(glance_client) + if images is None: + return -1 + dic_images.update({image.id: image.name for image in images}) return {'images': dic_images} @@ -65,7 +63,7 @@ def get_volumes(cinder_client): volumes = os_utils.get_volumes(cinder_client) if volumes is not None: for volume in volumes: - dic_volumes.update({volume.id: volume.display_name}) + dic_volumes.update({volume.id: volume.name}) return {'volumes': dic_volumes} @@ -99,13 +97,14 @@ def get_security_groups(neutron_client): return {'secgroups': dic_secgroups} -def get_floatinips(nova_client): +def get_floatingips(neutron_client): logger.debug("Getting Floating IPs...") dic_floatingips = {} - floatingips = os_utils.get_floating_ips(nova_client) + floatingips = os_utils.get_floating_ips(neutron_client) if not (floatingips is None or len(floatingips) == 0): for floatingip in floatingips: - dic_floatingips.update({floatingip.id: floatingip.ip}) + dic_floatingips.update({floatingip['id']: + floatingip['floating_ip_address']}) return {'floatingips': dic_floatingips} @@ -130,79 +129,31 @@ def get_tenants(keystone_client): return {'tenants': dic_tenants} -def get_tacker_vnfds(tacker_client): - logger.debug("Getting Tacker VNFDs...") - dic_vnfds = {} - vnfds = os_tacker.list_vnfds(tacker_client, verbose=True)['vnfds'] - if not (vnfds is None or len(vnfds) == 0): - for vnfd in vnfds: - dic_vnfds.update({vnfd['id']: - vnfd['name']}) - return {'vnfds': dic_vnfds} - - -def get_tacker_vnfs(tacker_client): - logger.debug("Getting Tacker VNFs...") - dic_vnfs = {} - vnfs = os_tacker.list_vnfs(tacker_client, verbose=True)['vnfs'] - if not (vnfs is None or len(vnfs) == 0): - for vnf in vnfs: - dic_vnfs.update({vnf['id']: - vnf['name']}) - return {'vnfs': dic_vnfs} - - -def get_tacker_sfcs(tacker_client): - logger.debug("Getting Tacker SFCs...") - dic_sfcs = {} - sfcs = os_tacker.list_sfcs(tacker_client, verbose=True)['sfcs'] - if not (sfcs is None or len(sfcs) == 0): - for sfc in sfcs: - dic_sfcs.update({sfc['id']: - sfc['name']}) - return {'sfcs': dic_sfcs} - - -def get_tacker_sfc_classifiers(tacker_client): - logger.debug("Getting Tacker SFC classifiers...") - dic_sfc_clfs = {} - sfc_clfs = os_tacker.list_sfc_clasifiers( - tacker_client, verbose=True)['sfc_classifiers'] - if not (sfc_clfs is None or len(sfc_clfs) == 0): - for sfc_clf in sfc_clfs: - dic_sfc_clfs.update({sfc_clf['id']: - sfc_clf['name']}) - return {'sfc_classifiers': dic_sfc_clfs} - - def main(): + logging.basicConfig() logger.info("Generating OpenStack snapshot...") nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() keystone_client = os_utils.get_keystone_client() cinder_client = os_utils.get_cinder_client() - tacker_client = os_tacker.get_tacker_client() + glance_client = os_utils.get_glance_client() if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run the" + "script again.") - exit(-1) + return -1 snapshot = {} snapshot.update(get_instances(nova_client)) - snapshot.update(get_images(nova_client)) + snapshot.update(get_images(glance_client)) snapshot.update(get_volumes(cinder_client)) snapshot.update(get_networks(neutron_client)) snapshot.update(get_routers(neutron_client)) snapshot.update(get_security_groups(neutron_client)) - snapshot.update(get_floatinips(nova_client)) + snapshot.update(get_floatingips(neutron_client)) snapshot.update(get_users(keystone_client)) snapshot.update(get_tenants(keystone_client)) - snapshot.update(get_tacker_vnfds(tacker_client)) - snapshot.update(get_tacker_vnfs(tacker_client)) - snapshot.update(get_tacker_sfcs(tacker_client)) - snapshot.update(get_tacker_sfc_classifiers(tacker_client)) with open(OS_SNAPSHOT_FILE, 'w+') as yaml_file: yaml_file.write(yaml.safe_dump(snapshot, default_flow_style=False)) @@ -211,7 +162,4 @@ def main(): % yaml_file.read()) logger.debug("NOTE: These objects will NOT be deleted after " + "running the test.") - - -if __name__ == '__main__': - main() + return 0