Skip to content

Commit 2612e1d

Browse files
author
mhecko
committed
tests: fix instantiation of the BootContent model missing hmac
1 parent c092cb2 commit 2612e1d

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

repos/system_upgrade/common/actors/addupgradebootentry/libraries/addupgradebootentry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def get_boot_file_paths():
8888
raise StopActorExecutionError('Could not create a GRUB boot entry for the upgrade initramfs',
8989
details={'details': 'Did not receive a message about the leapp-provided'
9090
'kernel and initramfs'})
91+
# Returning information about kernel hmac file path is needless as it is not used when adding boot entry
9192
return boot_content.kernel_path, boot_content.initram_path
9293

9394

repos/system_upgrade/common/actors/addupgradebootentry/tests/unit_test_addupgradebootentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get_boot_file_paths_mocked():
135135
def test_get_boot_file_paths(monkeypatch):
136136
# BootContent message available
137137
def consume_message_mocked(*models):
138-
yield BootContent(kernel_path='/ghi', initram_path='/jkl')
138+
yield BootContent(kernel_path='/ghi', initram_path='/jkl', kernel_hmac_path='/path')
139139

140140
monkeypatch.setattr('leapp.libraries.stdlib.api.consume', consume_message_mocked)
141141

repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/tests/unit_test_upgradeinitramfsgenerator.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,24 @@ def error(self, *args, **dummy):
132132

133133

134134
@pytest.mark.parametrize('arch', architecture.ARCH_SUPPORTED)
135-
@pytest.mark.parametrize('is_fips_enabled', (True, False))
136135
def test_copy_boot_files(monkeypatch, arch, is_fips_enabled):
137136
kernel = 'vmlinuz-upgrade.{}'.format(arch)
137+
kernel_hmac = 'vmlinuz-upgrade.{}.hmac'.format(arch)
138138
initram = 'initramfs-upgrade.{}.img'.format(arch)
139139
bootc = BootContent(
140140
kernel_path=os.path.join('/boot', kernel),
141+
kernel_hmac_path=os.path.join('/boot', kernel_hmac),
141142
initram_path=os.path.join('/boot', initram)
142143
)
143144

144-
kernel_hmac = '.vmlinuz-upgrade.{0}.hmac'.format(arch)
145-
if is_fips_enabled:
146-
bootc.kernel_hmac_path = os.path.join('/boot', kernel_hmac)
147-
148145
context = MockedContext()
149-
150-
fips_info = FIPSInfo(is_enabled=is_fips_enabled)
151-
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'current_actor', CurrentActorMocked(arch=arch,
152-
msgs=[fips_info]))
146+
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'current_actor', CurrentActorMocked(arch=arch))
153147
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'produce', produce_mocked())
154148

155149
def create_upgrade_hmac_from_target_hmac_mock(original_hmac_path, upgrade_hmac_path, upgrade_kernel):
156-
assert is_fips_enabled, 'The hmac for upgrade kernel should be created only when fips is enabled.'
157150
hmac_file = '.{}.hmac'.format(upgrade_kernel)
158151
assert original_hmac_path == os.path.join(context.full_path('/artifacts'), hmac_file)
159-
assert upgrade_hmac_path == os.path.join('/boot/', hmac_file)
152+
assert upgrade_hmac_path == bootc.kernel_hmac_path
160153

161154
monkeypatch.setattr(upgradeinitramfsgenerator,
162155
'create_upgrade_hmac_from_target_hmac',

repos/system_upgrade/common/actors/removebootfiles/tests/unit_test_removebootfiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def __call__(self, filename):
2020
def test_remove_boot_files(monkeypatch):
2121
# BootContent message available
2222
def consume_message_mocked(*models):
23-
yield BootContent(kernel_path='/abc', initram_path='/def')
23+
yield BootContent(kernel_path='/abc', initram_path='/def', kernel_hmac_path='/ghi')
2424

2525
monkeypatch.setattr('leapp.libraries.stdlib.api.consume', consume_message_mocked)
2626
monkeypatch.setattr(removebootfiles, 'remove_file', remove_file_mocked())
2727

2828
removebootfiles.remove_boot_files()
2929

30-
assert removebootfiles.remove_file.files_to_remove == ['/abc', '/def']
30+
assert removebootfiles.remove_file.files_to_remove == ['/abc', '/def', '/ghi']
3131

3232
# No BootContent message available
3333
def consume_no_message_mocked(*models):

repos/system_upgrade/common/actors/removeupgradebootentry/tests/unit_test_removeupgradebootentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def consume_systemfacts_mocked(*models):
5050
def test_get_upgrade_kernel_filepath(monkeypatch):
5151
# BootContent message available
5252
def consume_message_mocked(*models):
53-
yield BootContent(kernel_path='/abc', initram_path='/def')
53+
yield BootContent(kernel_path='/abc', initram_path='/def', kernel_hmac_path='/ghi')
5454

5555
monkeypatch.setattr(api, 'consume', consume_message_mocked)
5656

0 commit comments

Comments
 (0)