def test_tenants_update_tenant_validation_error(self): endpoint_array = {'token': {}} tenant_id = self.ADMIN_TENANT_ID job_config = config.JobConfig() try: tenants.OscTenants(job_config).update_tenant({}, tenant_id) except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise try: tenants.OscTenants(job_config).update_tenant(endpoint_array, '') except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise try: tenants.OscTenants(job_config).update_tenant( endpoint_array, tenant_id) except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise
def test_keystone_endpoint_not_found(self): endpoint = self.ENDPOINT_URL admin_user_name = 'admin' admin_password = '******' tenant_id = self.ADMIN_TENANT_ID job_config = config.JobConfig() # Create Token token = tokens.OscTokens(job_config)\ .create_token(admin_user_name, admin_password, endpoint) # Get Endpoints endpoint_array = tokens.OscTokens(job_config).get_endpoints( endpoint, token, admin_user_name, admin_password, tenant_id) endpoint_array['region_id'] = 'regionNotfound' # Create Server try: tenants.OscTenants(job_config)\ .create_tenant(endpoint_array, 'tenant_name_new1') except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG08: raise
def test_tenants_list_tenants_validation_error(self): job_config = config.JobConfig() try: tenants.OscTenants(job_config).list_tenants({}) except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise
def test_tenants_create_tenant_validation_error(self): endpoint_array = {'token': {}} tenant_name = 'test_tenant' job_config = config.JobConfig() try: tenants.OscTenants(job_config).create_tenant({}, tenant_name) except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise try: tenants.OscTenants(job_config).create_tenant(endpoint_array, '') except SystemError as e: if e.args[0] != tenants.OscTenants.EXCEPT_MSG01: raise
def __create_pod_tenant(self, job_input): # Get JOB Input Parameters tenant_name = job_input['tenant_name'] pod_id = job_input['pod_id'] iaas_tenant_name = job_input['IaaS_tenant_name'] operation_id = job_input['operation_id'] dc_id = job_input.get('dc_id', 'system') # Get Endpoint(DB Client) db_endpoint_tenant = self.get_db_endpoint( self.job_config.REST_URI_TENANT) # Create Instance(DB Client) db_list_instance = list.ListClient(self.job_config) db_update_instance = update.UpdateClient(self.job_config) # Get Endpoint(OpenStack:VIM) endpoint_config = self.nal_endpoint_config[dc_id]['vim'][pod_id] os_endpoint = self.get_os_endpoint_vim( pod_id, '', endpoint_config['admin_tenant_id'], dc_id) # Create Instance(OpenStack Client) osc_tenants = tenants.OscTenants(self.job_config) osc_roles = roles.OscRoles(self.job_config) # Create Tenant(OpenStack Client) os_tenant_res = osc_tenants.create_tenant(os_endpoint, iaas_tenant_name) # Add Admin Role To Tenant Admin User(OpenStack Client) osc_roles.add_role_to_user(os_endpoint, endpoint_config['user_key'], os_tenant_res['project']['id'], endpoint_config['role_id']) # List NAL_TENANT_MNG(DB Client) params = {} params['tenant_name'] = tenant_name params['delete_flg'] = 0 db_list_instance.set_context(db_endpoint_tenant, params) db_list_instance.execute() nal_tenant_list = db_list_instance.get_return_param() if len(nal_tenant_list) == 0: raise SystemError('tenant not exists.') rec_id = nal_tenant_list[0]['ID'] tenant_info = json.loads(nal_tenant_list[0]['tenant_info']) tenant_info_wk = os_tenant_res['project'] tenant_info_wk['pod_id'] = pod_id tenant_info_wk['msa_customer_name'] = '' tenant_info_wk['msa_customer_id'] = 0 tenant_info.append(tenant_info_wk) # Update NAL_VNF_MNG(DB Client):Set DeleteFlg On params = {} params['update_id'] = operation_id params['tenant_info'] = json.dumps(tenant_info) keys = [rec_id] db_update_instance.set_context(db_endpoint_tenant, keys, params) db_update_instance.execute() job_output = { 'nal_tenant_id': os_tenant_res['project']['id'], 'nal_tenant_name': os_tenant_res['project']['name'], } return job_output
def test_keystone(self): endpoint = self.ENDPOINT_URL admin_user_name = 'admin' admin_password = '******' tenant_name = 'test_tenant' tenant_id = self.ADMIN_TENANT_ID user_name = 'test_user' user_password = '******' role_id = self.ADMIN_ROLE_ID job_config = config.JobConfig() # Create Token token = tokens.OscTokens(job_config)\ .create_token(admin_user_name, admin_password, endpoint, tokens.OscTokens.DOMAIN_NAME_DEFAULT) print('create_token') print(token) # Assertion self.assertGreaterEqual(len(token), 1) # Get Endpoints endpoint_array = tokens.OscTokens(job_config).get_endpoints( endpoint, token, admin_user_name, admin_password, tenant_id, tokens.OscTokens.DOMAIN_NAME_DEFAULT) print('get_endpoints') print(json.dumps(endpoint_array)) # Assertion self.assertGreaterEqual(len(endpoint_array), 1) # Create Token token = tokens.OscTokens(job_config)\ .create_token(admin_user_name, admin_password, endpoint) print('create_token') print(token) # Assertion self.assertGreaterEqual(len(token), 1) # Get Endpoints endpoint_array = tokens.OscTokens(job_config).get_endpoints( endpoint, token, admin_user_name, admin_password, tenant_id) print('get_endpoints') print(json.dumps(endpoint_array)) # Assertion self.assertGreaterEqual(len(endpoint_array), 1) endpoint_array['region_id'] = self.REGION_ID # Create Tenant tenant_name_new1 = tenant_name + '1-' + datetime.datetime.today( ).strftime('%Y%m%d%H%M%S') res = tenants.OscTenants(job_config)\ .create_tenant(endpoint_array, tenant_name_new1) print('create_tenant') print(json.dumps(res)) tenant_id_new1 = res['project']['id'] # Assertion self.assertGreaterEqual(len(res), 1) tenant_name_new2 = tenant_name + '2-' + datetime.datetime.today( ).strftime('%Y%m%d%H%M%S') res = tenants.OscTenants(job_config)\ .create_tenant(endpoint_array, tenant_name_new2, 'test KeystoneV3', False, tenants.OscTenants.DOMAIN_ID_DEFAULT, False) print('create_tenant') print(json.dumps(res)) tenant_id_new2 = res['project']['id'] # Assertion self.assertGreaterEqual(len(res), 1) # Get Tenant res = tenants.OscTenants(job_config)\ .get_tenant(endpoint_array, tenant_id_new1) print('get_tenant') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Update Tenant res = tenants.OscTenants(job_config).update_tenant( endpoint_array, tenant_id_new1, tenant_name_new1 + 'upd') print('update_tenant') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) res = tenants.OscTenants(job_config).update_tenant( endpoint_array, tenant_id_new2, tenant_name_new2 + 'upd', 'update', True, tenants.OscTenants.DOMAIN_ID_DEFAULT, False) print('update_tenant') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Tenants res = tenants.OscTenants(job_config).list_tenants(endpoint_array) print('list_tenants') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create User user_name_new1 = user_name + '1-' + datetime.datetime.today().strftime( '%Y%m%d%H%M%S') res = users.OscUsers(job_config).create_user(endpoint_array, user_name_new1, user_password, tenant_id_new1) print('create_user') print(json.dumps(res)) user_id_new1 = res['user']['id'] # Assertion self.assertGreaterEqual(len(res), 1) # Create User user_name_new2 = user_name + '2-' + datetime.datetime.today().strftime( '%Y%m%d%H%M%S') res = users.OscUsers(job_config).create_user( endpoint_array, user_name_new2, user_password, tenant_id_new2, '*****@*****.**', True, users.OscUsers.DOMAIN_ID_DEFAULT) print('create_user') print(json.dumps(res)) user_id_new2 = res['user']['id'] # Assertion self.assertGreaterEqual(len(res), 1) # Get User res = users.OscUsers(job_config).get_user(endpoint_array, user_id_new1) print('get_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get User res = users.OscUsers(job_config).get_user(endpoint_array, user_id_new2) print('get_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Role For User res = roles.OscRoles(job_config)\ .list_roles_for_user(endpoint_array, user_id_new1, tenant_id_new1) print('list_roles_for_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Update User res = users.OscUsers(job_config).update_user(endpoint_array, user_id_new1, None, user_name_new1 + 'upd') print('update_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Update User res = users.OscUsers(job_config).update_user( endpoint_array, user_id_new2, tenant_id, user_name_new2 + 'upd', '*****@*****.**', 'pass-update', False, users.OscUsers.DOMAIN_ID_DEFAULT) print('update_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get User res = users.OscUsers(job_config).get_user(endpoint_array, user_id_new1) print('get_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get User res = users.OscUsers(job_config).get_user(endpoint_array, user_id_new2) print('get_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Users res = users.OscUsers(job_config).list_users(endpoint_array) print('list_users') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Role res = roles.OscRoles(job_config).list_roles(endpoint_array) print('list_roles') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Add Role To User res = roles.OscRoles(job_config).add_role_to_user( endpoint_array, user_id_new1, tenant_id_new1, role_id) print('add_role_to_user') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # List Role For User res = roles.OscRoles(job_config)\ .list_roles_for_user(endpoint_array, user_id_new1, tenant_id_new1) print('list_roles_for_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Remove Role From User res = roles.OscRoles(job_config).remove_role_from_user( endpoint_array, user_id_new1, tenant_id_new1, role_id) print('remove_role_from_user') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # List Role For User res = roles.OscRoles(job_config)\ .list_roles_for_user(endpoint_array, user_id_new1, tenant_id_new1) print('list_roles_for_user') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Delete User res = users.OscUsers(job_config)\ .delete_user(endpoint_array, user_id_new1) print('delete_user') print(json.dumps(res)) # Delete User res = users.OscUsers(job_config)\ .delete_user(endpoint_array, user_id_new2) print('delete_user') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # List Users res = users.OscUsers(job_config).list_users( endpoint_array, users.OscUsers.DOMAIN_ID_DEFAULT) print('list_users') print(json.dumps(res)) # Delete Tenant res = tenants.OscTenants(job_config)\ .delete_tenant(endpoint_array, tenant_id_new1) print('delete_tenant') print(json.dumps(res)) res = tenants.OscTenants(job_config)\ .delete_tenant(endpoint_array, tenant_id_new2) print('delete_tenant') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0)