Skip to content

Commit 5352dd9

Browse files
Daniel WatkinsServer Team CI Bot
authored andcommitted
helpers/openstack: Treat unknown link types as physical
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
1 parent edf052c commit 5352dd9

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

cloudinit/sources/helpers/openstack.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
OS_ROCKY,
6868
)
6969

70-
PHYSICAL_TYPES = (
70+
KNOWN_PHYSICAL_TYPES = (
7171
None,
7272
'bgpovs', # not present in OpenStack upstream but used on OVH cloud.
7373
'bridge',
@@ -600,9 +600,7 @@ def convert_net_json(network_json=None, known_macs=None):
600600
subnet['ipv6'] = True
601601
subnets.append(subnet)
602602
cfg.update({'subnets': subnets})
603-
if link['type'] in PHYSICAL_TYPES:
604-
cfg.update({'type': 'physical', 'mac_address': link_mac_addr})
605-
elif link['type'] in ['bond']:
603+
if link['type'] in ['bond']:
606604
params = {}
607605
if link_mac_addr:
608606
params['mac_address'] = link_mac_addr
@@ -641,8 +639,10 @@ def convert_net_json(network_json=None, known_macs=None):
641639
curinfo.update({'mac': link['vlan_mac_address'],
642640
'name': name})
643641
else:
644-
raise ValueError(
645-
'Unknown network_data link type: %s' % link['type'])
642+
if link['type'] not in KNOWN_PHYSICAL_TYPES:
643+
LOG.warning('Unknown network_data link type (%s); treating as'
644+
' physical', link['type'])
645+
cfg.update({'type': 'physical', 'mac_address': link_mac_addr})
646646

647647
config.append(cfg)
648648
link_id_info[curinfo['id']] = curinfo

tests/unittests/test_datasource/test_configdrive.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ def test_network_config_conversions(self):
600600

601601

602602
class TestConvertNetworkData(CiTestCase):
603+
604+
with_logs = True
605+
603606
def setUp(self):
604607
super(TestConvertNetworkData, self).setUp()
605608
self.tmp = self.tmp_dir()
@@ -726,6 +729,26 @@ def test_mac_addrs_can_be_upper_case(self):
726729
'enp0s2': 'fa:16:3e:d4:57:ad'}
727730
self.assertEqual(expected, config_name2mac)
728731

732+
def test_unknown_device_types_accepted(self):
733+
# If we don't recognise a link, we should treat it as physical for a
734+
# best-effort boot
735+
my_netdata = deepcopy(NETWORK_DATA)
736+
my_netdata['links'][0]['type'] = 'my-special-link-type'
737+
738+
ncfg = openstack.convert_net_json(my_netdata, known_macs=KNOWN_MACS)
739+
config_name2mac = {}
740+
for n in ncfg['config']:
741+
if n['type'] == 'physical':
742+
config_name2mac[n['name']] = n['mac_address']
743+
744+
expected = {'nic0': 'fa:16:3e:05:30:fe', 'enp0s1': 'fa:16:3e:69:b0:58',
745+
'enp0s2': 'fa:16:3e:d4:57:ad'}
746+
self.assertEqual(expected, config_name2mac)
747+
748+
# We should, however, warn the user that we don't recognise the type
749+
self.assertIn('Unknown network_data link type (my-special-link-type)',
750+
self.logs.getvalue())
751+
729752

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

0 commit comments

Comments
 (0)