コード例 #1
0
ファイル: create.py プロジェクト: vganapath/contrail-test
 def __init__(self, args):
     self.args = args
     self.connections = setup_test_infra(args.testbed_file)
     project_id = self.connections.get_project_id()
     project_fq_name = self.connections.get_project_fq_name()
     self.db = TestDB(args.db_file)
     self.db.set_project_id(project_fq_name, project_id)
     self.uuid = dict()
     self.vm_connections_map = dict()
コード例 #2
0
 def __init__(self, args):
     self.args = args
     self.connections = setup_test_infra(args.testbed_file)
     project_id = self.connections.get_project_id()
     project_fq_name = self.connections.get_project_fq_name()
     self.db = TestDB(args.db_file)
     self.db.set_project_id(project_fq_name, project_id)
     self.uuid = dict()
     self.vm_connections_map = dict()
コード例 #3
0
 def __init__(self, args):
     self.args = args
     self.connections = setup_test_infra(args.testbed_file)
     self.db = None
     if args.db_file:
         self.db = TestDB(args.db_file)
コード例 #4
0
class verify(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        self.db = None
        if args.db_file:
            self.db = TestDB(args.db_file)

    def verify_router(self):
        raise Exception('Not yet implemented')

    def get_vdns_ids(self):
        vdns = []
        if self.db:
            for fqname in self.db.list_vdns():
                vdns.append(self.db.get_vdns_id(fqname))
        return vdns

    def get_fip_pool_ids(self):
        fip_pools = []
        if self.db:
            for fqname in self.db.list_fip_pools():
                fip_pools.append(self.db.get_fip_pool_id(fqname))
        return fip_pools

    def get_tenant_fqnames(self):
        if self.args.tenant:
            return [':'.join([self.connections.inputs.domain_name, self.args.tenant])]
        if self.db:
            return self.db.list_projects()
        return []

    def get_ipam_ids(self, project_fqname):
        ipams = []
        if self.db:
            for fqname in self.db.list_ipams(project_fqname):
                ipams.append(self.db.get_ipam_id(fqname))
        return ipams

    def get_vn_ids(self, project_fqname, connections):
        if self.args.vn_name:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            assert vn_id, 'Unable to fetch ID of vn_name '+ self.args.vn_name
            return [vn_id]
        vns = []
        if self.db:
            for fqname in self.db.list_virtual_networks(project_fqname):
                vn_id  = self.db.get_virtual_network_id(fqname)
                vns.append(vn_id)
        return vns

    def get_vm_details(self, vm_name, project_fqname, connections):
        if self.args.vm_id:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            return (self.args.vm_id, [vn_id], self.args.username, self.args.password)
        if self.db:
            return self.db.get_virtual_machine(vm_name, project_fqname)
        return None

    def get_vm_names(self, project_fqname):
        if self.args.vm_id:
            return [self.args.vm_id]
        if self.db:
            return self.db.list_virtual_machines(project_fqname)
        return []

    def get_project_id(self, fqname):
        if self.db:
            return self.db.get_project_id(fqname)
        else:
            return self.connections.get_auth_h().get_project_id(fqname[-1])

    def get_fip_ids(self, vm_name, project_fqname):
        if self.db:
            return self.db.get_fip_id_assoc(vm_name, project_fqname)
        return []

    def verify(self):
        vdns_ids = self.args.vdns or self.get_vdns_ids()
        for vdns_id in vdns_ids:
            vDNS(self.connections).verify(vdns_id)

        fip_pool_ids = self.args.fip_pool_id or self.get_fip_pool_ids()
        for fip_pool in fip_pool_ids:
            FloatingIPPool(self.connections).verify(fip_pool)

        for tenant_fqname in self.get_tenant_fqnames():
            project_id = self.get_project_id(tenant_fqname)
            project_obj = Project(self.connections)
            project_obj.verify(project_id)
            connections = project_obj.get_connections()
            ipam_ids = self.args.ipam or self.get_ipam_ids(tenant_fqname)
            for ipam_id in ipam_ids:
                IPAM(connections).verify(ipam_id)

            for vn_id in self.get_vn_ids(tenant_fqname, connections):
                VN(connections).verify(vn_id)

            for vm_name in self.get_vm_names(tenant_fqname):
                (vm_id, vn_ids, username, password) = \
                        self.get_vm_details(vm_name, tenant_fqname, connections)
                vm_obj = VM(connections)
                vm_obj.verify(vm_id, vn_ids, username, password)
                if self.args.vm_id:
                    vm_name = vm_obj.fq_name()
                for fip_id in self.get_fip_ids(vm_name, tenant_fqname):
                    fip_obj = FloatingIPPool(self.connections)
                    fip_pool_id = fip_obj.get_fip_pool_id(fip_id)
                    fip_obj.verify_fip(fip_pool_id, fip_id, vm_id, vn_ids, connections)
コード例 #5
0
 def __init__(self, args):
     self.args = args
     self.connections = setup_test_infra(args.testbed_file)
     self.db = None
     if args.db_file:
         self.db = TestDB(args.db_file)
コード例 #6
0
class verify(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        self.db = None
        if args.db_file:
            self.db = TestDB(args.db_file)

    def verify_router(self):
        raise Exception('Not yet implemented')

    def get_vdns_ids(self):
        vdns = []
        if self.db:
            for fqname in self.db.list_vdns():
                vdns.append(self.db.get_vdns_id(fqname))
        return vdns

    def get_fip_pool_ids(self):
        fip_pools = []
        if self.db:
            for fqname in self.db.list_fip_pools():
                fip_pools.append(self.db.get_fip_pool_id(fqname))
        return fip_pools

    def get_tenant_fqnames(self):
        if self.args.tenant:
            return [
                ':'.join(
                    [self.connections.inputs.domain_name, self.args.tenant])
            ]
        if self.db:
            return self.db.list_projects()
        return []

    def get_ipam_ids(self, project_fqname):
        ipams = []
        if self.db:
            for fqname in self.db.list_ipams(project_fqname):
                ipams.append(self.db.get_ipam_id(fqname))
        return ipams

    def get_vn_ids(self, project_fqname, connections):
        if self.args.vn_name:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            assert vn_id, 'Unable to fetch ID of vn_name ' + self.args.vn_name
            return [vn_id]
        vns = []
        if self.db:
            for fqname in self.db.list_virtual_networks(project_fqname):
                vn_id = self.db.get_virtual_network_id(fqname)
                vns.append(vn_id)
        return vns

    def get_vm_details(self, vm_name, project_fqname, connections):
        if self.args.vm_id:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            return (self.args.vm_id, [vn_id], self.args.username,
                    self.args.password)
        if self.db:
            return self.db.get_virtual_machine(vm_name, project_fqname)
        return None

    def get_vm_names(self, project_fqname):
        if self.args.vm_id:
            return [self.args.vm_id]
        if self.db:
            return self.db.list_virtual_machines(project_fqname)
        return []

    def get_project_id(self, fqname):
        if self.db:
            return self.db.get_project_id(fqname)
        else:
            return self.connections.get_auth_h().get_project_id(fqname[-1])

    def get_fip_ids(self, vm_name, project_fqname):
        if self.db:
            return self.db.get_fip_id_assoc(vm_name, project_fqname)
        return []

    def verify(self):
        vdns_ids = self.args.vdns or self.get_vdns_ids()
        for vdns_id in vdns_ids:
            vDNS(self.connections).verify(vdns_id)

        fip_pool_ids = self.args.fip_pool_id or self.get_fip_pool_ids()
        for fip_pool in fip_pool_ids:
            FloatingIPPool(self.connections).verify(fip_pool)

        for tenant_fqname in self.get_tenant_fqnames():
            project_id = self.get_project_id(tenant_fqname)
            project_obj = Project(self.connections)
            project_obj.verify(project_id)
            connections = project_obj.get_connections()
            ipam_ids = self.args.ipam or self.get_ipam_ids(tenant_fqname)
            for ipam_id in ipam_ids:
                IPAM(connections).verify(ipam_id)

            for vn_id in self.get_vn_ids(tenant_fqname, connections):
                VN(connections).verify(vn_id)

            for vm_name in self.get_vm_names(tenant_fqname):
                (vm_id, vn_ids, username, password) = \
                        self.get_vm_details(vm_name, tenant_fqname, connections)
                vm_obj = VM(connections)
                vm_obj.verify(vm_id, vn_ids, username, password)
                if self.args.vm_id:
                    vm_name = vm_obj.fq_name()
                for fip_id in self.get_fip_ids(vm_name, tenant_fqname):
                    fip_obj = FloatingIPPool(self.connections)
                    fip_pool_id = fip_obj.get_fip_pool_id(fip_id)
                    fip_obj.verify_fip(fip_pool_id, fip_id, vm_id, vn_ids,
                                       connections)
コード例 #7
0
ファイル: delete.py プロジェクト: vganapath/contrail-test
class delete(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        self.db = None
        if args.db_file:
            self.db = TestDB(args.db_file)

    def get_vdns_ids(self):
        if not self.args.delete_vdns or self.args.tenant:
            return []
        vdns = []
        if self.db:
            for fqname in self.db.list_vdns():
                vdns.append(self.db.get_vdns_id(fqname))
        return vdns

    def get_fip_pool_ids(self):
        if not self.args.delete_fip_pool or self.args.tenant:
            return []
        fip_pools = []
        if self.db:
            for fqname in self.db.list_fip_pools():
                fip_pools.append(self.db.get_fip_pool_id(fqname))
        return fip_pools

    def get_tenant_fqnames(self):
        if self.args.tenant:
            return [
                ':'.join(
                    [self.connections.inputs.domain_name, self.args.tenant])
            ]
        if self.db:
            return self.db.list_projects()
        return []

    def get_ipam_ids(self, project_fqname):
        ipams = []
        if not self.args.delete_ipam or self.args.vn_name:
            return ipams
        if self.args.ipam:
            return self.args.ipam
        if self.db:
            for fqname in self.db.list_ipams(project_fqname):
                ipams.append(self.db.get_ipam_id(fqname))
        return ipams

    def get_vn_ids(self, project_fqname, connections):
        if self.args.vm_id:
            return []
        if self.args.vn_name:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            assert vn_id, 'Unable to fetch ID of vn_name ' + self.args.vn_name
            return [vn_id]
        vns = []
        if self.db:
            for fqname in self.db.list_virtual_networks(project_fqname):
                vn_id = self.db.get_virtual_network_id(fqname)
                vns.append(vn_id)
        return vns

    def get_vm_details(self, vm_name, project_fqname, connections):
        if self.args.vm_id:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            return (self.args.vm_id, [vn_id], '', '')
        if self.db:
            return self.db.get_virtual_machine(vm_name, project_fqname)
        return None

    def get_vm_names(self, project_fqname):
        if self.args.vm_id:
            return [self.args.vm_id]
        if self.db:
            return self.db.list_virtual_machines(project_fqname)
        return []

    def get_router_ids(self, project_fqname):
        if not self.args.delete_snat or self.args.vn_name:
            return []
        if self.args.router_id:
            return [self.args.router_id]
        if self.db:
            rtr_ids = []
            for rtr in self.db.list_logical_routers():
                if project_fqname not in rtr:
                    continue
                rtr_ids.append(self.db.get_logical_router_id(rtr))
            return rtr_ids
        return []

    def get_project_id(self, fqname):
        if self.db:
            return self.db.get_project_id(fqname)
        else:
            return self.connections.get_auth_h().get_project_id(fqname[-1])

    def get_fip_ids(self, vm_name, project_fqname):
        if self.db:
            return self.db.get_fip_id_assoc(vm_name, project_fqname)
        return []

    def _delete(self, tenant_fqname, connections):

        for vm_name in self.get_vm_names(tenant_fqname):
            (vm_id, vn_ids, username, password) = \
                    self.get_vm_details(vm_name, tenant_fqname, connections)
            obj = VM(connections)
            if self.args.vm_id:
                vm_name = obj.fq_name(vm_id)
            for fip_id in self.get_fip_ids(vm_name, tenant_fqname):
                fip_obj = FloatingIPPool(self.connections)
                fip_pool_id = fip_obj.get_fip_pool_id(fip_id)
                fip = fip_obj.get_fip_from_id(fip_id)
                fip_obj.disassociate_fip(fip_pool_id, fip_id)
                fip_obj.verify_no_fip(fip_pool_id, fip_id, vm_id, fip)
                if self.db:
                    self.db.delete_fip(fip_obj.fq_name(), fip_id)
                    self.db.disassociate_fip_from_vm(vm_name, tenant_fqname,
                                                     fip_id)
            obj.delete(vm_id, vn_ids)
            if self.db:
                self.db.delete_virtual_machine(vm_name, tenant_fqname)

        for router_id in self.get_router_ids(tenant_fqname):
            router_obj = LogicalRouter(connections)
            fqname = router_obj.fq_name(router_id)
            router_obj.delete(router_id)
            if self.db:
                self.db.delete_logical_router(fqname)


#ToDo: msenthil - Link LR and VNs

        for vn_id in self.get_vn_ids(tenant_fqname, connections):
            obj = VN(connections)
            fqname = obj.fq_name(vn_id)
            obj.delete(vn_id)
            if self.db:
                self.db.delete_virtual_network(fqname)

        ipam_ids = self.get_ipam_ids(tenant_fqname)
        for ipam_id in ipam_ids:
            obj = IPAM(connections)
            fqname = obj.fq_name(ipam_id)
            obj.delete(ipam_id)
            if self.db:
                self.db.delete_ipam(fqname)

    def delete(self):
        for tenant_fqname in self.get_tenant_fqnames():
            if tenant_fqname == ':'.join(
                    self.connections.get_project_fq_name()):
                continue
            project_obj = Project(self.connections)
            project_id = self.get_project_id(tenant_fqname)
            connections = project_obj.get_connections(project_id)
            self._delete(tenant_fqname, connections)
            if not self.args.vn_name and self.args.delete_ipam:
                project_obj.delete(project_id)
                if self.db:
                    self.db.delete_project(tenant_fqname)

        fip_pool_ids = self.get_fip_pool_ids()
        for fip_pool in fip_pool_ids:
            obj = FloatingIPPool(self.connections)
            fqname = obj.fq_name(fip_pool)
            obj.delete(fip_pool)
            if self.db:
                self.db.delete_fip_pool(fqname)

        self._delete(':'.join(self.connections.get_project_fq_name()),
                     self.connections)

        vdns_ids = self.get_vdns_ids()
        for vdns_id in vdns_ids:
            obj = vDNS(self.connections)
            fqname = obj.fq_name(vdns_id)
            obj.delete(vdns_id)
            if self.db:
                self.db.delete_vdns(fqname)
コード例 #8
0
class delete(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        self.db = None
        if args.db_file:
            self.db = TestDB(args.db_file)

    def get_vdns_ids(self):
        if not self.args.delete_vdns or self.args.tenant:
            return []
        vdns = []
        if self.db:
            for fqname in self.db.list_vdns():
                vdns.append(self.db.get_vdns_id(fqname))
        return vdns

    def get_fip_pool_ids(self):
        if not self.args.delete_fip_pool or self.args.tenant:
            return []
        fip_pools = []
        if self.db:
            for fqname in self.db.list_fip_pools():
                fip_pools.append(self.db.get_fip_pool_id(fqname))
        return fip_pools

    def get_tenant_fqnames(self):
        if self.args.tenant:
            return [':'.join([self.connections.inputs.domain_name, self.args.tenant])]
        if self.db:
            return self.db.list_projects()
        return []

    def get_ipam_ids(self, project_fqname):
        ipams = []
        if not self.args.delete_ipam or self.args.vn_name:
            return ipams
        if self.args.ipam:
            return self.args.ipam
        if self.db:
            for fqname in self.db.list_ipams(project_fqname):
                ipams.append(self.db.get_ipam_id(fqname))
        return ipams

    def get_vn_ids(self, project_fqname, connections):
        if self.args.vm_id:
            return []
        if self.args.vn_name:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            assert vn_id, 'Unable to fetch ID of vn_name '+ self.args.vn_name
            return [vn_id]
        vns = []
        if self.db:
            for fqname in self.db.list_virtual_networks(project_fqname):
                vn_id = self.db.get_virtual_network_id(fqname)
                vns.append(vn_id)
        return vns

    def get_vm_details(self, vm_name, project_fqname, connections):
        if self.args.vm_id:
            vn_id = connections.get_network_h().get_vn_id(self.args.vn_name)
            return (self.args.vm_id, [vn_id], '', '')
        if self.db:
            return self.db.get_virtual_machine(vm_name, project_fqname)
        return None

    def get_vm_names(self, project_fqname):
        if self.args.vm_id:
            return [self.args.vm_id]
        if self.db:
            return self.db.list_virtual_machines(project_fqname)
        return []

    def get_router_ids(self, project_fqname):
        if not self.args.delete_snat or self.args.vn_name:
            return []
        if self.args.router_id:
            return [self.args.router_id]
        if self.db:
            rtr_ids = []
            for rtr in self.db.list_logical_routers():
                if project_fqname not in rtr:
                    continue
                rtr_ids.append(self.db.get_logical_router_id(rtr))
            return rtr_ids
        return []

    def get_project_id(self, fqname):
        if self.db:
            return self.db.get_project_id(fqname)
        else:
            return self.connections.get_auth_h().get_project_id(fqname[-1])

    def get_fip_ids(self, vm_name, project_fqname):
        if self.db:
            return self.db.get_fip_id_assoc(vm_name, project_fqname)
        return []

    def _delete(self, tenant_fqname, connections):

        for vm_name in self.get_vm_names(tenant_fqname):
            (vm_id, vn_ids, username, password) = \
                    self.get_vm_details(vm_name, tenant_fqname, connections)
            obj = VM(connections)
            if self.args.vm_id:
                vm_name = obj.fq_name(vm_id)
            for fip_id in self.get_fip_ids(vm_name, tenant_fqname):
                fip_obj = FloatingIPPool(self.connections)
                fip_pool_id = fip_obj.get_fip_pool_id(fip_id)
                fip = fip_obj.get_fip_from_id(fip_id)
                fip_obj.disassociate_fip(fip_pool_id, fip_id)
                fip_obj.verify_no_fip(fip_pool_id, fip_id, vm_id, fip)
                if self.db:
                    self.db.delete_fip(fip_obj.fq_name(), fip_id)
                    self.db.disassociate_fip_from_vm(vm_name, tenant_fqname, fip_id)
            obj.delete(vm_id, vn_ids)
            if self.db:
                self.db.delete_virtual_machine(vm_name, tenant_fqname)

        for router_id in self.get_router_ids(tenant_fqname):
            router_obj = LogicalRouter(connections)
            fqname = router_obj.fq_name(router_id)
            router_obj.delete(router_id)
            if self.db:
                self.db.delete_logical_router(fqname)
#ToDo: msenthil - Link LR and VNs

        for vn_id in self.get_vn_ids(tenant_fqname, connections):
            obj = VN(connections)
            fqname = obj.fq_name(vn_id)
            obj.delete(vn_id)
            if self.db:
                self.db.delete_virtual_network(fqname)

        ipam_ids = self.get_ipam_ids(tenant_fqname)
        for ipam_id in ipam_ids:
            obj = IPAM(connections)
            fqname = obj.fq_name(ipam_id)
            obj.delete(ipam_id)
            if self.db:
                self.db.delete_ipam(fqname)

    def delete(self):
        for tenant_fqname in self.get_tenant_fqnames():
            if tenant_fqname == ':'.join(self.connections.get_project_fq_name()):
                continue
            project_obj = Project(self.connections)
            project_id = self.get_project_id(tenant_fqname)
            connections = project_obj.get_connections(project_id)
            self._delete(tenant_fqname, connections)
            if not self.args.vn_name and self.args.delete_ipam:
                project_obj.delete(project_id)
                if self.db:
                    self.db.delete_project(tenant_fqname)

        fip_pool_ids = self.get_fip_pool_ids()
        for fip_pool in fip_pool_ids:
            obj = FloatingIPPool(self.connections)
            fqname = obj.fq_name(fip_pool)
            obj.delete(fip_pool)
            if self.db:
                self.db.delete_fip_pool(fqname)

        self._delete(':'.join(self.connections.get_project_fq_name()),
                     self.connections)

        vdns_ids = self.get_vdns_ids()
        for vdns_id in vdns_ids:
            obj = vDNS(self.connections)
            fqname = obj.fq_name(vdns_id)
            obj.delete(vdns_id)
            if self.db:
                self.db.delete_vdns(fqname)
コード例 #9
0
ファイル: create.py プロジェクト: vganapath/contrail-test
class create(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        project_id = self.connections.get_project_id()
        project_fq_name = self.connections.get_project_fq_name()
        self.db = TestDB(args.db_file)
        self.db.set_project_id(project_fq_name, project_id)
        self.uuid = dict()
        self.vm_connections_map = dict()

    def setup(self):

        # Create vDNS
        vdns_id = self.args.vdns
        vdns_obj = vDNS(self.connections)
        vdns_fqname = None
        if self.args.create_vdns:
            vdns_id = vdns_obj.create(random_string('vDNS'))
        if vdns_id:
            vdns_fqname = vdns_obj.fq_name(vdns_id)
            self.db.set_vdns_id(vdns_fqname, vdns_id)

# Create Public Network in case of dNAT or sNAT
        if self.args.n_fips or self.args.create_snat or self.args.router_id:
            name = self.args.public_vn or random_string('Public')
            vn_obj = VN(self.connections)
            self.public_vn_id = vn_obj.create(name, external=True)
            vn_subnets = vn_obj.get_subnets(self.public_vn_id)
            self.db.add_virtual_network(vn_obj.fq_name(), self.public_vn_id,
                                        vn_subnets)

# Create Tenant
        for tenant_index in range(int(self.args.n_tenants)):
            self.tenant_name = self.args.tenant or random_string(
                self.args.tenant_prefix)
            tenant_obj = Project(self.connections)
            tenant_id = tenant_obj.create(self.tenant_name)
            tenant_obj.update_default_sg()
            tenant_connections = tenant_obj.get_connections()
            self.db.set_project_id(tenant_obj.fq_name(), tenant_id)
            self.uuid[self.tenant_name] = UUID()

            # Create IPAM
            ipam_id = self.args.ipam
            ipam_obj = IPAM(tenant_connections)
            if self.args.create_ipam:
                ipam_id = ipam_obj.create(self.get_name('ipam'), vdns_id)
            if ipam_id:
                ipam_fqname = ipam_obj.fq_name(ipam_id)
                self.uuid[self.tenant_name].ipam_id = ipam_id
                self.db.add_ipam(ipam_obj.fq_name(), ipam_id, vdns_fqname)

# Create sNAT instance
            self.router_id = self.args.router_id
            router_obj = LogicalRouter(tenant_connections)
            if self.args.create_snat:
                self.router_id = router_obj.create(self.get_name('rtr'),
                                                   gw=self.public_vn_id)
            if self.router_id:
                router_fqname = router_obj.fq_name(self.router_id)
                self.db.add_logical_router(router_fqname, self.router_id)
                self.db.set_gw_to_lr(router_fqname, self.public_vn_id)
                self.router_fqname = router_fqname

# Create Network
            self.create_vns(tenant_connections)

            # Create VMs
            for vn_name, vn_id in self.uuid[
                    self.tenant_name].vn_id.iteritems():
                self.create_vms(tenant_connections, vn_id, vn_name)


# Create FIP Pool and associate fips to VMs
        if self.args.n_fips:
            fip_pool_obj = FloatingIPPool(self.connections)
            self.fip_pool_id = fip_pool_obj.create(self.public_vn_id)
            self.fip_pool_fqname = fip_pool_obj.fq_name()
            self.db.add_fip_pool(self.fip_pool_fqname, self.fip_pool_id)
            self.associate_fips()

    def create_vns(self, connections):
        for index in range(int(self.args.n_vns)):
            name = self.args.vn_name or self.get_name('VN', index)
            ipam_id = self.uuid[self.tenant_name].ipam_id
            vn_obj = VN(connections)
            self.uuid[self.tenant_name].vn_id[name] = vn_obj.create(
                name, ipam_id=ipam_id)
            vn_fqname = vn_obj.fq_name()
            vn_subnets = vn_obj.get_subnets(
                self.uuid[self.tenant_name].vn_id[name])
            self.db.add_virtual_network(
                vn_fqname, self.uuid[self.tenant_name].vn_id[name], vn_subnets)
            if self.router_id:
                LogicalRouter(connections).attach_vn(
                    self.router_id, self.uuid[self.tenant_name].vn_id[name])
                self.db.add_vn_to_lr(self.router_fqname,
                                     self.uuid[self.tenant_name].vn_id[name])
                self.db.add_lr_to_vn(vn_fqname, self.router_id)

    def create_vms(self, connections, vn_id, vn_name):
        for index in range(int(self.args.n_vms)):
            name = random_string(vn_name + '-VM%s' % index)
            vm_obj = VM(connections)
            self.uuid[self.tenant_name].vm_id[name] = vm_obj.create(
                name, [vn_id], self.args.image)
            vm_fqname = vm_obj.fq_name()
            (self.username, self.password) = vm_obj.get_vm_creds()
            self.db.add_virtual_machine(
                name, connections.get_project_fq_name(),
                self.uuid[self.tenant_name].vm_id[name], [vn_id],
                self.username, self.password)
            self.vm_connections_map[name] = connections

    def associate_fips(self):
        vm_names = list()
        vm_ids = list()
        for uuid in self.uuid.itervalues():
            (names, ids) = (uuid.vm_id.keys(), uuid.vm_id.values())
            vm_names.extend(names)
            vm_ids.extend(ids)

        for index in range(int(self.args.n_fips)):
            connections = self.vm_connections_map[vm_names[index]]
            fip_id = FloatingIPPool(self.connections).associate_fip(
                self.fip_pool_id, vm_ids[index], connections, self.username,
                self.password)
            self.db.associate_fip_to_vm(vm_names[index],
                                        connections.get_project_fq_name(),
                                        fip_id)
            self.db.add_fip(self.fip_pool_fqname, fip_id)

    def get_name(self, prefix, index=''):
        return random_string(self.tenant_name + '-' + str(prefix) + str(index))
コード例 #10
0
    def setUp(self):

        global data_cidr_obj, default_sg_id, vms_info
        vms_info = {}

        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 = tenants['virtual_networks']['virtual_machines']['count']

        self.tenant_name_pattern = tenants['name']

        self.glance_image = self.ini_global_conf['GLOBALS'][
            'glance_image_name']
        cidr_start = tenants['virtual_networks']['subnets'][0]['cidr']
        mgmt_cidr_obj = CIDR(cidr_start)
        cidr_start = tenants['virtual_networks']['subnets'][1]['cidr']
        data_cidr_obj = CIDR(cidr_start)
        vm_obj_list = []

        self.db = TestDB("/var/tmp/db.test")

        self.connections = setup_test_infra(
            self.ini_global_conf['ENV']['testbed_file'])
        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()
        self.vnc = self.connections.get_vnc_lib_h().get_handle()

        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']

        mgmt_vn = self.test_conf['tenants']['virtual_networks']['mgmt_vn_name']
        mgmt_subnet = mgmt_vn + "_subnet"

        tenant_name_pattern = self.test_conf['tenants']['name']

        tenant_obj_l = []
        for tenant_index in xrange(tenant_count):
            tenant_name = re.sub("XXX", str(tenant_index), tenant_name_pattern)
            print "Tenant-name", tenant_name
            tenant_obj = PerTenant(self.vnc_lib, self.connections,
                                   self.test_conf['tenants'], tenant_index)
            tenant_obj.retrieve_existing_tenant_id()
            tenant_obj.clean_tenant()
            tenant_obj_l.append(tenant_obj)

        for subnet in subnet_list:
            if subnet['name'] == mgmt_subnet:
                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['name'] == mgmt_vn:
                print "Name:", net['name']
                net_id = net['id']
                self.ostack_admin_obj.neutron_client.delete_network(net_id)

        self.cleanup_ipam()
        self.cleanup_vdns()

        for tenant_index in xrange(tenant_count):
            tenant_name = re.sub("XXX", str(tenant_index), tenant_name_pattern)
            print "Deleting tenant:", tenant_name
            tenant_obj_l[tenant_index].delete_tenant()

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

        import pdb
        pdb.set_trace()
        self.create_global_vdns()

        mgmt_domain_name_pattern = self.test_conf['tenants'][
            'virtual_networks']['vDNS'][0]['domain_name']
        data_domain_name_pattern = self.test_conf['tenants'][
            'virtual_networks']['vDNS'][1]['domain_name']
        mgmt_vn_name = self.test_conf['tenants']['virtual_networks'][
            'mgmt_vn_name']

        mgmt_domain_name = re.sub('ZZZ', '2', mgmt_domain_name_pattern)

        ipam_name_pattern = self.test_conf['tenants']['virtual_networks'][
            'IPAM']['name']

        mgmt_ipam_name = re.sub('ZZZ', '2', ipam_name_pattern)
        mgmt_ipam_name = re.sub('CCC', 'mgmt', mgmt_ipam_name)

        ipam_delete_list = [mgmt_ipam_name]

        ipam_list = self.vnc_lib.network_ipams_list()['network-ipams']

        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)

        mgmt_vdns_id = self.global_vdns[mgmt_domain_name].get_uuid()

        #ipam_obj     = IPAM(self.connections)
        #mgmt_ipam_id = ipam_obj.create(mgmt_ipam_name, mgmt_vdns_id)
        #print "MGMT IPAM:",mgmt_ipam_id

        #vn_obj  = VN(self.connections)
        #cidr    = mgmt_cidr_obj.get_next_cidr()
        #vn_name = mgmt_vn_name
        #subnets = [{'cidr':cidr,'name':vn_name + "_subnet"}]
        #self.mgmt_vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=mgmt_ipam_id,disable_gateway=True,shared=True,rt_number=10000)
        self.mgmt_vn_id = None

        queues = list()
        kwargs_list = list()

        self.timeout = 3600
        tenant1_obj = self.create_tenant(self.test_conf['tenants'], 0)
        tenant2_obj = self.create_tenant(self.test_conf['tenants'], 1)

        return

        #time.sleep(10)
        #print tenant1_obj.get_vms_ips()
        #print tenant2_obj.get_vms_ips()

        tenant_count = 2

        for tenant_index in xrange(tenant_count):

            queues.append(Queue())
            kwargs_list.append({
                'queue': queues[tenant_index],
                'tenant_index': tenant_index,
                'tenant_conf': self.test_conf['tenants']
            })

        (success,
         timediff) = lib.create_n_process(self.create_tenant,
                                          tenant_count,
                                          kwargs_list,
                                          self.timeout,
                                          callback=self.read_from_queue)
コード例 #11
0
class create(object):
    def __init__(self, args):
        self.args = args
        self.connections = setup_test_infra(args.testbed_file)
        project_id = self.connections.get_project_id()
        project_fq_name = self.connections.get_project_fq_name()
        self.db = TestDB(args.db_file)
        self.db.set_project_id(project_fq_name, project_id)
        self.uuid = dict()
        self.vm_connections_map = dict()

    def setup(self):

# Create vDNS
        vdns_id = self.args.vdns
        vdns_obj = vDNS(self.connections)
        vdns_fqname = None
        if self.args.create_vdns:
            vdns_id = vdns_obj.create(random_string('vDNS'))
        if vdns_id:
            vdns_fqname = vdns_obj.fq_name(vdns_id)
            self.db.set_vdns_id(vdns_fqname, vdns_id)

# Create Public Network in case of dNAT or sNAT
        if self.args.n_fips or self.args.create_snat or self.args.router_id:
            name = self.args.public_vn or random_string('Public')
            vn_obj = VN(self.connections)
            self.public_vn_id = vn_obj.create(name, external=True)
            vn_subnets = vn_obj.get_subnets(self.public_vn_id)
            self.db.add_virtual_network(vn_obj.fq_name(), self.public_vn_id, vn_subnets)

# Create Tenant
        for tenant_index in range(int(self.args.n_tenants)):
            self.tenant_name = self.args.tenant or random_string(self.args.tenant_prefix)
            tenant_obj = Project(self.connections)
            tenant_id = tenant_obj.create(self.tenant_name)
            tenant_obj.update_default_sg()
            tenant_connections = tenant_obj.get_connections()
            self.db.set_project_id(tenant_obj.fq_name(), tenant_id)
            self.uuid[self.tenant_name] = UUID()

# Create IPAM
            ipam_id = self.args.ipam
            ipam_obj = IPAM(tenant_connections)
            if self.args.create_ipam:
                ipam_id = ipam_obj.create(self.get_name('ipam'), vdns_id)
            if ipam_id:
                ipam_fqname = ipam_obj.fq_name(ipam_id)
                self.uuid[self.tenant_name].ipam_id = ipam_id
                self.db.add_ipam(ipam_obj.fq_name(), ipam_id, vdns_fqname)

# Create sNAT instance
            self.router_id = self.args.router_id
            router_obj = LogicalRouter(tenant_connections)
            if self.args.create_snat:
                self.router_id = router_obj.create(self.get_name('rtr'), gw=self.public_vn_id)
            if self.router_id:
                router_fqname = router_obj.fq_name(self.router_id)
                self.db.add_logical_router(router_fqname, self.router_id)
                self.db.set_gw_to_lr(router_fqname, self.public_vn_id)
                self.router_fqname = router_fqname

# Create Network
            self.create_vns(tenant_connections)

# Create VMs
            for vn_name,vn_id in self.uuid[self.tenant_name].vn_id.iteritems():
                self.create_vms(tenant_connections, vn_id, vn_name)

# Create FIP Pool and associate fips to VMs
        if self.args.n_fips:
            fip_pool_obj = FloatingIPPool(self.connections)
            self.fip_pool_id = fip_pool_obj.create(self.public_vn_id)
            self.fip_pool_fqname = fip_pool_obj.fq_name()
            self.db.add_fip_pool(self.fip_pool_fqname, self.fip_pool_id)
            self.associate_fips()

    def create_vns(self, connections):
        for index in range(int(self.args.n_vns)):
            name = self.args.vn_name or self.get_name('VN', index)
            ipam_id = self.uuid[self.tenant_name].ipam_id
            vn_obj = VN(connections)
            self.uuid[self.tenant_name].vn_id[name] = vn_obj.create(name,
                                    ipam_id=ipam_id)
            vn_fqname = vn_obj.fq_name()
            vn_subnets = vn_obj.get_subnets(self.uuid[self.tenant_name].vn_id[name])
            self.db.add_virtual_network(vn_fqname, self.uuid[self.tenant_name].vn_id[name], vn_subnets)
            if self.router_id:
                LogicalRouter(connections).attach_vn(self.router_id, self.uuid[self.tenant_name].vn_id[name])
                self.db.add_vn_to_lr(self.router_fqname, self.uuid[self.tenant_name].vn_id[name])
                self.db.add_lr_to_vn(vn_fqname, self.router_id)

    def create_vms(self, connections, vn_id, vn_name):
        for index in range(int(self.args.n_vms)):
            name = random_string(vn_name+'-VM%s'%index)
            vm_obj = VM(connections)
            self.uuid[self.tenant_name].vm_id[name] = vm_obj.create(name, [vn_id], self.args.image)
            vm_fqname = vm_obj.fq_name()
            (self.username, self.password) = vm_obj.get_vm_creds()
            self.db.add_virtual_machine(name, connections.get_project_fq_name(),
                                        self.uuid[self.tenant_name].vm_id[name],
                                        [vn_id], self.username, self.password)
            self.vm_connections_map[name] = connections

    def associate_fips(self):
        vm_names = list(); vm_ids = list()
        for uuid in self.uuid.itervalues():
            (names, ids) = (uuid.vm_id.keys(), uuid.vm_id.values())
            vm_names.extend(names)
            vm_ids.extend(ids)

        for index in range(int(self.args.n_fips)):
            connections = self.vm_connections_map[vm_names[index]]
            fip_id = FloatingIPPool(self.connections).associate_fip(
                                                      self.fip_pool_id,
                                                      vm_ids[index],
                                                      connections,
                                                      self.username,
                                                      self.password)
            self.db.associate_fip_to_vm(vm_names[index],
                                        connections.get_project_fq_name(),
                                        fip_id)
            self.db.add_fip(self.fip_pool_fqname, fip_id)

    def get_name(self, prefix, index=''):
        return random_string(self.tenant_name + '-' + str(prefix) + str(index))