Skip to content

Commit

Permalink
add_upgrade_entry: use get_env instead of os.environ
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Hecko committed Aug 14, 2024
1 parent 8d930d2 commit 215dde8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common.config import architecture
from leapp.libraries.common.config import architecture, get_env
from leapp.libraries.stdlib import api, CalledProcessError, run
from leapp.models import (
BootContent,
Expand All @@ -23,10 +23,10 @@ def collect_boot_args(livemode_enabled):
'plymouth.enable': '0'
}

if os.getenv('LEAPP_DEBUG', '0') == '1':
if get_env('LEAPP_DEBUG', '0') == '1':
args['debug'] = None

if os.getenv('LEAPP_DEVEL_INITRAM_NETWORK') in ('network-manager', 'scripts'):
if get_env('LEAPP_DEVEL_INITRAM_NETWORK') in ('network-manager', 'scripts'):
args['ip'] = 'dhcp'
args['rd.neednet'] = '1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def get_boot_file_paths_mocked():

monkeypatch.setattr(addupgradebootentry, 'get_boot_file_paths', get_boot_file_paths_mocked)
monkeypatch.setattr(api, 'produce', produce_mocked())
monkeypatch.setenv('LEAPP_DEBUG', '1')
monkeypatch.setattr(addupgradebootentry, 'run', run_mocked())
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch))
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch, envars={'LEAPP_DEBUG': '1'}))

addupgradebootentry.add_boot_entry()

Expand All @@ -98,10 +97,10 @@ def get_boot_file_paths_mocked():

monkeypatch.setattr(addupgradebootentry, 'get_boot_file_paths', get_boot_file_paths_mocked)
monkeypatch.setattr(api, 'produce', produce_mocked())
monkeypatch.setenv('LEAPP_DEBUG', '1' if is_leapp_invoked_with_debug else '0')
monkeypatch.setattr(addupgradebootentry, 'run', run_mocked())

monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
monkeypatch.setattr(api, 'current_actor',
CurrentActorMocked(envars={'LEAPP_DEBUG': str(int(is_leapp_invoked_with_debug))}))

addupgradebootentry.add_boot_entry()

Expand All @@ -121,9 +120,8 @@ def get_boot_file_paths_mocked():
return '/abc', '/def'

monkeypatch.setattr(addupgradebootentry, 'get_boot_file_paths', get_boot_file_paths_mocked)
monkeypatch.setenv('LEAPP_DEBUG', '1')
monkeypatch.setattr(addupgradebootentry, 'run', run_mocked())
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(envars={'LEAPP_DEBUG': '1'}))
monkeypatch.setattr(api, 'produce', produce_mocked())

addupgradebootentry.add_boot_entry(CONFIGS)
Expand Down Expand Up @@ -185,10 +183,11 @@ def test_fix_grub_config_error(monkeypatch, error_type, test_file_name):
)
)
def test_collect_boot_args(monkeypatch, is_debug_enabled, network_enablement_type):
monkeypatch.setenv('LEAPP_DEBUG', str(int(is_debug_enabled)))
env_vars = {'LEAPP_DEBUG': str(int(is_debug_enabled))}
if network_enablement_type:
monkeypatch.setenv('LEAPP_DEVEL_INITRAM_NETWORK', network_enablement_type)
env_vars['LEAPP_DEVEL_INITRAM_NETWORK'] = network_enablement_type

monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(envars=env_vars))
monkeypatch.setattr(addupgradebootentry, 'construct_cmdline_args_for_livemode',
lambda *args: {'livemodearg': 'value'})

Expand Down

0 comments on commit 215dde8

Please sign in to comment.