Skip to content

Commit

Permalink
Enabling default RHSM convert2rhel repos (#118)
Browse files Browse the repository at this point in the history
Even with a list of specified custom repositories set during UI run, we
will add the default RHSM repositories that comes from convert2rhel
config.
  • Loading branch information
r0x0d authored Sep 24, 2024
1 parent f9757ed commit 6ac5644
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 35 deletions.
30 changes: 21 additions & 9 deletions convert2rhel_insights_tasks/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import copy
import json
import logging
import os
import re
import shutil
import subprocess
import copy
import sys
from time import gmtime, strftime

from urllib2 import urlopen, URLError
from urllib2 import URLError, urlopen

# SCRIPT_TYPE is either 'CONVERSION' or 'ANALYSIS'
# Value is set in signed yaml envelope in content_vars (SCRIPT_MODE)
Expand Down Expand Up @@ -63,6 +63,9 @@
"conversion" if IS_CONVERSION else "analysis"
)

DEFAULT_RHSM_CONVERT2RHEL_REPOS = "rhel-7-server-rpms"
DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS = "rhel-7-server-els-rpms"

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -511,7 +514,7 @@ def generate_report_message(highest_status):
conversion_succes_msg = (
"No problems found. The system was converted successfully. Please,"
" reboot your system at your earliest convenience to make sure that"
" the system is using the RHEL kernel."
" the system is using the RHEL Kernel."
)

if STATUS_CODE[highest_status] < STATUS_CODE["WARNING"]:
Expand Down Expand Up @@ -695,26 +698,35 @@ def run_convert2rhel(env):

command.append("-y")

repositories = []

# This will always be represented as either false/true, since this option
# comes from the input parameters through Insights UI.
els_disabled = json.loads(env.pop("ELS_DISABLED", "false").lower())
if not bool(els_disabled):
command.append("--els")
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS)
else:
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_REPOS)

optional_repositories = env.pop("OPTIONAL_REPOSITORIES", None)
# The `None` value that comes from the playbook gets converted to "None"
# when we parse it from the environment variable, to not mess with casting
# and converting, the easiest option is to check against that value for
# now.
# TODO(r0x0d): The ideal solution here would be coming with a pre-defined
# dictionary of values that have the correct values and types. Maybe for
# the future.
optional_repositories = env.pop("OPTIONAL_REPOSITORIES", [])
if optional_repositories and optional_repositories != "None":
repositories = optional_repositories.split(",")
repositories = [
"--enablerepo=%s" % repository.strip() for repository in repositories
]
command.extend(repositories)
enablerepo_cmd = []
repositories.extend(optional_repositories.split(","))
# Normalize the values removing whitespace. This is important for turning them into a set.
repositories = [repository.strip() for repository in repositories]
for repository in set(repositories):
enablerepo_cmd.append("--enablerepo")
enablerepo_cmd.append(repository)

command.extend(enablerepo_cmd)

env = prepare_environment_variables(env)
output, returncode = run_subprocess(command, env=env)
Expand Down
28 changes: 20 additions & 8 deletions playbooks/convert-to-rhel-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
insights_signature_exclude: /vars/insights_signature,/vars/content_vars
interpreter: /usr/bin/python2
content: |
import copy
import json
import logging
import os
import re
import shutil
import subprocess
import copy
import sys
from time import gmtime, strftime
from urllib2 import urlopen, URLError
from urllib2 import URLError, urlopen
# SCRIPT_TYPE is either 'CONVERSION' or 'ANALYSIS'
# Value is set in signed yaml envelope in content_vars (SCRIPT_MODE)
Expand Down Expand Up @@ -72,6 +72,9 @@
"conversion" if IS_CONVERSION else "analysis"
)
DEFAULT_RHSM_CONVERT2RHEL_REPOS = "rhel-7-server-rpms"
DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS = "rhel-7-server-els-rpms"
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -704,26 +707,35 @@
command.append("-y")
repositories = []
# This will always be represented as either false/true, since this option
# comes from the input parameters through Insights UI.
els_disabled = json.loads(env.pop("ELS_DISABLED", "false").lower())
if not bool(els_disabled):
command.append("--els")
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS)
else:
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_REPOS)
optional_repositories = env.pop("OPTIONAL_REPOSITORIES", None)
# The `None` value that comes from the playbook gets converted to "None"
# when we parse it from the environment variable, to not mess with casting
# and converting, the easiest option is to check against that value for
# now.
# TODO(r0x0d): The ideal solution here would be coming with a pre-defined
# dictionary of values that have the correct values and types. Maybe for
# the future.
optional_repositories = env.pop("OPTIONAL_REPOSITORIES", [])
if optional_repositories and optional_repositories != "None":
repositories = optional_repositories.split(",")
repositories = [
"--enablerepo=%s" % repository.strip() for repository in repositories
]
command.extend(repositories)
enablerepo_cmd = []
repositories.extend(optional_repositories.split(","))
# Normalize the values removing whitespace. This is important for turning them into a set.
repositories = [repository.strip() for repository in repositories]
for repository in set(repositories):
enablerepo_cmd.append("--enablerepo")
enablerepo_cmd.append(repository)
command.extend(enablerepo_cmd)
env = prepare_environment_variables(env)
output, returncode = run_subprocess(command, env=env)
Expand Down
28 changes: 20 additions & 8 deletions playbooks/convert-to-rhel-conversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
insights_signature_exclude: /vars/insights_signature,/vars/content_vars
interpreter: /usr/bin/python2
content: |
import copy
import json
import logging
import os
import re
import shutil
import subprocess
import copy
import sys
from time import gmtime, strftime
from urllib2 import urlopen, URLError
from urllib2 import URLError, urlopen
# SCRIPT_TYPE is either 'CONVERSION' or 'ANALYSIS'
# Value is set in signed yaml envelope in content_vars (SCRIPT_MODE)
Expand Down Expand Up @@ -72,6 +72,9 @@
"conversion" if IS_CONVERSION else "analysis"
)
DEFAULT_RHSM_CONVERT2RHEL_REPOS = "rhel-7-server-rpms"
DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS = "rhel-7-server-els-rpms"
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -704,26 +707,35 @@
command.append("-y")
repositories = []
# This will always be represented as either false/true, since this option
# comes from the input parameters through Insights UI.
els_disabled = json.loads(env.pop("ELS_DISABLED", "false").lower())
if not bool(els_disabled):
command.append("--els")
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_ELS_REPOS)
else:
repositories.append(DEFAULT_RHSM_CONVERT2RHEL_REPOS)
optional_repositories = env.pop("OPTIONAL_REPOSITORIES", None)
# The `None` value that comes from the playbook gets converted to "None"
# when we parse it from the environment variable, to not mess with casting
# and converting, the easiest option is to check against that value for
# now.
# TODO(r0x0d): The ideal solution here would be coming with a pre-defined
# dictionary of values that have the correct values and types. Maybe for
# the future.
optional_repositories = env.pop("OPTIONAL_REPOSITORIES", [])
if optional_repositories and optional_repositories != "None":
repositories = optional_repositories.split(",")
repositories = [
"--enablerepo=%s" % repository.strip() for repository in repositories
]
command.extend(repositories)
enablerepo_cmd = []
repositories.extend(optional_repositories.split(","))
# Normalize the values removing whitespace. This is important for turning them into a set.
repositories = [repository.strip() for repository in repositories]
for repository in set(repositories):
enablerepo_cmd.append("--enablerepo")
enablerepo_cmd.append(repository)
command.extend(enablerepo_cmd)
env = prepare_environment_variables(env)
output, returncode = run_subprocess(command, env=env)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_generate_report_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(
"No problems found. The system was converted successfully. Please,"
" reboot your system at your earliest convenience to make sure that"
" the system is using the RHEL kernel."
" the system is using the RHEL Kernel."
),
False,
),
Expand All @@ -21,7 +21,7 @@
(
"No problems found. The system was converted successfully. Please,"
" reboot your system at your earliest convenience to make sure that"
" the system is using the RHEL kernel."
" the system is using the RHEL Kernel."
),
False,
),
Expand All @@ -30,7 +30,7 @@
(
"No problems found. The system was converted successfully. Please,"
" reboot your system at your earliest convenience to make sure that"
" the system is using the RHEL kernel."
" the system is using the RHEL Kernel."
),
False,
),
Expand Down
44 changes: 37 additions & 7 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from mock import patch

from convert2rhel_insights_tasks import main
Expand Down Expand Up @@ -80,7 +79,10 @@ def test_run_convert2rhel_analysis(monkeypatch):
"analyze",
"-y",
"--els",
"--enablerepo=rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-els-rpms",
],
),
(
Expand All @@ -92,8 +94,12 @@ def test_run_convert2rhel_analysis(monkeypatch):
"analyze",
"-y",
"--els",
"--enablerepo=rhel-7-server-rpm",
"--enablerepo=rhel-7-server-rpm-extras",
"--enablerepo",
"rhel-7-server-rpm-extras",
"--enablerepo",
"rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-els-rpms",
],
),
# Make sure that this also pass for conversion
Expand All @@ -109,7 +115,10 @@ def test_run_convert2rhel_analysis(monkeypatch):
"/usr/bin/convert2rhel",
"-y",
"--els",
"--enablerepo=rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-els-rpms",
],
),
(
Expand All @@ -120,8 +129,29 @@ def test_run_convert2rhel_analysis(monkeypatch):
"/usr/bin/convert2rhel",
"-y",
"--els",
"--enablerepo=rhel-7-server-rpm",
"--enablerepo=rhel-7-server-rpm-extras",
"--enablerepo",
"rhel-7-server-rpm-extras",
"--enablerepo",
"rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-els-rpms",
],
),
# Make sure we don't have duplicates
(
False,
"False",
"rhel-7-server-rpm, rhel-7-server-rpm, rhel-7-server-rpm-extras",
[
"/usr/bin/convert2rhel",
"-y",
"--els",
"--enablerepo",
"rhel-7-server-rpm-extras",
"--enablerepo",
"rhel-7-server-rpm",
"--enablerepo",
"rhel-7-server-els-rpms",
],
),
),
Expand Down

0 comments on commit 6ac5644

Please sign in to comment.