コード例 #1
0
    def test_create_port_security_allowed_address_pairs(self):
        kwargs = {
            'allowed_address_pairs': [{
                "ip_address": "1.1.1.1"
            }, {
                "ip_address": "2.2.2.2",
                "mac_address": "22:22:22:22:22:22"
            }]
        }
        with self.network(set_context=True, tenant_id='test') as net1:
            with self.subnet(network=net1) as subnet1:
                with self.port(subnet=subnet1,
                               arg_list=('allowed_address_pairs', ),
                               set_context=True,
                               tenant_id='test',
                               **kwargs) as port:
                    port_ip = port['port'].get('fixed_ips')[0]['ip_address']
                    self.assertTrue(self.nb_ovn.create_lswitch_port.called)
                    called_args_dict = ((
                        self.nb_ovn.create_lswitch_port).call_args_list[0][1])
                    self.assertEqual(
                        tools.UnorderedList([
                            "22:22:22:22:22:22 2.2.2.2",
                            port['port']['mac_address'] + ' ' + port_ip + ' ' +
                            '1.1.1.1'
                        ]), called_args_dict.get('port_security'))

                    old_mac = port['port']['mac_address']

                    # we are updating only the port mac address. So the
                    # mac address of the allowed address pair ip 1.1.1.1
                    # will have old mac address
                    data = {'port': {'mac_address': '00:00:00:00:00:01'}}
                    req = self.new_update_request('ports', data,
                                                  port['port']['id'])
                    req.get_response(self.api)
                    self.assertTrue(self.nb_ovn.set_lswitch_port.called)
                    called_args_dict = ((
                        self.nb_ovn.set_lswitch_port).call_args_list[0][1])
                    self.assertEqual(
                        tools.UnorderedList([
                            "22:22:22:22:22:22 2.2.2.2",
                            "00:00:00:00:00:01 " + port_ip,
                            old_mac + " 1.1.1.1"
                        ]), called_args_dict.get('port_security'))
コード例 #2
0
ファイル: test_db.py プロジェクト: zhunzhong/neutron
 def test_get_ha_agents_by_router_id(self):
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     self._create_ha_router()
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     agents = l2pop_db.get_ha_agents_by_router_id(self.ctx, TEST_ROUTER_ID)
     ha_agents = [agent.host for agent in agents]
     self.assertEqual(tools.UnorderedList([HOST, HOST_2]), ha_agents)
コード例 #3
0
    def test_add_metering_label_rpc_call(self):
        second_uuid = 'e27fe2df-376e-4ac7-ae13-92f050a21f84'
        expected = [{
            'status': 'ACTIVE',
            'name': 'router1',
            'gw_port_id': None,
            'admin_state_up': True,
            'distributed': False,
            'tenant_id': self.tenant_id,
            '_metering_labels': [{
                'rules': [],
                'id': second_uuid
            }],
            'id': self.uuid
        }, {
            'status': 'ACTIVE',
            'name': 'router2',
            'gw_port_id': None,
            'admin_state_up': True,
            'distributed': False,
            'tenant_id': self.tenant_id,
            '_metering_labels': [{
                'rules': [],
                'id': second_uuid
            }],
            'id': second_uuid
        }]

        # bind each router to a specific agent
        agent1 = agent_model.Agent(host='agent1')
        agent2 = agent_model.Agent(host='agent2')

        agents = {self.uuid: agent1, second_uuid: agent2}

        def side_effect(context, routers, admin_state_up, active):
            return [agents[routers[0]]]

        self.l3routers_mock.side_effect = side_effect

        with self.router(name='router1',
                         tenant_id=self.tenant_id,
                         set_context=True):
            self.mock_uuid.return_value = second_uuid
            with self.router(name='router2',
                             tenant_id=self.tenant_id,
                             set_context=True):
                with self.metering_label(tenant_id=self.tenant_id,
                                         set_context=True):
                    self.mock_add.assert_called_with(
                        self.ctx, tools.UnorderedList(expected))
コード例 #4
0
    def test_create_port_security_allowed_address_pairs(self):
        self.skipTest("Fix this after allowed-address-pairs"
                      " extension is supported")
        self.plugin._ovn.create_lport = mock.Mock()
        self.plugin._ovn.set_lport = mock.Mock()
        kwargs = {
            'allowed_address_pairs': [{
                "ip_address": "1.1.1.1",
                "mac_address": "22:22:22:22:22:22"
            }]
        }
        with self.network(set_context=True, tenant_id='test') as net1:
            with self.subnet(network=net1) as subnet1:
                with self.port(subnet=subnet1,
                               arg_list=('allowed_address_pairs', ),
                               set_context=True,
                               tenant_id='test',
                               **kwargs) as port:
                    self.assertTrue(self.plugin._ovn.create_lport.called)
                    called_args_dict = ((
                        self.plugin._ovn.create_lport).call_args_list[0][1])
                    self.assertEqual(
                        called_args_dict.get('port_security'),
                        tools.UnorderedList("22:22:22:22:22:22",
                                            port['port']['mac_address']))

                    data = {'port': {'mac_address': '00:00:00:00:00:01'}}
                    req = self.new_update_request('ports', data,
                                                  port['port']['id'])
                    req.get_response(self.api)
                    self.assertTrue(self.plugin._ovn.set_lport.called)
                    called_args_dict = ((
                        self.plugin._ovn.set_lport).call_args_list[0][1])
                    self.assertEqual(
                        called_args_dict.get('port_security'),
                        tools.UnorderedList("22:22:22:22:22:22",
                                            "00:00:00:00:00:01"))
コード例 #5
0
 def test_convert_kvp_list_to_dict_succeeds_for_multiple_values(self):
     result = attributes.convert_kvp_list_to_dict(
         ['a=b', 'a=c', 'a=c', 'b=a'])
     expected = {'a': tools.UnorderedList(['c', 'b']), 'b': ['a']}
     self.assertEqual(expected, result)