예제 #1
0
    def test_get_private_router(self):
        fake_net = fake_network.FakeNetwork()
        fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip')
        fake_share_network = {
            'neutron_net_id': fake_net['id'],
            'neutron_subnet_id': fake_subnet['id']
        }
        self.stubs.Set(self._manager.db, 'share_network_get',
                       mock.Mock(return_value=fake_share_network))
        fake_port = fake_network.FakePort(fixed_ips=[{
            'subnet_id':
            fake_subnet['id'],
            'ip_address':
            fake_subnet['gateway_ip']
        }],
                                          device_id='fake_router_id')
        fake_router = fake_network.FakeRouter(id='fake_router_id')
        self.stubs.Set(self._manager.neutron_api, 'get_subnet',
                       mock.Mock(return_value=fake_subnet))
        self.stubs.Set(self._manager.neutron_api, 'list_ports',
                       mock.Mock(return_value=[fake_port]))
        self.stubs.Set(self._manager.neutron_api, 'show_router',
                       mock.Mock(return_value=fake_router))

        result = self._manager._get_private_router(fake_net['id'],
                                                   fake_subnet['id'])

        self._manager.neutron_api.get_subnet.assert_called_once_with(
            fake_subnet['id'])
        self._manager.neutron_api.list_ports.assert_called_once_with(
            network_id=fake_net['id'])
        self._manager.neutron_api.show_router.assert_called_once_with(
            fake_router['id'])
        self.assertEqual(result, fake_router)
예제 #2
0
    def test_get_cidr_for_subnet(self):
        serv_cidr = service_instance.netaddr.IPNetwork(
            CONF.service_network_cidr)
        fake_division_mask = CONF.service_network_division_mask
        cidrs = serv_cidr.subnet(fake_division_mask)
        cidr1 = str(cidrs.next())
        cidr2 = str(cidrs.next())
        self.stubs.Set(self._manager, '_get_all_service_subnets',
                       mock.Mock(return_value=[]))
        result = self._manager._get_cidr_for_subnet()
        self.assertEqual(result, cidr1)

        fake_subnet = fake_network.FakeSubnet(cidr=cidr1)
        self.stubs.Set(self._manager, '_get_all_service_subnets',
                       mock.Mock(return_value=[fake_subnet]))
        result = self._manager._get_cidr_for_subnet()
        self.assertEqual(result, cidr2)
예제 #3
0
    def test_get_private_router_exception(self):
        fake_net = fake_network.FakeNetwork()
        fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip')
        fake_share_network = {
            'neutron_net_id': fake_net['id'],
            'neutron_subnet_id': fake_subnet['id']
        }
        self.stubs.Set(self._manager.db, 'share_network_get',
                       mock.Mock(return_value=fake_share_network))
        self.stubs.Set(self._manager.neutron_api, 'get_subnet',
                       mock.Mock(return_value=fake_subnet))
        self.stubs.Set(self._manager.neutron_api, 'list_ports',
                       mock.Mock(return_value=[]))

        self.assertRaises(exception.ManilaException,
                          self._manager._get_private_router, fake_net['id'],
                          fake_subnet['id'])
예제 #4
0
    def test_setup_connectivity_with_service_instances(self):
        interface_name = 'fake_interface_name'
        fake_division_mask = CONF.service_network_division_mask
        fake_subnet = fake_network.FakeSubnet(cidr='10.254.0.0/%s' %
                                              fake_division_mask)
        fake_port = fake_network.FakePort(fixed_ips=[{
            'subnet_id':
            fake_subnet['id'],
            'ip_address':
            '10.254.0.2'
        }],
                                          mac_address='fake_mac_address')

        self.stubs.Set(self._manager, '_get_service_port',
                       mock.Mock(return_value=fake_port))
        self.stubs.Set(self._manager.vif_driver, 'get_device_name',
                       mock.Mock(return_value=interface_name))
        self.stubs.Set(self._manager.neutron_api, 'get_subnet',
                       mock.Mock(return_value=fake_subnet))
        self.stubs.Set(self._manager, '_remove_outdated_interfaces',
                       mock.Mock())
        self.stubs.Set(self._manager.vif_driver, 'plug', mock.Mock())
        device_mock = mock.Mock()
        self.stubs.Set(service_instance.ip_lib, 'IPDevice',
                       mock.Mock(return_value=device_mock))

        self._manager._setup_connectivity_with_service_instances()

        self._manager._get_service_port.assert_called_once_with()
        self._manager.vif_driver.get_device_name.assert_called_once_with(
            fake_port)
        self._manager.vif_driver.plug.assert_called_once_with(
            interface_name, fake_port['id'], fake_port['mac_address'])
        self._manager.neutron_api.get_subnet.assert_called_once_with(
            fake_subnet['id'])
        self._manager.vif_driver.init_l3.assert_called_once_with(
            interface_name, ['10.254.0.2/%s' % fake_division_mask])
        service_instance.ip_lib.IPDevice.assert_called_once_with(
            interface_name)
        device_mock.route.pullup_route.assert_called_once_with(interface_name)
        self._manager._remove_outdated_interfaces.assert_called_once_with(
            device_mock)