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.
This commit is contained in:
parent
f40626d3c0
commit
24278cb8cc
@ -68,13 +68,30 @@ class DataSourceConfigDrive(sources.DataSource):
|
|||||||
def _os_name_to_device(self, name):
|
def _os_name_to_device(self, name):
|
||||||
device = None
|
device = None
|
||||||
try:
|
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:
|
if dev_entries:
|
||||||
device = dev_entries[0]
|
device = dev_entries[0]
|
||||||
except util.ProcessExecutionError:
|
except util.ProcessExecutionError:
|
||||||
pass
|
pass
|
||||||
return device
|
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):
|
def device_name_to_device(self, name):
|
||||||
# Translate a 'name' to a 'physical' device
|
# Translate a 'name' to a 'physical' device
|
||||||
if not name:
|
if not name:
|
||||||
@ -86,31 +103,26 @@ class DataSourceConfigDrive(sources.DataSource):
|
|||||||
if name == 'ami':
|
if name == 'ami':
|
||||||
names.append('root')
|
names.append('root')
|
||||||
device = None
|
device = None
|
||||||
|
LOG.debug("Using ec2 metadata lookup to find device %s", names)
|
||||||
for n in names:
|
for n in names:
|
||||||
device = self._ec2_name_to_device(n)
|
device = self._ec2_name_to_device(n)
|
||||||
|
device = self._validate_device_name(device)
|
||||||
if device:
|
if device:
|
||||||
break
|
break
|
||||||
# Try the openstack way second
|
# Try the openstack way second
|
||||||
if not device:
|
if not device:
|
||||||
|
LOG.debug("Using os lookup to find device %s", names)
|
||||||
for n in names:
|
for n in names:
|
||||||
device = self._os_name_to_device(n)
|
device = self._os_name_to_device(n)
|
||||||
|
device = self._validate_device_name(device)
|
||||||
if device:
|
if device:
|
||||||
break
|
break
|
||||||
# Ok give up...
|
# Ok give up...
|
||||||
if not device:
|
if not device:
|
||||||
return None
|
return None
|
||||||
# Ensure translated ok
|
else:
|
||||||
if not device.startswith("/"):
|
LOG.debug("Using cfg drive lookup mapped to device %s", device)
|
||||||
device = "/dev/%s" % device
|
|
||||||
if os.path.exists(device):
|
|
||||||
return 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):
|
def get_data(self):
|
||||||
found = None
|
found = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user