def test_switching_profile_update(self):

        tags = [{
            'scope': 'os-project-id',
            'tag': 'tenant-1'
        }, {
            'scope': 'os-api-version',
            'tag': '2.1.1.0'
        }]

        mocked_resource = self._mocked_switching_profile()

        mocked_resource.update('a12bc1',
                               profile_types.PORT_MIRRORING,
                               tags=tags)

        test_client.assert_json_call(
            'put',
            mocked_resource,
            'https://1.2.3.4/api/v1/switching-profiles/a12bc1',
            data=jsonutils.dumps(
                {
                    'resource_type': profile_types.PORT_MIRRORING,
                    'tags': tags
                },
                sort_keys=True))
    def test_disable_qos_switching_profile_shaping(self):
        """
        Test updating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        burst_size = 100
        peak_bandwidth = 200
        average_bandwidth = 300
        original_profile = self._body_with_shaping(
            shaping_enabled=True,
            burst_size=burst_size,
            peak_bandwidth=peak_bandwidth,
            average_bandwidth=average_bandwidth,
            qos_marking="untrusted",
            dscp=10)
        with mock.patch.object(nsxlib.client, 'get_resource',
                        return_value=original_profile):
            # update the bw shaping of the profile
            nsxlib.update_qos_switching_profile_shaping(
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                shaping_enabled=False, qos_marking="trusted")

            test_client.assert_json_call(
                'put', api,
                'https://1.2.3.4/api/v1/switching-profiles/%s'
                % test_constants_v3.FAKE_QOS_PROFILE['id'],
                data=jsonutils.dumps(
                    self._body_with_shaping(qos_marking="trusted"),
                    sort_keys=True))
    def test_spoofgaurd_profile_create(self):

        tags = [{
            'scope': 'os-project-id',
            'tag': 'tenant-1'
        }, {
            'scope': 'os-api-version',
            'tag': '2.1.1.0'
        }]

        mocked_resource = self._mocked_switching_profile()

        mocked_resource.create_spoofguard_profile('neutron-spoof',
                                                  'spoofguard-for-neutron',
                                                  whitelist_ports=True,
                                                  tags=tags)

        test_client.assert_json_call(
            'post',
            mocked_resource,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(
                {
                    'resource_type': profile_types.SPOOF_GUARD,
                    'display_name': 'neutron-spoof',
                    'description': 'spoofguard-for-neutron',
                    'white_list_providers': ['LPORT_BINDINGS'],
                    'tags': tags
                },
                sort_keys=True))
Exemple #4
0
    def test_disable_qos_switching_profile_shaping(self):
        """
        Test updating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        burst_size = 100
        peak_bandwidth = 200
        average_bandwidth = 300
        original_profile = self._body_with_shaping(
            shaping_enabled=True,
            burst_size=burst_size,
            peak_bandwidth=peak_bandwidth,
            average_bandwidth=average_bandwidth,
            qos_marking="untrusted",
            dscp=10)
        with mock.patch.object(nsxlib.client,
                               'get_resource',
                               return_value=original_profile):
            # update the bw shaping of the profile
            nsxlib.update_qos_switching_profile_shaping(
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                shaping_enabled=False,
                qos_marking="trusted")

            test_client.assert_json_call(
                'put',
                api,
                'https://1.2.3.4/api/v1/switching-profiles/%s' %
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                data=jsonutils.dumps(
                    self._body_with_shaping(qos_marking="trusted"),
                    sort_keys=True))
    def test_create_mac_learning_profile(self):

        tags = [{
            'scope': 'os-project-id',
            'tag': 'tenant-1'
        }, {
            'scope': 'os-api-version',
            'tag': '2.1.1.0'
        }]

        mocked_resource = self._mocked_switching_profile()

        mocked_resource.create_mac_learning_profile('neutron-mac-learning',
                                                    'mac-learning-for-neutron',
                                                    tags=tags)

        test_client.assert_json_call(
            'post',
            mocked_resource,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(
                {
                    'mac_learning': {
                        'enabled': True,
                    },
                    'resource_type': profile_types.MAC_LEARNING,
                    'display_name': 'neutron-mac-learning',
                    'description': 'mac-learning-for-neutron',
                    'tags': tags,
                    'source_mac_change_allowed': True,
                },
                sort_keys=True))
 def test_list_all_profiles(self):
     mocked_resource = self._mocked_switching_profile()
     mocked_resource.list()
     test_client.assert_json_call(
         'get',
         mocked_resource, 'https://1.2.3.4/api/v1/switching-profiles/'
         '?include_system_owned=True',
         data=None)
 def test_delete_logical_router(self):
     """
     Test deleting router
     """
     router = self._mocked_lrouter()
     uuid = test_constants_v3.FAKE_ROUTER['id']
     router.delete(uuid)
     test_client.assert_json_call(
         'delete', router,
         'https://1.2.3.4/api/v1/logical-routers/%s' % uuid)
    def test_delete_logical_port(self):
        """
        Test deleting port
        """
        mocked_resource = self._mocked_lport()

        uuid = test_constants_v3.FAKE_PORT['id']
        mocked_resource.delete(uuid)
        test_client.assert_json_call(
            'delete', mocked_resource,
            'https://1.2.3.4/api/v1/logical-ports/%s?detach=true' % uuid)
    def test_delete_logical_router_port(self):
        """
        Test deleting router port
        """
        lrport = self._mocked_lrport()

        uuid = test_constants_v3.FAKE_ROUTER_PORT['id']
        lrport.delete(uuid)
        test_client.assert_json_call(
            'delete', lrport,
            'https://1.2.3.4/api/v1/logical-router-ports/%s' % uuid)
Exemple #10
0
    def test_delete_qos_switching_profile(self):
        """
        Test deleting qos-switching-profile
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.delete_qos_switching_profile(
            test_constants_v3.FAKE_QOS_PROFILE['id'])

        test_client.assert_json_call(
            'delete', api, 'https://1.2.3.4/api/v1/switching-profiles/%s' %
            test_constants_v3.FAKE_QOS_PROFILE['id'])
Exemple #11
0
    def test_delete_logical_switch(self):
        """
        Test deleting switch
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        fake_switch = nsx_v3_mocks.make_fake_switch()
        nsxlib.delete_logical_switch(fake_switch['id'])

        test_client.assert_json_call(
            'delete', api, 'https://1.2.3.4/api/v1/logical-switches/%s'
            '?detach=true&cascade=true' % fake_switch['id'])
    def test_delete_qos_switching_profile(self):
        """
        Test deleting qos-switching-profile
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.delete_qos_switching_profile(
            test_constants_v3.FAKE_QOS_PROFILE['id'])

        test_client.assert_json_call(
            'delete', api,
            'https://1.2.3.4/api/v1/switching-profiles/%s'
            % test_constants_v3.FAKE_QOS_PROFILE['id'])
    def test_create_logical_port(self):
        """
        Test creating a port returns the correct response and 200 status
        """
        fake_port = test_constants_v3.FAKE_PORT.copy()

        profile_dicts = []
        for profile_id in fake_port['switching_profile_ids']:
            profile_dicts.append({
                'resource_type': profile_id['key'],
                'id': profile_id['value']
            })

        pkt_classifiers = []
        binding_repr = []
        for i in range(0, 3):
            ip = "9.10.11.%s" % i
            mac = "00:0c:29:35:4a:%sc" % i
            pkt_classifiers.append(
                resources.PacketAddressClassifier(ip, mac, None))
            binding_repr.append({'ip_address': ip, 'mac_address': mac})

        fake_port['address_bindings'] = binding_repr

        mocked_resource = self._mocked_lport()

        switch_profile = resources.SwitchingProfile
        mocked_resource.create(
            fake_port['logical_switch_id'],
            fake_port['attachment']['id'],
            address_bindings=pkt_classifiers,
            switch_profile_ids=switch_profile.build_switch_profile_ids(
                mock.Mock(), *profile_dicts))

        resp_body = {
            'logical_switch_id': fake_port['logical_switch_id'],
            'switching_profile_ids': fake_port['switching_profile_ids'],
            'attachment': {
                'attachment_type': 'VIF',
                'id': fake_port['attachment']['id']
            },
            'admin_state': 'UP',
            'address_bindings': fake_port['address_bindings']
        }

        test_client.assert_json_call('post',
                                     mocked_resource,
                                     'https://1.2.3.4/api/v1/logical-ports',
                                     data=jsonutils.dumps(resp_body,
                                                          sort_keys=True))
Exemple #14
0
    def test_create_logical_switch(self):
        """
        Test creating a switch returns the correct response and 200 status
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.create_logical_switch(nsx_v3_mocks.FAKE_NAME,
                                     NsxLibSwitchTestCase._tz_id, [])

        test_client.assert_json_call('post',
                                     api,
                                     'https://1.2.3.4/api/v1/logical-switches',
                                     data=jsonutils.dumps(self._create_body(),
                                                          sort_keys=True))
    def test_create_logical_port_with_attachtype_cif(self):
        """
        Test creating a port returns the correct response and 200 status
        """
        fake_port = test_constants_v3.FAKE_CONTAINER_PORT.copy()

        profile_dicts = self._get_profile_dicts(fake_port)

        pkt_classifiers, binding_repr = self._get_pktcls_bindings()

        fake_port['address_bindings'] = binding_repr

        mocked_resource = self._mocked_lport()
        switch_profile = resources.SwitchingProfile
        fake_port_ctx = fake_port['attachment']['context']

        fake_container_host_vif_id = fake_port_ctx['container_host_vif_id']

        mocked_resource.create(
            fake_port['logical_switch_id'],
            fake_port['attachment']['id'],
            parent_vif_id=fake_container_host_vif_id,
            parent_tag=fake_port_ctx['vlan_tag'],
            address_bindings=pkt_classifiers,
            switch_profile_ids=switch_profile.build_switch_profile_ids(
                mock.Mock(), *profile_dicts))

        resp_body = {
            'logical_switch_id': fake_port['logical_switch_id'],
            'switching_profile_ids': fake_port['switching_profile_ids'],
            'attachment': {
                'attachment_type': 'CIF',
                'id': fake_port['attachment']['id'],
                'context': {
                    'vlan_tag': fake_port_ctx['vlan_tag'],
                    'container_host_vif_id': fake_container_host_vif_id,
                    'resource_type': 'CifAttachmentContext'
                }
            },
            'admin_state': 'UP',
            'address_bindings': fake_port['address_bindings']
        }

        test_client.assert_json_call('post',
                                     mocked_resource,
                                     'https://1.2.3.4/api/v1/logical-ports',
                                     data=jsonutils.dumps(resp_body,
                                                          sort_keys=True))
    def test_get_logical_router_port_by_switch_id(self):
        """
        Test getting a router port by switch id
        """
        fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()
        resp_resources = {'result_count': 1, 'results': [fake_router_port]}

        lrport = self._mocked_lrport(
            session_response=mocks.MockRequestsResponse(
                200, jsonutils.dumps(resp_resources)))

        switch_id = test_constants_v3.FAKE_SWITCH_UUID
        lrport.get_by_lswitch_id(switch_id)
        test_client.assert_json_call(
            'get', lrport, 'https://1.2.3.4/api/v1/logical-router-ports/?'
            'logical_switch_id=%s' % switch_id)
    def test_create_qos_switching_profile(self):
        """
        Test creating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.create_qos_switching_profile(
            tags=[],
            name=test_constants_v3.FAKE_NAME,
            description=test_constants_v3.FAKE_NAME)

        test_client.assert_json_call(
            'post', api,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(self._body(),
                                 sort_keys=True))
Exemple #18
0
    def test_create_logical_switch_vlan(self):
        """
        Test creating switch with provider:network_type VLAN
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.create_logical_switch(nsx_v3_mocks.FAKE_NAME,
                                     NsxLibSwitchTestCase._tz_id, [],
                                     vlan_id='123')

        test_client.assert_json_call('post',
                                     api,
                                     'https://1.2.3.4/api/v1/logical-switches',
                                     data=jsonutils.dumps(
                                         self._create_body(vlan_id='123'),
                                         sort_keys=True))
Exemple #19
0
    def test_create_qos_switching_profile(self):
        """
        Test creating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.create_qos_switching_profile(
            tags=[],
            name=test_constants_v3.FAKE_NAME,
            description=test_constants_v3.FAKE_NAME)

        test_client.assert_json_call(
            'post',
            api,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(self._body(), sort_keys=True))
    def test_get_logical_router_port_by_router_id(self):
        """
        Test getting a router port by router id
        """
        fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()
        resp_resources = {'results': [fake_router_port]}

        lrport = self._mocked_lrport(
            session_response=mocks.MockRequestsResponse(
                200, jsonutils.dumps(resp_resources)))

        router_id = fake_router_port['logical_router_id']
        result = lrport.get_by_router_id(router_id)
        self.assertEqual(fake_router_port, result[0])
        test_client.assert_json_call(
            'get', lrport, 'https://1.2.3.4/api/v1/logical-router-ports/?'
            'logical_router_id=%s' % router_id)
    def test_switching_profile_create(self):
        mocked_resource = self._mocked_switching_profile()

        mocked_resource.create(profile_types.PORT_MIRRORING, 'pm-profile',
                               'port mirror prof')

        test_client.assert_json_call(
            'post',
            mocked_resource,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(
                {
                    'resource_type': profile_types.PORT_MIRRORING,
                    'display_name': 'pm-profile',
                    'description': 'port mirror prof'
                },
                sort_keys=True))
Exemple #22
0
    def test_create_logical_switch_admin_down(self):
        """
        Test creating switch with admin_state down
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        nsxlib.create_logical_switch(nsx_v3_mocks.FAKE_NAME,
                                     NsxLibSwitchTestCase._tz_id, [],
                                     admin_state=False)

        test_client.assert_json_call(
            'post',
            api,
            'https://1.2.3.4/api/v1/logical-switches',
            data=jsonutils.dumps(
                self._create_body(admin_state=nsx_constants.ADMIN_STATE_DOWN),
                sort_keys=True))
    def test_create_dhcp_profile(self):

        tags = [{
            'scope': 'os-project-id',
            'tag': 'tenant-1'
        }, {
            'scope': 'os-api-version',
            'tag': '2.1.1.0'
        }]

        mocked_resource = self._mocked_switching_profile()

        mocked_resource.create_dhcp_profile('neutron-dhcp',
                                            'dhcp-for-neutron',
                                            tags=tags)

        test_client.assert_json_call(
            'post',
            mocked_resource,
            'https://1.2.3.4/api/v1/switching-profiles',
            data=jsonutils.dumps(
                {
                    'bpdu_filter': {
                        'enabled': True,
                        'white_list': []
                    },
                    'resource_type': profile_types.SWITCH_SECURITY,
                    'display_name': 'neutron-dhcp',
                    'description': 'dhcp-for-neutron',
                    'tags': tags,
                    'dhcp_filter': {
                        'client_block_enabled': True,
                        'server_block_enabled': False
                    },
                    'rate_limits': {
                        'enabled': False,
                        'rx_broadcast': 0,
                        'tx_broadcast': 0,
                        'rx_multicast': 0,
                        'tx_multicast': 0
                    },
                    'block_non_ip_traffic': True
                },
                sort_keys=True))
    def test_clear_port_bindings(self):
        fake_port = copy.copy(test_constants_v3.FAKE_PORT)
        fake_port['address_bindings'] = ['a', 'b']
        mocked_resource = self._mocked_lport()

        def get_fake_port(*args):
            return fake_port

        mocked_resource.get = get_fake_port
        mocked_resource.update(fake_port['id'],
                               fake_port['id'],
                               address_bindings=[])

        fake_port['address_bindings'] = []
        test_client.assert_json_call(
            'put',
            mocked_resource,
            'https://1.2.3.4/api/v1/logical-ports/%s' % fake_port['id'],
            data=jsonutils.dumps(fake_port, sort_keys=True))
    def test_update_qos_switching_profile(self):
        """
        Test updating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        original_profile = self._body()
        new_description = "Test"
        with mock.patch.object(nsxlib.client, 'get_resource',
                        return_value=original_profile):
            # update the description of the profile
            nsxlib.update_qos_switching_profile(
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                tags=[],
                description=new_description)

            test_client.assert_json_call(
                'put', api,
                'https://1.2.3.4/api/v1/switching-profiles/%s'
                % test_constants_v3.FAKE_QOS_PROFILE['id'],
                data=jsonutils.dumps(self._body(description=new_description),
                                     sort_keys=True))
    def test_create_logical_router(self):
        """
        Test creating a router returns the correct response and 201 status
        """
        fake_router = test_constants_v3.FAKE_ROUTER.copy()

        router = self._mocked_lrouter()

        tier0_router = True
        router.create(fake_router['display_name'], None, None, tier0_router)

        data = {
            'display_name': fake_router['display_name'],
            'router_type': 'TIER0' if tier0_router else 'TIER1',
            'tags': None
        }

        test_client.assert_json_call('post',
                                     router,
                                     'https://1.2.3.4/api/v1/logical-routers',
                                     data=jsonutils.dumps(data,
                                                          sort_keys=True))
    def test_create_logical_router_port(self):
        """
        Test creating a router port returns the correct response and 201 status
        """
        fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()

        lrport = self._mocked_lrport()

        lrport.create(fake_router_port['logical_router_id'],
                      fake_router_port['display_name'], None,
                      fake_router_port['resource_type'], None, None, None)

        data = {
            'display_name': fake_router_port['display_name'],
            'logical_router_id': fake_router_port['logical_router_id'],
            'resource_type': fake_router_port['resource_type'],
            'tags': []
        }

        test_client.assert_json_call(
            'post',
            lrport,
            'https://1.2.3.4/api/v1/logical-router-ports',
            data=jsonutils.dumps(data, sort_keys=True))
Exemple #28
0
    def test_update_qos_switching_profile(self):
        """
        Test updating a qos-switching profile returns the correct response
        """
        api = self.mocked_rest_fns(nsxlib, 'client')

        original_profile = self._body()
        new_description = "Test"
        with mock.patch.object(nsxlib.client,
                               'get_resource',
                               return_value=original_profile):
            # update the description of the profile
            nsxlib.update_qos_switching_profile(
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                tags=[],
                description=new_description)

            test_client.assert_json_call(
                'put',
                api,
                'https://1.2.3.4/api/v1/switching-profiles/%s' %
                test_constants_v3.FAKE_QOS_PROFILE['id'],
                data=jsonutils.dumps(self._body(description=new_description),
                                     sort_keys=True))