-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Grub on component devices if /boot is on md device
Previously, if /boot was on md device such as RAID consisting of multiple partitions on different drives, the part of Grub residing in the 512 Mb after MBR was only updated for one of the drives. This resulted in broken Grub. Now, Grub is updated on all the component devices of an md array if Grub was already installed on them before the upgrade.
- Loading branch information
1 parent
948c782
commit b37fb06
Showing
9 changed files
with
253 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from leapp.exceptions import StopActorExecution | ||
from leapp.libraries.stdlib import api, CalledProcessError, run | ||
|
||
|
||
def is_mdraid_dev(dev): | ||
""" | ||
Check if a given device is an md (Multiple Device) device | ||
:raises: StopActorExecution in case of error | ||
""" | ||
try: | ||
result = run(['mdadm', '--query', dev]) | ||
except CalledProcessError as err: | ||
api.current_logger().warning( | ||
'Could not check if device is an md device: {}'.format(err) | ||
) | ||
raise StopActorExecution() | ||
return '--detail' in result['stdout'] | ||
|
||
|
||
def get_component_devices(raid_dev): | ||
""" | ||
Get list of component devices in an md (Multiple Device) array | ||
:return: The list of component devices or None in case of error | ||
""" | ||
try: | ||
# using both --verbose and --brief for medium verbosity | ||
result = run(['mdadm', '--detail', '--verbose', '--brief', raid_dev]) | ||
except CalledProcessError as err: | ||
api.current_logger().warning( | ||
'Could not get md array component devices: {}'.format(err) | ||
) | ||
return None | ||
# example output: | ||
# ARRAY /dev/md0 level=raid1 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=c4acea6e:d56e1598:91822e3f:fb26832c # noqa: E501; pylint: disable=line-too-long | ||
# devices=/dev/vda1,/dev/vdb1 | ||
if 'does not appear to be an md device' in result['stdout']: | ||
raise ValueError("Expected md device, but got: {}".format(raid_dev)) | ||
|
||
return result['stdout'].rsplit('=', 2)[-1].strip().split(',') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
repos/system_upgrade/common/libraries/tests/test_mdraid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.libraries.common import mdraid | ||
from leapp.libraries.common.testutils import logger_mocked | ||
from leapp.libraries.stdlib import api, CalledProcessError | ||
|
||
MD_DEVICE = '/dev/md0' | ||
NOT_MD_DEVICE = '/dev/sda' | ||
|
||
CUR_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def raise_call_error(args=None): | ||
raise CalledProcessError( | ||
message='A Leapp Command Error occurred.', | ||
command=args, | ||
result={'signal': None, 'exit_code': 1, 'pid': 0, 'stdout': 'fake', 'stderr': 'fake'} | ||
) | ||
|
||
|
||
class RunMocked(object): | ||
|
||
def __init__(self, raise_err=False): | ||
self.called = 0 | ||
self.args = None | ||
self.raise_err = raise_err | ||
|
||
def __call__(self, args, encoding=None): | ||
self.called += 1 | ||
self.args = args | ||
if self.raise_err: | ||
raise_call_error(args) | ||
|
||
if self.args == ['mdadm', '--query', MD_DEVICE]: | ||
stdout = '/dev/md0: 1022.00MiB raid1 2 devices, 0 spares. Use mdadm --detail for more detail.' | ||
elif self.args == ['mdadm', '--query', NOT_MD_DEVICE]: | ||
stdout = '/dev/sda: is not an md array' | ||
|
||
elif self.args == ['mdadm', '--detail', '--verbose', '--brief', MD_DEVICE]: | ||
stdout = 'ARRAY /dev/md0 level=raid1 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=c4acea6e:d56e1598:91822e3f:fb26832c\n devices=/dev/sda1,/dev/sdb1' # noqa: E501; pylint: disable=line-too-long | ||
elif self.args == ['mdadm', '--detail', '--verbose', '--brief', NOT_MD_DEVICE]: | ||
stdout = 'mdadm: /dev/sda does not appear to be an md device' | ||
|
||
return {'stdout': stdout} | ||
|
||
|
||
@pytest.mark.parametrize('dev,expected', [(MD_DEVICE, True), (NOT_MD_DEVICE, False)]) | ||
def test_is_mdraid_dev(monkeypatch, dev, expected): | ||
run_mocked = RunMocked() | ||
monkeypatch.setattr(mdraid, 'run', run_mocked) | ||
monkeypatch.setattr(api, 'current_logger', logger_mocked()) | ||
|
||
result = mdraid.is_mdraid_dev(dev) | ||
assert mdraid.run.called == 1 | ||
assert expected == result | ||
assert not api.current_logger.warnmsg | ||
|
||
|
||
def test_get_component_devices_ok(monkeypatch): | ||
run_mocked = RunMocked() | ||
monkeypatch.setattr(mdraid, 'run', run_mocked) | ||
monkeypatch.setattr(api, 'current_logger', logger_mocked()) | ||
|
||
result = mdraid.get_component_devices(MD_DEVICE) | ||
assert mdraid.run.called == 1 | ||
assert ['/dev/sda1', '/dev/sdb1'] == result | ||
assert not api.current_logger.warnmsg | ||
|
||
|
||
def test_get_component_devices_not_md_device(monkeypatch): | ||
run_mocked = RunMocked() | ||
monkeypatch.setattr(mdraid, 'run', run_mocked) | ||
|
||
with pytest.raises(ValueError): | ||
mdraid.get_component_devices(NOT_MD_DEVICE) | ||
assert mdraid.run.called == 1 |
Oops, something went wrong.