Update BareMetal driver to current nova.network.model
Update baremetal driver and vif to use classes from nova.network.model instead of legacy "network,mapping" tuple. Partly implement blueprint nova-network-legacy Co-author: Amir Sadoughi<amir.sadoughi@gmail.com> Change-Id: Ia66360f51e1d7a12273df2a080931958cc4f86b5
This commit is contained in:
parent
c4e7df7a98
commit
a4cf3ef163
@ -121,7 +121,7 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
|
|||||||
None, result['instance']),
|
None, result['instance']),
|
||||||
injected_files=[('/fake/path', 'hello world')],
|
injected_files=[('/fake/path', 'hello world')],
|
||||||
instance=result['instance'],
|
instance=result['instance'],
|
||||||
network_info=utils.get_test_network_info(),
|
network_info=utils.get_test_network_info(legacy_model=False),
|
||||||
)
|
)
|
||||||
result['destroy_params'] = dict(
|
result['destroy_params'] = dict(
|
||||||
instance=result['instance'],
|
instance=result['instance'],
|
||||||
|
@ -69,7 +69,8 @@ class BareMetalPXETestCase(bm_db_base.BMDBTestCase):
|
|||||||
self.context = utils.get_test_admin_context()
|
self.context = utils.get_test_admin_context()
|
||||||
self.test_block_device_info = None,
|
self.test_block_device_info = None,
|
||||||
self.instance = utils.get_test_instance()
|
self.instance = utils.get_test_instance()
|
||||||
self.test_network_info = utils.get_test_network_info(),
|
self.test_network_info = utils.get_test_network_info(
|
||||||
|
legacy_model=False),
|
||||||
self.node_info = bm_db_utils.new_bm_node(
|
self.node_info = bm_db_utils.new_bm_node(
|
||||||
service_host='test_host',
|
service_host='test_host',
|
||||||
cpus=4,
|
cpus=4,
|
||||||
@ -146,23 +147,23 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase):
|
|||||||
pxe_network_config=True,
|
pxe_network_config=True,
|
||||||
group='baremetal',
|
group='baremetal',
|
||||||
)
|
)
|
||||||
net = utils.get_test_network_info(1)
|
net = utils.get_test_network_info(1, legacy_model=False)
|
||||||
config = pxe.build_pxe_network_config(net)
|
config = pxe.build_pxe_network_config(net)
|
||||||
self.assertIn('eth0:off', config)
|
self.assertIn('eth0:off', config)
|
||||||
self.assertNotIn('eth1', config)
|
self.assertNotIn('eth1', config)
|
||||||
|
|
||||||
net = utils.get_test_network_info(2)
|
net = utils.get_test_network_info(2, legacy_model=False)
|
||||||
config = pxe.build_pxe_network_config(net)
|
config = pxe.build_pxe_network_config(net)
|
||||||
self.assertIn('eth0:off', config)
|
self.assertIn('eth0:off', config)
|
||||||
self.assertIn('eth1:off', config)
|
self.assertIn('eth1:off', config)
|
||||||
|
|
||||||
def test_build_network_config(self):
|
def test_build_network_config(self):
|
||||||
net = utils.get_test_network_info(1)
|
net = utils.get_test_network_info(1, legacy_model=False)
|
||||||
config = pxe.build_network_config(net)
|
config = pxe.build_network_config(net)
|
||||||
self.assertIn('eth0', config)
|
self.assertIn('eth0', config)
|
||||||
self.assertNotIn('eth1', config)
|
self.assertNotIn('eth1', config)
|
||||||
|
|
||||||
net = utils.get_test_network_info(2)
|
net = utils.get_test_network_info(2, legacy_model=False)
|
||||||
config = pxe.build_network_config(net)
|
config = pxe.build_network_config(net)
|
||||||
self.assertIn('eth0', config)
|
self.assertIn('eth0', config)
|
||||||
self.assertIn('eth1', config)
|
self.assertIn('eth1', config)
|
||||||
@ -173,8 +174,8 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase):
|
|||||||
'net-dhcp.ubuntu.template',
|
'net-dhcp.ubuntu.template',
|
||||||
group='baremetal',
|
group='baremetal',
|
||||||
)
|
)
|
||||||
net = utils.get_test_network_info()
|
net = utils.get_test_network_info(legacy_model=False)
|
||||||
net[0][1]['ips'][0]['ip'] = '1.2.3.4'
|
net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4'
|
||||||
config = pxe.build_network_config(net)
|
config = pxe.build_network_config(net)
|
||||||
self.assertIn('iface eth0 inet dhcp', config)
|
self.assertIn('iface eth0 inet dhcp', config)
|
||||||
self.assertNotIn('address 1.2.3.4', config)
|
self.assertNotIn('address 1.2.3.4', config)
|
||||||
@ -185,12 +186,40 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase):
|
|||||||
'net-static.ubuntu.template',
|
'net-static.ubuntu.template',
|
||||||
group='baremetal',
|
group='baremetal',
|
||||||
)
|
)
|
||||||
net = utils.get_test_network_info()
|
net = utils.get_test_network_info(legacy_model=False)
|
||||||
net[0][1]['ips'][0]['ip'] = '1.2.3.4'
|
net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4'
|
||||||
config = pxe.build_network_config(net)
|
config = pxe.build_network_config(net)
|
||||||
self.assertIn('iface eth0 inet static', config)
|
self.assertIn('iface eth0 inet static', config)
|
||||||
self.assertIn('address 1.2.3.4', config)
|
self.assertIn('address 1.2.3.4', config)
|
||||||
|
|
||||||
|
def test_build_network_config_static_parameters(self):
|
||||||
|
self.flags(use_ipv6=True)
|
||||||
|
self.flags(
|
||||||
|
net_config_template='$pybasedir/nova/virt/baremetal/'
|
||||||
|
'net-static.ubuntu.template',
|
||||||
|
group='baremetal'
|
||||||
|
)
|
||||||
|
|
||||||
|
net = utils.get_test_network_info(legacy_model=False)
|
||||||
|
net[0]['network']['subnets'][0]['cidr'] = '10.1.1.0/24'
|
||||||
|
net[0]['network']['subnets'][0]['gateway']['address'] = '10.1.1.1'
|
||||||
|
net[0]['network']['subnets'][0]['dns'][0]['address'] = '10.1.1.2'
|
||||||
|
net[0]['network']['subnets'][0]['dns'][1]['address'] = '10.1.1.3'
|
||||||
|
|
||||||
|
net[0]['network']['subnets'][1]['cidr'] = 'fc00::/7'
|
||||||
|
net[0]['network']['subnets'][1]['ips'][0]['address'] = 'fc00::1'
|
||||||
|
net[0]['network']['subnets'][1]['gateway']['address'] = 'fc00::2'
|
||||||
|
config = pxe.build_network_config(net)
|
||||||
|
|
||||||
|
self.assertIn('iface eth0 inet static', config)
|
||||||
|
self.assertIn('gateway 10.1.1.1', config)
|
||||||
|
self.assertIn('dns-nameservers 10.1.1.2 10.1.1.3', config)
|
||||||
|
|
||||||
|
self.assertIn('iface eth0 inet6 static', config)
|
||||||
|
self.assertIn('address fc00::1', config)
|
||||||
|
self.assertIn('netmask 7', config)
|
||||||
|
self.assertIn('gateway fc00::2', config)
|
||||||
|
|
||||||
def test_image_dir_path(self):
|
def test_image_dir_path(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
pxe.get_image_dir_path(self.instance),
|
pxe.get_image_dir_path(self.instance),
|
||||||
@ -379,7 +408,7 @@ class PXEPrivateMethodsTestCase(BareMetalPXETestCase):
|
|||||||
self.instance['hostname'] = 'fake hostname'
|
self.instance['hostname'] = 'fake hostname'
|
||||||
files.append(('/etc/hostname', 'fake hostname'))
|
files.append(('/etc/hostname', 'fake hostname'))
|
||||||
self.instance['key_data'] = 'fake ssh key'
|
self.instance['key_data'] = 'fake ssh key'
|
||||||
net_info = utils.get_test_network_info(1)
|
net_info = utils.get_test_network_info(1, legacy_model=False)
|
||||||
net = pxe.build_network_config(net_info)
|
net = pxe.build_network_config(net_info)
|
||||||
admin_password = 'fake password'
|
admin_password = 'fake password'
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ class BareMetalTileraTestCase(bm_db_base.BMDBTestCase):
|
|||||||
self.context = utils.get_test_admin_context()
|
self.context = utils.get_test_admin_context()
|
||||||
self.test_block_device_info = None,
|
self.test_block_device_info = None,
|
||||||
self.instance = utils.get_test_instance()
|
self.instance = utils.get_test_instance()
|
||||||
self.test_network_info = utils.get_test_network_info(),
|
self.test_network_info = utils.get_test_network_info(
|
||||||
|
legacy_model=False),
|
||||||
self.node_info = bm_db_utils.new_bm_node(
|
self.node_info = bm_db_utils.new_bm_node(
|
||||||
service_host='test_host',
|
service_host='test_host',
|
||||||
cpus=4,
|
cpus=4,
|
||||||
@ -104,12 +105,12 @@ class BareMetalTileraTestCase(bm_db_base.BMDBTestCase):
|
|||||||
class TileraClassMethodsTestCase(BareMetalTileraTestCase):
|
class TileraClassMethodsTestCase(BareMetalTileraTestCase):
|
||||||
|
|
||||||
def test_build_network_config(self):
|
def test_build_network_config(self):
|
||||||
net = utils.get_test_network_info(1)
|
net = utils.get_test_network_info(1, legacy_model=False)
|
||||||
config = tilera.build_network_config(net)
|
config = tilera.build_network_config(net)
|
||||||
self.assertIn('eth0', config)
|
self.assertIn('eth0', config)
|
||||||
self.assertNotIn('eth1', config)
|
self.assertNotIn('eth1', config)
|
||||||
|
|
||||||
net = utils.get_test_network_info(2)
|
net = utils.get_test_network_info(2, legacy_model=False)
|
||||||
config = tilera.build_network_config(net)
|
config = tilera.build_network_config(net)
|
||||||
self.assertIn('eth0', config)
|
self.assertIn('eth0', config)
|
||||||
self.assertIn('eth1', config)
|
self.assertIn('eth1', config)
|
||||||
@ -120,8 +121,8 @@ class TileraClassMethodsTestCase(BareMetalTileraTestCase):
|
|||||||
'net-dhcp.ubuntu.template',
|
'net-dhcp.ubuntu.template',
|
||||||
group='baremetal',
|
group='baremetal',
|
||||||
)
|
)
|
||||||
net = utils.get_test_network_info()
|
net = utils.get_test_network_info(legacy_model=False)
|
||||||
net[0][1]['ips'][0]['ip'] = '1.2.3.4'
|
net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4'
|
||||||
config = tilera.build_network_config(net)
|
config = tilera.build_network_config(net)
|
||||||
self.assertIn('iface eth0 inet dhcp', config)
|
self.assertIn('iface eth0 inet dhcp', config)
|
||||||
self.assertNotIn('address 1.2.3.4', config)
|
self.assertNotIn('address 1.2.3.4', config)
|
||||||
@ -132,8 +133,8 @@ class TileraClassMethodsTestCase(BareMetalTileraTestCase):
|
|||||||
'net-static.ubuntu.template',
|
'net-static.ubuntu.template',
|
||||||
group='baremetal',
|
group='baremetal',
|
||||||
)
|
)
|
||||||
net = utils.get_test_network_info()
|
net = utils.get_test_network_info(legacy_model=False)
|
||||||
net[0][1]['ips'][0]['ip'] = '1.2.3.4'
|
net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4'
|
||||||
config = tilera.build_network_config(net)
|
config = tilera.build_network_config(net)
|
||||||
self.assertIn('iface eth0 inet static', config)
|
self.assertIn('iface eth0 inet static', config)
|
||||||
self.assertIn('address 1.2.3.4', config)
|
self.assertIn('address 1.2.3.4', config)
|
||||||
@ -235,7 +236,7 @@ class TileraPrivateMethodsTestCase(BareMetalTileraTestCase):
|
|||||||
self.instance['hostname'] = 'fake hostname'
|
self.instance['hostname'] = 'fake hostname'
|
||||||
files.append(('/etc/hostname', 'fake hostname'))
|
files.append(('/etc/hostname', 'fake hostname'))
|
||||||
self.instance['key_data'] = 'fake ssh key'
|
self.instance['key_data'] = 'fake ssh key'
|
||||||
net_info = utils.get_test_network_info(1)
|
net_info = utils.get_test_network_info(1, legacy_model=False)
|
||||||
net = tilera.build_network_config(net_info)
|
net = tilera.build_network_config(net_info)
|
||||||
admin_password = 'fake password'
|
admin_password = 'fake password'
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class BareMetalDriver(driver.ComputeDriver):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
def legacy_nwinfo(self):
|
def legacy_nwinfo(self):
|
||||||
return True
|
return False
|
||||||
|
|
||||||
def list_instances(self):
|
def list_instances(self):
|
||||||
l = []
|
l = []
|
||||||
@ -481,12 +481,12 @@ class BareMetalDriver(driver.ComputeDriver):
|
|||||||
for pif in pifs:
|
for pif in pifs:
|
||||||
if pif['vif_uuid']:
|
if pif['vif_uuid']:
|
||||||
db.bm_interface_set_vif_uuid(context, pif['id'], None)
|
db.bm_interface_set_vif_uuid(context, pif['id'], None)
|
||||||
for (network, mapping) in network_info:
|
for vif in network_info:
|
||||||
self.vif_driver.plug(instance, (network, mapping))
|
self.vif_driver.plug(instance, vif)
|
||||||
|
|
||||||
def _unplug_vifs(self, instance, network_info):
|
def _unplug_vifs(self, instance, network_info):
|
||||||
for (network, mapping) in network_info:
|
for vif in network_info:
|
||||||
self.vif_driver.unplug(instance, (network, mapping))
|
self.vif_driver.unplug(instance, vif)
|
||||||
|
|
||||||
def manage_image_cache(self, context, all_instances):
|
def manage_image_cache(self, context, all_instances):
|
||||||
"""Manage the local cache of images."""
|
"""Manage the local cache of images."""
|
||||||
|
@ -94,20 +94,32 @@ def map_network_interfaces(network_info, use_ipv6=False):
|
|||||||
network_info = [network_info]
|
network_info = [network_info]
|
||||||
|
|
||||||
interfaces = []
|
interfaces = []
|
||||||
for id, (network, mapping) in enumerate(network_info):
|
for id, vif in enumerate(network_info):
|
||||||
address_v6 = None
|
address_v6 = gateway_v6 = netmask_v6 = None
|
||||||
gateway_v6 = None
|
address_v4 = gateway_v4 = netmask_v4 = dns_v4 = None
|
||||||
netmask_v6 = None
|
|
||||||
if use_ipv6:
|
if use_ipv6:
|
||||||
address_v6 = mapping['ip6s'][0]['ip']
|
subnets_v6 = [s for s in vif['network']['subnets']
|
||||||
netmask_v6 = mapping['ip6s'][0]['netmask']
|
if s['version'] == 6]
|
||||||
gateway_v6 = mapping['gateway_v6']
|
if len(subnets_v6):
|
||||||
|
address_v6 = subnets_v6[0]['ips'][0]['address']
|
||||||
|
netmask_v6 = subnets_v6[0].as_netaddr()._prefixlen
|
||||||
|
gateway_v6 = subnets_v6[0]['gateway']['address']
|
||||||
|
|
||||||
|
subnets_v4 = [s for s in vif['network']['subnets']
|
||||||
|
if s['version'] == 4]
|
||||||
|
if len(subnets_v4):
|
||||||
|
address_v4 = subnets_v4[0]['ips'][0]['address']
|
||||||
|
netmask_v4 = subnets_v4[0].as_netaddr().netmask
|
||||||
|
gateway_v4 = subnets_v4[0]['gateway']['address']
|
||||||
|
dns_v4 = ' '.join([x['address'] for x in subnets_v4[0]['dns']])
|
||||||
|
|
||||||
interface = {
|
interface = {
|
||||||
'name': 'eth%d' % id,
|
'name': 'eth%d' % id,
|
||||||
'address': mapping['ips'][0]['ip'],
|
'address': address_v4,
|
||||||
'gateway': mapping['gateway'],
|
'gateway': gateway_v4,
|
||||||
'netmask': mapping['ips'][0]['netmask'],
|
'netmask': netmask_v4,
|
||||||
'dns': ' '.join(mapping['dns']),
|
'dns': dns_v4,
|
||||||
'address_v6': address_v6,
|
'address_v6': address_v6,
|
||||||
'gateway_v6': gateway_v6,
|
'gateway_v6': gateway_v6,
|
||||||
'netmask_v6': netmask_v6,
|
'netmask_v6': netmask_v6,
|
||||||
|
@ -28,17 +28,16 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class BareMetalVIFDriver(object):
|
class BareMetalVIFDriver(object):
|
||||||
|
|
||||||
def _after_plug(self, instance, network, mapping, pif):
|
def _after_plug(self, instance, vif, pif):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _after_unplug(self, instance, network, mapping, pif):
|
def _after_unplug(self, instance, vif, pif):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def plug(self, instance, vif):
|
def plug(self, instance, vif):
|
||||||
LOG.debug(_("plug: instance_uuid=%(uuid)s vif=%(vif)s")
|
LOG.debug(_("plug: instance_uuid=%(uuid)s vif=%(vif)s")
|
||||||
% {'uuid': instance['uuid'], 'vif': vif})
|
% {'uuid': instance['uuid'], 'vif': vif})
|
||||||
network, mapping = vif
|
vif_uuid = vif['id']
|
||||||
vif_uuid = mapping['vif_uuid']
|
|
||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])
|
node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ class BareMetalVIFDriver(object):
|
|||||||
bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
|
bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
|
||||||
LOG.debug(_("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)")
|
LOG.debug(_("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)")
|
||||||
% {'id': pif['id'], 'vif_uuid': vif_uuid})
|
% {'id': pif['id'], 'vif_uuid': vif_uuid})
|
||||||
self._after_plug(instance, network, mapping, pif)
|
self._after_plug(instance, vif, pif)
|
||||||
return
|
return
|
||||||
|
|
||||||
# NOTE(deva): should this really be raising an exception
|
# NOTE(deva): should this really be raising an exception
|
||||||
@ -63,14 +62,13 @@ class BareMetalVIFDriver(object):
|
|||||||
def unplug(self, instance, vif):
|
def unplug(self, instance, vif):
|
||||||
LOG.debug(_("unplug: instance_uuid=%(uuid)s vif=%(vif)s"),
|
LOG.debug(_("unplug: instance_uuid=%(uuid)s vif=%(vif)s"),
|
||||||
{'uuid': instance['uuid'], 'vif': vif})
|
{'uuid': instance['uuid'], 'vif': vif})
|
||||||
network, mapping = vif
|
vif_uuid = vif['id']
|
||||||
vif_uuid = mapping['vif_uuid']
|
|
||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
try:
|
try:
|
||||||
pif = bmdb.bm_interface_get_by_vif_uuid(ctx, vif_uuid)
|
pif = bmdb.bm_interface_get_by_vif_uuid(ctx, vif_uuid)
|
||||||
bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], None)
|
bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], None)
|
||||||
LOG.debug(_("pif:%(id)s is unplugged (vif_uuid=%(vif_uuid)s)")
|
LOG.debug(_("pif:%(id)s is unplugged (vif_uuid=%(vif_uuid)s)")
|
||||||
% {'id': pif['id'], 'vif_uuid': vif_uuid})
|
% {'id': pif['id'], 'vif_uuid': vif_uuid})
|
||||||
self._after_unplug(instance, network, mapping, pif)
|
self._after_unplug(instance, vif, pif)
|
||||||
except exception.NovaException:
|
except exception.NovaException:
|
||||||
LOG.warn(_("no pif for vif_uuid=%s") % vif_uuid)
|
LOG.warn(_("no pif for vif_uuid=%s") % vif_uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user