Implement BP untie-nova-network-models

Fixes LP853979
Remove the FK references for network data.
Remove unused db functions that used the FK's
Update db functions to not joinload
Update notification to optionally take network_info if compute has it
Update EC2 Api to use the network cache, falling back to rpc.call
Remove test_instance_get_project_vpn_joins which tests calls not used

Change-Id: I1a01ccc5ebcf7efeafe014af62be893325bb0825
This commit is contained in:
Jason Kölker
2012-01-04 11:10:10 -06:00
parent 70f300ef40
commit 1afb6549e9
7 changed files with 123 additions and 78 deletions

View File

@@ -86,7 +86,7 @@ class UsageInfoTestCase(test.TestCase):
type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
self.assertEquals(str(payload['instance_type_id']), str(type_id)) self.assertEquals(str(payload['instance_type_id']), str(type_id))
for attr in ('display_name', 'created_at', 'launched_at', for attr in ('display_name', 'created_at', 'launched_at',
'state', 'state_description', 'fixed_ips', 'state', 'state_description',
'bandwidth', 'audit_period_beginning', 'bandwidth', 'audit_period_beginning',
'audit_period_ending'): 'audit_period_ending'):
self.assertTrue(attr in payload, self.assertTrue(attr in payload,

View File

@@ -67,19 +67,6 @@ class DbApiTestCase(test.TestCase):
self.project_id) self.project_id)
self.assertEqual(instance['id'], result['id']) self.assertEqual(instance['id'], result['id'])
def test_instance_get_project_vpn_joins(self):
values = {'instance_type_id': FLAGS.default_instance_type,
'image_ref': FLAGS.vpn_image_id,
'project_id': self.project_id,
}
instance = db.instance_create(self.context, values)
_setup_networking(instance['id'])
result = db.instance_get_project_vpn(self.context.elevated(),
self.project_id)
self.assertEqual(instance['id'], result['id'])
self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
'1.2.1.2')
def test_instance_get_all_by_filters(self): def test_instance_get_all_by_filters(self):
args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'} args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args) inst1 = db.instance_create(self.context, args)

View File

@@ -1328,17 +1328,22 @@ class IptablesFirewallTestCase(test.TestCase):
return '', '' return '', ''
print cmd, kwargs print cmd, kwargs
network_info = _fake_network_info(self.stubs, 1)
def get_fixed_ips(*args, **kwargs): def get_fixed_ips(*args, **kwargs):
ips = [] ips = []
for network, info in network_info: for network, info in network_info:
ips.extend(info['ips']) ips.extend(info['ips'])
return [ip['ip'] for ip in ips] return [ip['ip'] for ip in ips]
def nw_info(*args, **kwargs):
return network_info
from nova.network import linux_net from nova.network import linux_net
linux_net.iptables_manager.execute = fake_iptables_execute linux_net.iptables_manager.execute = fake_iptables_execute
network_info = _fake_network_info(self.stubs, 1) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips) nw_info)
self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info)

View File

@@ -19,6 +19,7 @@ import os
import mox import mox
from nova import context
from nova import db from nova import db
from nova import flags from nova import flags
from nova import log as logging from nova import log as logging
@@ -102,8 +103,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0, 'instance_id': 0,
'allocated': True, 'allocated': True,
'virtual_interface_id': 0, 'virtual_interface_id': 0,
'virtual_interface': addresses[0], 'instance_id': 0,
'instance': instances[0],
'floating_ips': []}, 'floating_ips': []},
{'id': 1, {'id': 1,
'network_id': 1, 'network_id': 1,
@@ -111,8 +111,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0, 'instance_id': 0,
'allocated': True, 'allocated': True,
'virtual_interface_id': 1, 'virtual_interface_id': 1,
'virtual_interface': addresses[1], 'instance_id': 0,
'instance': instances[0],
'floating_ips': []}, 'floating_ips': []},
{'id': 2, {'id': 2,
'network_id': 1, 'network_id': 1,
@@ -120,8 +119,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1, 'instance_id': 1,
'allocated': True, 'allocated': True,
'virtual_interface_id': 2, 'virtual_interface_id': 2,
'virtual_interface': addresses[2], 'instance_id': 1,
'instance': instances[1],
'floating_ips': []}, 'floating_ips': []},
{'id': 3, {'id': 3,
'network_id': 0, 'network_id': 0,
@@ -129,8 +127,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1, 'instance_id': 1,
'allocated': True, 'allocated': True,
'virtual_interface_id': 3, 'virtual_interface_id': 3,
'virtual_interface': addresses[3], 'instance_id': 1,
'instance': instances[1],
'floating_ips': []}, 'floating_ips': []},
{'id': 4, {'id': 4,
'network_id': 0, 'network_id': 0,
@@ -138,8 +135,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0, 'instance_id': 0,
'allocated': True, 'allocated': True,
'virtual_interface_id': 4, 'virtual_interface_id': 4,
'virtual_interface': addresses[4], 'instance_id': 0,
'instance': instances[0],
'floating_ips': []}, 'floating_ips': []},
{'id': 5, {'id': 5,
'network_id': 1, 'network_id': 1,
@@ -147,8 +143,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1, 'instance_id': 1,
'allocated': True, 'allocated': True,
'virtual_interface_id': 5, 'virtual_interface_id': 5,
'virtual_interface': addresses[5], 'instance_id': 1,
'instance': instances[1],
'floating_ips': []}] 'floating_ips': []}]
@@ -156,37 +151,31 @@ vifs = [{'id': 0,
'address': 'DE:AD:BE:EF:00:00', 'address': 'DE:AD:BE:EF:00:00',
'uuid': '00000000-0000-0000-0000-0000000000000000', 'uuid': '00000000-0000-0000-0000-0000000000000000',
'network_id': 0, 'network_id': 0,
'network': networks[0],
'instance_id': 0}, 'instance_id': 0},
{'id': 1, {'id': 1,
'address': 'DE:AD:BE:EF:00:01', 'address': 'DE:AD:BE:EF:00:01',
'uuid': '00000000-0000-0000-0000-0000000000000001', 'uuid': '00000000-0000-0000-0000-0000000000000001',
'network_id': 1, 'network_id': 1,
'network': networks[1],
'instance_id': 0}, 'instance_id': 0},
{'id': 2, {'id': 2,
'address': 'DE:AD:BE:EF:00:02', 'address': 'DE:AD:BE:EF:00:02',
'uuid': '00000000-0000-0000-0000-0000000000000002', 'uuid': '00000000-0000-0000-0000-0000000000000002',
'network_id': 1, 'network_id': 1,
'network': networks[1],
'instance_id': 1}, 'instance_id': 1},
{'id': 3, {'id': 3,
'address': 'DE:AD:BE:EF:00:03', 'address': 'DE:AD:BE:EF:00:03',
'uuid': '00000000-0000-0000-0000-0000000000000003', 'uuid': '00000000-0000-0000-0000-0000000000000003',
'network_id': 0, 'network_id': 0,
'network': networks[0],
'instance_id': 1}, 'instance_id': 1},
{'id': 4, {'id': 4,
'address': 'DE:AD:BE:EF:00:04', 'address': 'DE:AD:BE:EF:00:04',
'uuid': '00000000-0000-0000-0000-0000000000000004', 'uuid': '00000000-0000-0000-0000-0000000000000004',
'network_id': 0, 'network_id': 0,
'network': networks[0],
'instance_id': 0}, 'instance_id': 0},
{'id': 5, {'id': 5,
'address': 'DE:AD:BE:EF:00:05', 'address': 'DE:AD:BE:EF:00:05',
'uuid': '00000000-0000-0000-0000-0000000000000005', 'uuid': '00000000-0000-0000-0000-0000000000000005',
'network_id': 1, 'network_id': 1,
'network': networks[1],
'instance_id': 1}] 'instance_id': 1}]
@@ -197,10 +186,20 @@ class LinuxNetworkTestCase(test.TestCase):
network_driver = FLAGS.network_driver network_driver = FLAGS.network_driver
self.driver = utils.import_object(network_driver) self.driver = utils.import_object(network_driver)
self.driver.db = db self.driver.db = db
self.context = context.RequestContext('testuser', 'testproject',
is_admin=True)
def test_update_dhcp_for_nw00(self): def test_update_dhcp_for_nw00(self):
self.flags(use_single_default_gateway=True) self.flags(use_single_default_gateway=True)
def get_vif(_context, vif_id):
return vifs[vif_id]
def get_instance(_context, instance_id):
return instances[instance_id]
self.stubs.Set(db, 'virtual_interface_get', get_vif)
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
self.mox.StubOutWithMock(self.driver, 'write_to_file') self.mox.StubOutWithMock(self.driver, 'write_to_file')
@@ -236,10 +235,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
self.driver.update_dhcp(None, "eth0", networks[0]) self.driver.update_dhcp(self.context, "eth0", networks[0])
def test_update_dhcp_for_nw01(self): def test_update_dhcp_for_nw01(self):
self.flags(use_single_default_gateway=True) self.flags(use_single_default_gateway=True)
def get_vif(_context, vif_id):
return vifs[vif_id]
def get_instance(_context, instance_id):
return instances[instance_id]
self.stubs.Set(db, 'virtual_interface_get', get_vif)
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
self.mox.StubOutWithMock(self.driver, 'write_to_file') self.mox.StubOutWithMock(self.driver, 'write_to_file')
@@ -275,10 +283,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
self.driver.update_dhcp(None, "eth0", networks[0]) self.driver.update_dhcp(self.context, "eth0", networks[0])
def test_get_dhcp_hosts_for_nw00(self): def test_get_dhcp_hosts_for_nw00(self):
self.flags(use_single_default_gateway=True) self.flags(use_single_default_gateway=True)
def get_vif(_context, vif_id):
return vifs[vif_id]
def get_instance(_context, instance_id):
return instances[instance_id]
self.stubs.Set(db, 'virtual_interface_get', get_vif)
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
db.network_get_associated_fixed_ips(mox.IgnoreArg(), db.network_get_associated_fixed_ips(mox.IgnoreArg(),
@@ -288,16 +305,25 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
expected = \ expected = \
"10.0.0.1,fake_instance00.novalocal,"\ "DE:AD:BE:EF:00:00,fake_instance00.novalocal,"\
"192.168.0.100,net:NW-i00000000-0\n"\ "192.168.0.100,net:NW-i00000000-0\n"\
"10.0.0.4,fake_instance01.novalocal,"\ "DE:AD:BE:EF:00:03,fake_instance01.novalocal,"\
"192.168.1.101,net:NW-i00000001-0" "192.168.1.101,net:NW-i00000001-0"
actual_hosts = self.driver.get_dhcp_hosts(None, networks[1]) actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[1])
self.assertEquals(actual_hosts, expected) self.assertEquals(actual_hosts, expected)
def test_get_dhcp_hosts_for_nw01(self): def test_get_dhcp_hosts_for_nw01(self):
self.flags(use_single_default_gateway=True) self.flags(use_single_default_gateway=True)
def get_vif(_context, vif_id):
return vifs[vif_id]
def get_instance(_context, instance_id):
return instances[instance_id]
self.stubs.Set(db, 'virtual_interface_get', get_vif)
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
db.network_get_associated_fixed_ips(mox.IgnoreArg(), db.network_get_associated_fixed_ips(mox.IgnoreArg(),
@@ -307,15 +333,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
expected = \ expected = \
"10.0.0.2,fake_instance00.novalocal,"\ "DE:AD:BE:EF:00:01,fake_instance00.novalocal,"\
"192.168.1.100,net:NW-i00000000-1\n"\ "192.168.1.100,net:NW-i00000000-1\n"\
"10.0.0.3,fake_instance01.novalocal,"\ "DE:AD:BE:EF:00:02,fake_instance01.novalocal,"\
"192.168.0.101,net:NW-i00000001-1" "192.168.0.101,net:NW-i00000001-1"
actual_hosts = self.driver.get_dhcp_hosts(None, networks[0]) actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[0])
self.assertEquals(actual_hosts, expected) self.assertEquals(actual_hosts, expected)
def test_get_dhcp_opts_for_nw00(self): def test_get_dhcp_opts_for_nw00(self):
def get_instance(_context, instance_id):
return instances[instance_id]
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
@@ -337,11 +367,16 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
expected_opts = 'NW-i00000001-0,3' expected_opts = 'NW-i00000001-0,3'
actual_opts = self.driver.get_dhcp_opts(None, networks[0]) actual_opts = self.driver.get_dhcp_opts(self.context, networks[0])
self.assertEquals(actual_opts, expected_opts) self.assertEquals(actual_opts, expected_opts)
def test_get_dhcp_opts_for_nw01(self): def test_get_dhcp_opts_for_nw01(self):
def get_instance(_context, instance_id):
print instance_id
return instances[instance_id]
self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
@@ -363,18 +398,20 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
expected_opts = "NW-i00000000-1,3" expected_opts = "NW-i00000000-1,3"
actual_opts = self.driver.get_dhcp_opts(None, networks[1]) actual_opts = self.driver.get_dhcp_opts(self.context, networks[1])
self.assertEquals(actual_opts, expected_opts) self.assertEquals(actual_opts, expected_opts)
def test_dhcp_opts_not_default_gateway_network(self): def test_dhcp_opts_not_default_gateway_network(self):
expected = "NW-i00000000-0,3" expected = "NW-i00000000-0,3"
actual = self.driver._host_dhcp_opts(fixed_ips[0]) actual = self.driver._host_dhcp_opts(fixed_ips[0], instances[0])
self.assertEquals(actual, expected) self.assertEquals(actual, expected)
def test_host_dhcp_without_default_gateway_network(self): def test_host_dhcp_without_default_gateway_network(self):
expected = ("10.0.0.1,fake_instance00.novalocal,192.168.0.100") expected = ','.join(['DE:AD:BE:EF:00:00',
actual = self.driver._host_dhcp(fixed_ips[0]) 'fake_instance00.novalocal',
'192.168.0.100'])
actual = self.driver._host_dhcp(fixed_ips[0], vifs[0], instances[0])
self.assertEquals(actual, expected) self.assertEquals(actual, expected)
def test_linux_bridge_driver_plug(self): def test_linux_bridge_driver_plug(self):

View File

@@ -35,15 +35,6 @@ LOG = logging.getLogger('nova.tests.network')
HOST = "testhost" HOST = "testhost"
class FakeModel(dict):
"""Represent a model from the db"""
def __init__(self, *args, **kwargs):
self.update(kwargs)
def __getattr__(self, name):
return self[name]
networks = [{'id': 0, networks = [{'id': 0,
'uuid': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", 'uuid': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
'label': 'test0', 'label': 'test0',
@@ -85,7 +76,6 @@ networks = [{'id': 0,
'project_id': 'fake_project', 'project_id': 'fake_project',
'vpn_public_address': '192.168.1.2'}] 'vpn_public_address': '192.168.1.2'}]
fixed_ips = [{'id': 0, fixed_ips = [{'id': 0,
'network_id': 0, 'network_id': 0,
'address': '192.168.0.100', 'address': '192.168.0.100',
@@ -118,19 +108,16 @@ vifs = [{'id': 0,
'address': 'DE:AD:BE:EF:00:00', 'address': 'DE:AD:BE:EF:00:00',
'uuid': '00000000-0000-0000-0000-0000000000000000', 'uuid': '00000000-0000-0000-0000-0000000000000000',
'network_id': 0, 'network_id': 0,
'network': FakeModel(**networks[0]),
'instance_id': 0}, 'instance_id': 0},
{'id': 1, {'id': 1,
'address': 'DE:AD:BE:EF:00:01', 'address': 'DE:AD:BE:EF:00:01',
'uuid': '00000000-0000-0000-0000-0000000000000001', 'uuid': '00000000-0000-0000-0000-0000000000000001',
'network_id': 1, 'network_id': 1,
'network': FakeModel(**networks[1]),
'instance_id': 0}, 'instance_id': 0},
{'id': 2, {'id': 2,
'address': 'DE:AD:BE:EF:00:02', 'address': 'DE:AD:BE:EF:00:02',
'uuid': '00000000-0000-0000-0000-0000000000000002', 'uuid': '00000000-0000-0000-0000-0000000000000002',
'network_id': 2, 'network_id': 2,
'network': None,
'instance_id': 0}] 'instance_id': 0}]
@@ -196,6 +183,7 @@ class FlatNetworkTestCase(test.TestCase):
self.assertDictListMatch(info['ips'], check) self.assertDictListMatch(info['ips'], check)
def test_validate_networks(self): def test_validate_networks(self):
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_get_all_by_uuids') self.mox.StubOutWithMock(db, 'network_get_all_by_uuids')
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address") self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
@@ -203,11 +191,13 @@ class FlatNetworkTestCase(test.TestCase):
"192.168.1.100")] "192.168.1.100")]
db.network_get_all_by_uuids(mox.IgnoreArg(), db.network_get_all_by_uuids(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks) mox.IgnoreArg()).AndReturn(networks)
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks[1])
fixed_ips[1]['network'] = FakeModel(**networks[1]) ip = fixed_ips[1].copy()
fixed_ips[1]['instance'] = None ip['instance_id'] = None
db.fixed_ip_get_by_address(mox.IgnoreArg(), db.fixed_ip_get_by_address(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(fixed_ips[1]) mox.IgnoreArg()).AndReturn(ip)
self.mox.ReplayAll() self.mox.ReplayAll()
self.network.validate_networks(self.context, requested_networks) self.network.validate_networks(self.context, requested_networks)
@@ -448,6 +438,10 @@ class VlanNetworkTestCase(test.TestCase):
cidr='192.168.0.1/24', network_size=100) cidr='192.168.0.1/24', network_size=100)
def test_validate_networks(self): def test_validate_networks(self):
def network_get(_context, network_id):
return networks[network_id]
self.stubs.Set(db, 'network_get', network_get)
self.mox.StubOutWithMock(db, 'network_get_all_by_uuids') self.mox.StubOutWithMock(db, 'network_get_all_by_uuids')
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address") self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
@@ -457,8 +451,8 @@ class VlanNetworkTestCase(test.TestCase):
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks) mox.IgnoreArg()).AndReturn(networks)
fixed_ips[1]['network'] = FakeModel(**networks[1]) fixed_ips[1]['network_id'] = networks[1]['id']
fixed_ips[1]['instance'] = None fixed_ips[1]['instance_id'] = None
db.fixed_ip_get_by_address(mox.IgnoreArg(), db.fixed_ip_get_by_address(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(fixed_ips[1]) mox.IgnoreArg()).AndReturn(fixed_ips[1])
@@ -613,14 +607,20 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1', return {'address': '10.0.0.1',
'pool': 'nova', 'pool': 'nova',
'interface': 'eth0', 'interface': 'eth0',
'network': {'multi_host': False, 'host': 'jibberjabber'}} 'network_id': 'blah'}
def fake4_network(*args, **kwargs):
return {'multi_host': False, 'host': 'jibberjabber'}
# fixed ip with local host # fixed ip with local host
def fake5(*args, **kwargs): def fake5(*args, **kwargs):
return {'address': '10.0.0.1', return {'address': '10.0.0.1',
'pool': 'nova', 'pool': 'nova',
'interface': 'eth0', 'interface': 'eth0',
'network': {'multi_host': False, 'host': 'testhost'}} 'network_id': 'blahblah'}
def fake5_network(*args, **kwargs):
return {'multi_host': False, 'host': 'testhost'}
def fake6(*args, **kwargs): def fake6(*args, **kwargs):
self.local = False self.local = False
@@ -643,6 +643,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call remotely # does not raise and makes call remotely
self.local = True self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake4) self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake4)
self.stubs.Set(self.network.db, 'network_get', fake4_network)
self.stubs.Set(rpc, 'cast', fake6) self.stubs.Set(rpc, 'cast', fake6)
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(), self.network.associate_floating_ip(ctxt, mox.IgnoreArg(),
mox.IgnoreArg()) mox.IgnoreArg())
@@ -651,6 +652,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call locally # does not raise and makes call locally
self.local = False self.local = False
self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake5) self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake5)
self.stubs.Set(self.network.db, 'network_get', fake5_network)
self.stubs.Set(self.network, '_associate_floating_ip', fake7) self.stubs.Set(self.network, '_associate_floating_ip', fake7)
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(), self.network.associate_floating_ip(ctxt, mox.IgnoreArg(),
mox.IgnoreArg()) mox.IgnoreArg())
@@ -682,14 +684,21 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1', return {'address': '10.0.0.1',
'pool': 'nova', 'pool': 'nova',
'interface': 'eth0', 'interface': 'eth0',
'network': {'multi_host': False, 'host': 'jibberjabber'}} 'network_id': 'blah'}
def fake4_network(*args, **kwargs):
return {'multi_host': False,
'host': 'jibberjabber'}
# fixed ip with local host # fixed ip with local host
def fake5(*args, **kwargs): def fake5(*args, **kwargs):
return {'address': '10.0.0.1', return {'address': '10.0.0.1',
'pool': 'nova', 'pool': 'nova',
'interface': 'eth0', 'interface': 'eth0',
'network': {'multi_host': False, 'host': 'testhost'}} 'network_id': 'blahblah'}
def fake5_network(*args, **kwargs):
return {'multi_host': False, 'host': 'testhost'}
def fake6(*args, **kwargs): def fake6(*args, **kwargs):
self.local = False self.local = False
@@ -711,6 +720,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call remotely # does not raise and makes call remotely
self.local = True self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get', fake4) self.stubs.Set(self.network.db, 'fixed_ip_get', fake4)
self.stubs.Set(self.network.db, 'network_get', fake4_network)
self.stubs.Set(rpc, 'cast', fake6) self.stubs.Set(rpc, 'cast', fake6)
self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg()) self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg())
self.assertFalse(self.local) self.assertFalse(self.local)
@@ -718,6 +728,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call locally # does not raise and makes call locally
self.local = False self.local = False
self.stubs.Set(self.network.db, 'fixed_ip_get', fake5) self.stubs.Set(self.network.db, 'fixed_ip_get', fake5)
self.stubs.Set(self.network.db, 'network_get', fake5_network)
self.stubs.Set(self.network, '_disassociate_floating_ip', fake7) self.stubs.Set(self.network, '_disassociate_floating_ip', fake7)
self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg()) self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg())
self.assertTrue(self.local) self.assertTrue(self.local)
@@ -752,6 +763,11 @@ class VlanNetworkTestCase(test.TestCase):
"""Makes sure that we cannot deallocaate or disassociate """Makes sure that we cannot deallocaate or disassociate
a public ip of other project""" a public ip of other project"""
def network_get(_context, network_id):
return networks[network_id]
self.stubs.Set(db, 'network_get', network_get)
context1 = context.RequestContext('user', 'project1') context1 = context.RequestContext('user', 'project1')
context2 = context.RequestContext('user', 'project2') context2 = context.RequestContext('user', 'project2')
@@ -789,6 +805,7 @@ class VlanNetworkTestCase(test.TestCase):
float_addr) float_addr)
# Clean up the ip addresses # Clean up the ip addresses
self.network.disassociate_floating_ip(context1, float_addr)
self.network.deallocate_floating_ip(context1, float_addr) self.network.deallocate_floating_ip(context1, float_addr)
self.network.deallocate_fixed_ip(context1, fix_addr) self.network.deallocate_fixed_ip(context1, fix_addr)
db.floating_ip_destroy(context1.elevated(), float_addr) db.floating_ip_destroy(context1.elevated(), float_addr)

View File

@@ -1411,14 +1411,19 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase):
instance_ref = db.instance_get(admin_ctxt, instance_ref['id']) instance_ref = db.instance_get(admin_ctxt, instance_ref['id'])
src_instance_ref = db.instance_get(admin_ctxt, src_instance_ref['id']) src_instance_ref = db.instance_get(admin_ctxt, src_instance_ref['id'])
network_info = fake_network.fake_get_instance_nw_info(self.stubs, 1)
def get_fixed_ips(*args, **kwargs): def get_fixed_ips(*args, **kwargs):
ips = [] ips = []
for _n, info in network_info: for _n, info in network_info:
ips.extend(info['ips']) ips.extend(info['ips'])
return [ip['ip'] for ip in ips] return [ip['ip'] for ip in ips]
network_info = fake_network.fake_get_instance_nw_info(self.stubs, 1) def nw_info(*args, **kwargs):
self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips) return network_info
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
nw_info)
self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info)

View File

@@ -96,10 +96,6 @@ def stub_out_db_instance_api(stubs):
"""Stubs out the db.instance_action_create method.""" """Stubs out the db.instance_action_create method."""
pass pass
def fake_instance_get_fixed_addresses(context, instance_id):
"""Stubs out the db.instance_get_fixed_address method."""
return '10.10.10.10'
def fake_instance_type_get_all(context, inactive=0, filters=None): def fake_instance_type_get_all(context, inactive=0, filters=None):
return INSTANCE_TYPES.values() return INSTANCE_TYPES.values()
@@ -109,7 +105,5 @@ def stub_out_db_instance_api(stubs):
stubs.Set(db, 'instance_create', fake_instance_create) stubs.Set(db, 'instance_create', fake_instance_create)
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance) stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
stubs.Set(db, 'instance_action_create', fake_instance_action_create) stubs.Set(db, 'instance_action_create', fake_instance_action_create)
stubs.Set(db, 'instance_get_fixed_addresses',
fake_instance_get_fixed_addresses)
stubs.Set(db, 'instance_type_get_all', fake_instance_type_get_all) stubs.Set(db, 'instance_type_get_all', fake_instance_type_get_all)
stubs.Set(db, 'instance_type_get_by_name', fake_instance_type_get_by_name) stubs.Set(db, 'instance_type_get_by_name', fake_instance_type_get_by_name)