|
30 | 30 | from six.moves import urllib |
31 | 31 |
|
32 | 32 | from convert2rhel import backup, i18n, pkghandler, utils |
| 33 | +from convert2rhel.redhatrelease import os_release_file |
33 | 34 | from convert2rhel.systeminfo import system_info |
34 | 35 | from convert2rhel.toolopts import tool_opts |
35 | 36 |
|
|
88 | 89 |
|
89 | 90 | _SUBMGR_PKG_REMOVED_IN_CL_85 = "subscription-manager-initial-setup-addon" |
90 | 91 |
|
| 92 | +# Path to the releasever variable file for dnf. |
| 93 | +DNF_RELEASEVER_FILE = "/etc/yum/vars/releasever" |
| 94 | + |
91 | 95 |
|
92 | 96 | class UnregisterError(Exception): |
93 | 97 | """Raised with problems unregistering a system.""" |
@@ -185,7 +189,15 @@ def register_system(): |
185 | 189 | registration_cmd = RegistrationCommand.from_tool_opts(tool_opts) |
186 | 190 |
|
187 | 191 | try: |
| 192 | + # The file /etc/os-release is needed for subscribing the system and is being removed with |
| 193 | + # <system-name>-release package in one of the steps before |
| 194 | + # RHELC-16 |
| 195 | + os_release_file.restore(rollback=False) |
188 | 196 | registration_cmd() |
| 197 | + # Need to remove the file, if it would stay there would be leftover /etc/os-release.rpmorig |
| 198 | + # after conversion |
| 199 | + # RHELC-16 |
| 200 | + os_release_file.remove() |
189 | 201 | loggerinst.info("System registration succeeded.") |
190 | 202 | except KeyboardInterrupt: |
191 | 203 | # When the user hits Control-C to exit, we shouldn't retry |
@@ -446,7 +458,8 @@ def __call__(self): |
446 | 458 | register_server = system_bus.get_object("com.redhat.RHSM1", "/com/redhat/RHSM1/RegisterServer") |
447 | 459 | loggerinst.debug("Starting a private DBus to talk to subscription-manager") |
448 | 460 | address = register_server.Start( |
449 | | - i18n.SUBSCRIPTION_MANAGER_LOCALE, dbus_interface="com.redhat.RHSM1.RegisterServer" |
| 461 | + i18n.SUBSCRIPTION_MANAGER_LOCALE, |
| 462 | + dbus_interface="com.redhat.RHSM1.RegisterServer", |
450 | 463 | ) |
451 | 464 |
|
452 | 465 | try: |
@@ -516,7 +529,10 @@ def __call__(self): |
516 | 529 | finally: |
517 | 530 | # Always shut down the private bus |
518 | 531 | loggerinst.debug("Shutting down private DBus instance") |
519 | | - register_server.Stop(i18n.SUBSCRIPTION_MANAGER_LOCALE, dbus_interface="com.redhat.RHSM1.RegisterServer") |
| 532 | + register_server.Stop( |
| 533 | + i18n.SUBSCRIPTION_MANAGER_LOCALE, |
| 534 | + dbus_interface="com.redhat.RHSM1.RegisterServer", |
| 535 | + ) |
520 | 536 |
|
521 | 537 | def _set_connection_opts_in_config(self): |
522 | 538 | """ |
@@ -767,10 +783,33 @@ def attach_subscription(): |
767 | 783 | def get_avail_subs(): |
768 | 784 | """Get list of all the subscriptions available to the user so they are |
769 | 785 | accessible by index once the user chooses one. |
| 786 | +
|
| 787 | + .. note:: |
| 788 | + Get multiline string holding all the subscriptions available to the |
| 789 | + logged-in user |
770 | 790 | """ |
771 | | - # Get multiline string holding all the subscriptions available to the |
772 | | - # logged-in user |
| 791 | + # With the current changes introduced in PR#627, we needed to remove the |
| 792 | + # non-RHEL packages that contain repofiles before we do any call to |
| 793 | + # subscription-manager, and since we are doing that, this function starts to |
| 794 | + # fail because it doesn't have the package that sets the releasever anymore. |
| 795 | + # For some reason, subscription-manager needs to call libdnf internally to |
| 796 | + # read the repositories on the system, and since libdnf needs to do |
| 797 | + # substitutions on those repofiles, mainly the releasever and any other file |
| 798 | + # placed in /etc/dnf/vars, this command call fails as it cannot replace the |
| 799 | + # releasever variable anymore. |
| 800 | + releaver_created = False |
| 801 | + if system_info.version.major >= 8: |
| 802 | + if not os.path.exists(DNF_RELEASEVER_FILE): |
| 803 | + with open(DNF_RELEASEVER_FILE, "w") as handler: |
| 804 | + handler.write(system_info.original_releasever) |
| 805 | + |
| 806 | + releaver_created = True |
| 807 | + |
773 | 808 | subs_raw, ret_code = utils.run_subprocess(["subscription-manager", "list", "--available"], print_output=False) |
| 809 | + |
| 810 | + if releaver_created: |
| 811 | + os.remove(DNF_RELEASEVER_FILE) |
| 812 | + |
774 | 813 | if ret_code != 0: |
775 | 814 | loggerinst.critical("Unable to get list of available subscriptions:\n%s" % subs_raw) |
776 | 815 | return list(get_sub(subs_raw)) |
@@ -996,7 +1035,12 @@ def _log_rhsm_download_directory_contents(directory, when_message): |
996 | 1035 | pkgs = ["<download directory does not exist>"] |
997 | 1036 | if os.path.isdir(SUBMGR_RPMS_DIR): |
998 | 1037 | pkgs = os.listdir(SUBMGR_RPMS_DIR) |
999 | | - loggerinst.debug("Contents of %s directory %s:\n%s", SUBMGR_RPMS_DIR, when_message, "\n".join(pkgs)) |
| 1038 | + loggerinst.debug( |
| 1039 | + "Contents of %s directory %s:\n%s", |
| 1040 | + SUBMGR_RPMS_DIR, |
| 1041 | + when_message, |
| 1042 | + "\n".join(pkgs), |
| 1043 | + ) |
1000 | 1044 |
|
1001 | 1045 |
|
1002 | 1046 | def exit_on_failed_download(paths): |
@@ -1027,7 +1071,11 @@ def lock_releasever_in_rhel_repositories(): |
1027 | 1071 | "Updating /etc/yum.repos.d/rehat.repo to point to RHEL %s instead of the default latest minor version." |
1028 | 1072 | % system_info.releasever |
1029 | 1073 | ) |
1030 | | - cmd = ["subscription-manager", "release", "--set=%s" % system_info.releasever] |
| 1074 | + cmd = [ |
| 1075 | + "subscription-manager", |
| 1076 | + "release", |
| 1077 | + "--set=%s" % system_info.releasever, |
| 1078 | + ] |
1031 | 1079 |
|
1032 | 1080 | output, ret_code = utils.run_subprocess(cmd, print_output=False) |
1033 | 1081 | if ret_code != 0: |
@@ -1056,7 +1104,9 @@ def update_rhsm_custom_facts(): |
1056 | 1104 |
|
1057 | 1105 | if ret_code != 0: |
1058 | 1106 | loggerinst.warning( |
1059 | | - "Failed to update the RHSM custom facts with return code '%s' and output '%s'.", ret_code, output |
| 1107 | + "Failed to update the RHSM custom facts with return code '%s' and output '%s'.", |
| 1108 | + ret_code, |
| 1109 | + output, |
1060 | 1110 | ) |
1061 | 1111 | else: |
1062 | 1112 | loggerinst.info("RHSM custom facts uploaded successfully.") |
|
0 commit comments