def clean_enviroment(self, cfy): # ########### CLOUDIFY UNDEPLOYMENT ############# cfy.undeploy_manager() # ############## TNENANT CLEANUP ################ self.ks_cresds = os_utils.get_credentials() self.logger.info("Removing %s tenant .." % CFY_INPUTS['keystone_tenant_name']) keystone = os_utils.get_keystone_client() tenant_id = os_utils.get_tenant_id(keystone, CFY_INPUTS['keystone_tenant_name']) if tenant_id == '': self.logger.error("Error : Failed to get id of %s tenant" % CFY_INPUTS['keystone_tenant_name']) else: resulut = os_utils.delete_tenant(keystone, tenant_id) if not resulut: self.logger.error("Error : Failed to remove %s tenant" % CFY_INPUTS['keystone_tenant_name']) self.logger.info("Removing %s user .." % CFY_INPUTS['keystone_username']) user_id = os_utils.get_user_id(keystone, CFY_INPUTS['keystone_username']) if user_id == '': self.logger.error("Error : Failed to get id of %s user" % CFY_INPUTS['keystone_username']) else: result = os_utils.delete_user(keystone, user_id) if not result: self.logger.error("Error : Failed to remove %s user" % CFY_INPUTS['keystone_username']) return self.set_resultdata(self.testcase_start_time, "", "", self.results)
def remove_users(keystone_client, default_users): logger.info("Removing Users...") users = os_utils.get_users(keystone_client) if users is None: logger.debug("There are no users in the deployment. ") return for user in users: user_name = getattr(user, 'name') user_id = getattr(user, 'id') logger.debug("'%s', ID=%s " % (user_name, user_id)) if user_id not in default_users: logger.debug(" Removing '%s'..." % user_name) if os_utils.delete_user(keystone_client, user_id): logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "user '%s'(%s)..." % (user_name, user_id)) else: logger.debug(" > this is a default user and will " "NOT be deleted.")
def clean(self): self.logger.info("test cleaning") self.logger.info("Removing %s tenant .." % self.tenant_name) tenant_id = os_utils.get_tenant_id(self.keystone_client, self.tenant_name) if tenant_id == '': self.logger.error("Error : Failed to get id of %s tenant" % self.tenant_name) else: if not os_utils.delete_tenant(self.keystone_client, tenant_id): self.logger.error("Error : Failed to remove %s tenant" % self.tenant_name) self.logger.info("Removing %s user .." % self.tenant_name) user_id = os_utils.get_user_id(self.keystone_client, self.tenant_name) if user_id == '': self.logger.error("Error : Failed to get id of %s user" % self.tenant_name) else: if not os_utils.delete_user(self.keystone_client, user_id): self.logger.error("Error : Failed to remove %s user" % self.tenant_name)
def main(): # ############### GENERAL INITIALISATION ################ if not os.path.exists(VIMS_DATA_DIR): os.makedirs(VIMS_DATA_DIR) ks_creds = os_utils.get_credentials("keystone") nv_creds = os_utils.get_credentials("nova") nt_creds = os_utils.get_credentials("neutron") logger.info("Prepare OpenStack plateform (create tenant and user)") keystone = ksclient.Client(**ks_creds) user_id = os_utils.get_user_id(keystone, ks_creds['username']) if user_id == '': step_failure("init", "Error : Failed to get id of " + ks_creds['username']) tenant_id = os_utils.create_tenant( keystone, TENANT_NAME, TENANT_DESCRIPTION) if tenant_id == '': step_failure("init", "Error : Failed to create " + TENANT_NAME + " tenant") roles_name = ["admin", "Admin"] role_id = '' for role_name in roles_name: if role_id == '': role_id = os_utils.get_role_id(keystone, role_name) if role_id == '': logger.error("Error : Failed to get id for %s role" % role_name) if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id): logger.error("Error : Failed to add %s on tenant" % ks_creds['username']) user_id = os_utils.create_user( keystone, TENANT_NAME, TENANT_NAME, None, tenant_id) if user_id == '': logger.error("Error : Failed to create %s user" % TENANT_NAME) logger.info("Update OpenStack creds informations") ks_creds.update({ "username": TENANT_NAME, "password": TENANT_NAME, "tenant_name": TENANT_NAME, }) nt_creds.update({ "tenant_name": TENANT_NAME, }) nv_creds.update({ "project_id": TENANT_NAME, }) logger.info("Upload some OS images if it doesn't exist") glance_endpoint = keystone.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token) for img in IMAGES.keys(): image_name = IMAGES[img]['image_name'] image_url = IMAGES[img]['image_url'] image_id = os_utils.get_image_id(glance, image_name) if image_id == '': logger.info("""%s image doesn't exist on glance repository. Try downloading this image and upload on glance !""" % image_name) image_id = download_and_add_image_on_glance( glance, image_name, image_url) if image_id == '': step_failure( "init", "Error : Failed to find or upload required OS " "image for this deployment") nova = nvclient.Client("2", **nv_creds) logger.info("Update security group quota for this tenant") neutron = ntclient.Client(**nt_creds) if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100): step_failure( "init", "Failed to update security group quota for tenant " + TENANT_NAME) logger.info("Update cinder quota for this tenant") from cinderclient import client as cinderclient creds_cinder = os_utils.get_credentials("cinder") cinder_client = cinderclient.Client('1', creds_cinder['username'], creds_cinder['api_key'], creds_cinder['project_id'], creds_cinder['auth_url'], service_type="volume") if not os_utils.update_cinder_quota(cinder_client, tenant_id, 20, 10, 150): step_failure( "init", "Failed to update cinder quota for tenant " + TENANT_NAME) # ############### CLOUDIFY INITIALISATION ################ cfy = orchestrator(VIMS_DATA_DIR, CFY_INPUTS, logger) cfy.set_credentials(username=ks_creds['username'], password=ks_creds[ 'password'], tenant_name=ks_creds['tenant_name'], auth_url=ks_creds['auth_url']) logger.info("Collect flavor id for cloudify manager server") nova = nvclient.Client("2", **nv_creds) flavor_name = "m1.medium" flavor_id = os_utils.get_flavor_id(nova, flavor_name) for requirement in CFY_MANAGER_REQUIERMENTS: if requirement == 'ram_min': flavor_id = os_utils.get_flavor_id_by_ram_range( nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196) if flavor_id == '': logger.error( "Failed to find %s flavor. " "Try with ram range default requirement !" % flavor_name) flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) if flavor_id == '': step_failure("orchestrator", "Failed to find required flavor for this deployment") cfy.set_flavor_id(flavor_id) image_name = "centos_7" image_id = os_utils.get_image_id(glance, image_name) for requirement in CFY_MANAGER_REQUIERMENTS: if requirement == 'os_image': image_id = os_utils.get_image_id( glance, CFY_MANAGER_REQUIERMENTS['os_image']) if image_id == '': step_failure( "orchestrator", "Error : Failed to find required OS image for cloudify manager") cfy.set_image_id(image_id) ext_net = os_utils.get_external_net(neutron) if not ext_net: step_failure("orchestrator", "Failed to get external network") cfy.set_external_network_name(ext_net) ns = functest_utils.get_resolvconf_ns() if ns: cfy.set_nameservers(ns) logger.info("Prepare virtualenv for cloudify-cli") cmd = "chmod +x " + VIMS_DIR + "create_venv.sh" functest_utils.execute_command(cmd, logger) time.sleep(3) cmd = VIMS_DIR + "create_venv.sh " + VIMS_DATA_DIR functest_utils.execute_command(cmd, logger) cfy.download_manager_blueprint( CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch']) # ############### CLOUDIFY DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("Cloudify deployment Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) error = cfy.deploy_manager() if error: step_failure("orchestrator", error) end_time_ts = time.time() duration = round(end_time_ts - start_time_ts, 1) logger.info("Cloudify deployment duration:'%s'" % duration) set_result("orchestrator", duration, "") # ############### CLEARWATER INITIALISATION ################ cw = clearwater(CW_INPUTS, cfy, logger) logger.info("Collect flavor id for all clearwater vm") nova = nvclient.Client("2", **nv_creds) flavor_name = "m1.small" flavor_id = os_utils.get_flavor_id(nova, flavor_name) for requirement in CW_REQUIERMENTS: if requirement == 'ram_min': flavor_id = os_utils.get_flavor_id_by_ram_range( nova, CW_REQUIERMENTS['ram_min'], 8196) if flavor_id == '': logger.error( "Failed to find %s flavor. Try with ram range " "default requirement !" % flavor_name) flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) if flavor_id == '': step_failure( "vIMS", "Failed to find required flavor for this deployment") cw.set_flavor_id(flavor_id) image_name = "ubuntu_14.04" image_id = os_utils.get_image_id(glance, image_name) for requirement in CW_REQUIERMENTS: if requirement == 'os_image': image_id = os_utils.get_image_id( glance, CW_REQUIERMENTS['os_image']) if image_id == '': step_failure( "vIMS", "Error : Failed to find required OS image for cloudify manager") cw.set_image_id(image_id) ext_net = os_utils.get_external_net(neutron) if not ext_net: step_failure("vIMS", "Failed to get external network") cw.set_external_network_name(ext_net) # ############### CLEARWATER DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("vIMS VNF deployment Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) error = cw.deploy_vnf(CW_BLUEPRINT) if error: step_failure("vIMS", error) end_time_ts = time.time() duration = round(end_time_ts - start_time_ts, 1) logger.info("vIMS VNF deployment duration:'%s'" % duration) set_result("vIMS", duration, "") # ############### CLEARWATER TEST ################ test_clearwater() # ########## CLEARWATER UNDEPLOYMENT ############ cw.undeploy_vnf() # ########### CLOUDIFY UNDEPLOYMENT ############# cfy.undeploy_manager() # ############## GENERAL CLEANUP ################ if args.noclean: exit(0) ks_creds = os_utils.get_credentials("keystone") keystone = ksclient.Client(**ks_creds) logger.info("Removing %s tenant .." % CFY_INPUTS['keystone_tenant_name']) tenant_id = os_utils.get_tenant_id( keystone, CFY_INPUTS['keystone_tenant_name']) if tenant_id == '': logger.error("Error : Failed to get id of %s tenant" % CFY_INPUTS['keystone_tenant_name']) else: if not os_utils.delete_tenant(keystone, tenant_id): logger.error("Error : Failed to remove %s tenant" % CFY_INPUTS['keystone_tenant_name']) logger.info("Removing %s user .." % CFY_INPUTS['keystone_username']) user_id = os_utils.get_user_id( keystone, CFY_INPUTS['keystone_username']) if user_id == '': logger.error("Error : Failed to get id of %s user" % CFY_INPUTS['keystone_username']) else: if not os_utils.delete_user(keystone, user_id): logger.error("Error : Failed to remove %s user" % CFY_INPUTS['keystone_username'])