From ac6c84a78bd96dedafa1c9c96c1ade06831eef8c Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 9 Dec 2020 11:37:43 +1300 Subject: [PATCH] check udev data directly when processing match: specs also allow matching on ID_VENDOR --- subiquity/models/filesystem.py | 20 ++++++++++++++------ subiquity/models/tests/test_filesystem.py | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index a6e6898f..8c45d235 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -1378,17 +1378,23 @@ class FilesystemModel(object): def _make_matchers(self, match): matchers = [] + def _udev_val(disk, key): + return self._probe_data['blockdev'].get(disk.path, {}).get(key, '') + def match_serial(disk): - if disk.serial is not None: - return fnmatch.fnmatchcase(disk.serial, match['serial']) + return fnmatch.fnmatchcase( + _udev_val(disk, "ID_SERIAL"), match['serial']) def match_model(disk): - if disk.model is not None: - return fnmatch.fnmatchcase(disk.model, match['model']) + return fnmatch.fnmatchcase( + _udev_val(disk, "ID_MODEL"), match['model']) + + def match_vendor(disk): + return fnmatch.fnmatchcase( + _udev_val(disk, "ID_VENDOR"), match['vendor']) def match_path(disk): - if disk.path is not None: - return fnmatch.fnmatchcase(disk.path, match['path']) + return fnmatch.fnmatchcase(disk.path, match['path']) def match_ssd(disk): is_ssd = disk.info_for_display()['rotational'] == 'false' @@ -1398,6 +1404,8 @@ class FilesystemModel(object): matchers.append(match_serial) if 'model' in match: matchers.append(match_model) + if 'vendor' in match: + matchers.append(match_vendor) if 'path' in match: matchers.append(match_path) if 'ssd' in match: diff --git a/subiquity/models/tests/test_filesystem.py b/subiquity/models/tests/test_filesystem.py index 7bc67220..7af1676d 100644 --- a/subiquity/models/tests/test_filesystem.py +++ b/subiquity/models/tests/test_filesystem.py @@ -145,7 +145,7 @@ def make_disk(fs_model, **kw): if 'serial' not in kw: kw['serial'] = 'serial%s' % len(fs_model._actions) if 'path' not in kw: - kw['path'] = '/dev/thing' + kw['path'] = '/dev/thing%s' % len(fs_model._actions) if 'ptable' not in kw: kw['ptable'] = 'gpt' size = kw.pop('size', 100*(2**30)) @@ -856,6 +856,8 @@ def fake_up_blockdata(model): for disk in model.all_disks(): bd[disk.path] = { 'DEVTYPE': 'disk', + 'ID_SERIAL': disk.serial, + 'ID_MODEL': disk.model, 'attrs': { 'size': disk.size, },