Example #1
0
 def __init__(self,
              connections,
              auth=None,
              domain_name=None,
              username=None,
              password=None,
              role='admin',
              uuid=None):
     self.inputs = connections.inputs
     self.vnc_lib_h = connections.get_vnc_lib_h()
     self.logger = connections.logger
     self.connections = connections
     self.auth = connections.auth
     self.domain_name = domain_name
     self.uuid = uuid
     self.domain_obj = None
     self.already_present = False
     self.domain_fq_name = [self.domain_name]
     self.username = username
     self.password = password
     self.role = role
     self.domain_connections = None
     self.api_server_inspect = self.connections.api_server_inspect
     self.verify_is_run = False
     if not self.auth:
         if self.inputs.orchestrator == 'openstack':
             self.auth = OpenstackAuth(self.inputs.admin_username,
                                       self.inputs.admin_password,
                                       self.inputs.admin_tenant,
                                       domain_name=self.inputs.admin_domain,
                                       inputs=self.inputs,
                                       logger=self.logger)
     self.domain_username = None
     self.domain_password = None
Example #2
0
    def get_auth_h(self,
                   refresh=False,
                   project_name=None,
                   username=None,
                   password=None,
                   domain_name=None):
        project_name = project_name or self.project_name
        username = username or self.username
        password = password or self.password
        attr = '_auth_' + project_name + '_' + username
        if not getattr(env, attr, None) or refresh:
            if self.inputs.orchestrator == 'openstack':
                env[attr] = OpenstackAuth(username,
                                          password,
                                          project_name,
                                          self.inputs,
                                          self.logger,
                                          domain_name=domain_name
                                          or self.orch_domain_name,
                                          scope=self.scope)
            elif self.inputs.orchestrator == 'vcenter':
                env[attr] = VcenterAuth(username, password, project_name,
                                        self.inputs)
#            elif self.inputs.orchestrator == 'kubernetes':
#                env[attr] = self.get_k8s_api_client_handle()
        return env.get(attr)
Example #3
0
    def setUpClass(cls):
        super(CeilometerBaseTest, cls).setUpClass()
        cls.auth = OpenstackAuth(cls.inputs.stack_user,
                              cls.inputs.stack_password,
                              cls.inputs.project_name, cls.inputs, cls.logger)
        if not cls.auth.verify_service_enabled('ceilometer'):
            inst = cls()
            raise inst.skipTest(
                "Skipping Test.Ceilometer not enabled in the setup")
        cls.quantum_h= cls.connections.quantum_h
        cls.nova_h = cls.connections.nova_h
        cls.vnc_lib= cls.connections.vnc_lib
        cls.agent_inspect= cls.connections.agent_inspect
        cls.cn_inspect= cls.connections.cn_inspect
        cls.analytics_obj=cls.connections.analytics_obj
        if cls.inputs.admin_username:
            public_creds = cls.admin_isolated_creds
        else:
            public_creds = cls.isolated_creds
        cls.public_vn_obj = create_public_vn.PublicVn(
            connections=cls.connections,
            isolated_creds_obj=public_creds,
            logger=cls.logger)

        resource_class = cls.__name__ + 'Resource'
        cls.res = ResourceFactory.createResource(resource_class)
 def __init__(self, vnc_lib_h, connections, auth=None, project_name=None,
              username=None, password=None, role='admin', scale= False):
     self.inputs = connections.inputs
     if not project_name:
         project_name = self.inputs.stack_tenant
     self.vnc_lib_h = vnc_lib_h
     self.connections = connections
     self.auth = auth
     self.project_name = project_name
     self.project_obj = None
     self.domain_name = 'default-domain'
     self.already_present = False
     self.logger = connections.inputs.logger
     self.project_fq_name = [self.domain_name, self.project_name]
     self.username = username
     self.password = password
     self.role = role
     self.user_dict = {}
     self._create_user_set = {}
     self.project_connections = None
     self.api_server_inspects = self.connections.api_server_inspects
     self.verify_is_run = False
     self.scale = scale
     if not self.auth:
         if self.inputs.orchestrator == 'openstack':
             self.auth = OpenstackAuth(self.inputs.stack_user,
                           self.inputs.stack_password,
                           self.inputs.project_name, self.inputs, self.logger)
         else: # vcenter
             self.auth = VcenterAuth(self.inputs.stack_user,
                           self.inputs.stack_password,
                           self.inputs.project_name, self.inputs)
Example #5
0
 def setUp(self):
     super(VncLibFixture, self).setUp()
     if not self.connections:
         self.logger = self.logger or contrail_logging.getLogger(__name__)
         self.vnc_api_h = VncApi(username=self.username,
                                 password=self.password,
                                 tenant_name=self.project_name,
                                 domain_name=self.orch_domain,
                                 api_server_host=self.cfgm_ip,
                                 api_server_port=self.api_server_port,
                                 auth_host=self.auth_server_ip,
                                 auth_port=self.auth_port,
                                 api_server_use_ssl=self.use_ssl,
                                 auth_url=self.authn_url)
         if self.orchestrator == 'openstack':
             self.auth_client = OpenstackAuth(self.username,
                                              self.password,
                                              self.project_name,
                                              domain_name=self.orch_domain,
                                              auth_url=self.auth_url,
                                              certfile=self.certfile,
                                              keyfile=self.keyfile,
                                              cacert=self.cacert,
                                              insecure=self.insecure,
                                              logger=self.logger,
                                              scope='project')
         elif self.orchestrator == 'vcenter':
             self.auth_client = VcenterAuth(self.username, self.password,
                                            self.project_name, self.inputs)
     if self.orch:
         self.vnc_h = self.orch.vnc_h
     else:
         self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
 def setUp(self):
     super(VncLibFixture, self).setUp()
     if self.connections:
         self.logger = self.connections.logger
         self.project_name = self.connections.project_name
         self.inputs = self.connections.inputs
         self.neutron_handle = self.connections.quantum_h
         self.vnc_api_h = self.connections.vnc_lib
         self.username = self.connections.username
         self.password = self.connections.password
         self.cfgm_ip = self.inputs.cfgm_ip
         self.auth_server_ip = self.inputs.auth_ip
         self.project_id = self.connections.project_id
         self.auth_url = 'http://' + self.inputs.auth_ip + ':5000/v2.0'
     else:
         self.vnc_api_h = VncApi(username=self.username,
                                 password=self.password,
                                 tenant_name=self.project_name,
                                 api_server_host=self.cfgm_ip,
                                 api_server_port=self.api_server_port,
                                 auth_host=self.auth_server_ip)
         if self.orchestrator == 'openstack':
             self.auth_client = OpenstackAuth(self.username,
                                              self.password,
                                              self.project_name,
                                              auth_url=self.auth_url,
                                              logger=self.logger)
             self.project_id = self.auth_client.get_project_id()
         elif self.orchestrator == 'vcenter':
             self.auth_client = VcenterAuth(self.username, self.password,
                                            self.project_name, self.inputs)
             self.project_id = self.auth_client.get_project_id()
Example #7
0
 def __init__(self, connections, auth=None, project_name=None,
              username=None, password=None, role='admin',
              domain_name=None, uuid=None):
     self.inputs = connections.inputs
     self.vnc_lib_h = connections.get_vnc_lib_h()
     self.vnc_lib_fixture = connections.vnc_lib_fixture
     self.logger = connections.logger
     self.connections = connections
     self.auth = auth
     self.project_name = project_name or self.inputs.stack_tenant
     self.domain_name = domain_name or self.connections.domain_name
     self.domain_id = self.connections.domain_id or 'default'
     self.uuid = uuid
     self.project_obj = None
     self.already_present = False
     self.project_fq_name = [self.domain_name, self.project_name]
     self.project_username = self.username = username or self.connections.username
     self.project_user_password = self.password = password or self.connections.password
     self.role = role
     self.user_dict = {}
     self._create_user_set = {}
     self.project_connections = dict()
     self.project_inputs = dict()
     self.api_server_inspects = self.connections.api_server_inspects
     self.verify_is_run = False
     if not self.auth:
         if self.inputs.orchestrator == 'openstack':
             if self.inputs.domain_isolation:
                 self.auth=OpenstackAuth(self.username, self.password,
                        self.project_name, self.inputs,
                        self.logger,domain_name=self.domain_name)
             else:
                 self.auth = OpenstackAuth(self.inputs.admin_username,
                                 self.inputs.admin_password,
                                 self.inputs.admin_tenant, self.inputs, self.logger,
                                 domain_name=self.inputs.admin_domain)
         elif self.inputs.orchestrator == 'vcenter':
             self.auth = VcenterAuth(self.inputs.admin_username,
                           self.inputs.admin_password,
                           self.inputs.admin_tenant, self.inputs)
         else:
             # Kubernetes 
             # Set no auth for now
             self.auth = None
Example #8
0
 def get_auth_h(self):
     if not getattr(self, 'auth', None):
         if self.inputs.orchestrator == 'openstack':
             self.auth = OpenstackAuth(self.username, self.password,
                                       self.project_name, self.inputs,
                                       self.logger)
         else:  # vcenter
             self.auth = VcenterAuth(self.username, self.password,
                                     self.project_name, self.inputs)
     return self.auth
Example #9
0
 def setUp(self):
     super(VncLibFixture, self).setUp()
     if self.connections:
         self.logger = self.connections.logger
         self.project_name = self.connections.project_name
         self.inputs = self.connections.inputs
         self.neutron_handle = self.connections.quantum_h
         self.vnc_api_h = self.connections.vnc_lib
         self.username = self.connections.username
         self.password = self.connections.password
         self.cfgm_ip = self.inputs.cfgm_ip
         self.auth_server_ip = self.inputs.auth_ip
         self.auth_client = self.connections.auth
         self.project_id = self.connections.project_id
     else:
         self.logger = self.logger or contrail_logging.getLogger(__name__)
         self.vnc_api_h = VncApi(
                           username=self.username,
                           password=self.password,
                           tenant_name=self.project_name,
                           domain_name=self.domain,
                           api_server_host=self.cfgm_ip,
                           api_server_port=self.api_server_port,
                           auth_host=self.auth_server_ip,
                           api_server_use_ssl=self.use_ssl,
                           auth_url=self.authn_url)
         if self.orchestrator == 'openstack':
             self.auth_client = OpenstackAuth(
                                 self.username,
                                 self.password,
                                 self.project_name,
                                 domain_name=self.domain,
                                 auth_url=self.auth_url,
                                 certfile=self.certfile,
                                 keyfile=self.keyfile,
                                 cacert=self.cacert,
                                 insecure=self.insecure,
                                 logger=self.logger)
         elif self.orchestrator == 'vcenter':
             self.auth_client = VcenterAuth(self.username,
                                             self.password,
                                             self.project_name,
                                             self.inputs
                                             )
         if not self.project_id:
             self.project_id = self.vnc_api_h.project_read(
                 fq_name=[self.domain, self.project_name]).uuid
     if self.orch:
         self.vnc_h = self.orch.vnc_h
     else:
         self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
Example #10
0
 def get_auth_h(self, refresh=False, project_name=None,
                username=None, password=None):
     project_name = project_name or self.project_name
     username = username or self.username
     password = password or self.password
     attr = '_auth_'+project_name+'_'+username
     if not getattr(env, attr, None) or refresh:
         if self.inputs.orchestrator == 'openstack':
             env[attr] = OpenstackAuth(username, password,
                        project_name, self.inputs, self.logger)
         else:
             env[attr] = VcenterAuth(username, password,
                                    project_name, self.inputs)
     return env[attr]
 def setUpClass(cls):
     super(CeilometerTest, cls).setUpClass()
     cls.res.setUp(cls.inputs, cls.connections, cls.public_vn_obj)
     cls.auth = OpenstackAuth(cls.inputs.stack_user,
                              cls.inputs.stack_password,
                              cls.inputs.project_name, cls.inputs,
                              cls.logger)
     cls.auth_url = cls.auth.auth_url
     cls.c_url = 'http://%s:8777/' % cls.inputs.openstack_ip
     cls.cclient = ceilometer_client.CeilometerClient(
         cls.auth_url,
         cls.inputs.stack_user,
         cls.inputs.stack_password,
         cls.inputs.project_name,
         cls.c_url,
         insecure=True)
     cls.cclient = cls.cclient.get_cclient()
Example #12
0
    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.username = username
        self.password = password
        self.project_name = project_name

        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_h = None
        self.quantum_h = None
        if self.inputs.orchestrator == 'openstack':
            self.auth = OpenstackAuth(username, password, project_name,
                                      self.inputs, logger)
            self.project_id = self.auth.get_project_id(self.inputs.domain_name,
                                                       project_name)

            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.orch = OpenstackOrchestrator(username=username,
                                              password=password,
                                              project_id=self.project_id,
                                              project_name=project_name,
                                              inputs=inputs,
                                              vnclib=self.vnc_lib,
                                              logger=logger)
            self.nova_h = self.orch.nova_h
            self.quantum_h = self.orch.quantum_h
        else:  # vcenter
            self.auth = VcenterAuth(username, password, project_name,
                                    self.inputs)
            self.orch = VcenterOrchestrator(user=username,
                                            pwd=password,
                                            host=self.inputs.auth_ip,
                                            port=self.inputs.auth_port,
                                            dc_name=self.inputs.vcenter_dc,
                                            vnc=self.vnc_lib,
                                            inputs=self.inputs,
                                            logger=logger)

        self.api_server_inspects = {}
        self.dnsagent_inspect = {}
        self.cn_inspect = {}
        self.agent_inspect = {}
        self.ops_inspects = {}
        self.ds_inspect = {}
        self.update_inspect_handles()
Example #13
0
class DomainFixture(fixtures.Fixture):
    def __init__(self,
                 connections,
                 auth=None,
                 domain_name=None,
                 username=None,
                 password=None,
                 role='admin',
                 uuid=None):
        self.inputs = connections.inputs
        self.vnc_lib_h = connections.get_vnc_lib_h()
        self.logger = connections.logger
        self.connections = connections
        self.auth = connections.auth
        self.domain_name = domain_name
        self.uuid = uuid
        self.domain_obj = None
        self.already_present = False
        self.domain_fq_name = [self.domain_name]
        self.username = username
        self.password = password
        self.role = role
        self.domain_connections = None
        self.api_server_inspect = self.connections.api_server_inspect
        self.verify_is_run = False
        if not self.auth:
            if self.inputs.orchestrator == 'openstack':
                self.auth = OpenstackAuth(self.inputs.admin_username,
                                          self.inputs.admin_password,
                                          self.inputs.admin_tenant,
                                          domain_name=self.inputs.admin_domain,
                                          inputs=self.inputs,
                                          logger=self.logger)
        self.domain_username = None
        self.domain_password = None

    # end __init__

    def read(self):
        try:
            self.logger.info('Reading existing Domain with UUID %s' %
                             (self.uuid))
            kwargs = dict()
            if self.uuid == 'default':
                kwargs['fq_name_str'] = 'default-domain'
            else:
                kwargs['id'] = self.uuid
            domain_obj = self.vnc_lib_h.domain_read(**kwargs)
        except NoIdError as e:
            self.logger.exception('UUID %s not found, unable to read Domain' %
                                  (self.uuid))
            raise e
        self._populate_attr(domain_obj)
        self.already_present = True

    # end read

    def _populate_attr(self, domain_obj):
        self.domain_obj = domain_obj
        self.domain_fq_name = domain_obj.fq_name
        self.domain_name = domain_obj.name

    # end _populate_attr

    def _create_domain(self):
        self.uuid = self.auth.create_domain(self.domain_name)
        domain_obj = self.vnc_lib_h.domain_read(id=self.uuid)
        self.logger.info('Created Domain:%s, ID : %s ' %
                         (self.domain_name, self.uuid))
        self._populate_attr(domain_obj)

    # end _create_domain

    def _delete_domain(self):
        self.auth.delete_domain(domain_name=self.domain_name)
        self.logger.info('Deleted Domain: %s, ID : %s ' %
                         (self.domain_name, self.uuid))

    # end _delete_domain

    def setUp(self):
        super(DomainFixture, self).setUp()
        self.create()

    def create(self):
        uuid = self.uuid or self.auth.get_domain_id(self.domain_name)
        self.uuid = self.uuid if uuid == 'default' else get_dashed_uuid(uuid)
        if self.uuid:
            self.read()
            self.logger.info('Using existing domain %s(%s)' %
                             (self.domain_fq_name, self.uuid))
        elif self.domain_name == self.inputs.admin_domain:
            self.logger.info('Domain %s found not creating' %
                             (self.domain_name))
        else:
            self.logger.info('Domain %s not found, creating it' %
                             (self.domain_name))
            self._create_domain()

    def get_uuid(self):
        return self.uuid

    def get_fq_name(self):
        return self.domain_fq_name

    def getObj(self):
        return self.domain_obj

    def cleanUp(self):
        self.delete()
        super(DomainFixture, self).cleanUp()

    def update_domain(self, domain_name, description='', enabled=True):
        try:
            obj = self.auth.update_domain(domain_id=get_plain_uuid(self.uuid),
                                          domain_name=domain_name,
                                          description=description,
                                          enabled=enabled)
            self.logger.info('Domain updated successfully %s', obj.name)
            self.read()
            return obj
        except:
            self.logger.info('Domain updation failed')

    def get_domain(self):
        return self.auth.get_domain(domain_id=get_plain_uuid(self.uuid))

    def get_domain_connections(self,
                               username=None,
                               password=None,
                               project_name=None):
        self.dm_connections = ContrailConnections(self.inputs,
                                                  self.logger,
                                                  project_name=project_name,
                                                  username=username
                                                  or self.domain_username,
                                                  password=password
                                                  or self.domain_password,
                                                  domain_name=self.domain_name)
        return self.dm_connections

    def delete(self, verify=False):
        do_cleanup = True
        if self.inputs.fixture_cleanup == 'no':
            do_cleanup = False
        if self.already_present:
            do_cleanup = False
        if self.inputs.fixture_cleanup == 'force':
            do_cleanup = True
        if do_cleanup:
            if not self.check_no_domain_references():
                self.logger.warn('One or more references still present'
                                 ', will not delete the Domain %s' %
                                 (self.domain_name))
                return
            self._delete_domain()
            if self.verify_is_run or verify:
                assert self.verify_on_cleanup()
        else:
            self.logger.debug('Skipping the deletion of Domain %s' %
                              self.domain_fq_name)

    # end cleanUp

    @retry(delay=2, tries=30)
    def check_no_domain_references(self):
        vnc_domain_obj = self.vnc_lib_h.domain_read(id=self.uuid)
        prjs = vnc_domain_obj.get_projects()
        if prjs:
            self.logger.debug(
                'Domain %s still has Projects %s before deletion' %
                (self.domain_name, prjs))
            return False
        svc_tmps = vnc_domain_obj.get_service_templates()
        if svc_tmps:
            self.logger.debug(
                'Domain %s still has Service Templates %s before deletion' %
                (self.domain_name, svc_tmps))
            return False
        vdns = vnc_domain_obj.get_virtual_DNSs()
        if vdns:
            self.logger.debug('Domain %s still has vDNSs %s before deletion' %
                              (self.domain_name, vdns))
            return False
        return True

    # end check_no_domain_references

    def verify_on_setup(self):
        result = True
        if not self.verify_domain_in_api_server():
            result &= False
            self.logger.error('Verification of domain %s in APIServer '
                              'failed!! ' % (self.domain_name))
        self.verify_is_run = True
        return result

    # end verify_on_setup

    @retry(delay=2, tries=6)
    def verify_domain_in_api_server(self):
        if self.inputs.orchestrator == 'vcenter':
            self.logger.debug('No need to verify domains in case of vcenter')
            return True
        result = True
        cs_domain_obj = self.api_s_inspect.get_cs_domain(self.domain_name)
        if not cs_domain_obj:
            self.logger.debug('Domain %s not found in API Server %s'
                              ' ' % (self.domain_name, api_s_inspect._ip))
            result &= False
            return result
        if cs_domain_obj['domain']['uuid'] != self.uuid:
            self.logger.warn('Domain id %s got from API Server is'
                             ' not matching expected ID %s' %
                             (cs_domain_obj['domain']['uuid'], self.uuid))
            result &= False
        if result:
            self.logger.info('Verification of Domain %s in API Server %s'
                             ' passed ' %
                             (self.domain_name, api_s_inspect._ip))
        return result

    # end verify_domain_in_api_server

    @retry(delay=2, tries=5)
    def verify_domain_not_in_api_server(self):
        if self.inputs.orchestrator == 'vcenter':
            self.logger.debug('No need to verify domains in case of vcenter')
            return True
        result = True
        cs_domain_obj = self.api_s_inspect.get_cs_domain(self.domain_name)
        self.logger.info(
            "Check for Domain %s after deletion, got cs_domain_obj %s" %
            (self.domain_name, cs_domain_obj))
        if cs_domain_obj:
            self.logger.debug('Domain %s is still found in API Server %s'
                              'with ID %s ' %
                              (self.domain_name, api_s_inspect._ip,
                               cs_domain_obj['domain']['uuid']))
            result &= False
        if result:
            self.logger.info('Verification of Domain %s removal in API Server '
                             ' %s passed ' %
                             (self.domain_name, api_s_inspect._ip))
        return result

    # end verify_domain_not_in_api_server

    @retry(delay=2, tries=10)
    def verify_on_cleanup(self):
        result = True
        if not self.verify_domain_not_in_api_server():
            result &= False
            self.logger.error('Domain %s is still present in API Server' %
                              (self.domain_name))
        return result

    # end verify_on_cleanup

    def set_user_creds(self, username, password):
        '''Set a user,password who is allowed to login to this domain
        '''
        self.domain_username = username
        self.domain_password = password