def assign_role(keystone, user_name, role, is_admin): is_platform = True if keystone == 'platform' else False LOG.tc_step('Assign test user {} with {}'.format(user_name, role)) admin_auth = Tenant.get('admin_platform') if is_platform else Tenant.get( 'admin') keystone_helper.add_or_remove_role(add_=is_admin, role='admin', user=user_name, auth_info=admin_auth, project='admin') user_dict_name = '{}_platform'.format( user_name) if is_platform else user_name password = Tenant.get(user_dict_name)['password'] LOG.tc_step( 'Run {} OpenStack command using {}/{} and ensure it works'.format( keystone, user_name, password)) verify_user(user_name, password, is_admin=is_admin, keystone=keystone)
def remove_shared_cpu(self, request, config_host_class): storage_backing, hosts = keywords.host_helper.get_storage_backing_with_max_hosts() assert hosts, "No hypervisor in storage aggregate" avail_zone = None hosts_unconfigured = [] for host in hosts: shared_cores_host = host_helper.get_host_cpu_cores_for_function(hostname=host, func='shared', thread=0) if shared_cores_host[0] or shared_cores_host.get(1, None): hosts_unconfigured.append(host) if not hosts_unconfigured: return storage_backing, avail_zone hosts_configured = list(set(hosts) - set(hosts_unconfigured)) hosts_to_configure = [] if len(hosts_configured) < 2: hosts_to_configure = hosts_unconfigured[:(2-len(hosts_configured))] for host_to_config in hosts_to_configure: shared_cores = host_helper.get_host_cpu_cores_for_function(host_to_config, 'shared', thread=0) p1_config = p1_revert = None if 1 in shared_cores: p1_config = 0 p1_revert = len(shared_cores[1]) def _modify(host_): host_helper.modify_host_cpu(host_, 'shared', p0=0, p1=p1_config) def _revert(host_): host_helper.modify_host_cpu(host_, 'shared', p0=len(shared_cores[0]), p1=p1_revert) config_host_class(host=host_to_config, modify_func=_modify, revert_func=_revert) host_helper.wait_for_hypervisors_up(host_to_config) hosts_configured.append(host_to_config) hosts_unconfigured.remove(host_to_config) if hosts_unconfigured: avail_zone = 'cgcsauto' LOG.fixture_step("({}) Add admin role to user under primary tenant and add configured hosts {} to " "cgcsauto aggregate".format('class', hosts_configured)) nova_helper.create_aggregate(name='cgcsauto', avail_zone='cgcsauto', check_first=True) code = keystone_helper.add_or_remove_role(add_=True, role='admin')[0] def remove_admin(): nova_helper.delete_aggregates(avail_zone, remove_hosts=True) if code != -1: LOG.fixture_step("({}) Remove admin role and cgcsauto aggregate".format('class')) keystone_helper.add_or_remove_role(add_=False, role='admin') request.addfinalizer(remove_admin) nova_helper.add_hosts_to_aggregate(aggregate=avail_zone, hosts=hosts_configured) return storage_backing, avail_zone
def __add_admin_role(scope, request): LOG.fixture_step( "({}) Add admin role to user under primary tenant".format(scope)) code = keystone_helper.add_or_remove_role(add_=True, role='admin')[0] def remove_admin(): if code != -1: LOG.fixture_step( "({}) Remove admin role from user under primary tenant".format( scope)) keystone_helper.add_or_remove_role(add_=False, role='admin') request.addfinalizer(remove_admin)
def create_tenants_and_update_quotas( new_tenants_index=(3, 6), add_swift_role=False): """ Create tenant3-6 and update quotas for admin and the new tenants """ projects = ['admin'] roles = ['_member_', 'admin'] if add_swift_role: roles.append('SwiftOperator') if new_tenants_index: for i in range(new_tenants_index[0], new_tenants_index[1] + 1): name = 'tenant{}'.format(i) keystone_helper.create_project(name=name, description=name, rtn_exist=True) keystone_helper.create_user(name=name, rtn_exist=True, password=USER_PASSWORD) for role in roles: if role == 'SwiftOperator' and name == 'admin': continue user = '******' if role == 'admin' else name keystone_helper.add_or_remove_role(role=role, project=name, user=user) projects.append(name) for project in projects: vm_helper.set_quotas(tenant=project, instances=20, cores=50, volumes=30, snapshots=20, ports=500, subnets=100, networks=100, **{'floating-ips': 50})
def create_test_user(request): keystone = request.param if keystone == 'stx-openstack' and not container_helper.is_stx_openstack_deployed( ): skip('stx-openstack is not applied') LOG.fixture_step( "Creating {} keystone user {} for password rules testing".format( keystone, TEST_USER_NAME)) auth_info = Tenant.get( 'admin_platform') if keystone == 'platform' else Tenant.get('admin') existing_users = keystone_helper.get_users(field='Name', auth_info=auth_info) print(existing_users, "exiting userssss") if TEST_USER_NAME in existing_users: keystone_helper.delete_users(TEST_USER_NAME, auth_info=auth_info) keystone_helper.create_user(name=TEST_USER_NAME, password=TEST_PASSWORD, auth_info=auth_info, project='admin') existing_users = keystone_helper.get_users(field='Name', auth_info=auth_info) print(existing_users, "exiting userssss") save_used_password(keystone, TEST_PASSWORD) keystone_helper.add_or_remove_role(add_=True, role='member', user=TEST_USER_NAME, auth_info=auth_info, project='admin') def delete(): LOG.fixture_step("Delete keystone test {}".format(TEST_USER_NAME)) keystone_helper.delete_users(TEST_USER_NAME, auth_info=auth_info) request.addfinalizer(delete) return keystone
def add_admin_role(request): if not system_helper.is_avs(): skip("vshell commands unsupported by OVS") primary_tenant = Tenant.get_primary() other_tenant = Tenant.get_secondary() tenants = [primary_tenant, other_tenant] res = [] for auth_info in tenants: code = keystone_helper.add_or_remove_role(add_=True, role='admin', user=auth_info.get('user'), project=auth_info.get('tenant'))[0] res.append(code) def remove_admin_role(): for i in range(len(res)): if res[i] != -1: auth_info_ = tenants[i] keystone_helper.add_or_remove_role(add_=False, role='admin', user=auth_info_.get('user'), project=auth_info_.get('tenant')) request.addfinalizer(remove_admin_role)
def remove_admin(): nova_helper.delete_aggregates(avail_zone, remove_hosts=True) if code != -1: LOG.fixture_step("({}) Remove admin role and cgcsauto aggregate".format('class')) keystone_helper.add_or_remove_role(add_=False, role='admin')
def remove_admin_role(): for i in range(len(res)): if res[i] != -1: auth_info_ = tenants[i] keystone_helper.add_or_remove_role(add_=False, role='admin', user=auth_info_.get('user'), project=auth_info_.get('tenant'))
def remove_admin(): if code != -1: LOG.fixture_step( "({}) Remove admin role from user under primary tenant".format( scope)) keystone_helper.add_or_remove_role(add_=False, role='admin')