コード例 #1
0
    def _get_api_client(self, username, password, project_name, role_name,
                        create_project=True):
        project = self.keystone.tenants.get(name=project_name)
        if not project:
            project = self.keystone.tenants.create(project_name)
        user = self.keystone.users.get(username) or self.keystone.users.create(
            username, password, '', project.id)
        role = self.keystone.roles.get(role_name)
        if not role:
            role = self.keystone.roles.create(role_name)
        self.keystone.roles.add_user_role(user, role, project)

        if create_project:
            p = Project(project.name)
            p.uuid = project.id
            self.admin_api.project_create(p)

        return MyVncApi(
            username=username,
            password=password,
            project_name=project.name,
            project_id=project.id,
            user_role=role_name,
            api_server_host=self._api_server_ip,
            api_server_port=self._api_server_port)
コード例 #2
0
 def _project_read(self, *args, **kwargs):
     """ Return a mock project with the expected values """
     project = Project()
     project.uuid = kwargs['id']
     project.fq_name = ['default-domain', 'test']
     self._project = project
     return project
コード例 #3
0
 def _project_read(self, *args, **kwargs):
     """ Return a mock project with the expected values """
     project = Project()
     project.uuid = kwargs['id']
     project.fq_name = ['default-domain', 'test']
     self._project = project
     return project
コード例 #4
0
    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
コード例 #5
0
    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
コード例 #6
0
 def _project_fetch_or_create(self, test_id):
     project = Project(name='project-{}'.format(test_id))
     try:
         uuid = self.api.project_create(project)
     except RefsExistError:
         uuid = self.api.fq_name_to_id('project', project.fq_name)
     project.set_uuid(uuid)
     return project
コード例 #7
0
    def test_create_project_scoped_tag(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)

        type = 'fake_type-%s' % self.id()
        value = 'fake_value-%s' % self.id()
        tag = Tag(parent_obj=project, tag_type_name=type, tag_value=value)
        tag_uuid = self.api.tag_create(tag)
        tag = self.api.tag_read(id=tag_uuid)

        self.assertEqual(
            tag.get_fq_name_str(),
            '%s:%s=%s' % (project.get_fq_name_str(), type.lower(), value),
        )
コード例 #8
0
    def test_create_project_scoped_tag(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)

        type = 'fake_type-%s' % self.id()
        value = 'fake_value-%s' % self.id()
        tag = Tag(parent_obj=project, tag_type_name=type, tag_value=value)
        tag_uuid = self.api.tag_create(tag)
        tag = self.api.tag_read(id=tag_uuid)

        self.assertEqual(
            tag.get_fq_name_str(),
            '%s:%s=%s' % (project.get_fq_name_str(), type.lower(), value),
        )
コード例 #9
0
    def setUp(self):
        VncApiMock.init()
        DBMock.init()
        vnc_kubernetes.VncKubernetes.reset()

        self.args = Mock()
        self.args.admin_user = "******"
        self.args.admin_password = "******"
        self.args.admin_tenant = "default"
        self.args.vnc_endpoint_ip = '127.0.0.1'
        self.args.vnc_endpoint_port = "8082"
        self.args.auth_token_url = "token"
        self.args.cluster_project = None
        self.args.cluster_network = None
        self.args.cluster_pod_network = None
        self.args.cluster_service_network = None
        self.args.pod_subnets = ['10.10.0.0/16']
        self.args.service_subnets = ['192.168.0.0/24']
        self.args.kubernetes_api_secure_port = "8443"
        self.args.auth_user = "******"
        self.args.auth_password = "******"
        self.args.auth_tenant = "default"
        self.args.cassandra_server_list = ()

        api = VncApiMock(self.args.auth_user, self.args.auth_password,
                         self.args.auth_tenant, self.args.vnc_endpoint_ip,
                         self.args.vnc_endpoint_port, self.args.auth_token_url)
        domain_uuid = api.domain_create(Domain("default-domain"))
        domain = api.domain_read(id=domain_uuid)

        proj_uuid = api.project_create(
            Project("default-project", parent_obj=domain))
        proj = api.project_read(id=proj_uuid)
        net = VirtualNetwork("ip-fabric", proj)
        api.virtual_network_create(net)
コード例 #10
0
    def test_valid_sub_interface_vlan_tag_id(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)

        test_suite = [
            (None, None),
            (VMIPT(None), None),
            (VMIPT(sub_interface_vlan_tag=None), None),
            (VMIPT(sub_interface_vlan_tag=-42), BadRequest),
            (VMIPT(sub_interface_vlan_tag=4095), BadRequest),
            (VMIPT(sub_interface_vlan_tag='fo'), BadRequest),
            (VMIPT(sub_interface_vlan_tag='42'), None),
            (VMIPT(sub_interface_vlan_tag=42), None),
        ]

        for (vmipt, result) in test_suite:
            vmi = VirtualMachineInterface('%s-vmi' % self.id(),
                                          parent_obj=project)
            vmi.set_virtual_network(vn)
            vmi.set_virtual_machine_interface_properties(vmipt)
            if result and issubclass(result, Exception):
                self.assertRaises(result,
                                  self.api.virtual_machine_interface_create,
                                  vmi)
            else:
                self.api.virtual_machine_interface_create(vmi)
                self.api.virtual_machine_interface_delete(id=vmi.uuid)
コード例 #11
0
    def test_context_undo_fail_db_delete(self):
        project = Project(name='p-{}'.format(self.id()))
        self.api.project_create(project)
        vn = VirtualNetwork(name='vn-{}'.format(self.id()), parent_obj=project)
        self.api.virtual_network_create(vn)
        vmi_obj = VirtualMachineInterface('vmi-{}'.format(self.id()),
                                          parent_obj=project)
        vmi_obj.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi_obj)
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_obj.uuid)

        mock_zk = self._api_server._db_conn._zk_db
        zk_alloc_count_before = mock_zk._vpg_id_allocator.get_alloc_count()

        def stub(*args, **kwargs):
            return False, (500, "Fake error")

        with ExpectedException(HttpError):
            with test_common.flexmocks([(self._api_server._db_conn,
                                         'dbe_delete', stub)]):
                self.api.virtual_machine_interface_delete(
                    fq_name=vmi_obj.fq_name)

        zk_alloc_count_after = mock_zk._vpg_id_allocator.get_alloc_count()
        self.assertEqual(zk_alloc_count_before, zk_alloc_count_after)
コード例 #12
0
    def test_virtual_port_group_delete(self):
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj)
        self.api.virtual_network_create(vn)

        vpg_name = "vpg-" + self.id()
        vpg_obj = VirtualPortGroup(vpg_name)
        self.api.virtual_port_group_create(vpg_obj)

        vmi_id_list = []
        for i in range(self.VMI_NUM):
            vmi_obj = VirtualMachineInterface(self.id() + str(i),
                                              parent_obj=proj_obj)
            vmi_obj.set_virtual_network(vn)
            vmi_id_list.append(
                self.api.virtual_machine_interface_create(vmi_obj))
            vpg_obj.add_virtual_machine_interface(vmi_obj)
            self.api.virtual_port_group_update(vpg_obj)
            self.api.ref_relax_for_delete(vpg_obj.uuid, vmi_id_list[i])

        # Make sure when VPG doesn't get deleted, since associated VMIs
        # still refers it.
        with ExpectedException(BadRequest):
            self.api.virtual_port_group_delete(id=vpg_obj.uuid)

        # Cleanup
        for i in range(self.VMI_NUM):
            self.api.virtual_machine_interface_delete(id=vmi_id_list[i])

        self.api.virtual_port_group_delete(id=vpg_obj.uuid)
コード例 #13
0
    def test_only_one_value_for_a_type_can_be_associate_to_a_resource2(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        tag_type = 'fake_type-%s' % self.id()
        global_tag = Tag(tag_type_name=tag_type,
                         tag_value='global_fake_value-%s' % self.id())
        self.api.tag_create(global_tag)
        scoped_tag = Tag(tag_type_name=tag_type,
                         tag_value='scoped_fake_value-%s' % self.id(),
                         parent_obj=project)
        self.api.tag_create(scoped_tag)

        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        vn.add_tag(global_tag)
        vn.add_tag(scoped_tag)
        self.assertRaises(BadRequest, self.api.virtual_network_create, vn)

        vn.set_tag(global_tag)
        self.api.virtual_network_create(vn)
        vn = self._vnc_lib.virtual_network_read(id=vn.uuid)
        self.assertEqual(len(vn.get_tag_refs()), 1)
        self.assertEqual(vn.get_tag_refs()[0]['uuid'], global_tag.uuid)

        vn.add_tag(scoped_tag)
        self.assertRaises(BadRequest, self.api.virtual_network_update, vn)
コード例 #14
0
    def test_context_undo_fail_db_update(self):
        project = Project(name='p-{}'.format(self.id()))
        self.api.project_create(project)
        vn_og = VirtualNetwork(name='og-vn-{}'.format(self.id()),
                               parent_obj=project)
        self.api.virtual_network_create(vn_og)
        vmi_obj = VirtualMachineInterface('vmi-{}'.format(self.id()),
                                          parent_obj=project)
        vmi_obj.set_virtual_network(vn_og)
        self.api.virtual_machine_interface_create(vmi_obj)
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_obj.uuid)

        # change virtual network for VMI
        vn_next = VirtualNetwork(name='next-vn-{}'.format(self.id()),
                                 parent_obj=project)
        vn_next.uuid = self.api.virtual_network_create(vn_next)
        vmi_obj.set_virtual_network(vn_next)

        def stub(*args, **kwargs):
            return False, (500, "Fake error")

        with ExpectedException(HttpError):
            with test_common.flexmocks([(self._api_server._db_conn,
                                         'dbe_update', stub)]):
                self.api.virtual_machine_interface_update(vmi_obj)
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_obj.uuid)
        vn_ref_fq_names = [n['to'] for n in vmi_obj.get_virtual_network_refs()]

        self.assertEqual(len(vn_ref_fq_names), 1)
        self.assertEqual(vn_ref_fq_names[0], vn_og.get_fq_name())
コード例 #15
0
    def _create_prerequisites(self, enterprise_style_flag=True,
                              create_second_pr=False):
        # Create project first
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        # Create Fabric with enterprise style flag set to false
        fabric_obj = Fabric('%s-fabric' % (self.id()))
        fabric_obj.set_fabric_enterprise_style(enterprise_style_flag)
        fabric_uuid = self.api.fabric_create(fabric_obj)
        fabric_obj = self.api.fabric_read(id=fabric_uuid)

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self._vnc_lib.physical_router_create(pr)
        pr_obj = self._vnc_lib.physical_router_read(id=pr_uuid)

        if create_second_pr:
            pr_name_2 = self.id() + '_physical_router_2'
            pr = PhysicalRouter(pr_name_2)
            pr_uuid_2 = self._vnc_lib.physical_router_create(pr)
            pr_obj_2 = self._vnc_lib.physical_router_read(id=pr_uuid_2)
            return proj_obj, fabric_obj, [pr_obj, pr_obj_2]

        return proj_obj, fabric_obj, pr_obj
コード例 #16
0
    def test_update_in_use_provider_vn(self):
        project = Project('%s-project' % self.id())
        project_uuid = self.api.project_create(project)
        project = self.api.project_read(id=project_uuid)

        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
        vn.set_is_provider_network(True)
        vn.set_provider_properties(
            ProviderDetails(
                params_dict={"segmentation_id": 100,
                             "physical_network": "physnet1"}))
        vn_uuid = self.api.virtual_network_create(vn)

        vmi = VirtualMachineInterface('%s-vmi' % self.id(), parent_obj=project)
        vmi.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi)

        vn = self.api.virtual_network_read(id=vn_uuid)

        vn.set_provider_properties(
            ProviderDetails(
                params_dict={"segmentation_id": 200,
                             "physical_network": "physnet2"}))
        with ExpectedException(RefsExistError):
            self.api.virtual_network_update(vn)

        updated_provider_properties = (self
                                       .api.virtual_network_read(id=vn.uuid)
                                       .get_provider_properties())
        segmentation_id = updated_provider_properties.get_segmentation_id()
        physical_network = updated_provider_properties.get_physical_network()

        self.assertEqual((100, "physnet1"),
                         (segmentation_id, physical_network))
コード例 #17
0
    def test_tag_created_before_associated_to_a_resource(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)

        type = 'fake_type-%s' % self.id()
        value = 'fake_value-%s' % self.id()

        # global
        tags_dict = {
            type: {
                'is_global': True,
                'value': value,
            }
        }
        with ExpectedException(exceptions.NoIdError):
            self.api.set_tags(vn, tags_dict)

        # scoped
        tags_dict = {
            type: {
                'value': value,
            }
        }
        with ExpectedException(exceptions.NoIdError):
            self.api.set_tags(vn, tags_dict)
コード例 #18
0
    def test_update_not_in_use_non_provider_vn_to_provider(self):
        project = Project('%s-project' % self.id())
        project_uuid = self.api.project_create(project)
        project = self.api.project_read(id=project_uuid)

        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
        vn_uuid = self.api.virtual_network_create(vn)
        vn = self.api.virtual_network_read(id=vn_uuid)
        is_provider_network = vn.get_is_provider_network()
        self.assertFalse(is_provider_network)

        vn.set_is_provider_network(True)
        vn.set_provider_properties(
            ProviderDetails(
                params_dict={"segmentation_id": 100,
                             "physical_network": "physnet1"}))
        self.api.virtual_network_update(vn)

        vn = self.api.virtual_network_read(id=vn_uuid)
        is_provider_network = vn.get_is_provider_network()
        self.assertTrue(is_provider_network)

        updated_provider_properties = vn.get_provider_properties()
        segmentation_id = updated_provider_properties.get_segmentation_id()
        physical_network = updated_provider_properties.get_physical_network()

        self.assertEqual((100, "physnet1"),
                         (segmentation_id, physical_network))
コード例 #19
0
    def test_set_tag_api_sanity(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        tag_type = 'fake_type-%s' % self.id()
        tag_value = 'fake_value-%s' % self.id()
        tag = Tag(tag_type_name=tag_type, tag_value=tag_value,
                  parent_obj=project)
        self.api.tag_create(tag)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)
        url = self.api._action_uri['set-tag']

        test_suite = [
            ({'obj_uuid': vn.uuid}, BadRequest),
            ({'obj_type': 'virtual_network'}, BadRequest),
            ({'obj_uuid': 'fake_uuid', 'obj_type': 'virtual_network'},
             NoIdError),
            ({'obj_uuid': vn.uuid, 'obj_type': 'wrong_type'}, BadRequest),
            ({
                'obj_uuid': vn.uuid, 'obj_type': 'virtual_network',
                tag_type: {'value': tag_value}
            }, None),
            ({
                'obj_uuid': vn.uuid, 'obj_type': 'virtual-network',
                tag_type: {'value': tag_value}
            }, None),
        ]

        for tags_dict, result in test_suite:
            if result and issubclass(result, Exception):
                self.assertRaises(result, self.api._request_server,
                                  OP_POST, url, json.dumps(tags_dict))
            else:
                self.api._request_server(OP_POST, url, json.dumps(tags_dict))
コード例 #20
0
    def test_disable_port_security_with_empty_allowed_address_pair_list(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)
        addr_pair = AllowedAddressPairs()

        vmi1 = VirtualMachineInterface(
            'vmi1-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=False,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi1.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi1)

        addr_pair = AllowedAddressPairs(allowed_address_pair=[
            AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
                               mac='02:ce:1b:d7:a6:e7')
        ])
        vmi2 = VirtualMachineInterface(
            'vmi2-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=True,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi2.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi2)

        addr_pair = AllowedAddressPairs()
        vmi2.set_virtual_machine_interface_allowed_address_pairs(addr_pair)
        self.api.virtual_machine_interface_update(vmi2)

        vmi2.set_port_security_enabled(False)
        self.api.virtual_machine_interface_update(vmi2)
コード例 #21
0
    def test_port_security_and_allowed_address_pairs(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)
        addr_pair = AllowedAddressPairs(allowed_address_pair=[
            AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
                               mac='02:ce:1b:d7:a6:e7')
        ])
        msg = (r"^Allowed address pairs are not allowed when port security is "
               "disabled$")

        vmi = VirtualMachineInterface(
            'vmi-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=False,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi.set_virtual_network(vn)
        with self.assertRaisesRegexp(BadRequest, msg):
            self.api.virtual_machine_interface_create(vmi)

        vmi = VirtualMachineInterface('vmi-%s' % self.id(),
                                      parent_obj=project,
                                      port_security_enabled=False)
        vmi.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi)

        # updating a port with allowed address pair should throw an exception
        # when port security enabled is set to false
        vmi.virtual_machine_interface_allowed_address_pairs = addr_pair
        with self.assertRaisesRegexp(BadRequest, msg):
            self.api.virtual_machine_interface_update(vmi)
コード例 #22
0
    def test_address_group_can_only_have_label_tag_type_ref(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        tag_type = 'fake_type-%s' % self.id()
        tag_value = 'fake_value-%s' % self.id()
        tag = Tag(tag_type_name=tag_type,
                  tag_value=tag_value,
                  parent_obj=project)
        self.api.tag_create(tag)

        # Cannot create AG with ref to a non label tag
        ag = AddressGroup('ag-%s' % self.id(), parent_obj=project)
        ag.add_tag(tag)
        self.assertRaises(BadRequest, self.api.address_group_create, ag)

        ag.set_tag_list([])
        self.api.address_group_create(ag)

        # Cannot set non lable tag to an AG with /set-tag API
        self.assertRaises(BadRequest, self.api.set_tag, ag, tag_type,
                          tag_value)

        # Cannot add ref to a non label tag to AG
        ag.add_tag(tag)
        self.assertRaises(BadRequest, self.api.address_group_update, ag)
コード例 #23
0
    def test_resources_exists(self):
        api = VncApiMock(
            self.args.auth_user,
            self.args.auth_password,
            self.args.auth_tenant,
            self.args.vnc_endpoint_ip,
            self.args.vnc_endpoint_port,
            self.args.auth_token_url
        )
        domain_fq_name = ['default-domain']
        domain = api.domain_read(fq_name=domain_fq_name)

        proj_uuid = api.project_create(Project("default", parent_obj=domain))
        proj = api.project_read(id=proj_uuid)

        # Create cluster-default-pod-network
        ipam_uuid = api.network_ipam_create(NetworkIpam("pod-ipam", proj))
        ipam = api.network_ipam_read(id=ipam_uuid)
        net = VirtualNetwork("cluster-default-pod-network", proj)
        # No subnets are associated with IPAM at this point.
        # Subnets will be updated in the IPAM, when cluster is created.
        net.add_network_ipam(ipam, VnSubnetsType([]))
        api.virtual_network_create(net)

        # Create cluster-default-service-network
        ipam_uuid = api.network_ipam_create(NetworkIpam("service-ipam", proj))
        ipam = api.network_ipam_read(id=ipam_uuid)
        net = VirtualNetwork("cluster-default-service-network", proj)
        # No subnets are associated with IPAM at this point.
        # Subnets will be updated in the IPAM, when cluster is created.
        net.add_network_ipam(ipam, VnSubnetsType([]))
        api.virtual_network_create(net)

        vnc_kubernetes.VncKubernetes(self.args, Mock())
コード例 #24
0
    def test_unset_tag_from_a_resource(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        vn_uuid = self.api.virtual_network_create(vn)

        tag_type = 'fake_type-%s' % self.id()
        tag_value = 'fake_value-%s' % self.id()
        tag = Tag(tag_type_name=tag_type,
                  tag_value=tag_value,
                  parent_obj=project)
        self.api.tag_create(tag)

        self.api.set_tag(vn, tag_type, tag_value)
        for system_tag_type in constants.TagTypeNameToId:
            self.api.tag_create(
                Tag(tag_type_name=system_tag_type, tag_value=tag_value))
            self.api.set_tag(vn, system_tag_type, tag_value, is_global=True)

        vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
        self.assertEqual(len(vn.get_tag_refs()),
                         len(constants.TagTypeNameToId) + 1)
        self.assertTrue(tag.uuid in {ref['uuid'] for ref in vn.get_tag_refs()})

        self.api.unset_tag(vn, tag_type)

        vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
        self.assertEqual(len(vn.get_tag_refs()),
                         len(constants.TagTypeNameToId))
        self.assertFalse(
            tag.uuid in {ref['uuid']
                         for ref in vn.get_tag_refs()})
コード例 #25
0
    def test_tag_created_before_associated_to_a_resource(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)

        tag_type = 'fake_type-%s' % self.id()
        tag_value = 'fake_value-%s' % self.id()

        # global
        tags_dict = {
            tag_type: {
                'is_global': True,
                'value': tag_value,
            }
        }
        self.assertRaises(NoIdError, self.api.set_tags, vn, tags_dict)

        # scoped
        tags_dict = {
            tag_type: {
                'value': tag_value,
            }
        }
        self.assertRaises(NoIdError, self.api.set_tags, vn, tags_dict)
コード例 #26
0
    def test_set_unset_multi_value_of_authorized_type_on_one_resource(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        vn_uuid = self.api.virtual_network_create(vn)

        # Label tag type is the only one type authorized to be set multiple
        # time on a same resource
        tag_type = 'label'
        tag_value1 = '%s-label1' % self.id()
        label_tag1 = Tag(tag_type_name=tag_type,
                         tag_value=tag_value1,
                         parent_obj=project)
        self.api.tag_create(label_tag1)
        tag_value2 = '%s-label2' % self.id()
        label_tag2 = Tag(tag_type_name=tag_type,
                         tag_value=tag_value2,
                         parent_obj=project)
        self.api.tag_create(label_tag2)
        tag_value3 = '%s-label3' % self.id()
        label_tag3 = Tag(tag_type_name=tag_type,
                         tag_value=tag_value3,
                         parent_obj=project)
        self.api.tag_create(label_tag3)

        tags_dict = {
            tag_type: {
                'value': tag_value1,
                'add_values': [tag_value2],
            },
        }
        self.api.set_tags(vn, tags_dict)

        vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
        self.assertEqual(len(vn.get_tag_refs()), 2)
        self.assertEqual({ref['uuid']
                          for ref in vn.get_tag_refs()},
                         set([label_tag1.uuid, label_tag2.uuid]))

        tags_dict = {
            tag_type: {
                'add_values': [tag_value3],
                'delete_values': [tag_value1],
            },
        }
        self.api.set_tags(vn, tags_dict)

        vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
        self.assertEqual(len(vn.get_tag_refs()), 2)
        self.assertEqual({ref['uuid']
                          for ref in vn.get_tag_refs()},
                         set([label_tag2.uuid, label_tag3.uuid]))

        self.api.unset_tag(vn, tag_type)

        vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
        self.assertIsNone(vn.get_tag_refs())
コード例 #27
0
    def test_associate_scoped_tag_to_project(self):
        project = Project('project-%s' % self.id())
        self.api.project_create(project)
        type = 'fake_type-%s' % self.id()
        value = 'fake_value-%s' % self.id()
        tag = Tag(tag_type_name=type, tag_value=value, parent_obj=project)
        self.api.tag_create(tag)

        self.api.set_tag(project, type, value)
コード例 #28
0
    def test_parallel_project_cassandra_create_read(self):
        project = Project('project-%s' % self.id())
        project.uuid = str(uuid.uuid4())
        default_aps_name = 'default-%s' % ApplicationPolicySet.resource_type
        aps_fq_name = project.fq_name + [default_aps_name]
        original_fq_name_to_uuid = self._api_server._db_conn.fq_name_to_uuid
        inoked = []

        def mock_fq_name_to_uuid(obj_type, fq_name):
            if not inoked and obj_type == 'application_policy_set'\
                    and fq_name == aps_fq_name:
                inoked.append(True)
                raise NoIdError('')
            return original_fq_name_to_uuid(obj_type, fq_name)

        self.api.project_create(project)
        with mock.patch.object(self._api_server._db_conn,
                               'fq_name_to_uuid',
                               side_effect=mock_fq_name_to_uuid):
            self.api.project_read(id=project.uuid)
コード例 #29
0
    def test_cannot_update_sub_interface_vlan_tag(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)
        parent_vmi = VirtualMachineInterface('%s-parent-vmi' % self.id(),
                                             parent_obj=project)
        parent_vmi.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(parent_vmi)

        vmi = VirtualMachineInterface('%s-vmi' % self.id(), parent_obj=project)
        vmi.set_virtual_network(vn)
        vmi.set_virtual_machine_interface(parent_vmi)
        self.api.virtual_machine_interface_create(vmi)
        vmi42 = VirtualMachineInterface('%s-vmi42' % self.id(),
                                        parent_obj=project)
        vmi42.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag=42))
        vmi42.set_virtual_network(vn)
        vmi42.set_virtual_machine_interface(parent_vmi)
        self.api.virtual_machine_interface_create(vmi42)

        # if we don't touch VMI props, we can update the VMI with or without
        # VLAN ID
        vmi.set_display_name('new vmi name')
        self.api.virtual_machine_interface_update(vmi)
        vmi42.set_display_name('new vmi42 name')
        self.api.virtual_machine_interface_update(vmi42)

        # if we change VMI props without specifying anything, we can update the
        # VMI if VLAN ID is not set or 0
        vmi.set_virtual_machine_interface_properties(None)
        self.api.virtual_machine_interface_update(vmi)
        vmi.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag=None))
        self.api.virtual_machine_interface_update(vmi)

        # if we change VMI props without specifying anything, we cannot update
        # the VMI if VLAN ID is not 0
        vmi42.set_virtual_machine_interface_properties(None)
        self.assertRaises(BadRequest,
                          self.api.virtual_machine_interface_update, vmi42)
        vmi42.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag=None))
        self.assertRaises(BadRequest,
                          self.api.virtual_machine_interface_update, vmi42)

        # if we update VMI VLAN ID to the same VLAN ID, no error raised
        vmi.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag=0))
        self.api.virtual_machine_interface_update(vmi)
        vmi42.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag=42))
        self.api.virtual_machine_interface_update(vmi42)
コード例 #30
0
    def test_mac_address_always_allocated(self):
        project = Project(name='p-{}'.format(self.id()))
        p_uuid = self.api.project_create(project)
        project.set_uuid(p_uuid)

        vn = VirtualNetwork(name='vn-{}'.format(self.id()), parent_obj=project)
        vn_uuid = self.api.virtual_network_create(vn)
        vn.set_uuid(vn_uuid)

        mac_addr_test_cases = [
            ['02:ce:1b:d7:a6:e7'],
            ['02-ce-1b-d7-a6-e8'],
            ['02:ce:1b:d7:a6:e9', '02-ce-1b-d7-a6-f1', '02:ce:1b:d7:a6:f2'],
            [],
            None,
        ]

        for i, macs_test_case in enumerate(mac_addr_test_cases):
            vmi = VirtualMachineInterface(name='vmi{}-{}'.format(i, self.id()),
                                          parent_obj=project)
            vmi.set_virtual_network(vn)
            vmi.set_virtual_machine_interface_mac_addresses(
                MacAddressesType(macs_test_case))

            vmi_uuid = self.api.virtual_machine_interface_create(vmi)
            vmi = self.api.virtual_machine_interface_read(id=vmi_uuid)

            vmi_macs = vmi.get_virtual_machine_interface_mac_addresses() \
                .get_mac_address()
            if macs_test_case:
                # check if vmi_macs len is the same as input len
                self.assertItemsEqual(
                    vmi_macs,
                    [mac.replace('-', ':') for mac in macs_test_case])
            else:
                # if input was empty or None, check if vmi_macs has been alloc
                self.assertEqual(len(vmi_macs), 1)

            for m in vmi_macs:
                # check if any of mac is not zero
                self.assertNotEqual(m, '00:00:00:00:00:00')
コード例 #31
0
    def create_project(self, name):
        proj_fq_name = ['default-domain', name]
        proj_obj = Project(name=name, fq_name=proj_fq_name)

        try:
            uid = self._vnc_lib.project_create(proj_obj)
            if uid:
                proj_obj = self._vnc_lib.project_read(id=uid)
        except RefsExistError:
            proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)

        return proj_obj
コード例 #32
0
 def test_default_kestone_domain_id_replaced(self):
     admin_token = get_token('admin', 'admin', 'Default', 'cloud-admin',
                             uuid.uuid4().hex, 'default')
     self._vnc_lib.set_auth_token(admin_token)
     project = Project('project-%s' % self.id())
     default_domain = self._vnc_lib.domain_read(['default-domain'])
     with mock.patch('vnc_cfg_api_server.vnc_cfg_api_server.VncApiServer.'
                     'default_domain', new_callable=mock.PropertyMock) as\
             dd_prop_mock:
         dd_prop_mock.return_value = default_domain.serialize_to_json()
         self._vnc_lib.project_create(project)
         dd_prop_mock.assert_called()
コード例 #33
0
    def test_tag_duplicable_between_project(self):
        tag_type = 'fake_type-%s' % self.id()
        tag_value = 'fake_value-%s' % self.id()

        project1 = Project('project1-%s' % self.id())
        self.api.project_create(project1)
        project1_tag = Tag(parent_obj=project1, tag_type_name=tag_type,
                           tag_value=tag_value)
        project1_tag_uuid = self.api.tag_create(project1_tag)
        project1_tag = self.api.tag_read(id=project1_tag_uuid)

        project2 = Project('project2-%s' % self.id())
        self.api.project_create(project2)
        project2_tag = Tag(parent_obj=project2, tag_type_name=tag_type,
                           tag_value=tag_value)
        project2_tag_uuid = self.api.tag_create(project2_tag)
        project2_tag = self.api.tag_read(id=project2_tag_uuid)

        self.assertNotEquals(project1_tag.uuid, project2_tag.uuid)
        self.assertNotEquals(project1_tag.fq_name, project2_tag.fq_name)
        self.assertNotEquals(project1_tag.tag_id, project2_tag.tag_id)