From f510d8f5762f3c9d27afcc57f63d7614ec6c05cd Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 5 Oct 2012 15:43:54 -0700 Subject: Add checks around the device names that are found to ensure that even if they are found that they are also valid, before they are assumed to be the correct device name. --- cloudinit/sources/DataSourceConfigDrive.py | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py index eebe44ec..4af2e5ae 100644 --- a/cloudinit/sources/DataSourceConfigDrive.py +++ b/cloudinit/sources/DataSourceConfigDrive.py @@ -68,13 +68,30 @@ class DataSourceConfigDrive(sources.DataSource): def _os_name_to_device(self, name): device = None try: - dev_entries = util.find_devs_with('LABEL=%s' % (name)) + criteria = 'LABEL=%s' % (name) + if name in ['swap']: + criteria = 'TYPE=%s' % (name) + dev_entries = util.find_devs_with(criteria) if dev_entries: device = dev_entries[0] except util.ProcessExecutionError: pass return device + def _validate_device_name(self, device): + if not device: + return None + if not device.startswith("/"): + device = "/dev/%s" % device + if os.path.exists(device): + return device + # Durn, try adjusting the mapping + remapped = self._remap_device(os.path.basename(device)) + if remapped: + LOG.debug("Remapped device name %s => %s", device, remapped) + return remapped + return None + def device_name_to_device(self, name): # Translate a 'name' to a 'physical' device if not name: @@ -86,31 +103,26 @@ class DataSourceConfigDrive(sources.DataSource): if name == 'ami': names.append('root') device = None + LOG.debug("Using ec2 metadata lookup to find device %s", names) for n in names: device = self._ec2_name_to_device(n) + device = self._validate_device_name(device) if device: break # Try the openstack way second if not device: + LOG.debug("Using os lookup to find device %s", names) for n in names: device = self._os_name_to_device(n) + device = self._validate_device_name(device) if device: break # Ok give up... if not device: return None - # Ensure translated ok - if not device.startswith("/"): - device = "/dev/%s" % device - if os.path.exists(device): + else: + LOG.debug("Using cfg drive lookup mapped to device %s", device) return device - # Durn, try adjusting the mapping - remapped = self._remap_device(os.path.basename(device)) - if remapped: - LOG.debug("Remapped device name %s => %s", device, remapped) - return remapped - # Really give up now - return None def get_data(self): found = None -- cgit v1.2.3