merge trunk

This commit is contained in:
Jason Koelker
2011-07-27 17:02:49 -05:00
6 changed files with 130 additions and 189 deletions

View File

@@ -583,8 +583,9 @@ class ComputeTestCase(test.TestCase):
the same host""" the same host"""
instance_id = self._create_instance() instance_id = self._create_instance()
self.compute.run_instance(self.context, instance_id) self.compute.run_instance(self.context, instance_id)
inst_ref = db.instance_get(self.context, instance_id)
self.assertRaises(exception.Error, self.compute.prep_resize, self.assertRaises(exception.Error, self.compute.prep_resize,
self.context, instance_id, 1) self.context, inst_ref['uuid'], 1)
self.compute.terminate_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id)
def test_migrate(self): def test_migrate(self):

View File

@@ -88,7 +88,7 @@ def _setup_networking(instance_id, ip='1.2.3.4'):
'virtual_interface_id': vif_ref['id']} 'virtual_interface_id': vif_ref['id']}
db.fixed_ip_create(ctxt, fixed_ip) db.fixed_ip_create(ctxt, fixed_ip)
db.fixed_ip_update(ctxt, ip, {'allocated': True, db.fixed_ip_update(ctxt, ip, {'allocated': True,
'instance_id': instance_id}) 'instance_id': instance_id})
class CacheConcurrencyTestCase(test.TestCase): class CacheConcurrencyTestCase(test.TestCase):
@@ -177,13 +177,13 @@ class LibvirtConnTestCase(test.TestCase):
self.context = context.get_admin_context() self.context = context.get_admin_context()
FLAGS.instances_path = '' FLAGS.instances_path = ''
self.call_libvirt_dependant_setup = False self.call_libvirt_dependant_setup = False
self.test_ip = '10.11.12.13'
def tearDown(self): def tearDown(self):
self.manager.delete_project(self.project) self.manager.delete_project(self.project)
self.manager.delete_user(self.user) self.manager.delete_user(self.user)
super(LibvirtConnTestCase, self).tearDown() super(LibvirtConnTestCase, self).tearDown()
test_ip = '10.11.12.13'
test_instance = {'memory_kb': '1024000', test_instance = {'memory_kb': '1024000',
'basepath': '/some/path', 'basepath': '/some/path',
'bridge_name': 'br100', 'bridge_name': 'br100',
@@ -232,6 +232,16 @@ class LibvirtConnTestCase(test.TestCase):
def setattr(self, key, val): def setattr(self, key, val):
self.__setattr__(key, val) self.__setattr__(key, val)
def plug(self, instance, network, mapping):
return {
'id': 'fake',
'bridge_name': 'fake',
'mac_address': 'fake',
'ip_address': 'fake',
'dhcp_server': 'fake',
'extra_params': 'fake'
}
# Creating mocks # Creating mocks
fake = FakeLibvirtConnection() fake = FakeLibvirtConnection()
fakeip = FakeIptablesFirewallDriver fakeip = FakeIptablesFirewallDriver
@@ -280,7 +290,6 @@ class LibvirtConnTestCase(test.TestCase):
return db.service_create(context.get_admin_context(), service_ref) return db.service_create(context.get_admin_context(), service_ref)
@test.skip_test("Please review this test to ensure intent")
def test_preparing_xml_info(self): def test_preparing_xml_info(self):
conn = connection.LibvirtConnection(True) conn = connection.LibvirtConnection(True)
instance_ref = db.instance_create(self.context, self.test_instance) instance_ref = db.instance_create(self.context, self.test_instance)
@@ -296,27 +305,23 @@ class LibvirtConnTestCase(test.TestCase):
_create_network_info(2)) _create_network_info(2))
self.assertTrue(len(result['nics']) == 2) self.assertTrue(len(result['nics']) == 2)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_xml_and_uri_no_ramdisk_no_kernel(self): def test_xml_and_uri_no_ramdisk_no_kernel(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
self._check_xml_and_uri(instance_data, self._check_xml_and_uri(instance_data,
expect_kernel=False, expect_ramdisk=False) expect_kernel=False, expect_ramdisk=False)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_xml_and_uri_no_ramdisk(self): def test_xml_and_uri_no_ramdisk(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
instance_data['kernel_id'] = 'aki-deadbeef' instance_data['kernel_id'] = 'aki-deadbeef'
self._check_xml_and_uri(instance_data, self._check_xml_and_uri(instance_data,
expect_kernel=True, expect_ramdisk=False) expect_kernel=True, expect_ramdisk=False)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_xml_and_uri_no_kernel(self): def test_xml_and_uri_no_kernel(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
instance_data['ramdisk_id'] = 'ari-deadbeef' instance_data['ramdisk_id'] = 'ari-deadbeef'
self._check_xml_and_uri(instance_data, self._check_xml_and_uri(instance_data,
expect_kernel=False, expect_ramdisk=False) expect_kernel=False, expect_ramdisk=False)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_xml_and_uri(self): def test_xml_and_uri(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
instance_data['ramdisk_id'] = 'ari-deadbeef' instance_data['ramdisk_id'] = 'ari-deadbeef'
@@ -324,7 +329,6 @@ class LibvirtConnTestCase(test.TestCase):
self._check_xml_and_uri(instance_data, self._check_xml_and_uri(instance_data,
expect_kernel=True, expect_ramdisk=True) expect_kernel=True, expect_ramdisk=True)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_xml_and_uri_rescue(self): def test_xml_and_uri_rescue(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
instance_data['ramdisk_id'] = 'ari-deadbeef' instance_data['ramdisk_id'] = 'ari-deadbeef'
@@ -332,7 +336,6 @@ class LibvirtConnTestCase(test.TestCase):
self._check_xml_and_uri(instance_data, expect_kernel=True, self._check_xml_and_uri(instance_data, expect_kernel=True,
expect_ramdisk=True, rescue=True) expect_ramdisk=True, rescue=True)
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_lxc_container_and_uri(self): def test_lxc_container_and_uri(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
self._check_xml_and_container(instance_data) self._check_xml_and_container(instance_data)
@@ -412,6 +415,15 @@ class LibvirtConnTestCase(test.TestCase):
self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['status'], 'active')
self.assertEquals(snapshot['name'], snapshot_name) self.assertEquals(snapshot['name'], snapshot_name)
def test_attach_invalid_device(self):
self.create_fake_libvirt_mock()
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
self.mox.ReplayAll()
conn = connection.LibvirtConnection(False)
self.assertRaises(exception.InvalidDevicePath,
conn.attach_volume,
"fake", "bad/device/path", "/dev/fake")
def test_multi_nic(self): def test_multi_nic(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
network_info = _create_network_info(2) network_info = _create_network_info(2)
@@ -432,24 +444,7 @@ class LibvirtConnTestCase(test.TestCase):
user_context = context.RequestContext(project=self.project, user_context = context.RequestContext(project=self.project,
user=self.user) user=self.user)
instance_ref = db.instance_create(user_context, instance) instance_ref = db.instance_create(user_context, instance)
# Re-get the instance so it's bound to an actual session _setup_networking(instance_ref['id'], self.test_ip)
instance_ref = db.instance_get(user_context, instance_ref['id'])
network_ref = db.project_get_networks(context.get_admin_context(),
self.project.id)[0]
vif = {'address': '56:12:12:12:12:12',
'network_id': network_ref['id'],
'instance_id': instance_ref['id']}
vif_ref = db.virtual_interface_create(self.context, vif)
fixed_ip = {'address': self.test_ip,
'network_id': network_ref['id'],
'virtual_interface_id': vif_ref['id']}
ctxt = context.get_admin_context()
fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip)
db.fixed_ip_update(ctxt, self.test_ip,
{'allocated': True,
'instance_id': instance_ref['id']})
self.flags(libvirt_type='lxc') self.flags(libvirt_type='lxc')
conn = connection.LibvirtConnection(True) conn = connection.LibvirtConnection(True)
@@ -481,7 +476,7 @@ class LibvirtConnTestCase(test.TestCase):
network_ref = db.project_get_networks(context.get_admin_context(), network_ref = db.project_get_networks(context.get_admin_context(),
self.project.id)[0] self.project.id)[0]
_setup_networking(instance_ref['id'], ip=self.test_ip) _setup_networking(instance_ref['id'], self.test_ip)
type_uri_map = {'qemu': ('qemu:///system', type_uri_map = {'qemu': ('qemu:///system',
[(lambda t: t.find('.').get('type'), 'qemu'), [(lambda t: t.find('.').get('type'), 'qemu'),
@@ -743,7 +738,6 @@ class LibvirtConnTestCase(test.TestCase):
db.volume_destroy(self.context, volume_ref['id']) db.volume_destroy(self.context, volume_ref['id'])
db.instance_destroy(self.context, instance_ref['id']) db.instance_destroy(self.context, instance_ref['id'])
@test.skip_test("test needs rewrite: instance no longer has mac_address")
def test_spawn_with_network_info(self): def test_spawn_with_network_info(self):
# Skip if non-libvirt environment # Skip if non-libvirt environment
if not self.lazy_load_library_exists(): if not self.lazy_load_library_exists():
@@ -762,17 +756,7 @@ class LibvirtConnTestCase(test.TestCase):
conn.firewall_driver.setattr('setup_basic_filtering', fake_none) conn.firewall_driver.setattr('setup_basic_filtering', fake_none)
conn.firewall_driver.setattr('prepare_instance_filter', fake_none) conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
network = db.project_get_networks(context.get_admin_context(), network_info = _create_network_info()
self.project.id)[0]
ip_dict = {'ip': self.test_ip,
'netmask': network['netmask'],
'enabled': '1'}
mapping = {'label': network['label'],
'gateway': network['gateway'],
'mac': instance['mac_address'],
'dns': [network['dns']],
'ips': [ip_dict]}
network_info = [(network, mapping)]
try: try:
conn.spawn(instance, network_info) conn.spawn(instance, network_info)
@@ -830,6 +814,7 @@ class IptablesFirewallTestCase(test.TestCase):
"""setup_basic_rules in nwfilter calls this.""" """setup_basic_rules in nwfilter calls this."""
pass pass
self.fake_libvirt_connection = FakeLibvirtConnection() self.fake_libvirt_connection = FakeLibvirtConnection()
self.test_ip = '10.11.12.13'
self.fw = firewall.IptablesFirewallDriver( self.fw = firewall.IptablesFirewallDriver(
get_connection=lambda: self.fake_libvirt_connection) get_connection=lambda: self.fake_libvirt_connection)
@@ -895,27 +880,11 @@ class IptablesFirewallTestCase(test.TestCase):
'project_id': 'fake', 'project_id': 'fake',
'instance_type_id': 1}) 'instance_type_id': 1})
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
def test_static_filters(self): def test_static_filters(self):
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
ip = '10.11.12.13' _setup_networking(instance_ref['id'], self.test_ip)
network_ref = db.project_get_networks(self.context,
'fake',
associate=True)[0]
vif = {'address': '56:12:12:12:12:12',
'network_id': network_ref['id'],
'instance_id': instance_ref['id']}
vif_ref = db.virtual_interface_create(self.context, vif)
fixed_ip = {'address': ip,
'network_id': network_ref['id'],
'virtual_interface_id': vif_ref['id']}
admin_ctxt = context.get_admin_context() admin_ctxt = context.get_admin_context()
db.fixed_ip_create(admin_ctxt, fixed_ip)
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
'instance_id': instance_ref['id']})
secgroup = db.security_group_create(admin_ctxt, secgroup = db.security_group_create(admin_ctxt,
{'user_id': 'fake', {'user_id': 'fake',
'project_id': 'fake', 'project_id': 'fake',
@@ -1047,7 +1016,6 @@ class IptablesFirewallTestCase(test.TestCase):
self.assertEquals(ipv6_network_rules, self.assertEquals(ipv6_network_rules,
ipv6_rules_per_network * networks_count) ipv6_rules_per_network * networks_count)
@test.skip_test("skipping libvirt tests")
def test_do_refresh_security_group_rules(self): def test_do_refresh_security_group_rules(self):
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
self.mox.StubOutWithMock(self.fw, self.mox.StubOutWithMock(self.fw,
@@ -1058,7 +1026,6 @@ class IptablesFirewallTestCase(test.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
self.fw.do_refresh_security_group_rules("fake") self.fw.do_refresh_security_group_rules("fake")
@test.skip_test("skip libvirt test project_get_network no longer exists")
def test_unfilter_instance_undefines_nwfilter(self): def test_unfilter_instance_undefines_nwfilter(self):
# Skip if non-libvirt environment # Skip if non-libvirt environment
if not self.lazy_load_library_exists(): if not self.lazy_load_library_exists():
@@ -1072,38 +1039,24 @@ class IptablesFirewallTestCase(test.TestCase):
self.fw.nwfilter._conn.nwfilterLookupByName =\ self.fw.nwfilter._conn.nwfilterLookupByName =\
fakefilter.nwfilterLookupByName fakefilter.nwfilterLookupByName
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
inst_id = instance_ref['id']
instance = db.instance_get(self.context, inst_id)
ip = '10.11.12.13' _setup_networking(instance_ref['id'], self.test_ip)
network_ref = db.project_get_network(self.context, 'fake') self.fw.setup_basic_filtering(instance_ref)
fixed_ip = {'address': ip, 'network_id': network_ref['id']} self.fw.prepare_instance_filter(instance_ref)
db.fixed_ip_create(admin_ctxt, fixed_ip) self.fw.apply_instance_filter(instance_ref)
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
'instance_id': inst_id})
self.fw.setup_basic_filtering(instance)
self.fw.prepare_instance_filter(instance)
self.fw.apply_instance_filter(instance)
original_filter_count = len(fakefilter.filters) original_filter_count = len(fakefilter.filters)
self.fw.unfilter_instance(instance) self.fw.unfilter_instance(instance_ref)
# should undefine just the instance filter # should undefine just the instance filter
self.assertEqual(original_filter_count - len(fakefilter.filters), 1) self.assertEqual(original_filter_count - len(fakefilter.filters), 1)
db.instance_destroy(admin_ctxt, instance_ref['id']) db.instance_destroy(admin_ctxt, instance_ref['id'])
@test.skip_test("skip libvirt test project_get_network no longer exists")
def test_provider_firewall_rules(self): def test_provider_firewall_rules(self):
# setup basic instance data # setup basic instance data
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
nw_info = _create_network_info(1) nw_info = _create_network_info(1)
ip = '10.11.12.13' _setup_networking(instance_ref['id'], self.test_ip)
network_ref = db.project_get_network(self.context, 'fake')
admin_ctxt = context.get_admin_context()
fixed_ip = {'address': ip, 'network_id': network_ref['id']}
db.fixed_ip_create(admin_ctxt, fixed_ip)
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
'instance_id': instance_ref['id']})
# FRAGILE: peeks at how the firewall names chains # FRAGILE: peeks at how the firewall names chains
chain_name = 'inst-%s' % instance_ref['id'] chain_name = 'inst-%s' % instance_ref['id']
@@ -1115,6 +1068,7 @@ class IptablesFirewallTestCase(test.TestCase):
if rule.chain == 'provider'] if rule.chain == 'provider']
self.assertEqual(0, len(rules)) self.assertEqual(0, len(rules))
admin_ctxt = context.get_admin_context()
# add a rule and send the update message, check for 1 rule # add a rule and send the update message, check for 1 rule
provider_fw0 = db.provider_fw_rule_create(admin_ctxt, provider_fw0 = db.provider_fw_rule_create(admin_ctxt,
{'protocol': 'tcp', {'protocol': 'tcp',
@@ -1173,6 +1127,7 @@ class NWFilterTestCase(test.TestCase):
self.fake_libvirt_connection = Mock() self.fake_libvirt_connection = Mock()
self.test_ip = '10.11.12.13'
self.fw = firewall.NWFilterFirewall( self.fw = firewall.NWFilterFirewall(
lambda: self.fake_libvirt_connection) lambda: self.fake_libvirt_connection)
@@ -1259,7 +1214,6 @@ class NWFilterTestCase(test.TestCase):
inst.update(params) inst.update(params)
return db.instance_type_create(context, inst)['id'] return db.instance_type_create(context, inst)['id']
@test.skip_test('Skipping this test')
def test_creates_base_rule_first(self): def test_creates_base_rule_first(self):
# These come pre-defined by libvirt # These come pre-defined by libvirt
self.defined_filters = ['no-mac-spoofing', self.defined_filters = ['no-mac-spoofing',
@@ -1291,21 +1245,11 @@ class NWFilterTestCase(test.TestCase):
instance_ref = self._create_instance() instance_ref = self._create_instance()
inst_id = instance_ref['id'] inst_id = instance_ref['id']
ip = '10.11.12.13' _setup_networking(instance_ref['id'], self.test_ip)
#network_ref = db.project_get_networks(self.context, 'fake')[0]
#fixed_ip = {'address': ip, 'network_id': network_ref['id']}
#admin_ctxt = context.get_admin_context()
#db.fixed_ip_create(admin_ctxt, fixed_ip)
#db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
# 'instance_id': inst_id})
self._setup_networking(instance_ref['id'], ip=ip)
def _ensure_all_called(): def _ensure_all_called():
instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'], instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
'00A0C914C829') '561212121212')
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id'] secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']
for required in [secgroup_filter, 'allow-dhcp-server', for required in [secgroup_filter, 'allow-dhcp-server',
'no-arp-spoofing', 'no-ip-spoofing', 'no-arp-spoofing', 'no-ip-spoofing',
@@ -1326,7 +1270,7 @@ class NWFilterTestCase(test.TestCase):
self.fw.apply_instance_filter(instance) self.fw.apply_instance_filter(instance)
_ensure_all_called() _ensure_all_called()
self.teardown_security_group() self.teardown_security_group()
db.instance_destroy(admin_ctxt, instance_ref['id']) db.instance_destroy(context.get_admin_context(), instance_ref['id'])
def test_create_network_filters(self): def test_create_network_filters(self):
instance_ref = self._create_instance() instance_ref = self._create_instance()
@@ -1336,7 +1280,6 @@ class NWFilterTestCase(test.TestCase):
"fake") "fake")
self.assertEquals(len(result), 3) self.assertEquals(len(result), 3)
@test.skip_test("skip libvirt test project_get_network no longer exists")
def test_unfilter_instance_undefines_nwfilters(self): def test_unfilter_instance_undefines_nwfilters(self):
admin_ctxt = context.get_admin_context() admin_ctxt = context.get_admin_context()
@@ -1354,12 +1297,7 @@ class NWFilterTestCase(test.TestCase):
instance = db.instance_get(self.context, inst_id) instance = db.instance_get(self.context, inst_id)
ip = '10.11.12.13' _setup_networking(instance_ref['id'], self.test_ip)
network_ref = db.project_get_network(self.context, 'fake')
fixed_ip = {'address': ip, 'network_id': network_ref['id']}
db.fixed_ip_create(admin_ctxt, fixed_ip)
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
'instance_id': inst_id})
self.fw.setup_basic_filtering(instance) self.fw.setup_basic_filtering(instance)
self.fw.prepare_instance_filter(instance) self.fw.prepare_instance_filter(instance)
self.fw.apply_instance_filter(instance) self.fw.apply_instance_filter(instance)

View File

@@ -19,9 +19,6 @@
Test suite for VMWareAPI. Test suite for VMWareAPI.
""" """
import stubout
from nova import context
from nova import db from nova import db
from nova import flags from nova import flags
from nova import test from nova import test
@@ -41,51 +38,66 @@ FLAGS = flags.FLAGS
class VMWareAPIVMTestCase(test.TestCase): class VMWareAPIVMTestCase(test.TestCase):
"""Unit tests for Vmware API connection calls.""" """Unit tests for Vmware API connection calls."""
# NOTE(jkoelker): This is leaking stubs into the db module. def setUp(self):
# Commenting out until updated for multi-nic. super(VMWareAPIVMTestCase, self).setUp()
#def setUp(self): self.flags(vmwareapi_host_ip='test_url',
# super(VMWareAPIVMTestCase, self).setUp() vmwareapi_host_username='test_username',
# self.flags(vmwareapi_host_ip='test_url', vmwareapi_host_password='test_pass')
# vmwareapi_host_username='test_username', self.manager = manager.AuthManager()
# vmwareapi_host_password='test_pass') self.user = self.manager.create_user('fake', 'fake', 'fake',
# self.manager = manager.AuthManager() admin=True)
# self.user = self.manager.create_user('fake', 'fake', 'fake', self.project = self.manager.create_project('fake', 'fake', 'fake')
# admin=True) self.network = utils.import_object(FLAGS.network_manager)
# self.project = self.manager.create_project('fake', 'fake', 'fake') vmwareapi_fake.reset()
# self.network = utils.import_object(FLAGS.network_manager) db_fakes.stub_out_db_instance_api(self.stubs)
# self.stubs = stubout.StubOutForTesting() stubs.set_stubs(self.stubs)
# vmwareapi_fake.reset() glance_stubs.stubout_glance_client(self.stubs)
# db_fakes.stub_out_db_instance_api(self.stubs) self.conn = vmwareapi_conn.get_connection(False)
# stubs.set_stubs(self.stubs) # NOTE(vish): none of the network plugging code is actually
# glance_stubs.stubout_glance_client(self.stubs, # being tested
# glance_stubs.FakeGlance) self.network_info = [({'bridge': 'fa0',
# self.conn = vmwareapi_conn.get_connection(False) 'id': 0,
'vlan': None,
'bridge_interface': None,
'injected': True},
{'broadcast': '192.168.0.255',
'dns': ['192.168.0.1'],
'gateway': '192.168.0.1',
'gateway6': 'dead:beef::1',
'ip6s': [{'enabled': '1',
'ip': 'dead:beef::dcad:beff:feef:0',
'netmask': '64'}],
'ips': [{'enabled': '1',
'ip': '192.168.0.100',
'netmask': '255.255.255.0'}],
'label': 'fake',
'mac': 'DE:AD:BE:EF:00:00',
'rxtx_cap': 3})]
#def tearDown(self): def tearDown(self):
# super(VMWareAPIVMTestCase, self).tearDown() super(VMWareAPIVMTestCase, self).tearDown()
# vmwareapi_fake.cleanup() vmwareapi_fake.cleanup()
# self.manager.delete_project(self.project) self.manager.delete_project(self.project)
# self.manager.delete_user(self.user) self.manager.delete_user(self.user)
# self.stubs.UnsetAll()
def _create_instance_in_the_db(self): def _create_instance_in_the_db(self):
values = {'name': 1, values = {'name': 1,
'id': 1, 'id': 1,
'project_id': self.project.id, 'project_id': self.project.id,
'user_id': self.user.id, 'user_id': self.user.id,
'image_id': "1", 'image_ref': "1",
'kernel_id': "1", 'kernel_id': "1",
'ramdisk_id': "1", 'ramdisk_id': "1",
'mac_address': "de:ad:be:ef:be:ef",
'instance_type': 'm1.large', 'instance_type': 'm1.large',
'mac_address': 'aa:bb:cc:dd:ee:ff',
} }
self.instance = db.instance_create(values) self.instance = db.instance_create(None, values)
def _create_vm(self): def _create_vm(self):
"""Create and spawn the VM.""" """Create and spawn the VM."""
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.type_data = db.instance_type_get_by_name(None, 'm1.large') self.type_data = db.instance_type_get_by_name(None, 'm1.large')
self.conn.spawn(self.instance) self.conn.spawn(self.instance, self.network_info)
self._check_vm_record() self._check_vm_record()
def _check_vm_record(self): def _check_vm_record(self):
@@ -129,24 +141,20 @@ class VMWareAPIVMTestCase(test.TestCase):
self.assertEquals(info["mem"], mem_kib) self.assertEquals(info["mem"], mem_kib)
self.assertEquals(info["num_cpu"], self.type_data['vcpus']) self.assertEquals(info["num_cpu"], self.type_data['vcpus'])
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_list_instances(self): def test_list_instances(self):
instances = self.conn.list_instances() instances = self.conn.list_instances()
self.assertEquals(len(instances), 0) self.assertEquals(len(instances), 0)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_list_instances_1(self): def test_list_instances_1(self):
self._create_vm() self._create_vm()
instances = self.conn.list_instances() instances = self.conn.list_instances()
self.assertEquals(len(instances), 1) self.assertEquals(len(instances), 1)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_spawn(self): def test_spawn(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_snapshot(self): def test_snapshot(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
@@ -155,27 +163,23 @@ class VMWareAPIVMTestCase(test.TestCase):
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_snapshot_non_existent(self): def test_snapshot_non_existent(self):
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.assertRaises(Exception, self.conn.snapshot, self.instance, self.assertRaises(Exception, self.conn.snapshot, self.instance,
"Test-Snapshot") "Test-Snapshot")
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_reboot(self): def test_reboot(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
self.conn.reboot(self.instance) self.conn.reboot(self.instance, self.network_info)
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_reboot_non_existent(self): def test_reboot_non_existent(self):
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.assertRaises(Exception, self.conn.reboot, self.instance) self.assertRaises(Exception, self.conn.reboot, self.instance)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_reboot_not_poweredon(self): def test_reboot_not_poweredon(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
@@ -185,7 +189,6 @@ class VMWareAPIVMTestCase(test.TestCase):
self._check_vm_info(info, power_state.PAUSED) self._check_vm_info(info, power_state.PAUSED)
self.assertRaises(Exception, self.conn.reboot, self.instance) self.assertRaises(Exception, self.conn.reboot, self.instance)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_suspend(self): def test_suspend(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
@@ -194,13 +197,11 @@ class VMWareAPIVMTestCase(test.TestCase):
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.PAUSED) self._check_vm_info(info, power_state.PAUSED)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_suspend_non_existent(self): def test_suspend_non_existent(self):
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.assertRaises(Exception, self.conn.suspend, self.instance, self.assertRaises(Exception, self.conn.suspend, self.instance,
self.dummy_callback_handler) self.dummy_callback_handler)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_resume(self): def test_resume(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
@@ -212,13 +213,11 @@ class VMWareAPIVMTestCase(test.TestCase):
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_resume_non_existent(self): def test_resume_non_existent(self):
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.assertRaises(Exception, self.conn.resume, self.instance, self.assertRaises(Exception, self.conn.resume, self.instance,
self.dummy_callback_handler) self.dummy_callback_handler)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_resume_not_suspended(self): def test_resume_not_suspended(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
@@ -226,49 +225,41 @@ class VMWareAPIVMTestCase(test.TestCase):
self.assertRaises(Exception, self.conn.resume, self.instance, self.assertRaises(Exception, self.conn.resume, self.instance,
self.dummy_callback_handler) self.dummy_callback_handler)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_get_info(self): def test_get_info(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_destroy(self): def test_destroy(self):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
instances = self.conn.list_instances() instances = self.conn.list_instances()
self.assertEquals(len(instances), 1) self.assertEquals(len(instances), 1)
self.conn.destroy(self.instance) self.conn.destroy(self.instance, self.network_info)
instances = self.conn.list_instances() instances = self.conn.list_instances()
self.assertEquals(len(instances), 0) self.assertEquals(len(instances), 0)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_destroy_non_existent(self): def test_destroy_non_existent(self):
self._create_instance_in_the_db() self._create_instance_in_the_db()
self.assertEquals(self.conn.destroy(self.instance), None) self.assertEquals(self.conn.destroy(self.instance, self.network_info),
None)
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_pause(self): def test_pause(self):
pass pass
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_unpause(self): def test_unpause(self):
pass pass
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_diagnostics(self): def test_diagnostics(self):
pass pass
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_get_console_output(self): def test_get_console_output(self):
pass pass
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def test_get_ajax_console(self): def test_get_ajax_console(self):
pass pass
@test.skip_test("DB stubbing not removed, needs updating for multi-nic")
def dummy_callback_handler(self, ret): def dummy_callback_handler(self, ret):
""" """
Dummy callback function to be passed to suspend, resume, etc., calls. Dummy callback function to be passed to suspend, resume, etc., calls.

View File

@@ -396,18 +396,22 @@ class XenAPIVMTestCase(test.TestCase):
def _test_spawn(self, image_ref, kernel_id, ramdisk_id, def _test_spawn(self, image_ref, kernel_id, ramdisk_id,
instance_type_id="3", os_type="linux", instance_type_id="3", os_type="linux",
architecture="x86-64", instance_id=1, architecture="x86-64", instance_id=1,
check_injection=False): check_injection=False,
create_record=True):
stubs.stubout_loopingcall_start(self.stubs) stubs.stubout_loopingcall_start(self.stubs)
values = {'id': instance_id, if create_record:
'project_id': self.project.id, values = {'id': instance_id,
'user_id': self.user.id, 'project_id': self.project.id,
'image_ref': image_ref, 'user_id': self.user.id,
'kernel_id': kernel_id, 'image_ref': image_ref,
'ramdisk_id': ramdisk_id, 'kernel_id': kernel_id,
'instance_type_id': instance_type_id, 'ramdisk_id': ramdisk_id,
'os_type': os_type, 'instance_type_id': instance_type_id,
'architecture': architecture} 'os_type': os_type,
instance = db.instance_create(self.context, values) 'architecture': architecture}
instance = db.instance_create(self.context, values)
else:
instance = db.instance_get(self.context, instance_id)
network_info = [({'bridge': 'fa0', 'id': 0, 'injected': True}, network_info = [({'bridge': 'fa0', 'id': 0, 'injected': True},
{'broadcast': '192.168.0.255', {'broadcast': '192.168.0.255',
'dns': ['192.168.0.1'], 'dns': ['192.168.0.1'],
@@ -599,41 +603,38 @@ class XenAPIVMTestCase(test.TestCase):
# guest agent is detected # guest agent is detected
self.assertFalse(self._tee_executed) self.assertFalse(self._tee_executed)
@test.skip_test("Never gets an address, not sure why")
def test_spawn_vlanmanager(self): def test_spawn_vlanmanager(self):
self.flags(xenapi_image_service='glance', self.flags(xenapi_image_service='glance',
network_manager='nova.network.manager.VlanManager', network_manager='nova.network.manager.VlanManager',
network_driver='nova.network.xenapi_net',
vlan_interface='fake0') vlan_interface='fake0')
def dummy(*args, **kwargs): def dummy(*args, **kwargs):
pass pass
self.stubs.Set(VMOps, 'create_vifs', dummy) self.stubs.Set(vmops.VMOps, 'create_vifs', dummy)
# Reset network table # Reset network table
xenapi_fake.reset_table('network') xenapi_fake.reset_table('network')
# Instance id = 2 will use vlan network (see db/fakes.py) # Instance id = 2 will use vlan network (see db/fakes.py)
ctxt = self.context.elevated() ctxt = self.context.elevated()
instance_ref = self._create_instance(2) instance = self._create_instance(2, False)
network_bk = self.network
# Ensure we use xenapi_net driver
self.network = utils.import_object(FLAGS.network_manager)
networks = self.network.db.network_get_all(ctxt) networks = self.network.db.network_get_all(ctxt)
for network in networks: for network in networks:
self.network.set_network_host(ctxt, network['id']) self.network.set_network_host(ctxt, network)
self.network.allocate_for_instance(ctxt, instance_id=instance_ref.id, self.network.allocate_for_instance(ctxt,
instance_type_id=1, project_id=self.project.id) instance_id=2,
self.network.setup_compute_network(ctxt, instance_ref.id) host=FLAGS.host,
vpn=None,
instance_type_id=1,
project_id=self.project.id)
self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE, self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE,
glance_stubs.FakeGlance.IMAGE_KERNEL, glance_stubs.FakeGlance.IMAGE_KERNEL,
glance_stubs.FakeGlance.IMAGE_RAMDISK, glance_stubs.FakeGlance.IMAGE_RAMDISK,
instance_id=instance_ref.id, instance_id=2,
create_record=False) create_record=False)
# TODO(salvatore-orlando): a complete test here would require # TODO(salvatore-orlando): a complete test here would require
# a check for making sure the bridge for the VM's VIF is # a check for making sure the bridge for the VM's VIF is
# consistent with bridge specified in nova db # consistent with bridge specified in nova db
self.network = network_bk
def test_spawn_with_network_qos(self): def test_spawn_with_network_qos(self):
self._create_instance() self._create_instance()
@@ -644,7 +645,7 @@ class XenAPIVMTestCase(test.TestCase):
str(3 * 1024)) str(3 * 1024))
def test_rescue(self): def test_rescue(self):
self.flags(xenapi_inject_image=False) self.flags(flat_injected=False)
instance = self._create_instance() instance = self._create_instance()
conn = xenapi_conn.get_connection(False) conn = xenapi_conn.get_connection(False)
conn.rescue(instance, None, []) conn.rescue(instance, None, [])
@@ -663,7 +664,7 @@ class XenAPIVMTestCase(test.TestCase):
self.vm = None self.vm = None
self.stubs.UnsetAll() self.stubs.UnsetAll()
def _create_instance(self, instance_id=1): def _create_instance(self, instance_id=1, spawn=True):
"""Creates and spawns a test instance.""" """Creates and spawns a test instance."""
stubs.stubout_loopingcall_start(self.stubs) stubs.stubout_loopingcall_start(self.stubs)
values = { values = {
@@ -691,7 +692,8 @@ class XenAPIVMTestCase(test.TestCase):
'label': 'fake', 'label': 'fake',
'mac': 'DE:AD:BE:EF:00:00', 'mac': 'DE:AD:BE:EF:00:00',
'rxtx_cap': 3})] 'rxtx_cap': 3})]
self.conn.spawn(instance, network_info) if spawn:
self.conn.spawn(instance, network_info)
return instance return instance

View File

@@ -70,8 +70,8 @@ def stub_out_db_instance_api(stubs):
'launch_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), 'launch_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
'instance_type': values['instance_type'], 'instance_type': values['instance_type'],
'memory_mb': type_data['memory_mb'], 'memory_mb': type_data['memory_mb'],
'mac_address': values['mac_address'],
'vcpus': type_data['vcpus'], 'vcpus': type_data['vcpus'],
'mac_addresses': [{'address': values['mac_address']}],
'local_gb': type_data['local_gb'], 'local_gb': type_data['local_gb'],
} }
return FakeModel(base_options) return FakeModel(base_options)
@@ -83,6 +83,8 @@ def stub_out_db_instance_api(stubs):
'bridge': 'vmnet0', 'bridge': 'vmnet0',
'netmask': '255.255.255.0', 'netmask': '255.255.255.0',
'gateway': '10.10.10.1', 'gateway': '10.10.10.1',
'broadcast': '10.10.10.255',
'dns1': 'fake',
'vlan': 100} 'vlan': 100}
return FakeModel(fields) return FakeModel(fields)
@@ -90,7 +92,7 @@ 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_address(context, instance_id): def fake_instance_get_fixed_addresses(context, instance_id):
"""Stubs out the db.instance_get_fixed_address method.""" """Stubs out the db.instance_get_fixed_address method."""
return '10.10.10.10' return '10.10.10.10'
@@ -103,7 +105,7 @@ 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_address', stubs.Set(db, 'instance_get_fixed_addresses',
fake_instance_get_fixed_address) 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)

View File

@@ -22,6 +22,8 @@ Stubouts for the test suite
from nova.virt import vmwareapi_conn from nova.virt import vmwareapi_conn
from nova.virt.vmwareapi import fake from nova.virt.vmwareapi import fake
from nova.virt.vmwareapi import vmware_images from nova.virt.vmwareapi import vmware_images
from nova.virt.vmwareapi import vmops
from nova.virt.vmwareapi import network_utils
def fake_get_vim_object(arg): def fake_get_vim_object(arg):
@@ -36,10 +38,15 @@ def fake_is_vim_object(arg, module):
def set_stubs(stubs): def set_stubs(stubs):
"""Set the stubs.""" """Set the stubs."""
stubs.Set(vmops.VMWareVMOps, 'plug_vifs', fake.fake_plug_vifs)
stubs.Set(network_utils, 'get_network_with_the_name',
fake.fake_get_network)
stubs.Set(vmware_images, 'fetch_image', fake.fake_fetch_image) stubs.Set(vmware_images, 'fetch_image', fake.fake_fetch_image)
stubs.Set(vmware_images, 'get_vmdk_size_and_properties', stubs.Set(vmware_images, 'get_vmdk_size_and_properties',
fake.fake_get_vmdk_size_and_properties) fake.fake_get_vmdk_size_and_properties)
stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image) stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object",
fake_get_vim_object)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object", stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object",
fake_get_vim_object) fake_get_vim_object)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object", stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object",