Skip to content

Commit

Permalink
helpers/openstack: Treat unknown link types as physical
Browse files Browse the repository at this point in the history
Some deployments of OpenStack expose link types to the guest which
cloud-init doesn't recognise. These will almost always be physical, so
we can operate more robustly if we assume that they are (whilst warning
the user that we're seeing something unexpected).

LP: #1639263
  • Loading branch information
Daniel Watkins authored and Server Team CI Bot committed Mar 4, 2019
1 parent edf052c commit 5352dd9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cloudinit/sources/helpers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
OS_ROCKY,
)

PHYSICAL_TYPES = (
KNOWN_PHYSICAL_TYPES = (
None,
'bgpovs', # not present in OpenStack upstream but used on OVH cloud.
'bridge',
Expand Down Expand Up @@ -600,9 +600,7 @@ def convert_net_json(network_json=None, known_macs=None):
subnet['ipv6'] = True
subnets.append(subnet)
cfg.update({'subnets': subnets})
if link['type'] in PHYSICAL_TYPES:
cfg.update({'type': 'physical', 'mac_address': link_mac_addr})
elif link['type'] in ['bond']:
if link['type'] in ['bond']:
params = {}
if link_mac_addr:
params['mac_address'] = link_mac_addr
Expand Down Expand Up @@ -641,8 +639,10 @@ def convert_net_json(network_json=None, known_macs=None):
curinfo.update({'mac': link['vlan_mac_address'],
'name': name})
else:
raise ValueError(
'Unknown network_data link type: %s' % link['type'])
if link['type'] not in KNOWN_PHYSICAL_TYPES:
LOG.warning('Unknown network_data link type (%s); treating as'
' physical', link['type'])
cfg.update({'type': 'physical', 'mac_address': link_mac_addr})

config.append(cfg)
link_id_info[curinfo['id']] = curinfo
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/test_datasource/test_configdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ def test_network_config_conversions(self):


class TestConvertNetworkData(CiTestCase):

with_logs = True

def setUp(self):
super(TestConvertNetworkData, self).setUp()
self.tmp = self.tmp_dir()
Expand Down Expand Up @@ -726,6 +729,26 @@ def test_mac_addrs_can_be_upper_case(self):
'enp0s2': 'fa:16:3e:d4:57:ad'}
self.assertEqual(expected, config_name2mac)

def test_unknown_device_types_accepted(self):
# If we don't recognise a link, we should treat it as physical for a
# best-effort boot
my_netdata = deepcopy(NETWORK_DATA)
my_netdata['links'][0]['type'] = 'my-special-link-type'

ncfg = openstack.convert_net_json(my_netdata, known_macs=KNOWN_MACS)
config_name2mac = {}
for n in ncfg['config']:
if n['type'] == 'physical':
config_name2mac[n['name']] = n['mac_address']

expected = {'nic0': 'fa:16:3e:05:30:fe', 'enp0s1': 'fa:16:3e:69:b0:58',
'enp0s2': 'fa:16:3e:d4:57:ad'}
self.assertEqual(expected, config_name2mac)

# We should, however, warn the user that we don't recognise the type
self.assertIn('Unknown network_data link type (my-special-link-type)',
self.logs.getvalue())


def cfg_ds_from_dir(base_d, files=None):
run = os.path.join(base_d, "run")
Expand Down

0 comments on commit 5352dd9

Please sign in to comment.