Exemple #1
0
    def get_connection_handle(self):

        self.inputs = ContrailTestInit(self.ini_file,logger=self.logger)
        self.inputs.setUp()
        self.connections= ContrailConnections(self.inputs, self.logger)
        self.connections.get_vnc_lib_h() # will set self.vnc_lib in the object
        self.auth = self.connections.get_auth_h()
Exemple #2
0
    def get_conections(self): 
        connections= ContrailConnections(self.inputs,
                                   project_name= self.project_name,
				   username=self.inputs.stack_user,
                                   password= self.inputs.stack_password,
                                   logger = self.logger)
        connections.get_all_handles()
        return connections
 def get_conections(self):
     connections = ContrailConnections(self.inputs,
                                       project_name=self.project_name,
                                       username=self.inputs.stack_user,
                                       password=self.inputs.stack_password,
                                       logger=self.logger)
     connections.get_all_handles()
     return connections
 def get_conections(self):
     self.project_connections = ContrailConnections(
         self.project_inputs,
         project_name=self.project_name,
         username=self.project.username,
         password=self.project.password,
         logger=self.logger)
     self.project_connections.get_all_handles()
     return self.project_connections
Exemple #5
0
 def setUp(self):
     super(TestEncapsulation, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.agent_inspect = self.connections.agent_inspect
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.analytics_obj = self.connections.analytics_obj
Exemple #6
0
 def setUpClass(cls):
     super(BaseK8sTest, cls).setUpClass()
     cls.connections = ContrailConnections(
         cls.inputs,
         project_name=cls.inputs.admin_tenant,
         username=cls.inputs.admin_username,
         password=cls.inputs.admin_password,
         logger=cls.logger)
     cls.vnc_lib_fixture = cls.connections.vnc_lib_fixture
     cls.vnc_lib = cls.connections.vnc_lib
     cls.vnc_h = cls.vnc_lib_fixture.vnc_h
     cls.agent_inspect = cls.connections.agent_inspect
     cls.cn_inspect = cls.connections.cn_inspect
     cls.analytics_obj = cls.connections.analytics_obj
     cls.api_s_inspect = cls.connections.api_server_inspect
     cls.logger = cls.connections.logger
     cls.k8s_client = cls.connections.k8s_client
     cls.setup_namespace_isolation = False
     cls.setup_custom_isolation = False
     cls.public_vn = create_public_vn.PublicVn(
         connections=cls.connections,
         public_vn=K8S_PUBLIC_VN_NAME,
         public_tenant=cls.inputs.admin_tenant,
         logger=cls.logger,
         fip_pool_name=K8S_PUBLIC_FIP_POOL_NAME,
         api_option='contrail')
Exemple #7
0
 def setUp(self):
     self.connections = ContrailConnections(self.inputs, self.logger,
         project_name=self.project_name,
         username=self.username,
         password=self.password)
     self.vnc_lib = self.connections.vnc_lib
     self.auth = self.connections.auth
Exemple #8
0
 def get_connections(self, project_inputs):
     self.project_connections= ContrailConnections(project_inputs,
                                 project_name=self.project_name,
                                 username=self.username,
                                 password=self.password,
                                 logger=self.logger)
     return self.project_connections
Exemple #9
0
    def get_connection_handle(self):

        self.inputs = ContrailTestInit(self.ini_file, logger=self.logger)
        self.inputs.setUp()
        self.connections = ContrailConnections(self.inputs, self.logger)
        self.connections.get_vnc_lib_h()  # will set self.vnc_lib in the object
        self.auth = self.connections.get_auth_h()
Exemple #10
0
 def setUp(self):
     super(IsolatedCreds, self).setUp()
     self.connections= ContrailConnections(self.inputs, self.logger,
         username=self.username,
         password=self.password,
         project_name=self.project_name)
     self.vnc_lib= self.connections.vnc_lib
     self.auth = self.connections.auth
Exemple #11
0
    def get_conections(self):
        self.project_connections= ContrailConnections(self.project_inputs,
                                    project_name= self.project_name,
				    username=self.project.username,
                                    password= self.project.password,
                                    logger = self.logger)
        self.project_connections.get_all_handles()
        return self.project_connections
Exemple #12
0
    def get_connections_handle(self):

        self.inputs = ContrailTestInit(self.input_file, logger=self.logger)
        self.connections = ContrailConnections(self.inputs, self.logger)
        self.vnc_lib = self.connections.vnc_lib
        self.auth = self.connections.auth
        self.lib_handle = ConfigScale(self.inputs, self.logger,
                                      self.connections, self.vnc_lib,
                                      self.auth)
 def setUp(self):
     super(AnalyticsScaleTest, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.logger = self.inputs.logger
     self.analytics_obj = self.connections.analytics_obj
     self.ops_inspect = self.connections.ops_inspect
Exemple #14
0
 def setUp(self):
     super(VPCSanityTests, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.agent_inspect_h = self.connections.agent_inspect
     self.logger = self.inputs.logger
 def get_project_connections(self, username=None, password=None):
     if not username:
         username = self.username or self.inputs.stack_user
     if not password:
         password = self.password or self.inputs.stack_password
     if not self.project_connections:
         self.project_connections = ContrailConnections(
             inputs=self.inputs,
             logger=self.logger,
             project_name=self.project_name,
             username=username,
             password=password)
     return self.project_connections
Exemple #16
0
 def setUp(self):
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = ContrailTestInit(self.ini_file)
     self.inputs.setUp()
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     return self
 def get_project_connections(self, username=None, password=None):
     username = username or self.project_username or self.inputs.stack_user
     password = password or self.project_user_password or \
         self.inputs.stack_password
     if not self.project_connections:
         self.project_connections = ContrailConnections(
             inputs=self.inputs,
             logger=self.logger,
             project_name=self.project_name,
             username=username,
             password=password,
             domain_name=self.domain_name)
     return self.project_connections
 def setUp(self):
     super(SecurityGroupSanityTestsBase, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.analytics_obj = self.connections.analytics_obj
Exemple #19
0
 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
Exemple #20
0
 def get_project_connections(self, username=None, password=None):
     if not username:
         username = '******'
     if not password:
         password = '******'
     if not self.project_connections:
         self.project_connections = ContrailConnections(
             inputs=self.inputs,
             logger=self.logger,
             project_name=self.vpc_id,
             username=username,
             password=password)
     return self.project_connections
def setup_test_infra():
    import logging
    from common.log_orig import ContrailLogger
    logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
    logging.getLogger('paramiko.transport').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.session').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.httpclient').setLevel(logging.WARN)
    logging.getLogger('neutronclient.client').setLevel(logging.WARN)
    logger = ContrailLogger('event')
    logger.setUp()
    mylogger = logger.logger
    from common.connections import ContrailConnections
    connections = ContrailConnections(logger=mylogger)
    return connections
Exemple #22
0
 def setUp(self):
     super(PerformanceSanity, self).setUp()
     if 'TEST_CONFIG_FILE' in os.environ:
         self.input_file = os.environ.get('TEST_CONFIG_FILE')
     else:
         self.input_file = 'params.ini'
     self.inputs = ContrailTestInit(self.input_file)
     self.connections = ContrailConnections(self.inputs)
     self.agent_inspect = self.connections.agent_inspect
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.analytics_obj = self.connections.analytics_obj
Exemple #23
0
class ConfigScaleSetup:
    def __init__(self):

        self.ini_file= 'sanity_params.ini'
        self.log_name='tor-scale.log'
        Logger = logging.ContrailLogger(self.log_name)
        Logger.setUp()
        self.logger = Logger.logger

    def get_connection_handle(self):

        self.inputs = ContrailTestInit(self.ini_file,logger=self.logger)
        self.inputs.setUp()
        self.connections= ContrailConnections(self.inputs, self.logger)
        self.connections.get_vnc_lib_h() # will set self.vnc_lib in the object
        self.auth = self.connections.get_auth_h()

    def config_test(self):

        self.get_connection_handle()
        tenant_name = "tenant" + "".join([random.choice(string.ascii_uppercase + string.digits) for i in xrange(10)])
        project_obj = Project(self.connections)
        project_obj.create(tenant_name)
 def get_project_connections(self, username=None, password=None):
     if not username:
         username = self.username
     if not password:
         password = self.password
     project_inputs = self.get_project_inputs()
     if not getattr(self, 'project_connections', None):
         self.project_connections = ContrailConnections(
             inputs=project_inputs,
             logger=project_inputs.logger,
             project_name=self.project_name,
             username=username,
             password=password)
     return self.project_connections
Exemple #25
0
class ConfigScaleSetup:
    def __init__(self):

        self.ini_file = "sanity_params.ini"
        self.log_name = "tor-scale.log"
        Logger = logging.ContrailLogger(self.log_name)
        Logger.setUp()
        self.logger = Logger.logger

    def get_connection_handle(self):

        self.inputs = ContrailTestInit(self.ini_file, logger=self.logger)
        self.inputs.setUp()
        self.connections = ContrailConnections(self.inputs, self.logger)
        self.connections.get_vnc_lib_h()  # will set self.vnc_lib in the object
        self.auth = self.connections.get_auth_h()

    def config_test(self):

        self.get_connection_handle()
        tenant_name = "tenant" + "".join([random.choice(string.ascii_uppercase + string.digits) for i in xrange(10)])
        project_obj = Project(self.connections)
        project_obj.create(tenant_name)
Exemple #26
0
 def setUp(self):
     super(SolnSetup, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = ContrailTestInit(self.ini_file)
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.setup_common_objects()
     return self
 def setUp(self):
     super(SolnSetup, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.quantum_fixture = self.connections.quantum_fixture
     self.nova_fixture = self.connections.nova_fixture
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.setup_common_objects()
     return self
Exemple #28
0
 def get_project_connections(self, username=None, password=None):
     username = username or self.project_username or self.inputs.stack_user
     password = password or self.project_user_password or \
         self.inputs.stack_password
     inputs = self.get_inputs(username=username, password=password)
     if username not in self.project_connections:
         self.project_connections[username] = ContrailConnections(
             inputs=inputs,
             logger=self.logger,
             project_name=self.project_name,
             username=username,
             password=password,
             domain_name=self.orch_domain_name,
             scope='project')
     return self.project_connections[username]
Exemple #29
0
 def setUpClass(cls):
     super(BaseVgwTest, cls).setUpClass()
     cls.connections = ContrailConnections(
         cls.inputs,
         project_name=cls.inputs.project_name,
         username=cls.inputs.stack_user,
         password=cls.inputs.stack_password,
         logger=cls.logger)
     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
     cls.setup_common_objects()
Exemple #30
0
def setup_test_infra(testbed_file):
    import logging
    from common.log_orig import ContrailLogger
    logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
    logging.getLogger('paramiko.transport').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.session').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.httpclient').setLevel(logging.WARN)
    logging.getLogger('neutronclient.client').setLevel(logging.WARN)
    logger = ContrailLogger('verify')
    logger.setUp()
    mylogger = logger.logger
    inputs = ContrailTestInit(testbed_file, logger=mylogger)
    inputs.setUp()
    connections = ContrailConnections(inputs=inputs, logger=mylogger)
    return connections
Exemple #31
0
def setup_test_infra():
    import logging
    from common.contrail_test_init import ContrailTestInit
    from common.connections import ContrailConnections
    from common.log_orig import ContrailLogger
    logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
    logging.getLogger('paramiko.transport').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.session').setLevel(logging.WARN)
    logging.getLogger('keystoneclient.httpclient').setLevel(logging.WARN)
    logging.getLogger('neutronclient.client').setLevel(logging.WARN)
    logger = ContrailLogger('event')
    logger.setUp()
    mylogger = logger.logger
    inputs = ContrailTestInit('./sanity_params.ini', logger=mylogger)
    connections = ContrailConnections(inputs=inputs, logger=mylogger)
    return connections
Exemple #32
0
 def setUp(self):
     super(AnalyticsTestPerformance, self).setUp()
     if 'PARAMS_FILE' in os.environ:
         self.ini_file = os.environ.get('PARAMS_FILE')
     else:
         self.ini_file = 'params.ini'
     self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
     self.connections = ContrailConnections(self.inputs)
     self.quantum_h = self.connections.quantum_h
     self.nova_h = self.connections.nova_h
     self.vnc_lib = self.connections.vnc_lib
     self.logger = self.inputs.logger
     self.agent_inspect = self.connections.agent_inspect
     self.cn_inspect = self.connections.cn_inspect
     self.analytics_obj = self.connections.analytics_obj
     self.sender_list = []
     self.receiver_list = []
Exemple #33
0
    def setUp(self):
        super(SecurityGroupSetup, self).setUp()
        if 'PARAMS_FILE' in os.environ:
            self.ini_file = os.environ.get('PARAMS_FILE')
        else:
            self.ini_file = 'params.ini'
        self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
        self.connections = ContrailConnections(self.inputs)
        self.quantum_h = self.connections.quantum_h
        self.nova_h = self.connections.nova_h
        self.vnc_lib = self.connections.vnc_lib
        self.logger = self.inputs.logger

        self.logger.info("Configuring setup for security group tests.")
        self.setup()
        self.logger.info("Verifying setup of security group tests.")
        self.verify()
        self.logger.info(
            "Finished configuring setup for security group tests.")
        return self
Exemple #34
0
 def setUpClass(cls):
     super(BaseMultitenancyTest, cls).setUpClass()
     cls.connections = ContrailConnections(
         cls.inputs,
         project_name=cls.inputs.project_name,
         username=cls.inputs.stack_user,
         password=cls.inputs.stack_password,
         logger=cls.logger)
     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
     auth_url = os.getenv('OS_AUTH_URL') or \
                    'http://' + cls.inputs.openstack_ip + ':5000/v2.0'
     insecure = bool(os.getenv('OS_INSECURE', True))
     cls.key_stone_clients = KeystoneCommands(
         username=cls.inputs.stack_user,
         password=cls.inputs.stack_password,
         tenant=cls.inputs.project_name,
         auth_url=auth_url,
         insecure=insecure)
Exemple #35
0
 def setUpClass(cls):
     super(BaseK8sTest, cls).setUpClass()
     """ cls.connections = ContrailConnections(cls.inputs,
                                           project_name=cls.inputs.admin_tenant,
                                           username=cls.inputs.admin_username,
                                           password=cls.inputs.admin_password,
                                           logger=cls.logger) """
     cls.vnc_lib_fixture = cls.connections.vnc_lib_fixture
     cls.vnc_lib = cls.connections.vnc_lib
     cls.vnc_h = cls.vnc_lib_fixture.vnc_h
     cls.agent_inspect = cls.connections.agent_inspect
     cls.cn_inspect = cls.connections.cn_inspect
     cls.analytics_obj = cls.connections.analytics_obj
     cls.api_s_inspect = cls.connections.api_server_inspect
     cls.logger = cls.connections.logger
     cls.setup_namespace_isolation = False
     cls.setup_custom_isolation = False
     cls.public_vn = create_public_vn.PublicVn(
         connections=cls.connections,
         public_vn=cls.inputs.public_vn,
         public_tenant=cls.inputs.admin_tenant,
         logger=cls.logger,
         fip_pool_name=cls.inputs.fip_pool_name,
         api_option='contrail')
     cls.cluster_connections = []
     if cls.inputs.slave_orchestrator == 'kubernetes':
         for cluster in cls.inputs.k8s_clusters:
             cls.cluster_connections.append(
                 ContrailConnections(cls.inputs,
                                     project_name=cluster['name'],
                                     username=cls.inputs.admin_username,
                                     password=cls.inputs.admin_password,
                                     logger=cls.logger))
     # Hack: sunil/venky to relook when enabling nested multi-cluster tests
     cls._connections = cls.connections
     del cls.connections
     cls.connections = cls.get_connections
Exemple #36
0
class TestEncapsulation(testtools.TestCase, fixtures.TestWithFixtures):

#    @classmethod
    def setUp(self):
        super(TestEncapsulation, self).setUp()
        if 'PARAMS_FILE' in os.environ:
            self.ini_file = os.environ.get('PARAMS_FILE')
        else:
            self.ini_file = 'params.ini'
        self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
        self.connections = ContrailConnections(self.inputs)
        self.quantum_h = self.connections.quantum_h
        self.nova_h = self.connections.nova_h
        self.agent_inspect = self.connections.agent_inspect
        self.vnc_lib = self.connections.vnc_lib
        self.logger = self.inputs.logger
        self.analytics_obj = self.connections.analytics_obj
    # end setUpClass

    def cleanUp(self):
        super(TestEncapsulation, self).cleanUp()
    # end cleanUp

    def runTest(self):
        pass
    # end runTest

    @preposttest_wrapper
    def test_encaps_mx_gateway(self):
        '''Test to validate floating-ip froma a public pool  assignment to a VM. It creates a VM, assigns a FIP to it and pings to outside the cluster.'''

        if (('MX_GW_TEST' in os.environ) and (os.environ.get('MX_GW_TEST') == '1')):
            if len(self.connections.nova_h.get_hosts()) < 2:
                raise self.skipTest(
                    'Skipping Test. At least 2 compute node required to run the test')

            self.logger.info('Deleting any Encap before continuing')
            out = self.connections.delete_vrouter_encap()
            if (out != 'No config id found'):
                self.addCleanup(
                    self.connections.set_vrouter_config_encap, out[0], out[1], out[2])

            self.logger.info('Setting new Encap before continuing')
            config_id = self.connections.set_vrouter_config_encap(
                'MPLSoUDP', 'MPLSoGRE', 'VXLAN')
            self.logger.info('Created.UUID is %s' % (config_id))
            self.addCleanup(self.connections.delete_vrouter_encap)

            configured_encap_list = [
                unicode('MPLSoUDP'), unicode('MPLSoGRE'), unicode('VXLAN')]
            encap_list = self.connections.read_vrouter_config_encap()
            if configured_encap_list != encap_list:

                self.logger.error(
                    "Configured Encap Priority order is NOT matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))
                assert False
            else:
                self.logger.error(
                    "Configured Encap Priority order is matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))

            result = True
            fip_pool_name = self.inputs.fip_pool_name
            fvn_name = 'public100'
            fip_subnets = [self.inputs.fip_pool]
            vm1_name = 'vm200'
            vn1_name = 'vn200'
            vn1_subnets = ['11.1.1.0/24']
            api_server_port = self.inputs.api_server_port
            api_server_ip = self.inputs.cfgm_ip
            mx_rt = self.inputs.mx_rt
            router_name = self.inputs.ext_routers[0][0]
            router_ip = self.inputs.ext_routers[0][1]

            self.project_fixture = self.useFixture(ProjectFixture(
                vnc_lib_h=self.vnc_lib, project_name=self.inputs.project_name, connections=self.connections))
            self.logger.info(
                'Default SG to be edited for allow all on project: %s' %
                self.inputs.project_name)
            self.project_fixture.set_sec_group_for_allow_all(
                self.inputs.project_name, 'default')

            fvn_fixture = self.useFixture(
                VNFixture(
                    project_name=self.inputs.project_name, connections=self.connections,
                    vn_name=fvn_name, inputs=self.inputs, subnets=fip_subnets, router_asn=self.inputs.router_asn, rt_number=mx_rt))
            assert fvn_fixture.verify_on_setup()
            vn1_fixture = self.useFixture(
                VNFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_name=vn1_name, inputs=self.inputs, subnets=vn1_subnets))
            assert vn1_fixture.verify_on_setup()
            vm1_fixture = self.useFixture(
                VMFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_obj=vn1_fixture.obj, vm_name=vm1_name))
            assert vm1_fixture.wait_till_vm_is_up()
            assert vm1_fixture.verify_on_setup()

            fip_fixture = self.useFixture(
                FloatingIPFixture(
                    project_name=self.inputs.project_name, inputs=self.inputs,
                    connections=self.connections, pool_name=fip_pool_name, vn_id=fvn_fixture.vn_id))
            assert fip_fixture.verify_on_setup()
            fip_id = fip_fixture.create_and_assoc_fip(
                fvn_fixture.vn_id, vm1_fixture.vm_id)
            assert fip_fixture.verify_fip(fip_id, vm1_fixture, fvn_fixture)
            routing_instance = fvn_fixture.ri_name

            # Configuring all control nodes here
            for entry in self.inputs.bgp_ips:
                hostname = self.inputs.host_data[entry]['name']
                entry_control_ip = self.inputs.host_data[
                    entry]['host_control_ip']
                cn_fixture1 = self.useFixture(
                    CNFixture(connections=self.connections,
                              router_name=hostname, router_ip=entry_control_ip, router_type='contrail', inputs=self.inputs))
            cn_fixturemx = self.useFixture(
                CNFixture(connections=self.connections,
                          router_name=router_name, router_ip=router_ip, router_type='mx', inputs=self.inputs))
            sleep(10)
            assert cn_fixturemx.verify_on_setup()
            # TODO Configure MX. Doing Manually For Now
            self.logger.info(
                "BGP Peer configuraion done and trying to outside the VN cluster")
            self.logger.info(
                "Checking the basic routing. Pinging known local IP bng2-core-gw1.jnpr.net")
            assert vm1_fixture.ping_with_certainty('10.206.255.2')
            self.logger.info("Now trying to ping www-int.juniper.net")
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty('www-int.juniper.net', count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'GRE')
            fip_fixture.disassoc_and_delete_fip(fip_id)
            if not result:
                self.logger.error(
                    'Test  ping outside VN cluster from VM %s failed' % (vm1_name))
                assert result
        else:
            self.logger.info(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")
            raise self.skipTest(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")

        return True
    # end test_encaps_mx_gateway

    @preposttest_wrapper
    def test_apply_policy_fip_on_same_vn_gw_mx(self):
        """A particular VN is configure with policy to talk accross VN's and FIP to access outside
        1. Set encap priority before starting test
        2. Create two networks and launch instance each
        3. Conifgure policy to allow traffic between networks
        4. Send ICMP traffic, verify traffic & encap type using tcpdump on compute
        5. Assign floating up to VM and check public connectivity from VM
        """

        if (('MX_GW_TEST' in os.environ) and (os.environ.get('MX_GW_TEST') == '1')):

            if len(self.connections.nova_h.get_hosts()) < 2:
                self.logger.info(
                    "Skipping Test. At least 2 compute node required to run the test")
                raise self.skipTest(
                    'Skipping Test. At least 2 compute node required to run the test')

            self.logger.info('Deleting any Encap before continuing')
            out = self.connections.delete_vrouter_encap()
            if (out != 'No config id found'):
                self.addCleanup(
                    self.connections.set_vrouter_config_encap, out[0], out[1], out[2])

            self.logger.info('Setting new Encap before continuing')
            config_id = self.connections.set_vrouter_config_encap(
                'MPLSoUDP', 'MPLSoGRE', 'VXLAN')
            self.logger.info('Created.UUID is %s' % (config_id))
            self.addCleanup(self.connections.delete_vrouter_encap)

            configured_encap_list = [
                unicode('MPLSoUDP'), unicode('MPLSoGRE'), unicode('VXLAN')]
            encap_list = self.connections.read_vrouter_config_encap()
            if configured_encap_list != encap_list:

                self.logger.error(
                    "Configured Encap Priority order is NOT matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))
                assert False
            else:
                self.logger.error(
                    "Configured Encap Priority order is matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))

            result = True
            fip_pool_name = self.inputs.fip_pool_name
            fvn_name = 'public100'
            fip_subnets = [self.inputs.fip_pool]
            vm1_name = 'vm200'
            vn1_name = 'vn200'
            vn1_subnets = ['11.1.1.0/24']
            vm2_name = 'vm300'
            vn2_name = 'vn300'
            vn2_subnets = ['22.1.1.0/24']
            api_server_port = self.inputs.api_server_port
            api_server_ip = self.inputs.cfgm_ip
            mx_rt = self.inputs.mx_rt
            router_name = self.inputs.ext_routers[0][0]
            router_ip = self.inputs.ext_routers[0][1]

            self.project_fixture = self.useFixture(ProjectFixture(
                vnc_lib_h=self.vnc_lib, project_name=self.inputs.project_name, connections=self.connections))
            self.logger.info(
                'Default SG to be edited for allow all on project: %s' %
                self.inputs.project_name)
            self.project_fixture.set_sec_group_for_allow_all(
                self.inputs.project_name, 'default')

            # Get all compute host
            host_list = self.connections.nova_h.get_hosts()

            fvn_fixture = self.useFixture(
                VNFixture(
                    project_name=self.inputs.project_name, connections=self.connections,
                    vn_name=fvn_name, inputs=self.inputs, subnets=fip_subnets, router_asn=self.inputs.router_asn, rt_number=mx_rt))
            assert fvn_fixture.verify_on_setup()
            vn1_fixture = self.useFixture(
                VNFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_name=vn1_name, inputs=self.inputs, subnets=vn1_subnets))
            assert vn1_fixture.verify_on_setup()
            vm1_fixture = self.useFixture(
                VMFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_obj=vn1_fixture.obj, vm_name=vm1_name, node_name=host_list[0]))
            assert vm1_fixture.wait_till_vm_is_up()
            assert vm1_fixture.verify_on_setup()

            vn2_fixture = self.useFixture(
                VNFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_name=vn2_name, inputs=self.inputs, subnets=vn2_subnets))
            assert vn2_fixture.verify_on_setup()
            vm2_fixture = self.useFixture(
                VMFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_obj=vn2_fixture.obj, vm_name=vm2_name, node_name=host_list[1]))
            assert vm2_fixture.wait_till_vm_is_up()
            assert vm2_fixture.verify_on_setup()

            # Fip
            fip_fixture = self.useFixture(
                FloatingIPFixture(
                    project_name=self.inputs.project_name, inputs=self.inputs,
                    connections=self.connections, pool_name=fip_pool_name, vn_id=fvn_fixture.vn_id))
            assert fip_fixture.verify_on_setup()
            fip_id = fip_fixture.create_and_assoc_fip(
                fvn_fixture.vn_id, vm1_fixture.vm_id)
            self.addCleanup(fip_fixture.disassoc_and_delete_fip, fip_id)
            assert fip_fixture.verify_fip(fip_id, vm1_fixture, fvn_fixture)
            routing_instance = fvn_fixture.ri_name

            # Configuring all control nodes here
            for entry in self.inputs.bgp_ips:
                hostname = self.inputs.host_data[entry]['name']
                entry_control_ip = self.inputs.host_data[
                    entry]['host_control_ip']
                cn_fixture1 = self.useFixture(
                    CNFixture(connections=self.connections,
                              router_name=hostname, router_ip=entry_control_ip, router_type='contrail', inputs=self.inputs))
            cn_fixturemx = self.useFixture(
                CNFixture(connections=self.connections,
                          router_name=router_name, router_ip=router_ip, router_type='mx', inputs=self.inputs))
            sleep(10)
            assert cn_fixturemx.verify_on_setup()

            # Policy
            # Apply policy in between VN
            policy1_name = 'policy1'
            policy2_name = 'policy2'
            rules = [
                {
                    'direction': '<>', 'simple_action': 'pass',
                    'protocol': 'icmp',
                    'source_network': vn1_name,
                    'dest_network': vn2_name,
                },
            ]
            rev_rules = [
                {
                    'direction': '<>', 'simple_action': 'pass',
                    'protocol': 'icmp',
                    'source_network': vn2_name,
                    'dest_network': vn1_name,
                },
            ]

            policy1_fixture = self.useFixture(PolicyFixture(
                policy_name=policy1_name, rules_list=rules, inputs=self.inputs, connections=self.connections))
            policy2_fixture = self.useFixture(PolicyFixture(
                policy_name=policy2_name, rules_list=rev_rules, inputs=self.inputs, connections=self.connections))

            self.logger.info('Apply policy between VN %s and %s' %
                             (vn1_name, vn2_name))
            vn1_fixture.bind_policies(
                [policy1_fixture.policy_fq_name], vn1_fixture.vn_id)
            self.addCleanup(vn1_fixture.unbind_policies,
                            vn1_fixture.vn_id, [policy1_fixture.policy_fq_name])
            vn2_fixture.bind_policies(
                [policy2_fixture.policy_fq_name], vn2_fixture.vn_id)
            self.addCleanup(vn2_fixture.unbind_policies,
                            vn2_fixture.vn_id, [policy2_fixture.policy_fq_name])

            self.logger.info(
                'Checking connectivity within VNS cluster through Policy')
            self.logger.info('Ping from %s to %s' % (vm1_name, vm2_name))
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty(vm2_fixture.vm_ip, count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            comp_vm2_ip = vm2_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'UDP')
            self.tcpdump_analyze_on_compute(comp_vm2_ip, 'UDP')

            self.logger.info(
                'Checking connectivity outside VNS cluster through FIP')
            self.logger.info(
                "Checking the basic routing. Pinging known local IP bng2-core-gw1.jnpr.net")
            assert vm1_fixture.ping_with_certainty('10.206.255.2')
            self.logger.info("Now trying to ping www-int.juniper.net")
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty('www-int.juniper.net', count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'GRE')
            if not result:
                self.logger.error(
                    'Test to verify the Traffic to Inside and Outside Virtual network cluster simaltaneiously failed')
                assert result
        else:
            self.logger.info(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")
            raise self.skipTest(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")

        return True
    # end test_apply_policy_fip_on_same_vn_gw_mx

    @preposttest_wrapper
    def test_apply_policy_fip_vn_with_encaps_change_gw_mx(self):
        '''A particular VN is configured with policy to talk across VN's and FIP to access outside.The encapsulation prioritis set at the start of testcase are changed and verified '''

        if (('MX_GW_TEST' in os.environ) and (os.environ.get('MX_GW_TEST') == '1')):

            if len(self.connections.nova_h.get_hosts()) < 2:
                self.logger.info(
                    "Skipping Test. At least 2 compute node required to run the test")
                raise self.skipTest(
                    'Skipping Test. At least 2 compute node required to run the test')

            self.logger.info('Deleting any Encap before continuing')
            out = self.connections.delete_vrouter_encap()
            if (out != 'No config id found'):
                self.addCleanup(
                    self.connections.set_vrouter_config_encap, out[0], out[1], out[2])

            self.logger.info('Setting new Encap before continuing')
            config_id = self.connections.set_vrouter_config_encap(
                'MPLSoUDP', 'MPLSoGRE', 'VXLAN')
            self.logger.info('Created.UUID is %s' % (config_id))
            self.addCleanup(self.connections.delete_vrouter_encap)

            configured_encap_list = [
                unicode('MPLSoUDP'), unicode('MPLSoGRE'), unicode('VXLAN')]
            encap_list = self.connections.read_vrouter_config_encap()
            if configured_encap_list != encap_list:

                self.logger.error(
                    "Configured Encap Priority order is NOT matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))
                assert False
            else:
                self.logger.error(
                    "Configured Encap Priority order is matching with expected order. Configured: %s ,Expected: %s" %
                    (configured_encap_list, encap_list))

            result = True
            fip_pool_name = self.inputs.fip_pool_name
            fvn_name = 'public100'
            fip_subnets = [self.inputs.fip_pool]
            vm1_name = 'vm200'
            vn1_name = 'vn200'
            vn1_subnets = ['11.1.1.0/24']
            vm2_name = 'vm300'
            vn2_name = 'vn300'
            vn2_subnets = ['22.1.1.0/24']
            api_server_port = self.inputs.api_server_port
            api_server_ip = self.inputs.cfgm_ip
            mx_rt = self.inputs.mx_rt
            router_name = self.inputs.ext_routers[0][0]
            router_ip = self.inputs.ext_routers[0][1]

            self.project_fixture = self.useFixture(ProjectFixture(
                vnc_lib_h=self.vnc_lib, project_name=self.inputs.project_name, connections=self.connections))
            self.logger.info(
                'Default SG to be edited for allow all on project: %s' %
                self.inputs.project_name)
            self.project_fixture.set_sec_group_for_allow_all(
                self.inputs.project_name, 'default')

            # Get all compute host
            host_list = self.connections.nova_h.get_hosts()

            fvn_fixture = self.useFixture(
                VNFixture(
                    project_name=self.inputs.project_name, connections=self.connections,
                    vn_name=fvn_name, inputs=self.inputs, subnets=fip_subnets, router_asn=self.inputs.router_asn, rt_number=mx_rt))
            assert fvn_fixture.verify_on_setup()
            vn1_fixture = self.useFixture(
                VNFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_name=vn1_name, inputs=self.inputs, subnets=vn1_subnets))
            assert vn1_fixture.verify_on_setup()
            vm1_fixture = self.useFixture(
                VMFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_obj=vn1_fixture.obj, vm_name=vm1_name, node_name=host_list[0]))
            assert vm1_fixture.wait_till_vm_is_up()
            assert vm1_fixture.verify_on_setup()

            vn2_fixture = self.useFixture(
                VNFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_name=vn2_name, inputs=self.inputs, subnets=vn2_subnets))
            assert vn2_fixture.verify_on_setup()
            vm2_fixture = self.useFixture(
                VMFixture(project_name=self.inputs.project_name,
                          connections=self.connections, vn_obj=vn2_fixture.obj, vm_name=vm2_name, node_name=host_list[1]))
            assert vm2_fixture.wait_till_vm_is_up()
            assert vm2_fixture.verify_on_setup()

            # Fip
            fip_fixture = self.useFixture(
                FloatingIPFixture(
                    project_name=self.inputs.project_name, inputs=self.inputs,
                    connections=self.connections, pool_name=fip_pool_name, vn_id=fvn_fixture.vn_id))
            assert fip_fixture.verify_on_setup()
            fip_id = fip_fixture.create_and_assoc_fip(
                fvn_fixture.vn_id, vm1_fixture.vm_id)
            self.addCleanup(fip_fixture.disassoc_and_delete_fip, fip_id)
            assert fip_fixture.verify_fip(fip_id, vm1_fixture, fvn_fixture)
            routing_instance = fvn_fixture.ri_name

            # Configuring all control nodes here
            for entry in self.inputs.bgp_ips:
                hostname = self.inputs.host_data[entry]['name']
                entry_control_ip = self.inputs.host_data[
                    entry]['host_control_ip']
                cn_fixture1 = self.useFixture(
                    CNFixture(connections=self.connections,
                              router_name=hostname, router_ip=entry_control_ip, router_type='contrail', inputs=self.inputs))
            cn_fixturemx = self.useFixture(
                CNFixture(connections=self.connections,
                          router_name=router_name, router_ip=router_ip, router_type='mx', inputs=self.inputs))
            sleep(10)
            assert cn_fixturemx.verify_on_setup()

            # Policy
            # Apply policy in between VN
            policy1_name = 'policy1'
            policy2_name = 'policy2'
            rules = [
                {
                    'direction': '<>', 'simple_action': 'pass',
                    'protocol': 'icmp',
                    'source_network': vn1_name,
                    'dest_network': vn2_name,
                },
            ]
            rev_rules = [
                {
                    'direction': '<>', 'simple_action': 'pass',
                    'protocol': 'icmp',
                    'source_network': vn2_name,
                    'dest_network': vn1_name,
                },
            ]

            policy1_fixture = self.useFixture(PolicyFixture(
                policy_name=policy1_name, rules_list=rules, inputs=self.inputs, connections=self.connections))
            policy2_fixture = self.useFixture(PolicyFixture(
                policy_name=policy2_name, rules_list=rev_rules, inputs=self.inputs, connections=self.connections))

            self.logger.info('Apply policy between VN %s and %s' %
                             (vn1_name, vn2_name))
            vn1_fixture.bind_policies(
                [policy1_fixture.policy_fq_name], vn1_fixture.vn_id)
            self.addCleanup(vn1_fixture.unbind_policies,
                            vn1_fixture.vn_id, [policy1_fixture.policy_fq_name])
            vn2_fixture.bind_policies(
                [policy2_fixture.policy_fq_name], vn2_fixture.vn_id)
            self.addCleanup(vn2_fixture.unbind_policies,
                            vn2_fixture.vn_id, [policy2_fixture.policy_fq_name])

            self.logger.info(
                'Checking connectivity within VNS cluster through Policy')
            self.logger.info('Ping from %s to %s' % (vm1_name, vm2_name))
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty(vm2_fixture.vm_ip, count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            comp_vm2_ip = vm2_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'UDP')
            self.tcpdump_analyze_on_compute(comp_vm2_ip, 'UDP')

            self.logger.info(
                'Checking connectivity outside VNS cluster through FIP')
            self.logger.info(
                "Checking the basic routing. Pinging known local IP bng2-core-gw1.jnpr.net")
            assert vm1_fixture.ping_with_certainty('10.206.255.2')
            self.logger.info("Now trying to ping www-int.juniper.net")
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty('www-int.juniper.net', count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'GRE')
            if not result:
                self.logger.error(
                    'Test to verify the Traffic to Inside and Outside Virtual network cluster simaltaneiously failed')
                assert result
            self.logger.info('Now changing the encapsulation priorities')
            self.logger.info(
                'The new encapsulation will take effect once bug 1422 is fixed')
            res = self.connections.update_vrouter_config_encap(
                'MPLSoGRE', 'MPLSoUDP', 'VXLAN')
            self.logger.info('Updated.%s' % (res))
            self.logger.info(
                'Checking connectivity within VNS cluster through Policy')
            self.logger.info('Ping from %s to %s' % (vm1_name, vm2_name))
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty(vm2_fixture.vm_ip, count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            comp_vm2_ip = vm2_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'GRE')
            self.tcpdump_analyze_on_compute(comp_vm2_ip, 'GRE')

            self.logger.info(
                'Checking connectivity outside VNS cluster through FIP')
            self.logger.info(
                "Checking the basic routing. Pinging known local IP bng2-core-gw1.jnpr.net")
            assert vm1_fixture.ping_with_certainty('10.206.255.2')
            self.logger.info("Now trying to ping www-int.juniper.net")
            self.tcpdump_start_on_all_compute()
            if not vm1_fixture.ping_with_certainty('www-int.juniper.net', count='15'):
                result = result and False
            comp_vm1_ip = vm1_fixture.vm_node_ip
            self.tcpdump_analyze_on_compute(comp_vm1_ip, 'GRE')
            if not result:
                self.logger.error(
                    'Test to verify the Traffic to Inside and Outside Virtual network cluster simaltaneiously failed after changing the encapsulation')
                assert result

        else:
            self.logger.info(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")
            raise self.skipTest(
                "Skipping Test. Env variable MX_TEST is not set. Skipping the test")
        return True
    # end test_apply_policy_fip_vn_with_encaps_change_gw_mx

# end TestEncapsulation
#
    def start_tcpdump(self, session, cmd):
        self.logger.info("Starting tcpdump to capture the packets.")
        result = execute_cmd(session, cmd, self.logger)
   # end start_tcpdump

    def stop_tcpdump(self, session):
        self.logger.info("Stopping any tcpdump process running")
        cmd = 'kill $(pidof tcpdump)'
        execute_cmd(session, cmd, self.logger)
        self.logger.info("Removing any encap-pcap files in /tmp")
        cmd = 'rm -f /tmp/encap*pcap'
        execute_cmd(session, cmd, self.logger)
    # end stop_tcpdump

    def tcpdump_start_on_all_compute(self):
        for compute_ip in self.inputs.compute_ips:
            compute_user = self.inputs.host_data[compute_ip]['username']
            compute_password = self.inputs.host_data[compute_ip]['password']
            session = ssh(compute_ip, compute_user, compute_password)
            self.stop_tcpdump(session)
            inspect_h = self.agent_inspect[compute_ip]
            comp_intf = inspect_h.get_vna_interface_by_type('eth')
            if len(comp_intf) == 1:
                comp_intf = comp_intf[0]
            self.logger.info('Agent interface name: %s' % comp_intf)
            pcap1 = '/tmp/encap-udp.pcap'
            pcap2 = '/tmp/encap-gre.pcap'
            pcap3 = '/tmp/encap-vxlan.pcap'
            cmd1 = 'tcpdump -ni %s udp port 51234 -w %s -s 0' % (comp_intf, pcap1)
            cmd_udp = "nohup " + cmd1 + " >& /dev/null < /dev/null &"
            cmd2 = 'tcpdump -ni %s proto 47 -w %s -s 0' % (comp_intf, pcap2)
            cmd_gre = "nohup " + cmd2 + " >& /dev/null < /dev/null &"
            cmd3 = 'tcpdump -ni %s dst port 4789 -w %s -s 0' % (comp_intf, pcap3)
            cmd_vxlan = "nohup " + cmd3 + " >& /dev/null < /dev/null &"

            self.start_tcpdump(session, cmd_udp)
            self.start_tcpdump(session, cmd_gre)
            self.start_tcpdump(session, cmd_vxlan)

    # end tcpdump_on_all_compute

    def tcpdump_stop_on_all_compute(self):
        sessions = {}
        for compute_ip in self.inputs.compute_ips:
            compute_user = self.inputs.host_data[compute_ip]['username']
            compute_password = self.inputs.host_data[compute_ip]['password']
            session = ssh(compute_ip, compute_user, compute_password)
            self.stop_tcpdump(session)

    # end tcpdump_on_all_compute

    def tcpdump_stop_on_compute(self, compute_ip):
        sessions = {}
        compute_user = self.inputs.host_data[compute_ip]['username']
        compute_password = self.inputs.host_data[compute_ip]['password']
        session = ssh(compute_ip, compute_user, compute_password)
        self.stop_tcpdump(session)

    def tcpdump_analyze_on_compute(self, comp_ip, pcaptype, vxlan_id=None, vlan_id=None):
        sessions = {}
        compute_user = self.inputs.host_data[comp_ip]['username']
        compute_password = self.inputs.host_data[comp_ip]['password']
        session = ssh(comp_ip, compute_user, compute_password)
        self.logger.info("Analyzing on compute node %s" % comp_ip)
        if pcaptype == 'UDP':
            pcaps1 = '/tmp/encap-udp.pcap'
            pcaps2 = '/tmp/encap-gre.pcap'
            cmd2 = 'tcpdump  -r %s | grep UDP |wc -l' % pcaps1
            out2, err = execute_cmd_out(session, cmd2, self.logger)
            cmd3 = 'tcpdump  -r %s | grep GRE | wc -l' % pcaps2
            out3, err = execute_cmd_out(session, cmd3, self.logger)
            count2 = int(out2.strip('\n'))
            count3 = int(out3.strip('\n'))
            if count2 != 0 and count3 == 0:
                self.logger.info(
                    "%s UDP encapsulated packets are seen and %s GRE encapsulated packets are seen as expected" % (count2, count3))
                return True
            else:
                errmsg = "%s UDP encapsulated packets are seen and %s GRE encapsulated packets are seen.Not expected" % (
                    count2, count3)
                self.logger.error(errmsg)
                assert False, errmsg
        elif pcaptype == 'GRE':
            pcaps1 = '/tmp/encap-udp.pcap'
            pcaps2 = '/tmp/encap-gre.pcap'
            cmd2 = 'tcpdump  -r %s | grep UDP |wc -l' % pcaps1
            out2, err = execute_cmd_out(session, cmd2, self.logger)
            cmd3 = 'tcpdump  -r %s | grep GRE | wc -l' % pcaps2
            out3, err = execute_cmd_out(session, cmd3, self.logger)
            count2 = int(out2.strip('\n'))
            count3 = int(out3.strip('\n'))
            if count2 == 0 and count3 != 0:
                self.logger.info(
                    "%s GRE encapsulated packets are seen and %s UDP encapsulated packets are seen as expected" % (count3, count2))
                # self.tcpdump_stop_on_all_compute()
                self.tcpdump_stop_on_compute(comp_ip)
                return True
            else:
                errmsg = "%s UDP encapsulated packets are seen and %s GRE encapsulated packets are seen.Not expected" % (
                    count2, count3)
                self.logger.error(errmsg)
                # self.tcpdump_stop_on_all_compute()
                self.tcpdump_stop_on_compute(comp_ip)
                assert False, errmsg

        elif pcaptype == 'VXLAN':
            pcaps1 = '/tmp/encap-udp.pcap'
            pcaps2 = '/tmp/encap-gre.pcap'
            pcaps3 = '/tmp/encap-vxlan.pcap'
            cmd2 = 'tcpdump  -r %s | grep UDP |wc -l' % pcaps1
            out2, err = execute_cmd_out(session, cmd2, self.logger)
            cmd3 = 'tcpdump  -r %s | grep GRE | wc -l' % pcaps2
            out3, err = execute_cmd_out(session, cmd3, self.logger)
            count2 = int(out2.strip('\n'))
            count3 = int(out3.strip('\n'))

            cmd3 = 'tcpdump  -r %s | egrep "UDP|VXLAN" |wc -l' % pcaps3
            out3, err = execute_cmd_out(session, cmd3, self.logger)
            count = int(out3.strip('\n'))

            if count2 == 0 and count3 == 0 and count != 0:
                self.logger.info(
                    "%s GRE encapsulated packets are seen and %s UDP encapsulated packets are seen and %s vxlan packets are seen  as expected" %
                    (count3, count2, count))
                # self.tcpdump_stop_on_all_compute()
                if vxlan_id is not None:
                    cmd4 = 'tcpdump -AX -r %s | grep ' % pcaps3 + \
                        vxlan_id + ' |wc -l'
                    out4, err = execute_cmd_out(session, cmd4, self.logger)
                    count_vxlan_id = int(out4.strip('\n'))

                    if count_vxlan_id < count:
                        errmsg = "%s vxlan packet are seen with %s vxlan_id . Not Expected . " % (
                            count, count_vxlan_id)
                        self.tcpdump_stop_on_compute(comp_ip)
                        self.logger.error(errmsg)
                        assert False, errmsg
                    else:
                        self.logger.info(
                            "%s vxlan packets are seen with %s vxlan_id as expexted . " % (count, count_vxlan_id))
                        self.tcpdump_stop_on_compute(comp_ip)
            else:
                errmsg = "%s UDP encapsulated packets are seen and %s GRE encapsulated packets are seen.Not expected, %s vxlan packet seen" % (
                    count2, count3, count)
                self.logger.error(errmsg)
                # self.tcpdump_stop_on_all_compute()
                self.tcpdump_stop_on_compute(comp_ip)
                assert False, errmsg
            if vlan_id is not None:
                cmd5 = 'tcpdump -AX -r %s | grep %s |wc -l' % (pcaps3, vlan_id)
                out5, err = execute_cmd_out(session, cmd5, self.logger)
                count_vlan_id = int(out5.strip('\n'))

                if count_vlan_id < count:
                    errmsg = "%s vxlan packet are seen with %s vlan_id . Not Expected . " % (
                        count, count_vlan_id)
                    self.logger.error(errmsg)
                    assert False, errmsg
                else:
                    self.logger.info(
                        "%s vxlan packets are seen with %s vlan_id as expexted . " % (count, count_vlan_id))
        return True
Exemple #37
0
class IsolatedCreds(fixtures.Fixture):

    def __init__(self,project_name, inputs, ini_file=None, logger=None,
                 username=None, password=None):

        self.inputs = inputs
        if (self.inputs.public_tenant == project_name):
            self.project_name = project_name
        else: 
            self.project_name = get_random_name(project_name) 
        if username:
            self.user = username
        else:
            self.user = project_name
        if password:
            self.password = password
        else:
            self.password = project_name
        self.ini_file = ini_file
        self.logger = logger
        if self.inputs.orchestrator == 'vcenter':
            self.project_name = self.inputs.stack_tenant
            self.user = self.inputs.stack_user
            self.password = self.inputs.stack_password

    def setUp(self):
        super(IsolatedCreds, self).setUp()
        self.connections= ContrailConnections(self.inputs, self.logger)
        self.auth = self.connections.get_auth_h()

    def create_tenant(self): 
        self.project = None
        try:
            self.project = project_test.ProjectFixture(project_name = self.project_name,
					username= self.user, password= self.password,
                                        connections= self.connections)
            self.project.setUp()
        except Exception as e:
            self.logger.warn("got exception as %s"%(e)) 
        finally:
            return self.project

    def delete_tenant(self):

        self.project.cleanUp()

    def delete_user(self,user=None):
        if self.inputs.orchestrator == 'vcenter':
            return
        if user:
            user = user
	else:
	    user = self.user
        self.auth.delete_user(user)

    def create_and_attach_user_to_tenant(self,user = None , password=None):
        if self.inputs.orchestrator == 'vcenter':
            return
        user = user if user else self.user
        password = password if password else self.password
        self.auth.create_user(user,password)
        self.auth.add_user_to_project(user, self.project_name)
        self.auth.add_user_to_project('admin', self.project_name)
        time.sleep(4)

    def get_inputs(self):

        self.project_inputs= self.useFixture(ContrailTestInit(self.ini_file, 
                            stack_user=self.project.username,
                            stack_password=self.project.password,
                            project_fq_name=['default-domain',self.project_name],logger = self.logger))
        return self.project_inputs

    def get_conections(self):
        self.project_connections= ContrailConnections(self.project_inputs,
                                    project_name= self.project_name,
				    username=self.project.username,
                                    password= self.project.password,
                                    logger = self.logger)
        self.project_connections.get_all_handles()
        return self.project_connections

    def get_admin_inputs(self):
        admin = AdminCreds(self.inputs, self.ini_file, self.logger)
        return admin.get_inputs()

    def get_admin_connections(self):
        admin = AdminCreds(self.inputs, self.ini_file, self.logger)
        return admin.get_conections()	

    def cleanUp(self):
        super(IsolatedCreds, self).cleanUp()
Exemple #38
0
 def setUp(self):
     super(IsolatedCreds, self).setUp()
     self.connections= ContrailConnections(self.inputs, self.logger)
     self.auth = self.connections.get_auth_h()
Exemple #39
0
class Test(object):

    def __init__(self,global_conf,test_conf):

        self.global_conf = global_conf
        self.test_conf = test_conf
        self.connections = setup_test_infra(global_conf['ENV']['testbed_file'])
        self.uuid = dict()
        self.tenant_ids = list()
        self.vm_connections_map = dict()
        self.ostack_admin_obj = Openstack(OS_AUTH_URL,OS_USERNAME,OS_PASSWORD,OS_TENANT_NAME)

        self.mysql_passwd = get_mysql_token()

    @retry(delay=60, tries=30)
    def wait_until_vms_deleted(self,tenant_id):

        vm_list = self.ostack_admin_obj.nova_client.servers.list(search_opts={'all_tenants': 1})
        print "VM_list:",vm_list
        vm_to_be_deleted = []

        for vm in vm_list:
            vm_id = vm.id
            if vm.tenant_id == re.sub("-","",tenant_id) :
               vm_to_be_deleted.append(vm)

        if len(vm_to_be_deleted) == 0 :
           return True
        else:
           return False

    def delete_vms(self,tenant_id):

        vm_list = self.ostack_admin_obj.nova_client.servers.list(search_opts={'all_tenants': 1})
        print "VM_list:",vm_list
        vm_to_be_deleted = []

        for vm in vm_list:
            vm_id = vm.id
            #print vm.tenant_id,tenant_id
            if vm.tenant_id == re.sub("-","",tenant_id) :
               vm_to_be_deleted.append(vm)

        for vm in vm_to_be_deleted:
            vm_id = vm.id
            print "deletingvm:%s"%str(vm_id)
            self.ostack_admin_obj.nova_client.servers.delete(vm_id) 

        self.wait_until_vms_deleted(tenant_id)

    def cleanup(self,tenant_obj,tenant_id):

        net_list = self.ostack_admin_obj.neutron_client.list_networks()['networks']
        subnet_list = self.ostack_admin_obj.neutron_client.list_subnets()['subnets']
        port_list = self.ostack_admin_obj.neutron_client.list_ports()['ports']

        self.delete_vms(tenant_id)
    
        for subnet in subnet_list :
           if subnet["tenant_id"] == re.sub("-","",tenant_id) :
              print "Name:",subnet['name']
              subnet_id = subnet['id']
              self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id)

        for net in net_list :
           if net["tenant_id"] == re.sub("-","",tenant_id) :
              print "Name:",net['name']
              net_id = net['id']
              self.ostack_admin_obj.neutron_client.delete_network(net_id)

        tenant_obj.delete(tenant_id)

    def create_vm(self,tenant_name,vm_name,shared_vn_id,vn_id,image):
         
        self.connections.inputs.project_name = tenant_name
        self.connections.project_name = tenant_name

        self.connections.inputs.stack_tenant = tenant_name

        vm_obj = VM(self.connections)
        vm_obj.flavor=5
        vm_obj.zone="nova"
        #vm_obj.sg_ids=["4dd30150-f3ff-43d9-afcc-102df8dc658a"]
        
        print "VM:",vm_name,vn_id,image,shared_vn_id,vn_id
        vm_id  = vm_obj.create(vm_name,[shared_vn_id,vn_id],image)
        return vm_id

    def setUp(self):

        tenants = self.test_conf['tenants'][0]
        tenant_count = tenants['count'] 
        vns_count    = tenants['virtual_networks'][0]['count'] 
        subnet_count = tenants['virtual_networks'][0]['subnets'][0]['count']
        vm_count     = tenants['virtual_networks'][0]['virtual_machines'][0]['count'] + tenants['virtual_networks'][0]['virtual_machines'][1]['count']

        glance_image = self.global_conf['GLOBALS']['glance_image_name']
        cidr_start   = tenants['virtual_networks'][0]['subnets'][0]['cidr']
        cidr_obj     = CIDR(cidr_start)
        vm_obj_list = []

        self.connections.project_name = "admin"
        self.connections = ContrailConnections(inputs=inputs, logger=mylogger)
        self.connections.vnc_lib = self.connections.get_vnc_lib_h()

        vdns_obj = vDNS(self.connections)
        vdns_id = vdns_obj.create('vDNS-test')
        vdns_fqname = vdns_obj.fq_name(vdns_id)
        print "vDNS:",vdns_fqname
        
        ipam_obj = IPAM(self.connections)
        ipam_id = ipam_obj.create('ipam-test', vdns_id)    
        ipam_fqname = ipam_obj.fq_name(ipam_id)
        print "IPAM:",ipam_fqname 

          
        vn_obj = VN(self.connections)
       
        cidr = "192.167.0.0/16"
        vn_name = "shared_net"
        subnets = [{'cidr':cidr,'name':"shared_subnet"}]
        vn_obj.shared=True
        shared_vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=ipam_id)
  
        tenant_obj = Project(self.connections)
        admin_tenant_id = self.connections.get_auth_h().get_project_id('default_domain','admin')

        for tenant_index in xrange(tenant_count):

          self.connections.project_id   = admin_tenant_id
          self.connections.inputs.project_name = "admin"
          self.connections.project_name = "admin"
          self.connections.project_fq_name = "admin"
          self.connections.domain_name = "admin"


          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name="admin")
          self.connections.vnc_lib = self.connections.get_vnc_lib_h()

          self.tenant_name = "TC002_tenant_%d"%tenant_index

          tenant_id = self.connections.get_auth_h().get_project_id('default_domain',self.tenant_name)
          if not tenant_id:
             tenant_id = tenant_obj.create(self.tenant_name)

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name=self.tenant_name)
          self.connections.vnc_lib = self.connections.get_vnc_lib_h()

          self.connections.inputs.project_name = self.tenant_name
          self.connections.project_name = self.tenant_name
          self.connections.project_fq_name = self.tenant_name
          self.connections.domain_name = self.tenant_name
          self.connections.project_id   = tenant_id
Exemple #40
0
def global_configuration(yaml_global_conf,ini_conf):

        global shared_subnet_name,shared_vnet_name
        connections = setup_test_infra(ini_conf['ENV']['testbed_file'])

        shared_vnet_name   = yaml_global_conf['virtual_network_shared']['name']
        shared_subnet_name = yaml_global_conf['virtual_network_shared']['subnets']['name']
        shared_subnet_cidr = yaml_global_conf['virtual_network_shared']['subnets']['cidr']

        shared_vdns_name        = yaml_global_conf['vDNS_shared']['name']
        shared_vdns_domain_name = yaml_global_conf['vDNS_shared']['domain_name']
        shared_vdns_dns_domain  = yaml_global_conf['vDNS_shared']['dns_domain']
        shared_vdns_rec_order   = yaml_global_conf['vDNS_shared']['rec_resolution_order']
        shared_vdns_ttl         = yaml_global_conf['vDNS_shared']['ttl']
        shared_vdns_next_vdns   = yaml_global_conf['vDNS_shared']['next_vdns']
        shared_vdns_fip_record  = yaml_global_conf['vDNS_shared']['floating_ip_record']
        shared_vdns_external_visible   = yaml_global_conf['vDNS_shared']['external_visible']
        shared_vdns_reverse_resolution = yaml_global_conf['vDNS_shared']['reverse_resolution']

        shared_ipame_name = yaml_global_conf['IPAM']['name']

        connections = ContrailConnections(inputs=inputs, logger=mylogger)
        auth_host   = connections.inputs.get_auth_host()
        vnc_lib_fixture = VncLibHelper(
                username=connections.inputs.stack_user, password=connections.inputs.stack_password,
                domain=connections.inputs.domain_name, project=connections.project_name,
                inputs=connections.inputs, cfgm_ip=connections.inputs.cfgm_ip,
                api_port=connections.inputs.api_server_port, auth_host=auth_host)
        vnc_lib = vnc_lib_fixture.get_handle()

        connections.project_name = "admin"

        vdns_name   = shared_vdns_name 
        domain_name = shared_vdns_domain_name
        dns_domain  = shared_vdns_dns_domain
        dyn_updates = True
        rec_order   = shared_vdns_rec_order
        ttl         = shared_vdns_ttl
        next_vdns   = shared_vdns_next_vdns
        fip_record  = shared_vdns_fip_record
        external_visible = shared_vdns_external_visible
        reverse_resolution = shared_vdns_reverse_resolution

        tenant_name = "admin"
        connections.inputs.domain_name = "default-domain"

        vdns_id = add_virtual_dns(vnc_lib,vdns_name,domain_name,dns_domain,dyn_updates,rec_order,\
                                                 ttl,next_vdns,fip_record,external_visible,reverse_resolution)
        ipam_obj = IPAM(connections)
        print "vdns-id:",vdns_id
        ipam_id = ipam_obj.create(shared_ipame_name, vdns_id)
        print "IPAM:",ipam_id

        vn_obj = VN(connections)
       
        cidr = shared_subnet_cidr
        vn_name = shared_vnet_name
        subnets = [{'cidr':cidr,'name':"shared_subnet"}]
        shared_vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=ipam_id,shared=True)

        return shared_vn_id
class SolnSetup(fixtures.Fixture):

    def __init__(self, test_resource):
        super(SolnSetup, self).__init__()
        self.test_resource = test_resource

    def setUp(self):
        super(SolnSetup, self).setUp()
        if 'PARAMS_FILE' in os.environ:
            self.ini_file = os.environ.get('PARAMS_FILE')
        else:
            self.ini_file = 'params.ini'
        self.inputs = self.useFixture(ContrailTestInit(self.ini_file))
        self.connections = ContrailConnections(self.inputs)
        self.quantum_fixture = self.connections.quantum_fixture
        self.nova_fixture = self.connections.nova_fixture
        self.vnc_lib = self.connections.vnc_lib
        self.logger = self.inputs.logger
        self.setup_common_objects()
        return self
    # end setUp

    def setup_common_objects(self):

        # Setting up default encapsulation
#        self.logger.info('Deleting any Encap before continuing')
#        out=self.connections.delete_vrouter_encap()
        self.logger.info('Setting new Encap before continuing')
        config_id = self.connections.update_vrouter_config_encap(
            'MPLSoGRE', 'MPLSoUDP', 'VXLAN')
        self.logger.info('updated.UUID is %s' % (config_id))

        (self.vn1_name, self.vn1_subnets) = ("EVPN-VN1", ["33.1.1.0/24"])
        (self.vn2_name, self.vn2_subnets) = ("EVPN-VN2", ["22.1.1.0/24"])
        (self.vn3_name, self.vn3_subnets) = ("EVPN-MGMT-VN", ["11.1.1.0/24"])
        (self.vn4_name, self.vn4_subnets) = ("EVPN-L2-VN", ["44.1.1.0/24"])
        (self.vn1_vm1_name) = 'EVPN_VN1_VM1'
        (self.vn1_vm2_name) = 'EVPN_VN1_VM2'
        (self.vn2_vm1_name) = 'EVPN_VN2_VM1'
        (self.vn2_vm2_name) = 'EVPN_VN2_VM2'
        (self.vn_l2_vm1_name) = 'EVPN_VN_L2_VM1'
        (self.vn_l2_vm2_name) = 'EVPN_VN_L2_VM2'
        # Get all compute host
        host_list = []
        for host in self.inputs.compute_ips:
            host_list.append(self.inputs.host_data[host]['name'])
        compute_1 = host_list[0]
        compute_2 = host_list[0]
        if len(host_list) > 1:
            compute_1 = host_list[0]
            compute_2 = host_list[1]

        self.vn1_fixture = self.useFixture(
            VNFixture(project_name=self.inputs.project_name,
                      connections=self.connections, inputs=self.inputs, vn_name=self.vn1_name, subnets=self.vn1_subnets))
        self.vn2_fixture = self.useFixture(
            VNFixture(project_name=self.inputs.project_name,
                      connections=self.connections, inputs=self.inputs, vn_name=self.vn2_name, subnets=self.vn2_subnets))
        self.vn3_fixture = self.useFixture(
            VNFixture(
                project_name=self.inputs.project_name, connections=self.connections,
                inputs=self.inputs, vn_name=self.vn3_name, subnets=self.vn3_subnets, forwarding_mode='l2_l3'))
        self.vn4_fixture = self.useFixture(
            VNFixture(
                project_name=self.inputs.project_name, connections=self.connections,
                inputs=self.inputs, vn_name=self.vn4_name, subnets=self.vn4_subnets, forwarding_mode='l2'))

        #self.vn1_vm1_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_obj= self.vn1_fixture.obj, flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn1_vm1_name,node_name= compute_1))
        #self.vn1_vm2_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_obj= self.vn1_fixture.obj, flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn1_vm2_name,node_name= compute_2))
        #self.vn2_vm1_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_obj= self.vn2_fixture.obj, flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn2_vm1_name,node_name= compute_1))
        #self.vn2_vm2_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_obj= self.vn2_fixture.obj, flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn2_vm2_name,node_name= compute_2))
        #self.vn_l2_vm1_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_objs= [self.vn3_fixture.obj , self.vn4_fixture.obj], flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn_l2_vm1_name,node_name= compute_1))
        #self.vn_l2_vm2_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,connections= self.connections, vn_objs= [self.vn3_fixture.obj , self.vn4_fixture.obj], flavor='contrail_flavor_small', image_name= 'ubuntu-traffic', vm_name= self.vn_l2_vm2_name,node_name= compute_2))
        # end setup_common_objects

    def tearDown(self):
        print "Tearing down resources"
        super(SolnSetup, self).cleanUp()

    def dirtied(self):
        self.test_resource.dirtied(self)
Exemple #42
0
    def setUp(self):

        tenants = self.test_conf['tenants'][0]
        tenant_count = tenants['count'] 
        vns_count    = tenants['virtual_networks'][0]['count'] 
        subnet_count = tenants['virtual_networks'][0]['subnets'][0]['count']
        vm_count     = tenants['virtual_networks'][0]['virtual_machines'][0]['count'] + tenants['virtual_networks'][0]['virtual_machines'][1]['count']

        glance_image = self.global_conf['GLOBALS']['glance_image_name']
        cidr_start   = tenants['virtual_networks'][0]['subnets'][0]['cidr']
        cidr_obj     = CIDR(cidr_start)
        vm_obj_list = []

        self.connections.project_name = "admin"
        self.connections = ContrailConnections(inputs=inputs, logger=mylogger)
        self.connections.vnc_lib = self.connections.get_vnc_lib_h()

        vdns_obj = vDNS(self.connections)
        vdns_id = vdns_obj.create('vDNS-test')
        vdns_fqname = vdns_obj.fq_name(vdns_id)
        print "vDNS:",vdns_fqname
        
        ipam_obj = IPAM(self.connections)
        ipam_id = ipam_obj.create('ipam-test', vdns_id)    
        ipam_fqname = ipam_obj.fq_name(ipam_id)
        print "IPAM:",ipam_fqname 

          
        vn_obj = VN(self.connections)
       
        cidr = "192.167.0.0/16"
        vn_name = "shared_net"
        subnets = [{'cidr':cidr,'name':"shared_subnet"}]
        vn_obj.shared=True
        shared_vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=ipam_id)
  
        tenant_obj = Project(self.connections)
        admin_tenant_id = self.connections.get_auth_h().get_project_id('default_domain','admin')

        for tenant_index in xrange(tenant_count):

          self.connections.project_id   = admin_tenant_id
          self.connections.inputs.project_name = "admin"
          self.connections.project_name = "admin"
          self.connections.project_fq_name = "admin"
          self.connections.domain_name = "admin"


          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name="admin")
          self.connections.vnc_lib = self.connections.get_vnc_lib_h()

          self.tenant_name = "TC002_tenant_%d"%tenant_index

          tenant_id = self.connections.get_auth_h().get_project_id('default_domain',self.tenant_name)
          if not tenant_id:
             tenant_id = tenant_obj.create(self.tenant_name)

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name=self.tenant_name)
          self.connections.vnc_lib = self.connections.get_vnc_lib_h()

          self.connections.inputs.project_name = self.tenant_name
          self.connections.project_name = self.tenant_name
          self.connections.project_fq_name = self.tenant_name
          self.connections.domain_name = self.tenant_name
          self.connections.project_id   = tenant_id
Exemple #43
0
    def setUp(self):

        tenants      = self.test_conf['tenants']
        tenant_count = tenants['count'] 
        vns_count    = tenants['virtual_networks']['count'] 
        subnet_count = tenants['virtual_networks']['subnets'][0]['count']
        vm_count     = 1
         
        tenant_name_prefix = tenants['name']

        glance_image = self.global_conf['GLOBALS']['glance_image_name']
        cidr_start   = tenants['virtual_networks']['subnets'][0]['cidr']
        cidr_obj     = CIDR(cidr_start)
        vm_obj_list = []

        self.connections.project_name = "admin"
        self.connections = ContrailConnections(inputs=inputs, logger=mylogger)
        auth_host = self.connections.inputs.get_auth_host()
        self.vnc_lib_fixture = VncLibHelper(
                username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password,
                domain=self.connections.inputs.domain_name, project=self.connections.project_name,
                inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip,
                api_port=self.connections.inputs.api_server_port, auth_host=auth_host)
        self.vnc_lib = self.vnc_lib_fixture.get_handle()

        
        admin_tenant_id = self.connections.get_auth_h().get_project_id('default_domain','admin')

        for tenant_index in xrange(tenant_count):

          self.connections.project_id   = admin_tenant_id
          self.connections.inputs.project_name = "admin"
          self.connections.project_name = "admin"
          self.connections.project_fq_name = "admin"

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name="admin")
          self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index)
          tenant_obj = ConfigProject(self.connections)

          tenant_id = self.connections.get_auth_h().get_project_id('default_domain',self.tenant_name)
          if tenant_id:
              print "Tenant : %s available...cleaning it..."%self.tenant_name
              self.cleanup(tenant_obj,tenant_id)

        net_list = self.ostack_admin_obj.neutron_client.list_networks()['networks']
        subnet_list = self.ostack_admin_obj.neutron_client.list_subnets()['subnets']

        #shared_vnet_name   = self.yaml_global_conf['virtual_network_shared']['name']
        #shared_subnet_name = self.yaml_global_conf['virtual_network_shared']['subnets']['name']
        #shared_subnet_cidr = self.yaml_global_conf['virtual_network_shared']['subnets']['cidr']
        #shared_ipame_name  = self.yaml_global_conf['IPAM']['name']

        #for subnet in subnet_list:
        #   if subnet["name"] == shared_subnet_name :
        #      subnet_id = subnet['id']
        #      self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id)

        #for net in net_list :
        #   if net["name"] == shared_vnet_name :
        #      net_id = net['id']
        #      self.ostack_admin_obj.neutron_client.delete_network(net_id)


        #ipam_list = self.vnc_lib.network_ipams_list()['network-ipams']
        #print "Existing IPAM list:",ipam_list

        #ipam_delete_list = [shared_ipame_name]

        #for ipam in ipam_list:
        #  domain,project,fq_name = ipam['fq_name']
        #  if fq_name in ipam_delete_list:
        #    obj = IPAM(self.connections)
        #    ipam_id = ipam['uuid']
        #    obj.delete(ipam_id)

        #self.shared_vn_id = global_configuration(self.yaml_global_conf,self.global_conf)

        for tenant_index in xrange(tenant_count):

          self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index)
          tenant_id = tenant_obj.create(self.tenant_name)
          tenant_obj.update_default_sg()
          return

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name=self.tenant_name)

          self.connections.inputs.project_name = self.tenant_name
          self.connections.project_name = self.tenant_name
          self.connections.project_fq_name = self.tenant_name
          self.connections.domain_name = self.tenant_name
          self.connections.project_id   = tenant_id

          #self.vdns_name   = "test1"
          #self.dns_domain  = "test1"
          #self.domain_name = "default-domain"

          #self.vnc_lib_fixture = VncLibHelper(
          #      username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password,
          #      domain=self.domain_name, project=self.connections.project_name,
          #      inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip,
          #      api_port=self.connections.inputs.api_server_port, auth_host=auth_host)
          #self.vnc_lib = self.vnc_lib_fixture.get_handle()

   
          #tenant_vdns_id = self.add_virtual_dns(self.vdns_name,self.domain_name,self.dns_domain,self.dyn_updates,self.rec_order,\
          #                               self.ttl,self.next_vdns,self.fip_record,self.external_visible,self.reverse_resolution)
          #ipam_obj = IPAM(self.connections)
          #
          #tenant_ipam_id = ipam_obj.create('T-%s-ipam'%self.tenant_name, tenant_vdns_id)
          #print "Tenant IPAM:",tenant_ipam_id
          tenant_ipam_id = None

          for vn_index in xrange(vns_count):
             vn_name = "%s_%d_VN_%d"%(tenant_name_prefix,tenant_index,vn_index) 
             
             vn_obj = VN(self.connections)
             try:
               vn_id = self.connections.get_network_h().get_vn_id(vn_name)
               if vn_id:
                vn_obj.delete(vn_id)
             except:
                pass
             cidr = cidr_obj.get_next_cidr()
             subnets = [{'cidr':cidr,'name':vn_name+"_subnet"}]
             vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=tenant_ipam_id)

             for vm_index in xrange(vm_count):
               vm_name = "Tenant%dVN%dVM%d"%(tenant_index,vn_index,vm_index) 
               vm_obj  = self.create_vm(self.tenant_name,vm_name,self.shared_vn_id,vn_id,glance_image)

        for obj in vm_obj_list:
           obj.print_params()
Exemple #44
0
class Test(object):

    def __init__(self,global_yaml_conf,global_conf,test_conf):

        self.yaml_global_conf = global_yaml_conf
        self.global_conf = global_conf
        self.test_conf = test_conf
        self.connections = setup_test_infra(global_conf['ENV']['testbed_file'])
        self.uuid = dict()
        self.tenant_ids = list()
        self.vm_connections_map = dict()
        self.ostack_admin_obj = Openstack(OS_AUTH_URL,OS_USERNAME,OS_PASSWORD,OS_TENANT_NAME)

        self.mysql_passwd = get_mysql_token()

    @retry(delay=60, tries=30)
    def wait_until_vms_deleted(self,tenant_id):

        vm_list = self.ostack_admin_obj.nova_client.servers.list(search_opts={'all_tenants': 1})
        print "VM_list:",vm_list
        vm_to_be_deleted = []

        for vm in vm_list:
            vm_id = vm.id
            if vm.tenant_id == re.sub("-","",tenant_id) :
               vm_to_be_deleted.append(vm)

        if len(vm_to_be_deleted) == 0 :
           return True
        else:
           return False

    def check_virtual_dns(self,vnc_lib,domain_name):

        domain_name_list = []
        domain_name_list.append(domain_name)
        domain_name_list_list = list(domain_name_list)
        try:
            domain_obj = vnc_lib.domain_read(fq_name=domain_name_list_list)
            print 'Domain ' + domain_name + 'found!' + domain_obj.uuid
            return domain_obj.uuid
        except NoIdError:
            print 'Domain ' + domain_name + ' not found!'
            return False


    def delete_vms(self,tenant_id):

        vm_list = self.ostack_admin_obj.nova_client.servers.list(search_opts={'all_tenants': 1})
        print "VM_list:",vm_list
        vm_to_be_deleted = []

        for vm in vm_list:
            vm_id = vm.id
            #print vm.tenant_id,tenant_id
            if vm.tenant_id == re.sub("-","",tenant_id) :
               vm_to_be_deleted.append(vm)

        for vm in vm_to_be_deleted:
            vm_id = vm.id
            print "deletingvm:%s"%str(vm_id)
            self.ostack_admin_obj.nova_client.servers.delete(vm_id) 

        self.wait_until_vms_deleted(tenant_id)

    def cleanup(self,tenant_obj,tenant_id):

        net_list = self.ostack_admin_obj.neutron_client.list_networks()['networks']
        subnet_list = self.ostack_admin_obj.neutron_client.list_subnets()['subnets']
        port_list = self.ostack_admin_obj.neutron_client.list_ports()['ports']

        self.delete_vms(tenant_id)
    
        for subnet in subnet_list :
           if subnet["tenant_id"] == re.sub("-","",tenant_id) :
              print "Name:",subnet['name']
              subnet_id = subnet['id']
              self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id)

        for net in net_list :
           if net["tenant_id"] == re.sub("-","",tenant_id) :
              print "Name:",net['name']
              net_id = net['id']
              self.ostack_admin_obj.neutron_client.delete_network(net_id)

        print dir(tenant_obj)
        tenant_obj.delete(tenant_id)

    def create_vm(self,tenant_name,vm_name,shared_vn_id,vn_id,image):
         
        self.connections.inputs.project_name = tenant_name
        self.connections.project_name = tenant_name

        self.connections.inputs.stack_tenant = tenant_name

        vm_obj = VM(self.connections)
        vm_obj.flavor="m1.small"
        vm_obj.zone="nova"
        #vm_obj.sg_ids=["4dd30150-f3ff-43d9-afcc-102df8dc658a"]
        
        print "VM:",vm_name,vn_id,image,shared_vn_id,vn_id
        vm_id  = vm_obj.create(vm_name,[shared_vn_id,vn_id],image)
        return vm_id

    def setUp(self):

        tenants      = self.test_conf['tenants']
        tenant_count = tenants['count'] 
        vns_count    = tenants['virtual_networks']['count'] 
        subnet_count = tenants['virtual_networks']['subnets'][0]['count']
        vm_count     = 1
         
        tenant_name_prefix = tenants['name']

        glance_image = self.global_conf['GLOBALS']['glance_image_name']
        cidr_start   = tenants['virtual_networks']['subnets'][0]['cidr']
        cidr_obj     = CIDR(cidr_start)
        vm_obj_list = []

        self.connections.project_name = "admin"
        self.connections = ContrailConnections(inputs=inputs, logger=mylogger)
        auth_host = self.connections.inputs.get_auth_host()
        self.vnc_lib_fixture = VncLibHelper(
                username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password,
                domain=self.connections.inputs.domain_name, project=self.connections.project_name,
                inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip,
                api_port=self.connections.inputs.api_server_port, auth_host=auth_host)
        self.vnc_lib = self.vnc_lib_fixture.get_handle()

        
        admin_tenant_id = self.connections.get_auth_h().get_project_id('default_domain','admin')

        for tenant_index in xrange(tenant_count):

          self.connections.project_id   = admin_tenant_id
          self.connections.inputs.project_name = "admin"
          self.connections.project_name = "admin"
          self.connections.project_fq_name = "admin"

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name="admin")
          self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index)
          tenant_obj = ConfigProject(self.connections)

          tenant_id = self.connections.get_auth_h().get_project_id('default_domain',self.tenant_name)
          if tenant_id:
              print "Tenant : %s available...cleaning it..."%self.tenant_name
              self.cleanup(tenant_obj,tenant_id)

        net_list = self.ostack_admin_obj.neutron_client.list_networks()['networks']
        subnet_list = self.ostack_admin_obj.neutron_client.list_subnets()['subnets']

        #shared_vnet_name   = self.yaml_global_conf['virtual_network_shared']['name']
        #shared_subnet_name = self.yaml_global_conf['virtual_network_shared']['subnets']['name']
        #shared_subnet_cidr = self.yaml_global_conf['virtual_network_shared']['subnets']['cidr']
        #shared_ipame_name  = self.yaml_global_conf['IPAM']['name']

        #for subnet in subnet_list:
        #   if subnet["name"] == shared_subnet_name :
        #      subnet_id = subnet['id']
        #      self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id)

        #for net in net_list :
        #   if net["name"] == shared_vnet_name :
        #      net_id = net['id']
        #      self.ostack_admin_obj.neutron_client.delete_network(net_id)


        #ipam_list = self.vnc_lib.network_ipams_list()['network-ipams']
        #print "Existing IPAM list:",ipam_list

        #ipam_delete_list = [shared_ipame_name]

        #for ipam in ipam_list:
        #  domain,project,fq_name = ipam['fq_name']
        #  if fq_name in ipam_delete_list:
        #    obj = IPAM(self.connections)
        #    ipam_id = ipam['uuid']
        #    obj.delete(ipam_id)

        #self.shared_vn_id = global_configuration(self.yaml_global_conf,self.global_conf)

        for tenant_index in xrange(tenant_count):

          self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index)
          tenant_id = tenant_obj.create(self.tenant_name)
          tenant_obj.update_default_sg()
          return

          self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name=self.tenant_name)

          self.connections.inputs.project_name = self.tenant_name
          self.connections.project_name = self.tenant_name
          self.connections.project_fq_name = self.tenant_name
          self.connections.domain_name = self.tenant_name
          self.connections.project_id   = tenant_id

          #self.vdns_name   = "test1"
          #self.dns_domain  = "test1"
          #self.domain_name = "default-domain"

          #self.vnc_lib_fixture = VncLibHelper(
          #      username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password,
          #      domain=self.domain_name, project=self.connections.project_name,
          #      inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip,
          #      api_port=self.connections.inputs.api_server_port, auth_host=auth_host)
          #self.vnc_lib = self.vnc_lib_fixture.get_handle()

   
          #tenant_vdns_id = self.add_virtual_dns(self.vdns_name,self.domain_name,self.dns_domain,self.dyn_updates,self.rec_order,\
          #                               self.ttl,self.next_vdns,self.fip_record,self.external_visible,self.reverse_resolution)
          #ipam_obj = IPAM(self.connections)
          #
          #tenant_ipam_id = ipam_obj.create('T-%s-ipam'%self.tenant_name, tenant_vdns_id)
          #print "Tenant IPAM:",tenant_ipam_id
          tenant_ipam_id = None

          for vn_index in xrange(vns_count):
             vn_name = "%s_%d_VN_%d"%(tenant_name_prefix,tenant_index,vn_index) 
             
             vn_obj = VN(self.connections)
             try:
               vn_id = self.connections.get_network_h().get_vn_id(vn_name)
               if vn_id:
                vn_obj.delete(vn_id)
             except:
                pass
             cidr = cidr_obj.get_next_cidr()
             subnets = [{'cidr':cidr,'name':vn_name+"_subnet"}]
             vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=tenant_ipam_id)

             for vm_index in xrange(vm_count):
               vm_name = "Tenant%dVN%dVM%d"%(tenant_index,vn_index,vm_index) 
               vm_obj  = self.create_vm(self.tenant_name,vm_name,self.shared_vn_id,vn_id,glance_image)

        for obj in vm_obj_list:
           obj.print_params()