Esempio n. 1
0
 def __init__(self, topology, subnet_id, cidr):
     """Create the subnet under the given topology, with the given ID, and
     the given address range.
     :param topology:  The topology to which the subnet belongs
     :type topology:   Topology
     :param subnet_id: The subnet's ID in the topology. Created by topology
     :type subnet_id:  Number (Opaque)
     :param cidr:      The address range for this subnet. Format IP/MaskLen
     :type cidr:       String
     """
     self.topology = topology
     self.subnet_id = subnet_id
     self.ports = []
     self.subnet = objects.SubnetTestObj(
         self.topology.neutron,
         self.topology.nb_api,
         self.topology.network.network_id
     )
     self.subnet.create(subnet={
         'cidr': cidr,
         'ip_version': 4,
         'network_id': topology.network.network_id,
         'host_routes': [
             {
                 'destination': '1.1.1.0/24',
                 'nexthop': '2.2.2.2'
             },
             {
                 'destination': '1.1.2.0/24',
                 'nexthop': '3.3.3.3'
             },
         ]
     })
Esempio n. 2
0
    def test_router_version(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet_id = subnet.create()
        self.assertTrue(subnet.exists())
        router = objects.RouterTestObj(self.neutron, self.nb_api)
        self.addCleanup(router.close)
        router_id = router.create()
        self.assertTrue(router.exists())
        prev_version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version

        subnet_msg = {'subnet_id': subnet_id}
        self.neutron.add_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
        self.assertGreater(version, prev_version)
        prev_version = version

        self.neutron.remove_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
        self.assertGreater(version, prev_version)

        router.close()
        self.assertFalse(router.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Esempio n. 3
0
    def test_router_version(self):
        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet_id = subnet.create()
        self.assertTrue(subnet.exists())
        router_id = router.create()
        self.assertTrue(router.exists())
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 0)

        subnet_msg = {'subnet_id': subnet_id}
        self.neutron.add_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 1)

        self.neutron.remove_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 2)

        router.close()
        self.assertFalse(router.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Esempio n. 4
0
 def __init__(self, topology, network, subnet_id, cidr, enable_dhcp):
     """Create the subnet under the given topology, with the given ID, and
     the given address range.
     :param topology:  The topology to which the subnet belongs
     :type topology:   Topology
     :param network:   The network to which the subnet belongs
     :type network:    NetworkTestObj
     :param subnet_id: The subnet's ID in the topology. Created by topology
     :type subnet_id:  Number (Opaque)
     :param cidr:      The address range for this subnet. Format IP/MaskLen.
                       If it is None, the cidr will be allocated from
                       default subnetpool.
     :type cidr:       String
     :param enable_dhcp: Whether to enable dhcp for this subnet.
     :type cidr:  Boolean
     """
     self.topology = topology
     self.subnet_id = subnet_id
     self.ports = []
     self.network = network
     self.subnet = objects.SubnetTestObj(
         self.topology.neutron,
         self.topology.nb_api,
         self.network.network_id
     )
     if cidr:
         ip_version = self._get_ip_version(cidr)
         self.subnet.create(subnet={
             'cidr': cidr,
             'enable_dhcp': enable_dhcp,
             'ip_version': ip_version,
             'network_id': self.network.network_id
         })
     else:
         self.subnet.create()
Esempio n. 5
0
 def test_create_subnet_with_host_routes(self):
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = self.store(
         objects.SubnetTestObj(
             self.neutron,
             self.nb_api,
             network_id,
         ))
     subnet_data = {
         'cidr':
         '192.168.199.0/24',
         'ip_version':
         4,
         'network_id':
         network_id,
         'host_routes': [
             {
                 'destination': '1.1.1.0/24',
                 'nexthop': '2.2.2.2'
             },
             {
                 'destination': '1.1.2.0/24',
                 'nexthop': '3.3.3.3'
             },
         ]
     }
     subnet.create(subnet_data)
     lswitch = self.nb_api.get_lswitch(network_id)
     subnet = lswitch.get_subnets()
     self.assertEqual(
         0, cmp(subnet_data['host_routes'], subnet[0].get_host_routes()))
Esempio n. 6
0
    def test_port_version(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet = self.store(
            objects.SubnetTestObj(self.neutron, self.nb_api, network_id))
        subnet.create()
        self.assertTrue(subnet.exists())

        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        port_id = port.create()
        self.assertTrue(port.exists())
        prev_version = self.nb_api.get_logical_port(port_id).get_version()

        port.update()
        self.assertTrue(port.exists())
        version = self.nb_api.get_logical_port(port_id).get_version()
        self.assertGreater(version, prev_version)

        port.close()
        self.assertFalse(port.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Esempio n. 7
0
 def test_create_router_interface(self):
     router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = self.store(objects.SubnetTestObj(
         self.neutron,
         self.nb_api,
         network_id,
     ))
     subnet_id = subnet.create()
     router_id = router.create()
     self.assertTrue(router.exists())
     subnet_msg = {'subnet_id': subnet_id}
     port = self.neutron.add_interface_router(router_id, body=subnet_msg)
     port2 = self.nb_api.get_logical_port(port['port_id'])
     self.assertIsNotNone(port2)
     router.close()
     utils.wait_until_none(
         lambda: self.nb_api.get_logical_port(port['port_id']),
         exception=Exception('Port was not deleted')
     )
     subnet.close()
     network.close()
     self.assertFalse(router.exists())
     self.assertFalse(network.exists())
Esempio n. 8
0
    def _prepare_ext_net(self):
        external_net = objects.find_first_network(self.neutron,
                                                  {'router:external': True})
        if not external_net:
            network = objects.NetworkTestObj(self.neutron, self.nb_api)
            self.addCleanup(network.close)
            external_net_para = {'name': 'public', 'router:external': True}
            external_network_id = network.create(network=external_net_para)
            self.assertTrue(network.exists())
            ext_subnet = objects.SubnetTestObj(self.neutron, self.nb_api,
                                               external_network_id)
            self.addCleanup(ext_subnet.close)
            external_subnet_para = {
                'cidr': '192.168.199.0/24',
                'ip_version': 4,
                'network_id': external_network_id
            }
            ext_subnet.create(external_subnet_para)
            self.assertTrue(ext_subnet.exists())
        else:
            external_network_id = external_net['id']
        self.assertIsNotNone(external_network_id)

        # return external network
        yield external_network_id

        if not external_net:
            ext_subnet.close()
            self.assertFalse(ext_subnet.exists())
            network.close()
            self.assertFalse(network.exists())
Esempio n. 9
0
    def test_port_version(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet.create()
        self.assertTrue(subnet.exists())

        port = objects.PortTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(port.close)
        port_id = port.create()
        self.assertTrue(port.exists())
        prev_version = self.nb_api.get(l2.LogicalPort(id=port_id)).version

        port.update()
        self.assertTrue(port.exists())
        version = self.nb_api.get(l2.LogicalPort(id=port_id)).version
        self.assertGreater(version, prev_version)

        port.close()
        self.assertFalse(port.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Esempio n. 10
0
 def test_create_subnet_with_host_routes(self):
     network = objects.NetworkTestObj(self.neutron, self.nb_api)
     self.addCleanup(network.close)
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
     self.addCleanup(subnet.close)
     subnet_data = {
         'cidr':
         '192.168.199.0/24',
         'ip_version':
         4,
         'network_id':
         network_id,
         'host_routes': [
             {
                 'destination': '1.1.1.0/24',
                 'nexthop': '2.2.2.2'
             },
             {
                 'destination': '1.1.2.0/24',
                 'nexthop': '3.3.3.3'
             },
         ]
     }
     subnet.create(subnet_data)
     db_subnet = subnet.get_subnet()
     self.assertEqual(
         subnet_data['host_routes'],
         [host_route.to_struct() for host_route in db_subnet.host_routes])
Esempio n. 11
0
    def test_disassociate_floatingip(self):
        with self._prepare_ext_net() as external_network_id:
            router = self.store(
                objects.RouterTestObj(self.neutron, self.nb_api))
            fip = self.store(
                objects.FloatingipTestObj(self.neutron, self.nb_api))

            router_para = {
                'name': 'myrouter1', 'admin_state_up': True,
                'external_gateway_info': {"network_id": external_network_id}}
            router.create(router=router_para)
            self.assertTrue(router.exists())

            # private network
            private_network = self.store(
                objects.NetworkTestObj(self.neutron, self.nb_api))
            private_network_id = private_network.create()
            self.assertTrue(private_network.exists())
            # private subnet
            priv_subnet = self.store(objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                private_network_id,
            ))
            private_subnet_para = {'cidr': '10.0.0.0/24',
                                   'ip_version': 4,
                                   'network_id': private_network_id}
            priv_subnet_id = priv_subnet.create(private_subnet_para)
            self.assertTrue(priv_subnet.exists())
            router_interface = router.add_interface(subnet_id=priv_subnet_id)
            router_lport = self.nb_api.get(
                l2.LogicalPort(id=router_interface['port_id']))
            self.assertIsNotNone(router_lport)

            port = self.store(
                objects.PortTestObj(self.neutron,
                                    self.nb_api, private_network_id))
            port_id = port.create()
            self.assertIsNotNone(port.get_logical_port())

            fip_para = {'floating_network_id': external_network_id,
                        'port_id': port_id}
            # create
            fip.create(fip_para)
            self.assertTrue(fip.exists())

            # disassociate with port
            fip.update({})
            fip_obj = fip.get_floatingip()
            self.assertIsNone(fip_obj.lport)

            fip.close()
            self.assertFalse(fip.exists())
            port.close()
            self.assertFalse(port.exists())
            router.close()
            self.assertFalse(router.exists())
            priv_subnet.close()
            self.assertFalse(priv_subnet.exists())
Esempio n. 12
0
    def test_remote_port(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet_info = {
            'network_id': network_id,
            'cidr': '192.168.150.0/24',
            'gateway_ip': '192.168.150.1',
            'ip_version': 4,
            'name': 'subnet1',
            'enable_dhcp': True
        }
        subnet = objects.SubnetTestObj(self.neutron,
                                       self.nb_api,
                                       network_id=network_id)
        self.addCleanup(subnet.close)
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        port = objects.PortTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(port.close)
        port_body = {
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'binding:profile': {
                'port_key': 'remote_port',
                'host_ip': '10.10.10.10'
            }
        }
        port.create(port=port_body)
        self.assertTrue(port.exists())

        time.sleep(test_const.DEFAULT_CMD_TIMEOUT)
        network_obj = network.get_network()['network']
        network_type = network_obj['provider:network_type']
        segmentation_id = network_obj['provider:segmentation_id']
        port_num = self.vswitch_api.get_vtp_ofport(network_type)
        port_unique_key = port.get_logical_port().unique_key

        match = "reg7=" + str(hex(port_unique_key))
        action = ("set_field:10.10.10.10" + "->tun_dst,set_field:" +
                  str(hex(segmentation_id)) + "->tun_id,output:" +
                  str(port_num))
        ovs = utils.OvsFlowsParser()
        matched = False
        for flow in ovs.dump(self.integration_bridge):
            if flow['table'] == str(const.EGRESS_TABLE):
                if match in flow['match']:
                    matched = True
                    self.assertEqual(action, flow['actions'])

        if not matched:
            raise Exception("Can't find flows for remote port!")
Esempio n. 13
0
 def _create_network(self):
     network = objects.NetworkTestObj(self.neutron, self.nb_api)
     self.addCleanup(network.close)
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
     self.addCleanup(subnet.close)
     subnet.create()
     self.assertTrue(subnet.exists())
     return network
Esempio n. 14
0
    def test_remote_port(self):
        if cfg.CONF.core_plugin == DF_PLUGIN:
            return

        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'network1'})
        self.assertTrue(network.exists())

        subnet_info = {
            'network_id': network_id,
            'cidr': '192.168.150.0/24',
            'gateway_ip': '192.168.150.1',
            'ip_version': 4,
            'name': 'subnet1',
            'enable_dhcp': True
        }
        subnet = self.store(
            objects.SubnetTestObj(self.neutron,
                                  self.nb_api,
                                  network_id=network_id))
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        port_body = {
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'binding:profile': {
                'port_key': 'remote_port',
                'host_ip': '10.10.10.10'
            }
        }
        port.create(port=port_body)
        self.assertTrue(port.exists())

        ovsdb = utils.OvsDBParser()
        utils.wait_until_true(
            lambda: self._get_wanted_tunnel_port(ovsdb, '10.10.10.10'),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=2,
            exception=Exception('Could not get wanted tunnel port'))

        port.close()
        self.assertFalse(port.exists())

        utils.wait_until_none(
            lambda: ovsdb.get_tunnel_ofport('10.10.10.10'),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=2,
            exception=Exception('Could not delete wanted tunnel port'))

        subnet.close()
        network.close()
Esempio n. 15
0
 def _create_network(self):
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create(network={'name': 'private'})
     self.assertTrue(network.exists())
     subnet = self.store(objects.SubnetTestObj(
         self.neutron,
         self.nb_api,
         network_id,
     ))
     subnet.create()
     self.assertTrue(subnet.exists())
     return network
Esempio n. 16
0
    def test_arp_responder(self):
        """
        Add a VM. Verify it's ARP flow is there.
        """
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'arp_responder_test'})
        subnet_obj = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))

        subnet = {
            'network_id': network_id,
            'cidr': '10.10.10.0/24',
            'gateway_ip': '10.10.10.1',
            'ip_version': 4,
            'name': 'arp_responder_test',
            'enable_dhcp': True
        }
        subnet = subnet_obj.create(subnet)

        flows_before = self._get_arp_table_flows()
        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)
        ip = vm.get_first_ipv4()
        self.assertIsNotNone(ip)

        flows_middle = self._get_arp_table_flows()

        vm.server.stop()
        vm.close()
        eventlet.sleep(test_utils.DEFAULT_CMD_TIMEOUT)
        flows_delta = [
            flow for flow in flows_middle if flow not in flows_before
        ]
        self.assertIsNotNone(
            self._find_arp_responder_flow_by_ip(flows_delta, ip))

        condition = lambda: self._check_arp_flow_removal(ip)
        try:
            utils.wait_until_true(
                condition,
                timeout=40,
                sleep=1,
                exception=RuntimeError(
                    "Timed out waiting for arp responedr flow from  %(ip)s"
                    " to be removed" % {'ip': ip}))
        except Exception as e:
            self.assertIsNone(e)
        finally:
            network.close()
    def test_anti_spoof_flows(self):

        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'test_network1'})
        self.assertTrue(network.exists())

        subnet_info = {'network_id': network_id,
                       'cidr': '192.168.130.0/24',
                       'gateway_ip': '192.168.130.1',
                       'ip_version': 4,
                       'name': 'test_subnet1',
                       'enable_dhcp': True}
        subnet = self.store(objects.SubnetTestObj(self.neutron,
                                                  self.nb_api,
                                                  network_id=network_id))
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)

        addresses = vm.server.addresses['test_network1']
        self.assertIsNotNone(addresses)
        ip = addresses[0]['addr']
        self.assertIsNotNone(ip)
        mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac)
        port = utils.wait_until_is_and_return(
            lambda: self._get_vm_port(ip, mac),
            exception=Exception('No port assigned to VM')
        )

        ovsdb = utils.OvsDBParser()
        of_port = ovsdb.get_ofport(port.get_id())
        self.assertIsNotNone(of_port)

        # Check if the associating flows were installed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, of_port
        )
        self._check_all_flows_existed(expected_flow_list)

        vm.server.stop()
        vm.close()

        time.sleep(utils.DEFAULT_CMD_TIMEOUT)

        # Check if the associating flows were removed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, of_port
        )
        self._check_not_flow_existed(expected_flow_list)
Esempio n. 18
0
 def test_create_delete_subnet(self):
     network = objects.NetworkTestObj(self.neutron, self.nb_api)
     self.addCleanup(network.close)
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
     self.addCleanup(subnet.close)
     subnet_id = subnet.create()
     self.assertTrue(subnet.exists())
     self.assertEqual(subnet_id, subnet.get_subnet().id)
     subnet.close()
     self.assertFalse(subnet.exists())
     network.close()
Esempio n. 19
0
    def test_reply_message(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet_body = {
            'network_id': network_id,
            'cidr': '10.20.0.0/24',
            'gateway_ip': '10.20.0.1',
            'ip_version': 4,
            'name': 'private',
            'enable_dhcp': True
        }
        subnet.create(subnet=subnet_body)
        self.assertTrue(network.exists())
        self.assertTrue(subnet.exists())

        vm1 = objects.VMTestObj(self, self.neutron)
        self.addCleanup(vm1.close)
        vm1.create(network=network)
        self.assertIsNotNone(vm1.server.addresses['mynetwork'])
        mac1 = vm1.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac1)

        vm2 = objects.VMTestObj(self, self.neutron)
        self.addCleanup(vm2.close)
        vm2.create(network=network)
        self.assertIsNotNone(vm2.server.addresses['mynetwork'])
        mac2 = vm2.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac2)

        # wait util get the message we want
        self.set_wanted_vms.clear()
        utils.wait_until_true(
            lambda: self._get_all_wanted_vms_online(mac1, mac2),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Could not get wanted online vm'))
        vm1.close()
        vm2.close()
        utils.wait_until_none(
            lambda: utils.find_logical_port(self.nb_api, ip=None, mac=mac1),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Port was not deleted'))
        utils.wait_until_none(
            lambda: utils.find_logical_port(self.nb_api, ip=None, mac=mac2),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Port was not deleted'))
Esempio n. 20
0
    def test_add_remove_allowed_address_pairs(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet.create({
            'cidr': '192.168.127.0/24',
            'ip_version': 4,
            'network_id': network_id
        })
        self.assertTrue(subnet.exists())

        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        expected_pairs = [{
            "ip_address": "192.168.127.201",
            "mac_address": "11:22:33:44:55:66"
        }, {
            "ip_address": "192.168.127.202",
            "mac_address": "22:22:33:44:55:66"
        }]
        port.create({
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'allowed_address_pairs': expected_pairs
        })
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_pairs = lport.get_allow_address_pairs()
        self.assertEqual(expected_pairs, real_pairs)

        expected_pairs = [{
            "ip_address": "192.168.127.211",
            "mac_address": "33:22:33:44:55:66"
        }, {
            "ip_address": "192.168.127.212",
            "mac_address": "44:22:33:44:55:66"
        }]
        port.update({'allowed_address_pairs': expected_pairs})
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_pairs = lport.get_allow_address_pairs()
        self.assertEqual(expected_pairs, real_pairs)
Esempio n. 21
0
 def test_create_delete_subnet(self):
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = self.store(objects.SubnetTestObj(
         self.neutron,
         self.nb_api,
         network_id,
     ))
     subnet_id = subnet.create()
     self.assertTrue(subnet.exists())
     self.assertEqual(subnet_id, subnet.get_subnet().get_id())
     subnet.close()
     self.assertFalse(subnet.exists())
     network.close()
Esempio n. 22
0
    def test_add_remove_allowed_address_pairs(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet.create({
            'cidr': '192.168.127.0/24',
            'ip_version': 4,
            'network_id': network_id
        })
        self.assertTrue(subnet.exists())

        port = objects.PortTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(port.close)
        expected_pairs = [{
            "ip_address": "192.168.127.201",
            "mac_address": "00:22:33:44:55:66"
        }, {
            "ip_address": "192.168.127.202",
            "mac_address": "22:22:33:44:55:66"
        }]
        port.create({
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'allowed_address_pairs': expected_pairs
        })
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_pairs = [aap.to_struct() for aap in lport.allowed_address_pairs]
        self.assertItemsEqual(expected_pairs, real_pairs)

        expected_pairs = [{
            "ip_address": "192.168.127.211",
            "mac_address": "00:22:33:44:55:66"
        }, {
            "ip_address": "192.168.127.212",
            "mac_address": "44:22:33:44:55:66"
        }]
        port.update({'allowed_address_pairs': expected_pairs})
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_pairs = [aap.to_struct() for aap in lport.allowed_address_pairs]
        self.assertItemsEqual(expected_pairs, real_pairs)
Esempio n. 23
0
    def _test_anti_spoof_flows(self, subnet_info):

        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())

        subnet_info['network_id'] = network_id
        subnet = objects.SubnetTestObj(self.neutron,
                                       self.nb_api,
                                       network_id=network_id)
        self.addCleanup(subnet.close)
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        vm = objects.VMTestObj(self, self.neutron)
        self.addCleanup(vm.close)
        vm.create(network=network)

        addresses = vm.server.addresses['mynetwork']
        self.assertIsNotNone(addresses)
        ip = addresses[0]['addr']
        self.assertIsNotNone(ip)
        mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac)
        port = utils.wait_until_is_and_return(
            lambda: utils.find_logical_port(self.nb_api, ip, mac),
            exception=Exception('No port assigned to VM'))

        of_port = self.vswitch_api.get_port_ofport_by_id(port.id)
        self.assertIsNotNone(of_port)
        unique_key = port.unique_key

        # Check if the associating flows were installed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, unique_key)
        self._check_all_flows_existed(expected_flow_list)

        vm.close()

        time.sleep(test_const.DEFAULT_RESOURCE_READY_TIMEOUT)

        # Check if the associating flows were removed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, unique_key)
        self._check_not_flow_existed(expected_flow_list)
Esempio n. 24
0
    def test_reply_message(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'private'})
        subnet = self.store(
            objects.SubnetTestObj(self.neutron, self.nb_api, network_id))
        subnet_body = {
            'network_id': network_id,
            'cidr': '10.20.0.0/24',
            'gateway_ip': '10.20.0.1',
            'ip_version': 4,
            'name': 'private',
            'enable_dhcp': True
        }
        subnet.create(subnet=subnet_body)
        self.assertTrue(network.exists())
        self.assertTrue(subnet.exists())

        vm1 = self.store(objects.VMTestObj(self, self.neutron))
        vm1.create(network=network)
        self.assertIsNotNone(vm1.server.addresses['private'])
        mac1 = vm1.server.addresses['private'][0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac1)

        vm2 = self.store(objects.VMTestObj(self, self.neutron))
        vm2.create(network=network)
        self.assertIsNotNone(vm2.server.addresses['private'])
        mac2 = vm2.server.addresses['private'][0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac2)

        #wait util get the message we want
        self.set_wanted_vms.clear()
        wait_until_true(lambda: self._get_all_wanted_vms_online(mac1, mac2),
                        timeout=30,
                        sleep=1,
                        exception=Exception('Could not get wanted online vm'))
        vm1.close()
        vm2.close()
        utils.wait_until_none(lambda: self._get_vm_port_by_mac_address(mac1),
                              timeout=30,
                              sleep=1,
                              exception=Exception('Port was not deleted'))
        utils.wait_until_none(lambda: self._get_vm_port_by_mac_address(mac2),
                              timeout=30,
                              sleep=1,
                              exception=Exception('Port was not deleted'))
Esempio n. 25
0
    def test_delete_router_interface_port(self):
        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet_id = subnet.create({
            'cidr': '91.126.188.0/24',
            'ip_version': 4,
            'network_id': network_id
        })
        router_id = router.create()
        self.assertTrue(router.exists())
        interface_msg = {'subnet_id': subnet_id}
        router_l = self.neutron.add_interface_router(router_id,
                                                     body=interface_msg)
        routers = self.nb_api.get_all(l3.LogicalRouter)
        router2 = None
        for r in routers:
            if r.id == router_l['id']:
                router2 = r
                break
        self.assertIsNotNone(router2)
        interface_port = self.neutron.show_port(router_l['port_id'])
        self.assertRaises(n_exc.Conflict, self.neutron.delete_port,
                          interface_port['port']['id'])
        self.assertIsNotNone(
            self.nb_api.get(l2.LogicalPort(id=interface_port['port']['id'])))

        self.neutron.remove_interface_router(router.router_id,
                                             body=interface_msg)
        port2 = self.nb_api.get(
            l2.LogicalPort(id=interface_port['port']['id']))
        self.assertIsNone(port2)
        subnet.close()
        router.close()
        network.close()
        self.assertFalse(router.exists())
        self.assertFalse(network.exists())
Esempio n. 26
0
    def test_notify_message(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        subnet = self.store(
            objects.SubnetTestObj(self.neutron, self.nb_api, network_id))
        subnet_body = {
            'network_id': network_id,
            'cidr': '10.10.0.0/24',
            'gateway_ip': '10.10.0.1',
            'ip_version': 4,
            'name': 'private',
            'enable_dhcp': True
        }
        subnet.create(subnet=subnet_body)
        self.assertTrue(network.exists())
        self.assertTrue(subnet.exists())

        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)
        self.assertIsNotNone(vm.server.addresses['mynetwork'])
        mac = vm.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac)
        # wait util get the message we want
        utils.wait_until_true(
            lambda: self._get_wanted_vm_online(mac),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Could not get wanted online vm'))

        # wait util get the message we want
        vm.close()
        utils.wait_until_true(
            lambda: self._get_wanted_vm_offline(mac),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Could not get wanted offline vm'))
        utils.wait_until_none(
            lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=1,
            exception=Exception('Port was not deleted'))
Esempio n. 27
0
    def test_network_version(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())
        version = self.nb_api.get_lswitch(network_id).get_version()

        subnet = self.store(
            objects.SubnetTestObj(self.neutron, self.nb_api, network_id))
        subnet.create()
        self.assertTrue(subnet.exists())
        new_version = self.nb_api.get_lswitch(network_id).get_version()
        self.assertGreater(new_version, version)

        subnet.close()
        self.assertFalse(subnet.exists())
        version = new_version
        new_version = self.nb_api.get_lswitch(network_id).get_version()
        self.assertGreater(new_version, version)

        network.close()
        self.assertFalse(network.exists())
Esempio n. 28
0
    def test_network_version(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        lean_lswitch = l2.LogicalSwitch(id=network_id)
        self.assertTrue(network.exists())
        version = self.nb_api.get(lean_lswitch).version

        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet.create()
        self.assertTrue(subnet.exists())
        new_version = self.nb_api.get(lean_lswitch).version
        self.assertGreater(new_version, version)

        subnet.close()
        self.assertFalse(subnet.exists())
        version = new_version
        new_version = self.nb_api.get(lean_lswitch).version
        self.assertGreater(new_version, version)

        network.close()
        self.assertFalse(network.exists())
Esempio n. 29
0
    def test_enable_disable_portsec(self):
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())

        network2 = self.store(objects.NetworkTestObj(self.neutron,
                                                     self.nb_api))
        network_id2 = network2.create({
            'name': 'mynetwork1',
            'admin_state_up': True,
            'port_security_enabled': False
        })
        self.assertTrue(network2.exists())

        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet.create({
            'cidr': '192.168.125.0/24',
            'ip_version': 4,
            'network_id': network_id
        })
        self.assertTrue(subnet.exists())

        subnet2 = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id2,
            ))
        subnet2.create({
            'cidr': '192.168.126.0/24',
            'ip_version': 4,
            'network_id': network_id2
        })
        self.assertTrue(subnet2.exists())

        network_portsec_switch = True
        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        port.create()
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_switch = lport.get_port_security_enable()
        self.assertEqual(network_portsec_switch, real_switch)

        network_portsec_switch = False
        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id2))
        port.create()
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_switch = lport.get_port_security_enable()
        self.assertEqual(network_portsec_switch, real_switch)

        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        expected_switch = False
        port.create({
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'port_security_enabled': expected_switch
        })
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_switch = lport.get_port_security_enable()
        self.assertEqual(expected_switch, real_switch)

        expected_switch = True
        port.update({'port_security_enabled': expected_switch})
        lport = port.get_logical_port()
        self.assertIsNotNone(lport)
        real_switch = lport.get_port_security_enable()
        self.assertEqual(expected_switch, real_switch)
Esempio n. 30
0
    def test_icmp_responder(self):
        """
        Add a VM. Verify the icmp flow is there.
        """
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'icmp_responder_test'})
        subnet_obj = self.store(objects.SubnetTestObj(
            self.neutron,
            self.nb_api,
            network_id,
        ))

        subnet = {'network_id': network_id,
                  'cidr': '10.10.10.0/24',
                  'gateway_ip': '10.10.10.1',
                  'ip_version': 4,
                  'name': 'arp_responder_test',
                  'enable_dhcp': True}
        subnet_id = subnet_obj.create(subnet)

        flows_before = self._get_l3_lookup_table_flows()

        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        router_id = router.create()
        subnet_msg = {'subnet_id': subnet_id}
        interface = self.neutron.add_interface_router(router_id,
                                                      body=subnet_msg)
        port_id = interface['port_id']
        router_port = self.neutron.list_ports(id=port_id)['ports'][0]
        router_ip = None
        for ip in router_port['fixed_ips']:
            if ip['subnet_id'] == subnet_id:
                router_ip = ip['ip_address']
                break

        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)
        ip = vm.get_first_ipv4()
        self.assertIsNotNone(ip)

        flows_middle = self._get_l3_lookup_table_flows()

        vm.close()
        router.close()
        time.sleep(test_const.DEFAULT_RESOURCE_READY_TIMEOUT)

        flows_delta = [flow for flow in flows_middle
                       if flow not in flows_before]

        self.assertIsNotNone(
            self._find_icmp_responder_flow_by_ip(flows_delta, router_ip)
        )
        condition = lambda: self._check_icmp_flow_removal(router_ip)
        try:
            test_utils.wait_until_true(
                condition, timeout=test_const.DEFAULT_RESOURCE_READY_TIMEOUT,
                sleep=1,
                exception=RuntimeError(
                    "Timed out waiting for icmp responder flow from %(ip)s"
                    " to be removed" % {'ip': router_ip}))
        except Exception as e:
            self.assertIsNone(e)
        finally:
            network.close()