Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
OddBloke authored Jun 1, 2020
1 parent 0fdad32 commit 51b34ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cloudinit/config/cc_grub_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fetch_idevs(log):
# grub-common may not be installed, especially on containers
# FileNotFoundError is a nested exception of ProcessExecutionError
if isinstance(e.reason, FileNotFoundError):
log.debug("grub-common is not installed, e.g. inside a container")
log.debug("'grub-probe' not found in $PATH")
# disks from the container host are present in /proc and /sys
# which is where grub-probe determines where /boot is.
# it then checks for existence in /dev, which fails as host disks
Expand All @@ -81,12 +81,12 @@ def fetch_idevs(log):

try:
# check if disk exists and use udevadm to fetch symlinks
if os.path.exists(disk):
devices = util.subp(['udevadm', 'info', '-r',
if disk and os.path.exists(disk):
devices = util.subp(['udevadm', 'info', '--root',
'--query=symlink', disk],
capture=True)[0].strip().split()
except Exception:
util.logexc(log, "udevadm failed to gather devices for grub-dpkg")
util.logexc(log, "udevadm DEVLINKS symlink query failed for disk='%s'", disk)

# filter symlinks for /dev/disk/by-id entries
devices = [dev for dev in devices if 'disk/by-id' in dev]
Expand Down
6 changes: 1 addition & 5 deletions cloudinit/config/tests/test_grub_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,8 @@ def test_handle(self, m_subp, m_logexc, m_get_cfg_str, m_fetch_idevs,
cfg_idevs_empty
]
m_fetch_idevs.return_value = fetch_idevs_output
name = mock.Mock()
cfg = mock.Mock()
_cloud = mock.Mock()
log = mock.Mock(spec=Logger)
_args = mock.Mock()
handle(name, cfg, _cloud, log, _args)
handle(mock.Mock(), mock.Mock(), mock.Mock(), log, mock.Mock())
log.debug.assert_called_with("".join(expected_log_output))


Expand Down

0 comments on commit 51b34ba

Please sign in to comment.