def get_project_id(self, name=None): if not name: return get_dashed_uuid(self.keystone.tenant_id) try: obj = self.keystone.tenants.find(name=name) return get_dashed_uuid(obj.id) except ks_exceptions.NotFound: return None
def create_project(self, project_name, domain_name='Default'): if self.version == '3': domain = self.find_domain(domain_name) return get_dashed_uuid( self.keystone.projects.create(name=project_name, domain=domain).id) else: return get_dashed_uuid( self.keystone.tenants.create(project_name).id)
def get_vn_obj_if_present(self, vn_name, project_id=None): if not project_id: project_id = get_dashed_uuid(self.project_id) try: net_rsp = self.obj.list_networks() for (x, y, z) in [(network['name'], network['id'], network['tenant_id']) for network in net_rsp['networks']]: dashed_tenant_id = get_dashed_uuid(z) if vn_name == x and project_id in dashed_tenant_id: net_id = y return self.obj.show_network(network=net_id) except CommonNetworkClientException as e: self.logger.exception( "Some exception while doing Quantum net-list") raise NetworkClientException(message=str(e)) return None
def setUp(self): super(UserFixture, self).setUp() try: ks_project = self.keystone.tenants.find(name=self.inputs.project_name) if ks_project: self.project_id = get_dashed_uuid(ks_project.id) self.logger.debug( 'Project %s already present. Check user %s exist' % (self.inputs.project_name, self.username)) if self.get_user_dct(self.username): self.logger.info('User %s already exist, skip creation' % self.username) self.already_present = True else: try: self.create_user( self.username, self.password, email=self.email, tenant_name=self.inputs.project_name, enabled=True) assert self.verify_on_setup() except Exception as e: self.logger.warn('User creation failed for exception %s...' % (e)) #if test tenant already created, associate user to tenant if self.tenant: if self.get_tenant_dct(self.tenant): self.logger.info('Tenant %s exists, associate user %s..' % (self.tenant, self.username)) self.add_user_to_tenant(self.tenant, self.username, self.role) except ks_exceptions.NotFound, e: self.logger.info('Project %s not found, skip creating user %s' % ( self.project_name, self.username))
def get_project_id(self, name, domain_id): try: if self.version == '3': domain_id = domain_id or 'default' obj = self.keystone.projects.find(name=name, domain_id=domain_id) else: obj = self.keystone.tenants.find(name=name) return get_dashed_uuid(obj.id) except ks_exceptions.NotFound: return None
def __init__(self, inputs,logger, project_name=None, username=None, password=None): self.inputs = inputs project_name = project_name or self.inputs.project_name username = username or self.inputs.stack_user password = password or self.inputs.stack_password self.keystone_ip = self.inputs.keystone_ip insecure = bool(os.getenv('OS_INSECURE', True)) self.ks_client = ks_client.Client( username=username, password=password, tenant_name=project_name, auth_url = os.getenv('OS_AUTH_URL') or \ 'http://' + self.keystone_ip + ':5000/v2.0', insecure=insecure) self.project_id = get_dashed_uuid(self.ks_client.tenant_id) if self.inputs.verify_thru_gui(): self.ui_login = UILogin(self, self.inputs, project_name, username, password) self.browser = self.ui_login.browser self.browser_openstack = self.ui_login.browser_openstack self.quantum_fixture = QuantumFixture( username=username, inputs=self.inputs, project_id=self.project_id, password=password, cfgm_ip=self.inputs.cfgm_ip, openstack_ip=self.inputs.openstack_ip) self.quantum_fixture.setUp() inputs.openstack_ip = self.inputs.openstack_ip self.vnc_lib_fixture = VncLibFixture( username=username, password=password, domain=self.inputs.domain_name, project=project_name, inputs=self.inputs, cfgm_ip=self.inputs.cfgm_ip, api_port=self.inputs.api_server_port) self.vnc_lib_fixture.setUp() self.vnc_lib = self.vnc_lib_fixture.get_handle() self.nova_fixture = NovaFixture(inputs=inputs, project_name=project_name, username=username, password=password) self.nova_fixture.setUp() self.api_server_inspects = {} self.dnsagent_inspect = {} self.cn_inspect = {} self.agent_inspect = {} self.ops_inspects = {} self.ds_inspect = {} self.update_inspect_handles()
def setUp(self): super(UserFixture, self).setUp() if self.inputs.orchestrator == 'vcenter': # No concept of user in vcenter return try: ks_project = self.keystone.tenants.find( name=self.inputs.project_name) if ks_project: self.project_id = get_dashed_uuid(ks_project.id) self.logger.debug( 'Project %s already present. Check user %s exist' % (self.inputs.project_name, self.username)) if self.get_user_dct(self.username): self.logger.info( 'User %s already exists, skipping creation' % self.username) self.already_present = True else: try: self.create_user(self.username, self.password, email=self.email, tenant_name=self.inputs.project_name, enabled=True) assert self.verify_on_setup() except Exception as e: self.logger.warn( 'User creation failed for exception %s...' % (e)) #if test tenant already created, associate user to tenant if self.tenant: if self.get_tenant_dct(self.tenant): self.logger.info( 'Tenant %s exists, associate user %s..' % (self.tenant, self.username)) self.add_user_to_tenant(self.tenant, self.username, self.role) except ks_exceptions.NotFound, e: self.logger.info('Project %s not found, skip creating user %s' % (self.project_name, self.username))
def get_id(self): return get_dashed_uuid(self.keystone.auth_tenant_id)
def get_id(self): return get_dashed_uuid(self.session.get_project_id())
def get_id(self): if self.version == '3' and self.scope == 'domain': return self.get_project_id(self.project, self.domain_id) return get_dashed_uuid(self.session.get_project_id())
def __init__(self, inputs,logger, project_name=None, username=None, password=None): self.inputs = inputs project_name = project_name or self.inputs.project_name username = username or self.inputs.stack_user password = password or self.inputs.stack_password self.keystone_ip = self.inputs.keystone_ip self.ks_client = ks_client.Client( username=username, password=password, tenant_name=project_name, auth_url = os.getenv('OS_AUTH_URL') or \ 'http://' + self.keystone_ip + ':5000/v2.0' ) self.project_id = get_dashed_uuid(self.ks_client.tenant_id) if self.inputs.webui_verification_flag: self.os_type = self.inputs.os_type self.webui_ip = self.inputs.webui_ip self.os_name = self.os_type[self.webui_ip] self.start_virtual_display() self.delay = 30 self.frequency = 1 if not ContrailConnections.browser: if self.inputs.webui_verification_flag == 'firefox': ContrailConnections.browser = webdriver.Firefox() ContrailConnections.browser_openstack = webdriver.Firefox() elif self.inputs.webui_verification_flag == 'chrome': ContrailConnections.browser = webdriver.Chrome() ContrailConnections.browser_openstack = webdriver.Chrome() else: self.inputs.logger.error("Invalid browser type") self.login_webui(project_name, username, password) self.login_openstack(project_name, username, password) self.quantum_fixture = QuantumFixture( username=username, inputs=self.inputs, project_id=self.project_id, password=password, cfgm_ip=self.inputs.cfgm_ip, openstack_ip=self.inputs.openstack_ip) self.quantum_fixture.setUp() inputs.openstack_ip = self.inputs.openstack_ip self.vnc_lib_fixture = VncLibFixture( username=username, password=password, domain=self.inputs.domain_name, project=project_name, inputs=self.inputs, cfgm_ip=self.inputs.cfgm_ip, api_port=self.inputs.api_server_port) self.vnc_lib_fixture.setUp() self.vnc_lib = self.vnc_lib_fixture.get_handle() self.nova_fixture = NovaFixture(inputs=inputs, project_name=project_name, username=username, password=password) self.nova_fixture.setUp() self.api_server_inspects = {} for cfgm_ip in self.inputs.cfgm_ips: self.api_server_inspects[cfgm_ip] = VNCApiInspect(cfgm_ip, args=self.inputs, logger=self.inputs.logger) self.api_server_inspect = VNCApiInspect(cfgm_ip, args=self.inputs, logger=self.inputs.logger) self.cn_inspect = {} for bgp_ip in self.inputs.bgp_ips: self.cn_inspect[bgp_ip] = ControlNodeInspect(bgp_ip, logger=self.inputs.logger) self.agent_inspect = {} for compute_ip in self.inputs.compute_ips: self.agent_inspect[compute_ip] = AgentInspect(compute_ip, logger=self.inputs.logger) self.dnsagent_inspect = {} for bgp_ip in self.inputs.bgp_ips: self.dnsagent_inspect[bgp_ip] = DnsAgentInspect( bgp_ip, logger=self.inputs.logger) self.ops_inspects = {} for collector_ip in self.inputs.collector_ips: self.ops_inspects[collector_ip] = VerificationOpsSrv(collector_ip, logger=self.inputs.logger) self.ops_inspect = VerificationOpsSrv(self.inputs.collector_ip, logger=self.inputs.logger) for collector_name in self.inputs.collector_names: self.ops_inspects[collector_name] = VerificationOpsSrv( collector_ip, logger=self.inputs.logger) self.analytics_obj = AnalyticsVerification( self.inputs, self.api_server_inspect, self.cn_inspect, self.agent_inspect, self.ops_inspects, logger=self.inputs.logger) self.ds_inspect = {} for ds_ip in self.inputs.ds_server_ip: self.ds_inspect[ds_ip] = VerificationDsSrv( ds_ip, logger=self.inputs.logger) self.ds_verification_obj = DiscoveryVerification( self.inputs, self.api_server_inspect, self.cn_inspect, self.agent_inspect, self.ops_inspects, self.ds_inspect, logger=self.inputs.logger)
def delete(self): if self.is_already_present: self.logger.info('Skipping deletion of InterfaceRouteTable %s' % (self.fq_name)) return if self.inputs.is_gui_based_config(): self.webui.delete_intf_route_table(self) else: if self.inputs.ns_agilio_vrouter_data: vmi_id = self.obj.get_virtual_machine_interface_back_refs( )[0]['uuid'] self.vnc_h.unbind_vmi_from_interface_route_table( vmi_id, self.obj) self.vnc_h.delete_interface_route_table(self.uuid) self.verify_on_cleanup() # end delete if __name__ == "__main__": rtb_fixture = InterfaceRouteTableFixture( name='rtb1', prefixes=['10.1.1.0/24'], project_id=get_dashed_uuid('24c8d6f768c843a2ac83f5a8ff847073'), auth_server_ip='10.204.216.184', cfgm_ip='10.204.216.184') rtb_fixture.setUp() import pdb pdb.set_trace() rtb_fixture.cleanUp()
def __init__(self, inputs,logger, project_name=None, username=None, password=None): self.inputs = inputs project_name = project_name or self.inputs.project_name username = username or self.inputs.stack_user password = password or self.inputs.stack_password self.keystone_ip = self.inputs.keystone_ip insecure = bool(os.getenv('OS_INSECURE', True)) self.ks_client = ks_client.Client( username=username, password=password, tenant_name=project_name, auth_url = os.getenv('OS_AUTH_URL') or \ 'http://' + self.keystone_ip + ':5000/v2.0', insecure=insecure) self.project_id = get_dashed_uuid(self.ks_client.tenant_id) if self.inputs.verify_thru_gui(): global webui if not webui: raise ImportError("Selenium and/or pyvirtualdisplay python packages are missing") self.ui_login = UILogin(self, self.inputs, project_name, username, password) self.browser = self.ui_login.browser self.browser_openstack = self.ui_login.browser_openstack self.quantum_fixture = QuantumFixture( username=username, inputs=self.inputs, project_id=self.project_id, password=password, cfgm_ip=self.inputs.cfgm_ip, openstack_ip=self.inputs.openstack_ip) self.quantum_fixture.setUp() inputs.openstack_ip = self.inputs.openstack_ip self.vnc_lib_fixture = VncLibFixture( username=username, password=password, domain=self.inputs.domain_name, project=project_name, inputs=self.inputs, cfgm_ip=self.inputs.cfgm_ip, api_port=self.inputs.api_server_port) self.vnc_lib_fixture.setUp() self.vnc_lib = self.vnc_lib_fixture.get_handle() self.nova_fixture = NovaFixture(inputs=inputs, project_name=project_name, username=username, password=password) self.nova_fixture.setUp() self.api_server_inspects = {} for cfgm_ip in self.inputs.cfgm_ips: self.api_server_inspects[cfgm_ip] = VNCApiInspect(cfgm_ip, args=self.inputs, logger=self.inputs.logger) self.api_server_inspect = VNCApiInspect(cfgm_ip, args=self.inputs, logger=self.inputs.logger) self.cn_inspect = {} for bgp_ip in self.inputs.bgp_ips: self.cn_inspect[bgp_ip] = ControlNodeInspect(bgp_ip, logger=self.inputs.logger) self.agent_inspect = {} for compute_ip in self.inputs.compute_ips: self.agent_inspect[compute_ip] = AgentInspect(compute_ip, logger=self.inputs.logger) self.dnsagent_inspect = {} for bgp_ip in self.inputs.bgp_ips: self.dnsagent_inspect[bgp_ip] = DnsAgentInspect( bgp_ip, logger=self.inputs.logger) self.ops_inspects = {} for collector_ip in self.inputs.collector_ips: self.ops_inspects[collector_ip] = VerificationOpsSrv(collector_ip, logger=self.inputs.logger) self.ops_inspect = VerificationOpsSrv(self.inputs.collector_ip, logger=self.inputs.logger) for collector_name in self.inputs.collector_names: self.ops_inspects[collector_name] = VerificationOpsSrv( collector_ip, logger=self.inputs.logger) self.analytics_obj = AnalyticsVerification( self.inputs, self.api_server_inspect, self.cn_inspect, self.agent_inspect, self.ops_inspects, logger=self.inputs.logger) self.ds_inspect = {} for ds_ip in self.inputs.ds_server_ip: self.ds_inspect[ds_ip] = VerificationDsSrv( ds_ip, logger=self.inputs.logger) self.ds_verification_obj = DiscoveryVerification( self.inputs, self.api_server_inspect, self.cn_inspect, self.agent_inspect, self.ops_inspects, self.ds_inspect, logger=self.inputs.logger)
def create_project(self, name): return get_dashed_uuid(self.keystone.tenants.create(name).id)
def get_project_id(self, name): try: obj = self.keystone.tenants.find(name=name) return get_dashed_uuid(obj.id) except ks_exceptions.NotFound: return None
def create_domain(self, domain_name): return get_dashed_uuid(self.keystone.domains.create(domain_name).id)
def create_project(self, project_name, domain_name='Default'): if self.version == '3': domain=self.find_domain(domain_name) return get_dashed_uuid(self.keystone.projects.create(name=project_name, domain=domain).id) else: return get_dashed_uuid(self.keystone.tenants.create(project_name).id)
self._populate_attr(intf_rtb_obj) self.is_already_present = True # end read def add_routes(self, prefixes): intf_rtb_obj = self.vnc_h.add_interface_route_table_routes(self.uuid, prefixes=prefixes) self._populate_attr(intf_rtb_obj) def del_routes(self, prefixes): self.vnc_h.del_interface_route_table_routes(prefixes) self._populate_attr(intf_rtb_obj) # end del_routes def delete(self): if self.is_already_present: self.logger.info('Skipping deletion of InterfaceRouteTable %s' % ( self.fq_name)) return self.vnc_h.delete_interface_route_table(self.uuid) self.verify_on_cleanup() # end delete if __name__ == "__main__": rtb_fixture = InterfaceRouteTableFixture( name='rtb1', prefixes=['10.1.1.0/24'], project_id=get_dashed_uuid('24c8d6f768c843a2ac83f5a8ff847073'), auth_server_ip='10.204.216.184', cfgm_ip='10.204.216.184') rtb_fixture.setUp() import pdb pdb.set_trace() rtb_fixture.cleanUp()