Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #25908: Allow passing env vars to package managers #1436

Draft
wants to merge 1 commit into
base: branches/rudder/8.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tree/10_ncf_internals/modules/packages/apt_get
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,17 @@ def package_arguments_builder(is_apt_install):

elif line.startswith("options="):
global apt_get_options
option = line.split("=", 1)[1].rstrip()
option = line.split("=", 1)[1].rstrip()
if option:
apt_get_options.append(option)
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
else:
apt_get_options.append(option)

if name:
args.extend(one_package_argument(name, arch, version, is_apt_install))
Expand Down
14 changes: 14 additions & 0 deletions tree/10_ncf_internals/modules/packages/yum
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def list_updates(online):
yum_options.append(option)
elif option.startswith("enablerepo=") or option.startswith("disablerepo="):
yum_options.append("--" + option)
elif option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value

online_flag = []
if not online:
Expand Down Expand Up @@ -237,6 +244,13 @@ def package_arguments_builder(is_yum_install):
yum_options.append(option)
elif option.startswith("enablerepo=") or option.startswith("disablerepo="):
yum_options.append("--" + option)
elif option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
if line.startswith("Name="):
if name:
# Each new "Name=" triggers a new entry.
Expand Down
14 changes: 14 additions & 0 deletions tree/10_ncf_internals/modules/packages/zypper
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ def package_arguments_builder(is_zypper_install):
elif line.startswith("Architecture="):
arch = line.split("=", 1)[1].rstrip()

elif line.startswith("options="):
global zypper_options
option = line.split("=", 1)[1].rstrip()
if option:
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
else:
zypper_options.append(option)

if name:
single_list, multi_list = one_package_argument(name, arch, version, is_zypper_install)
single_cmd_args += single_list
Expand Down
16 changes: 14 additions & 2 deletions tree/10_ncf_internals/modules/packages/zypper_pattern
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,20 @@ def construct_complete_package_names():
version = "=" + line.split("=", 1)[1].rstrip()
if (flag == 'Architecture'):
architecture = "." + line.split("=", 1)[1].rstrip()
if (flag == 'Options'):
pass
if (flag == 'options'):
global zypper_options
option = line.split("=", 1)[1].rstrip()
if option:
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
else:
zypper_options.append(option)

complete_names.append(pattern + architecture + version)
return complete_names

Expand Down