Updates to work with latest Nova.

Specifically, updates network_info since legacy is no longer supported, as
well as other minor updates.

Change-Id: Idf1d848594826b051d6444475faed6f9812c8ba7
This commit is contained in:
Paul Marshall 2013-10-03 15:53:08 -05:00
parent fabe341771
commit bd7b336187
7 changed files with 135 additions and 186 deletions

View File

@ -210,12 +210,6 @@ class OpenVzDriver(driver.ComputeDriver):
self.vif_driver = importutils.import_object(CONF.ovz_vif_driver)
LOG.debug(_('__init__ complete in OpenVzDriver'))
def legacy_nwinfo(self):
"""
Indicate if the driver requires the legacy network_info format.
"""
return True
def init_host(self, host=socket.gethostname()):
"""
Initialize anything that is necessary for the driver to function,
@ -370,8 +364,8 @@ class OpenVzDriver(driver.ComputeDriver):
# TODO(imsplitbit): There's probably a better way to do this
has_networking = False
try:
for network, mapping in network_info:
if mapping['ips']:
for vif in network_info:
if vif.labeled_ips():
has_networking = True
except ValueError:
has_networking = False
@ -612,28 +606,28 @@ class OpenVzDriver(driver.ComputeDriver):
# TODO(imsplitbit): send id, iface, container mac, container ip and
# gateway to _send_garp
iface_counter = -1
for network in network_info:
for vif in network_info:
network = vif['network']
v4_subnets = []
for subnet in network['subnets']:
if subnet['version'] == 4:
v4_subnets.append(subnet)
iface_counter += 1
vz_iface = "eth%d" % iface_counter
LOG.debug(_('VZ interface: %s') % vz_iface)
bridge_info = network[0]
LOG.debug(_('bridge interface: %s') %
bridge_info['bridge_interface'])
LOG.debug(_('bridge: %s') % bridge_info['bridge'])
LOG.debug(_('address block: %s') % bridge_info['cidr'])
address_info = network[1]
LOG.debug(_('network label: %s') % address_info['label'])
for address in address_info['ips']:
LOG.debug(_('Address enabled: %s') % address['enabled'])
LOG.debug(_('Address enabled type: %s') %
(type(address['enabled'])))
if address['enabled'] == u'1':
LOG.debug(_('Address: %s') % address['ip'])
network.get_meta('bridge_interface'))
LOG.debug(_('bridge: %s') % network['bridge'])
LOG.debug(_('address block: %s') % v4_subnets[0]['cidr'])
LOG.debug(_('network label: %s') % network['label'])
for v4_subnet in v4_subnets:
for ip in v4_subnet['ips']:
LOG.debug(_('Address: %s') % ip['address'])
LOG.debug(
_('Running _send_garp(%(id)s %(ip)s %(vz_iface)s)') %
{'id': instance['id'], 'ip': address['ip'],
{'id': instance['id'], 'ip': ip['address'],
'vz_iface': vz_iface})
self._send_garp(instance['id'], address['ip'], vz_iface)
self._send_garp(instance['id'], ip['address'], vz_iface)
def _send_garp(self, instance_id, ip_address, interface):
"""
@ -1179,9 +1173,9 @@ class OpenVzDriver(driver.ComputeDriver):
Plug vifs into networks and configure network devices in the
container. This is necessary to make multi-nic go.
"""
for (network, mapping) in network_info:
if mapping['ips']:
self.vif_driver.plug(instance, network, mapping)
for vif in network_info:
if vif.labeled_ips():
self.vif_driver.plug(instance, vif)
def reboot(self, context, instance, network_info, reboot_type,
block_device_info=None, bad_volumes_callback=None):
@ -1455,9 +1449,9 @@ class OpenVzDriver(driver.ComputeDriver):
running_delete.wait()
LOG.debug(_('Timer finished'))
for (network, mapping) in network_info:
for vif in network_info:
LOG.debug('Unplugging vifs')
self.vif_driver.unplug(instance, network, mapping)
self.vif_driver.unplug(instance, vif)
self._clean_orphaned_files(instance['id'])

View File

@ -34,6 +34,8 @@ class OVZMigration(object):
def __init__(self, instance, interfaces, block_device_info=None,
dest=None, live=False):
self.instance = instance
# TODO(pdmars): does interfaces need to be in the legacy
# network_info format? because it's not anymore
self.interfaces = interfaces
self.block_device_info = block_device_info
self.destination_host = dest

View File

@ -32,27 +32,27 @@ class OVZNetworkBridgeDriver(object):
VIF driver for a Linux Bridge
"""
def plug(self, instance, network, mapping):
def plug(self, instance, vif):
"""
Ensure that the bridge exists and add a vif to it.
"""
if (not network.get('should_create_bridge') and
mapping.get('should_create_vlan')):
if mapping.get('should_create_vlan'):
if (not vif['network'].get_meta('should_create_bridge', False) and
vif['network'].get_meta('should_create_vlan', False)):
if vif['network'].get_meta('should_create_vlan', False):
LOG.debug(_('Ensuring bridge %(bridge)s and vlan %(vlan)s') %
{'bridge': network['bridge'],
'vlan': network['vlan']})
{'bridge': vif['network']['bridge'],
'vlan': vif['network'].get_meta('vlan')})
linux_net.LinuxBridgeInterfaceDriver.ensure_vlan_bridge(
network['vlan'],
network['bridge'],
network['bridge_interface'])
vif['network'].get_meta('vlan'),
vif['network']['bridge'],
vif['network'].get_meta('bridge_interface'))
else:
LOG.debug(_('Ensuring bridge %s') % network['bridge'])
LOG.debug(_('Ensuring bridge %s') % vif['network']['bridge'])
linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(
network['bridge'],
network['bridge_interface'])
vif['network']['bridge'],
vif['network'].get_meta('bridge_interface'))
def unplug(self, instance, network, mapping):
def unplug(self, instance, vif):
"""
No manual unplugging required
"""

View File

@ -521,30 +521,37 @@ def remove_instance_metadata(instance_id):
def generate_network_dict(instance_id, network_info):
interfaces = list()
interface_num = -1
for (network, mapping) in network_info:
if mapping['ips']:
for vif in network_info:
if vif.labeled_ips():
interface_num += 1
v6_subnets = []
v4_subnets = []
for subnet in vif['network']['subnets']:
if subnet['version'] == 4:
v4_subnets.append(subnet)
elif subnet['version'] == 6:
v6_subnets.append(subnet)
#TODO(imsplitbit): make this work for ipv6
address_v6 = None
gateway_v6 = None
netmask_v6 = None
if CONF.use_ipv6:
address_v6 = mapping['ip6s'][0]['ip']
netmask_v6 = mapping['ip6s'][0]['netmask']
gateway_v6 = mapping['gateway6']
if v6_subnets:
address_v6 = v6_subnets[0]['ips'][0]['address']
netmask_v6 = v6_subnets[0].as_netaddr()._prefixlen
gateway_v6 = v6_subnets[0]['gateway']
interface_info = {
'id': instance_id,
'interface_number': interface_num,
'bridge': network['bridge'],
'bridge': vif['network']['bridge'],
'name': 'eth%d' % interface_num,
'mac': mapping['mac'],
'address': mapping['ips'][0]['ip'],
'netmask': mapping['ips'][0]['netmask'],
'gateway': mapping['gateway'],
'broadcast': mapping['broadcast'],
'dns': ' '.join(mapping['dns']),
'mac': vif['address'],
'address': v4_subnets[0]['ips'][0]['address'],
'netmask': v4_subnets[0].as_netaddr().netmask,
'gateway': v4_subnets[0]['gateway'],
'broadcast': v4_subnets[0].as_netaddr().broadcast,
'dns': ' '.join([ip['address'] for ip in v4_subnets[0]['dns']]),
'address_v6': address_v6,
'gateway_v6': gateway_v6,
'netmask_v6': netmask_v6

View File

@ -718,72 +718,6 @@ FILECONTENTS = """mount UUID=FEE52433-F693-448E-B6F6-AA6D0124118B /mnt/foo
mount --bind /mnt/foo /vz/private/1/mnt/foo
"""
NETWORKINFO = [
[
{
u'bridge': u'br100',
u'multi_host': False,
u'bridge_interface': u'eth0',
u'vlan': None,
u'id': 1,
u'injected': True,
u'cidr': u'10.0.2.0/24',
u'cidr_v6': None
},
{
u'should_create_bridge': True,
u'dns': [
u'192.168.2.1'
],
u'label': u'usernet',
u'broadcast': u'10.0.2.255',
u'ips': [
{
u'ip': u'10.0.2.16',
u'netmask': u'255.255.255.0',
u'enabled': u'1'
}
],
u'mac': u'02:16:3e:0c:2c:08',
u'rxtx_cap': 0,
u'should_create_vlan': True,
u'dhcp_server': u'10.0.2.2',
u'gateway': u'10.0.2.2'
}
],
[
{
u'bridge': u'br200',
u'multi_host': False,
u'bridge_interface': u'eth1',
u'vlan': None,
u'id': 2,
u'injected': True,
u'cidr': u'10.0.4.0/24',
u'cidr_v6': None
},
{
u'should_create_bridge': False,
u'dns': [
u'192.168.2.1'
],
u'label': u'infranet',
u'broadcast': u'10.0.4.255',
u'ips': [
{
u'ip': u'10.0.4.16',
u'netmask': u'255.255.255.0',
u'enabled': u'1'
}
],
u'mac': u'02:16:3e:40:5e:1b',
u'rxtx_cap': 0,
u'should_create_vlan': False,
u'dhcp_server': u'10.0.2.2',
u'gateway': u'10.0.2.2'
}
]
]
INTERFACEINFO = [
{

View File

@ -23,6 +23,7 @@ from nova.compute import power_state
from nova import exception
from nova.openstack.common import processutils
from nova import test
from nova.tests import fake_network
from ovznovadriver.tests.openvz import fakes
from ovznovadriver.openvz import driver as openvz_conn
from ovznovadriver.openvz.file_ext import ext_storage
@ -32,6 +33,7 @@ import os
from oslo.config import cfg
CONF = cfg.CONF
_fake_network_info = fake_network.fake_get_instance_nw_info
class OpenVzDriverTestCase(test.TestCase):
@ -50,11 +52,8 @@ class OpenVzDriverTestCase(test.TestCase):
fakes.INSTANCE['id'])
self.ext_str_filename = os.path.abspath(self.ext_str_filename)
self.ext_str_permissions = 600
self.network_info = _fake_network_info(self.stubs, 1)
def test_legacy_nwinfo(self):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
self.assertTrue(ovz_conn.legacy_nwinfo())
def test_start_success(self):
# Testing happy path :-D
@ -399,9 +398,9 @@ class OpenVzDriverTestCase(test.TestCase):
def test_set_numtcpsock(self):
instance_meta = ovz_utils.format_system_metadata(
fakes.INSTANCE['system_metadata'])
numtcpsock = json.loads(
CONF.ovz_numtcpsock_map
)[str(instance_meta['instance_type_memory_mb'])]
numtcpsock_map = CONF.ovz_numtcpsock_map
flavor_memory = str(instance_meta['instance_type_memory_mb'])
numtcpsock = numtcpsock_map[flavor_memory]
self.mox.StubOutWithMock(openvz_conn.ovz_utils, 'execute')
openvz_conn.ovz_utils.execute(
'vzctl', 'set', fakes.INSTANCE['id'], '--save', '--numtcpsock',
@ -464,10 +463,10 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_set_diskspace')
ovz_conn._set_diskspace(fakes.INSTANCE, fakes.INSTANCETYPE['root_gb'])
self.mox.StubOutWithMock(ovz_conn, '_generate_tc_rules')
ovz_conn._generate_tc_rules(fakes.INSTANCE, fakes.NETWORKINFO, False)
ovz_conn._generate_tc_rules(fakes.INSTANCE, self.network_info, False)
self.mox.ReplayAll()
ovz_conn._set_instance_size(
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
def test_set_instance_size_without_instance_type_id(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -510,10 +509,10 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_utils.format_system_metadata(
fakes.INSTANCE['system_metadata'])['instance_type_root_gb'])
self.mox.StubOutWithMock(ovz_conn, '_generate_tc_rules')
ovz_conn._generate_tc_rules(fakes.INSTANCE, fakes.NETWORKINFO, False)
ovz_conn._generate_tc_rules(fakes.INSTANCE, self.network_info, False)
self.mox.ReplayAll()
ovz_conn._set_instance_size(
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
def test_generate_tc_rules(self):
self.mox.StubOutWithMock(openvz_conn.ovzboot, 'OVZBootFile')
@ -536,7 +535,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
self.mox.ReplayAll()
ovz_conn._generate_tc_rules(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn._generate_tc_rules(fakes.INSTANCE, self.network_info)
def test_set_onboot_success(self):
self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
@ -887,36 +886,40 @@ class OpenVzDriverTestCase(test.TestCase):
fakes.INSTANCE['id'], mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes()
self.mox.ReplayAll()
conn._gratuitous_arp_all_addresses(fakes.INSTANCE, fakes.NETWORKINFO)
conn._gratuitous_arp_all_addresses(fakes.INSTANCE, self.network_info)
def test_send_garp_success(self):
self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
ovz_utils.utils.execute(
'vzctl', 'exec2', fakes.INSTANCE['id'], 'arping', '-q', '-c', '5',
'-A', '-I', fakes.NETWORKINFO[0][0]['bridge_interface'],
fakes.NETWORKINFO[0][1]['ips'][0]['ip'],
'-A', '-I',
self.network_info[0]['network'].get_meta('bridge_interface'),
self.network_info[0]['network']['subnets'][0]['ips'][0]['address'],
run_as_root=True).AndReturn(
('', fakes.ERRORMSG))
self.mox.ReplayAll()
conn = openvz_conn.OpenVzDriver(manager.ComputeVirtAPI(None), False)
conn._send_garp(
fakes.INSTANCE['id'], fakes.NETWORKINFO[0][1]['ips'][0]['ip'],
fakes.NETWORKINFO[0][0]['bridge_interface'])
fakes.INSTANCE['id'],
self.network_info[0]['network']['subnets'][0]['ips'][0]['address'],
self.network_info[0]['network'].get_meta('bridge_interface'))
def test_send_garp_faiure(self):
self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
ovz_utils.utils.execute(
'vzctl', 'exec2', fakes.INSTANCE['id'], 'arping', '-q', '-c', '5',
'-A', '-I', fakes.NETWORKINFO[0][0]['bridge_interface'],
fakes.NETWORKINFO[0][1]['ips'][0]['ip'],
'-A', '-I',
self.network_info[0]['network'].get_meta('bridge_interface'),
self.network_info[0]['network']['subnets'][0]['ips'][0]['address'],
run_as_root=True).AndRaise(
exception.InstanceUnacceptable(fakes.ERRORMSG))
self.mox.ReplayAll()
conn = openvz_conn.OpenVzDriver(manager.ComputeVirtAPI(None), False)
self.assertRaises(
exception.InstanceUnacceptable, conn._send_garp,
fakes.INSTANCE['id'], fakes.NETWORKINFO[0][1]['ips'][0]['ip'],
fakes.NETWORKINFO[0][0]['bridge_interface'])
fakes.INSTANCE['id'],
self.network_info[0]['network']['subnets'][0]['ips'][0]['address'],
self.network_info[0]['network'].get_meta('bridge_interface'))
def test_init_host_success(self):
self.mox.StubOutWithMock(openvz_conn.ovzboot, 'OVZBootFile')
@ -1071,7 +1074,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn.vif_driver.plug(
fakes.INSTANCE, mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
ovz_conn.plug_vifs(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.plug_vifs(fakes.INSTANCE, self.network_info)
def test_reboot_success(self):
self.mox.StubOutWithMock(openvz_conn.ovzshutdown, 'OVZShutdownFile')
@ -1097,7 +1100,7 @@ class OpenVzDriverTestCase(test.TestCase):
fakes.INSTANCE).MultipleTimes().AndReturn(fakes.GOODSTATUS)
self.mox.ReplayAll()
timer = ovz_conn.reboot(
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.NETWORKINFO, None)
fakes.ADMINCONTEXT, fakes.INSTANCE, self.network_info, None)
timer.wait()
def test_reboot_fail_in_get_info(self):
@ -1120,7 +1123,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn.get_info(fakes.INSTANCE).AndRaise(exception.NotFound)
self.mox.ReplayAll()
timer = ovz_conn.reboot(
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.NETWORKINFO, None)
fakes.ADMINCONTEXT, fakes.INSTANCE, self.network_info, None)
self.assertRaises(exception.NotFound, timer.wait)
def test_reboot_fail_because_not_found(self):
@ -1143,7 +1146,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn.get_info(fakes.INSTANCE).AndReturn(fakes.NOSTATUS)
self.mox.ReplayAll()
timer = ovz_conn.reboot(
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.NETWORKINFO, None)
fakes.ADMINCONTEXT, fakes.INSTANCE, self.network_info, None)
timer.wait()
def test_reboot_failure(self):
@ -1165,7 +1168,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(
exception.InstanceUnacceptable, ovz_conn.reboot,
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.NETWORKINFO, None)
fakes.ADMINCONTEXT, fakes.INSTANCE, self.network_info, None)
def test_inject_files(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1336,7 +1339,7 @@ class OpenVzDriverTestCase(test.TestCase):
{'power_state': power_state.RUNNING})
self.mox.ReplayAll()
conn.resume(fakes.INSTANCE, fakes.NETWORKINFO)
conn.resume(fakes.INSTANCE, self.network_info)
def test_resume_db_not_found(self):
self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
@ -1351,7 +1354,7 @@ class OpenVzDriverTestCase(test.TestCase):
{'power_state': power_state.RUNNING}).AndRaise(
exception.InstanceNotFound(fakes.ERRORMSG))
self.mox.ReplayAll()
conn.resume(fakes.INSTANCE, fakes.NETWORKINFO)
conn.resume(fakes.INSTANCE, self.network_info)
def test_resume_failure(self):
self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
@ -1397,7 +1400,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(
exception.InstanceTerminationFailure, ovz_conn.destroy,
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
def test_destroy_success(self):
self.mox.StubOutWithMock(
@ -1423,7 +1426,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_detach_volumes')
ovz_conn._detach_volumes(fakes.INSTANCE, fakes.BDM)
self.mox.ReplayAll()
ovz_conn.destroy(fakes.INSTANCE, fakes.NETWORKINFO, fakes.BDM)
ovz_conn.destroy(fakes.INSTANCE, self.network_info, fakes.BDM)
def test_get_info_running_state(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1508,6 +1511,9 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn.utility['MEMORY_MB'] = 16384
# get_memory_mb_total just returns 1 if you're not on linux
self.mox.StubOutWithMock(ovz_utils, 'get_memory_mb_total')
ovz_utils.get_memory_mb_total().AndReturn(16384)
self.mox.ReplayAll()
self.assertTrue(
ovz_conn._percent_of_resource(fakes.INSTANCE['memory_mb']) < 1)
@ -1540,13 +1546,13 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_set_description')
ovz_conn._set_description(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_setup_networking')
ovz_conn._setup_networking(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn._setup_networking(fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, '_set_onboot')
ovz_conn._set_onboot(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_name')
ovz_conn._set_name(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, 'plug_vifs')
ovz_conn.plug_vifs(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.plug_vifs(fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, '_set_hostname')
ovz_conn._set_hostname(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_instance_size')
@ -1559,7 +1565,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn._start(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_gratuitous_arp_all_addresses')
ovz_conn._gratuitous_arp_all_addresses(
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, 'set_admin_password')
ovz_conn.set_admin_password(
fakes.ADMINCONTEXT, fakes.INSTANCE['id'],
@ -1569,7 +1575,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
timer = ovz_conn.spawn(
fakes.ADMINCONTEXT, fakes.INSTANCE, None, fakes.FILESTOINJECT,
fakes.ROOTPASS, fakes.NETWORKINFO, fakes.BDM)
fakes.ROOTPASS, self.network_info, fakes.BDM)
timer.wait()
def test_spawn_failure(self):
@ -1591,13 +1597,13 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_set_description')
ovz_conn._set_description(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_setup_networking')
ovz_conn._setup_networking(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn._setup_networking(fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, '_set_onboot')
ovz_conn._set_onboot(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_name')
ovz_conn._set_name(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, 'plug_vifs')
ovz_conn.plug_vifs(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.plug_vifs(fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, '_set_hostname')
ovz_conn._set_hostname(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_instance_size')
@ -1610,7 +1616,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn._start(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_gratuitous_arp_all_addresses')
ovz_conn._gratuitous_arp_all_addresses(
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, 'set_admin_password')
ovz_conn.set_admin_password(
fakes.ADMINCONTEXT, fakes.INSTANCE['id'],
@ -1620,7 +1626,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
timer = ovz_conn.spawn(
fakes.ADMINCONTEXT, fakes.INSTANCE, None, fakes.FILESTOINJECT,
fakes.ROOTPASS, fakes.NETWORKINFO, fakes.BDM)
fakes.ROOTPASS, self.network_info, fakes.BDM)
timer.wait()
def test_snapshot(self):
@ -1634,13 +1640,13 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn.rescue(
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.NETWORKINFO,
fakes.ADMINCONTEXT, fakes.INSTANCE, self.network_info,
fakes.INSTANCE['image_ref'], fakes.ROOTPASS)
def test_unrescue(self):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn.unrescue(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.unrescue(fakes.INSTANCE, self.network_info)
def test_get_diagnostics(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1766,12 +1772,12 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
result = ovz_conn.ensure_filtering_rules_for_instance(
fakes.INSTANCE, fakes.NETWORKINFO)
fakes.INSTANCE, self.network_info)
def test_unfilter_instance(self):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
result = ovz_conn.unfilter_instance(fakes.INSTANCE, fakes.NETWORKINFO)
result = ovz_conn.unfilter_instance(fakes.INSTANCE, self.network_info)
def test_refresh_provider_fw_rules(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1820,14 +1826,14 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_pymigration_send_to_host')
ovz_conn._pymigration_send_to_host(
fakes.INSTANCE, ovz_utils.generate_network_dict(
fakes.INSTANCE['id'], fakes.NETWORKINFO),
fakes.INSTANCE['id'], self.network_info),
fakes.BDM, fakes.DESTINATION, False)
self.mox.StubOutWithMock(ovz_conn, '_detach_volumes')
ovz_conn._detach_volumes(fakes.INSTANCE, fakes.BDM, True, False)
self.mox.ReplayAll()
ovz_conn.migrate_disk_and_power_off(
fakes.ADMINCONTEXT, fakes.INSTANCE, fakes.DESTINATION,
fakes.INSTANCETYPE, fakes.NETWORKINFO, fakes.BDM)
fakes.INSTANCETYPE, self.network_info, fakes.BDM)
def test_migrate_disk_and_power_off_success_without_storage(self):
INSTANCE = fakes.INSTANCE.copy()
@ -1839,12 +1845,12 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_pymigration_send_to_host')
ovz_conn._pymigration_send_to_host(
INSTANCE, ovz_utils.generate_network_dict(
INSTANCE['id'], fakes.NETWORKINFO),
INSTANCE['id'], self.network_info),
None, fakes.DESTINATION, True)
self.mox.ReplayAll()
ovz_conn.migrate_disk_and_power_off(
fakes.ADMINCONTEXT, INSTANCE, fakes.DESTINATION,
fakes.INSTANCETYPE, fakes.NETWORKINFO)
fakes.INSTANCETYPE, self.network_info)
def test_migrate_disk_and_power_off_no_dest(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1852,7 +1858,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.assertRaises(
exception.MigrationError, ovz_conn.migrate_disk_and_power_off,
fakes.ADMINCONTEXT, fakes.INSTANCE, None, fakes.INSTANCETYPE,
fakes.NETWORKINFO)
self.network_info)
def test_migrate_disk_and_power_off_same_host(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1863,7 +1869,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
ovz_conn.migrate_disk_and_power_off(
fakes.ADMINCONTEXT, fakes.INSTANCE, CONF.host,
fakes.INSTANCETYPE, fakes.NETWORKINFO)
fakes.INSTANCETYPE, self.network_info)
def test_pymigration_send_to_host(self):
self.mox.StubOutWithMock(
@ -1875,7 +1881,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn._pymigration_send_to_host(
fakes.INSTANCE, fakes.NETWORKINFO, fakes.BDM,
fakes.INSTANCE, self.network_info, fakes.BDM,
fakes.DESTINATION, False)
def test_vzmigration_send_to_host(self):
@ -1895,10 +1901,10 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
self.mox.StubOutWithMock(ovz_conn, '_set_instance_size')
ovz_conn._set_instance_size(fakes.INSTANCE, fakes.NETWORKINFO, False)
ovz_conn._set_instance_size(fakes.INSTANCE, self.network_info, False)
self.mox.ReplayAll()
ovz_conn.finish_migration(
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, fakes.NETWORKINFO,
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, self.network_info,
None, None, fakes.BDM)
def test_finish_migration_no_resize(self):
@ -1910,18 +1916,18 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn._attach_volumes(fakes.INSTANCE, fakes.BDM)
self.mox.StubOutWithMock(ovz_conn, '_pymigrate_finish_migration')
ovz_conn._pymigrate_finish_migration(
fakes.INSTANCE, fakes.NETWORKINFO, False)
fakes.INSTANCE, self.network_info, False)
self.mox.StubOutWithMock(ovz_conn, '_set_name')
ovz_conn._set_name(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_description')
ovz_conn._set_description(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_generate_tc_rules')
ovz_conn._generate_tc_rules(fakes.INSTANCE, fakes.NETWORKINFO, True)
ovz_conn._generate_tc_rules(fakes.INSTANCE, self.network_info, True)
self.mox.StubOutWithMock(ovz_conn, '_start')
ovz_conn._start(fakes.INSTANCE)
self.mox.ReplayAll()
ovz_conn.finish_migration(
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, fakes.NETWORKINFO,
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, self.network_info,
None, False, fakes.BDM)
def test_finish_migration_resize(self):
@ -1933,18 +1939,18 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn._attach_volumes(fakes.INSTANCE, fakes.BDM)
self.mox.StubOutWithMock(ovz_conn, '_pymigrate_finish_migration')
ovz_conn._pymigrate_finish_migration(
fakes.INSTANCE, fakes.NETWORKINFO, False)
fakes.INSTANCE, self.network_info, False)
self.mox.StubOutWithMock(ovz_conn, '_set_name')
ovz_conn._set_name(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_set_instance_size')
ovz_conn._set_instance_size(fakes.INSTANCE, fakes.NETWORKINFO, True)
ovz_conn._set_instance_size(fakes.INSTANCE, self.network_info, True)
self.mox.StubOutWithMock(ovz_conn, '_set_description')
ovz_conn._set_description(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, '_start')
ovz_conn._start(fakes.INSTANCE)
self.mox.ReplayAll()
ovz_conn.finish_migration(
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, fakes.NETWORKINFO,
fakes.ADMINCONTEXT, None, fakes.INSTANCE, None, self.network_info,
None, True, fakes.BDM)
def test_pymigrate_finish_migration(self):
@ -1956,7 +1962,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn._pymigrate_finish_migration(
fakes.INSTANCE, fakes.NETWORKINFO, False)
fakes.INSTANCE, self.network_info, False)
def test_vzmigrate_setup_dest_host(self):
ovz_conn = openvz_conn.OpenVzDriver(
@ -1964,11 +1970,11 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_stop')
ovz_conn._stop(fakes.INSTANCE)
self.mox.StubOutWithMock(ovz_conn, 'plug_vifs')
ovz_conn.plug_vifs(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.plug_vifs(fakes.INSTANCE, self.network_info)
self.mox.StubOutWithMock(ovz_conn, '_start')
ovz_conn._start(fakes.INSTANCE)
self.mox.ReplayAll()
ovz_conn._vzmigrate_setup_dest_host(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn._vzmigrate_setup_dest_host(fakes.INSTANCE, self.network_info)
def test_confirm_migration_resize_in_place(self):
self.mox.StubOutWithMock(ovz_utils, 'read_instance_metadata')
@ -1983,7 +1989,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.ReplayAll()
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
ovz_conn.confirm_migration(None, fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.confirm_migration(None, fakes.INSTANCE, self.network_info)
def test_confirm_migration(self):
self.mox.StubOutWithMock(migration.OVZMigration, 'cleanup_source')
@ -2002,7 +2008,7 @@ class OpenVzDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(ovz_conn, '_clean_orphaned_files')
ovz_conn._clean_orphaned_files(fakes.INSTANCE['id'])
self.mox.ReplayAll()
ovz_conn.confirm_migration(None, fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.confirm_migration(None, fakes.INSTANCE, self.network_info)
def test_finish_revert_migration(self):
self.mox.StubOutWithMock(ovz_utils, 'read_instance_metadata')
@ -2012,7 +2018,7 @@ class OpenVzDriverTestCase(test.TestCase):
ovz_conn = openvz_conn.OpenVzDriver(
manager.ComputeVirtAPI(None), False)
self.mox.StubOutWithMock(ovz_conn, 'resume')
ovz_conn.resume(fakes.INSTANCE, fakes.NETWORKINFO)
ovz_conn.resume(fakes.INSTANCE, self.network_info)
self.mox.ReplayAll()
ovz_conn.finish_revert_migration(
fakes.INSTANCE, fakes.NETWORKINFO, None)
fakes.INSTANCE, self.network_info, None)

View File

@ -18,6 +18,7 @@
import mox
from nova import exception
from nova import test
from nova.tests import fake_network
from nova.tests.openvz import fakes
from ovznovadriver.openvz import driver as openvz_conn
from ovznovadriver.openvz import network as openvz_net
@ -25,6 +26,7 @@ from ovznovadriver.openvz.network_drivers import network_bridge
from oslo.config import cfg
CONF = cfg.CONF
_fake_network_info = fake_network.fake_get_instance_nw_info
class OpenVzNetworkTestCase(test.TestCase):
@ -210,5 +212,9 @@ class OpenVzNetworkTestCase(test.TestCase):
)
self.mox.ReplayAll()
driver = network_bridge.OVZNetworkBridgeDriver()
for network, mapping in fakes.NETWORKINFO:
driver.plug(fakes.INSTANCE, network, mapping)
network_info = _fake_network_info(self.stubs, 1)
for vif in network_info:
# should_create_vlan isn't included in nova's fake network info by
# default so we need to inject it to hit this code
vif['network']['meta']['should_create_vlan'] = True
driver.plug(fakes.INSTANCE, vif)