MOON
Server: Apache
System: Linux server2.shieldcogroup.com 3.10.0-1160.119.1.el7.tuxcare.els12.x86_64 #1 SMP Fri Nov 8 05:49:38 UTC 2024 x86_64
User: jacom (1029)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //etc/leapp/repos.d/system_upgrade/common/libraries/rhsm.pyc
�
��ic@sddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZmZddlmZejd�Zejd	�Zejd
�ZdZdZdZd
Zdd�Zejdd��Zd�Zd�Zed��Z ed��Z!d�Z"d�Z#d�Z$ed��Z%eedede�d���Z&eedede�d���Z'ed��Z(eedede�d���Z)ed��Z*d�Z+ed ��Z,ed!��Z-dS("i����N(t	reporting(tStopActorExecutionError(t
repofileutils(tget_env(tapitCalledProcessError(tRHSMInfosRepo ID:\s*([^\s]+)sRelease:\s*([^\s]+)sSKU:\s*([^\s]+)is/etc/yum.repos.d/redhat.repos3Content Access Mode is set to Simple Content Accesscs��fd�}|S(sM
    A decorator to retry executing a function/method if unsuccessful.

    The function/method execution is considered unsuccessful when it raises StopActorExecutionError.

    :param max_attempts: Maximum number of attempts to execute the decorated function/method.
    :param sleep: Time to wait between attempts. In seconds.
    cs(tj�����fd��}|S(Ncs�d}x�tr�|d7}y�||�SWq	tk
r��|krktj�jd|��j��n�r�tj�jd|��jt���tj	��q�tj�jd|��j�q	Xq	WdS(NiisRAttempt %d of %d to perform %s failed. Maximum number of retries has been reached.sAAttempt %d of %d to perform %s failed - Retrying after %s secondss3Attempt %d of %d to perform %s failed - Retrying...(
tTrueRRtcurrent_loggertwarningt__name__tinfotstrttimetsleep(targstkwargstattempts(tftmax_attemptsR(sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytwrapper"s$	

(t	functoolstwraps(RR(RR(RsP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytimpl!s$((RRR((RRsP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt_rhsm_retrys	ccs�y	dVWn�tk
r\}tj�jd�tddjt|��didd6��nYtk
r�}d}tdd	dit|�d6|jd
6|p�|d6dd6��nXdS(
sm
    Context manager based function that handles exceptions of `run` for the subscription-manager calls.
    Ns1Failed to execute subscription-manager executabletmessages5Unable to execute subscription-manager executable: {}tdetailss?Please ensure subscription-manager is installed and executable.thints�Please ensure you have a valid RHEL subscription and your network is up. If you are using proxy for Red Hat subscription-manager, please make sure it is specified inside the /etc/rhsm/rhsm.conf file. Or use the --no-rhsm option when running leapp, if you do not want to use subscription-manager for the in-place upgrade and you want to deliver all target repositories by yourself or using RHUI on public cloud.s0A subscription-manager command failed to executetstderrs+https://access.redhat.com/solutions/6138372tlink(	tOSErrorRRterrorRtformatRRR(Rtet	_def_hint((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt_handle_rhsm_exceptions;s"	


cCstS(s/Check whether we should skip RHSM related code.(R(((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt	skip_rhsm^scs"tj���fd��}|S(s@Decorator to allow skipping RHSM functions by executing a no-op.cst�s�||�SdS(N(R$tNone(RR(R(sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyRes	
(RR(RR((RsP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt	with_rhsmcscCsCt��4|jdddgdt�}tj|d�SWdQXdS(s%
    Retrieve the list of the SKUs the system is attached to with the subscription-manager.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: SKUs the current system is attached to.
    :rtype: List(string)
    ssubscription-managertlists
--consumedtsplittstdoutN(R#tcalltFalset_RE_SKU_CONSUMEDtfindall(tcontexttresult((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytget_attached_skusms

cCs1t��"|jddg�}|dSWdQXdS(s�
    Retrieve "subscription-manager status" output.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: "subscription manager status" output
    :rtype: String
    ssubscription-managertstatusR)N(R#R*(R.R/((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytget_rhsm_status|s

cCstt|�kS(s�
    Check if SCA manifest is used in Satellite.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: True if SCA manifest is used else False
    :rtype: Boolean
    (tSCA_TEXTR2(R.((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytis_manifest_sca�s	cCs"dddg}y|j|�Wn<tk
r^}tddit|�d6|jd6��nXtj|�}t|�g}xS|D]K}|jt	kr�|j
r�g|j
D]}|j^q�}|j�Pq�q�Wd}|rt
j�jdj||j|���nt
j�jd	�|S(
sS
    Retrieve repo ids of all the repositories available through the subscription-manager.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: Repositories that are available to the current system through the subscription-manager
    :rtype: List(string)
    tyumtcleantallsUnable to use yum successfullyRRs
    - s7The following repoids are available through RHSM:{0}{1}s*There are no repos available through RHSM.(R*RRRRRtget_parsed_repofilest_inhibit_on_duplicate_repostfilet_DEFAULT_RHSM_REPOFILEtdatatrepoidtsortRRRR tjoin(R.tcmdtexct	repofilest
rhsm_repostrfiletrepotlist_separator_fmt((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytget_available_repo_ids�s*$


c	Cs�tj|�j�}|sdSd}tj�jdj||j|���tj	tj
d�tjdj||j|���tjtjj
�tjtjjg�tjtjjg�tjdd�g�dS(s�
    Inhibit the upgrade if any repoid is defined multiple times.

    When that happens, it not only shows misconfigured system, but then
    we can't get details of all the available repos as well.
    Ns
    - s7The following repoids are defined multiple times:{0}{1}s+A YUM/DNF repository defined multiple timess<The following repositories are defined multiple times:{0}{1}Rs,Remove the duplicate repository definitions.(Rtget_duplicate_repositoriestkeysRRR	R R?Rt
create_reporttTitletSummarytSeveritytMEDIUMtGroupst
REPOSITORYt	INHIBITORtRemediation(RBt
duplicatesRF((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyR9�s cCsCt��4|jdddgdt�}tj|d�SWdQXdS(sP
    Retrieve repo ids of all the repositories enabled through the subscription-manager.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: Repositories that are enabled on the current system through the subscription-manager.
    :rtype: List(string)
    ssubscription-managertreposs--list-enabledR(R)N(R#R*R+t_RE_REPO_UIDR-(R.R/((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytget_enabled_repo_ids�s

RRcCs0t��!|jdddgdt�WdQXdS(s�
    Unset the configured release from the subscription-manager.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    ssubscription-managertreleases--unsetR(N(R#R*R+(R.((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt
unset_release�s	
c	Cs3t��$|jddd|gdt�WdQXdS(s
    Set the release (RHEL minor version) through the subscription-manager.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :param release: Release to set the subscription-manager to.
    :type release: str
    ssubscription-managerRWs--setR(N(R#R*R+(R.RW((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytset_release�s
cCsTt��E|jddgdt�}tj|d�}|rF|dSdSWdQXdS(s
    Retrieves the release the subscription-manager has been pinned to, if applicable.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: Release the subscription-manager is set to.
    :rtype: string
    ssubscription-managerRWR(R)itN(R#R*R+t_RE_RELEASER-(R.R/((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytget_release
s

cCs-t��|jddgdt�WdQXdS(s�
    Calls 'subscription-manager refresh'

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    ssubscription-managertrefreshR(N(R#R*R+(R.((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyR]s	
cCs�g}x�dD]�}tjj|j|��s4q
ngtj|j|��D]E}tjjtjj|j|�|��rMtjj||�^qM}|r
|j|�q
q
W|S(s9
    Retrieves information about existing product certificates on the system.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: Paths to product certificates that are currently installed on the system.
    :rtype: List(string)
    s/etc/pki/products/etc/pki/product-default(s/etc/pki/products/etc/pki/product-default(tostpathtisdirt	full_pathtlistdirtisfileR?textend(R.tcertsR_Rt
curr_certs((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt!get_existing_product_certificates*s

EcCsg|j�s#tj�jd�dSy|jddddg�Wn tk
rbtdd��nXdS(	s�
    Put RHSM into the container mode.

    Inside the container, we have to ensure the RHSM is not used AND that host
    is not affected. If the RHSM is not set into the container mode, the host
    could be affected and the generated repo file in the container could be
    affected as well (e.g. when the release is set, using rhsm, on the host).

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    sGTrying to set RHSM into the container modeon host. Skipping the action.Ntlns-ss	/etc/rhsms/etc/rhsm-hostRs;Cannot set the container mode for the subscription-manager.(tis_isolatedRRRR*RR(R.((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytset_container_mode@s
cCs�xR|jD]G}y|j|�Wq
tk
rPtj�jd|dt�q
Xq
WxWdD]O}tjj	|j
|��r\|j|tjj|tjj
|���q\q\WdS(s(
    Perform all actions needed to switch the passed RHSM product certificate.

    This function will copy the certificate to /etc/pki/product, and /etc/pki/product-default if necessary, and
    remove other product certificates from there.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :param rhsm_info: An instance of the RHSMInfo model
    :type rhsm_info: RHSMInfo model
    :param cert_path: Path to the product certificate to switch to
    :type cert_path: string
    s)Failed to remove existing certificate: %stexc_infos/etc/pki/products/etc/pki/product-defaultN(s/etc/pki/products/etc/pki/product-default(texisting_product_certificatestremoveRRRR	RR^R_R`Ratcopy_toR?tbasename(R.t	rhsm_infot	cert_pathtexistingR_((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytswitch_certificateWs
$
cCsnt�}t|�|_t|�|_t|�|_t|�|_|j	j
t|��t|�|_
|S(s[
    Gather all the RHSM information of the source system.

    It's not intended for gathering RHSM info about the target system within a container.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: An instance of an RHSMInfo model.
    :rtype: RHSMInfo model
    (RR0t
attached_skusRGtavailable_reposRVt
enabled_reposR\RWRlRdRgR4tsca_detected(R.R((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pytscan_rhsm_infoqs	(.t
contextlibRR^treR
tleappRtleapp.exceptionsRtleapp.libraries.commonRtleapp.libraries.common.configRtleapp.libraries.stdlibRRtleapp.modelsRtcompileRUR[R,t	_ATTEMPTSt_RETRY_SLEEPR;R3R%RtcontextmanagerR#R$R&R0R2R4RGR9RVRXRYR\R]RgRjRsRx(((sP/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/rhsm.pyt<module>sN#"		
		-	!!!