Ejemplo n.º 1
0
import logging
import os
import re
import rpm

from convert2rhel.systeminfo import system_info
from convert2rhel import utils
from convert2rhel import pkgmanager
from convert2rhel.toolopts import tool_opts

# Limit the number of loops over yum command calls for the case there was
# an error.
MAX_YUM_CMD_CALLS = 2

_VERSIONLOCK_FILE_PATH = '/etc/yum/pluginconf.d/versionlock.list'  # This file is used by the dnf plugin as well
versionlock_file = utils.RestorableFile(_VERSIONLOCK_FILE_PATH)  # pylint: disable=C0103


class PkgWFingerprint(object):
    """Tuple-like storage for a package object and a fingerprint with which the package was signed."""

    def __init__(self, pkg_obj, fingerprint):
        self.pkg_obj = pkg_obj
        self.fingerprint = fingerprint


def call_yum_cmd_w_downgrades(cmd, fingerprints):
    """Calling yum command is prone to end up with an error due to unresolved
    dependencies, especially when it tries to downgrade pkgs. This function
    tries to resolve the dependency errors where yum is not able to.
    """
Ejemplo n.º 2
0
        self.loggerinst.debug("%s patched." % self._yum_conf_path)
        return

    def _insert_distroverpkg_tag(self):
        if "distroverpkg=" not in self._yum_conf_content:
            self._yum_conf_content = sub(
                r"(\[main\].*)", r"\1\ndistroverpkg=%s" %
                get_release_pkg_name(),
                self._yum_conf_content)
        else:
            self._yum_conf_content = sub(
                r"(distroverpkg=).*",
                r"\1%s" % get_release_pkg_name(),
                self._yum_conf_content)

    def _write_altered_yum_conf(self):
        file_to_write = open(self._yum_conf_path, 'w')
        try:
            file_to_write.write(self._yum_conf_content)
        finally:
            file_to_write.close()

    @staticmethod
    def get_yum_conf_filepath():
        return YumConf._yum_conf_path


# Code to be executed upon module import
system_release_file = utils.RestorableFile(get_system_release_filepath())
yum_conf = utils.RestorableFile(YumConf.get_yum_conf_filepath())
Ejemplo n.º 3
0
    def patch(self):
        """Comment out the distroverpkg variable in yum.conf so yum can determine
        release version ($releasever) based on the installed redhat-release
        package.
        """
        self._comment_out_distroverpkg_tag()
        self._write_altered_yum_conf()
        self.loggerinst.debug("%s patched." % self._yum_conf_path)
        return

    def _comment_out_distroverpkg_tag(self):
        if re.search(r'^distroverpkg=', self._yum_conf_content, re.MULTILINE):
            self._yum_conf_content = re.sub(r"\n(distroverpkg=).*", r"\n#\1",
                                            self._yum_conf_content)

    def _write_altered_yum_conf(self):
        file_to_write = open(self._yum_conf_path, 'w')
        try:
            file_to_write.write(self._yum_conf_content)
        finally:
            file_to_write.close()

    @staticmethod
    def get_yum_conf_filepath():
        return YumConf._yum_conf_path


# Code to be executed upon module import
system_release_file = utils.RestorableFile(get_system_release_filepath())  # pylint: disable=C0103
yum_conf = utils.RestorableFile(YumConf.get_yum_conf_filepath())  # pylint: disable=C0103
Ejemplo n.º 4
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import os
import re
import shutil
import logging

from convert2rhel.toolopts import tool_opts
from convert2rhel import utils

_RHN_REGISTRATION_FILE = "/etc/sysconfig/rhn/systemid"
rhn_reg_file = utils.RestorableFile(_RHN_REGISTRATION_FILE)  # pylint: disable=C0103


def unregister_from_rhn_classic():
    loggerinst = logging.getLogger(__name__)
    if os.path.isfile(_RHN_REGISTRATION_FILE):
        loggerinst.warning("The use of RHN Classic is not allowed during the conversion.\n"
                           "The convert2rhel is going to unregister from RHN Classic.\n"
                           "See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/installation_guide/unregister-rhn for details.")
        utils.ask_to_continue()
        rhn_reg_file.remove()
    else:
        loggerinst.info("RHN Classic not detected.")


def subscribe_system():