id_nddlZddlZddlZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZmZddlmZmZddlmZddlmZddlmZ ddlZdZd Zd Zd Z Gd deZ!dZ"dZ#dZ$Gdde!Z%Gdde%Z&Gdde%Z'Gdde%Z(Gdde'Z)Gdde!Z*y#e$rd ZYcwxYw)N) RedHatPlugin) RHEL_PRESETSATOMIC_PRESETSRHVRHELCBRHOSPRHOCPRH_CFME RH_SATELLITEATOMIC) LinuxPolicyENV_HOST_SYSROOT)RpmPackageManager)bold)_sosTFz/etc/os-releasezRed Hat Enterprise LinuxAtomicceZdZdZdZddgZdZdZdZdZ dZ dZ d Z d Z d Z dfd Zedd ZefdZdZdZdZxZS) RedHatPolicyRed Hat)zDistribution Websitezhttps://www.redhat.com/)zCommercial Supportzhttps://access.redhat.com/z/var/tmpFz/opt/rhfriendlyNpodmansosz /usr/sbinctt| ||||d|_t |j ||_|xjtgz c_|j j|_ |js4tjjdtjd|j|j|_|jrd|_nd|_|xj t"j$dzz c_|xj t"j$d zz c_|j&s|j)|j+y) Nsysrootinit probe_runtime remote_execF)chrootrz'Could not obtain installed package listz/usr/sbin:/usr/bin:/root/binz'/sbin:/bin:/usr/sbin:/usr/bin:/root/binz/usr/local/binz/usr/local/sbin)superr__init__usrmoverrpackage_managervalid_subclassesrpackagespkgssysstderrwriteexit check_usrmovePATHospathsepr set_exec_path load_presetsselfrrrr __class__s =/usr/lib/python3/dist-packages/sos/policies/distros/redhat.pyr#zRedHatPolicy.__init__5s  lD*79F7B + D 0 =H J ,/((11 yy JJ  F G HHQK))$))4 <<6DIADI RZZ"222  RZZ"333      cy)aThis method checks to see if we are running on Red Hat. It must be overriden by concrete subclasses to return True when running on a Fedora, RHEL or other Red Hat distribution or False otherwise. If `remote` is provided, it should be the contents of a remote host's os-release, or comparable, file to be used in place of the locally available one. Fclsremotes r6checkzRedHatPolicy.checkTsr7c |turtt| |y|jdtt t td}|D]A}td|z}|jdjd|||jdCy)NzThis policy is a building block for all other Red Hat family distributions. You are likely looking for one of the distributions listed below. )centosrhel redhatcoreosfedoraz policies.%sz{:>8}{:<35}{:<30} F)newline) rr"display_distro_helpadd_text CentOsPolicy RHELPolicyRedHatCoreOSPolicy FedoraPolicyrformatdistro)r;sectionsubssubcsublnr5s r6rEz RedHatPolicy.display_distro_help`s l " , 8 A  , #."   D-.E   #**3tDz7H7HI   r7cd|vr@tjjdxrtjjdS|dd}|ddk(rdSdS) aqTest whether the running system implements UsrMove. If the 'filesystem' package is present, it will check that the version is greater than 3. If the package is not present the '/bin' and '/sbin' paths are checked and UsrMove is assumed if both are symbolic links. :param pkgs: a packages dictionary filesystemz/binz/sbinversionr3TF)r/pathislink)r4r(filesys_versions r6r-zRedHatPolicy.check_usrmoveysW t #77>>&)EbggnnW.E E"<0;O*1-44 ?% ?r7chg}d}|jr |D]}|j|||S|S)a2Mangle paths for post-UsrMove systems. If the system implements UsrMove, all files will be in '/usr/[s]bin'. This method substitutes all the /[s]bin references in the 'files' list with '/usr/[s]bin'. :param files: the list of package managed files cddg}||vr%|tjjd|ddfStjdd|fS)Nz/bin/rpmz /bin/mailxz/usrr!z (^)(/s?bin)z\1/usr\2)r/rUjoinresub)rU skip_pathss r6transform_pathz8RedHatPolicy.mangle_package_path..transform_pathsL%l3Jz!bggll648<==FF>;=? ?r7)r$extend)r4filespathsr^fs r6mangle_package_pathz RedHatPolicy.mangle_package_pathsB @ << 0 ^A./ 0LLr7c"|s |jS|SN)_tmp_dir)r4 opt_tmp_dirs r6 get_tmp_dirzRedHatPolicy.get_tmp_dirs== r7NNTN)__name__ __module__ __qualname__rLvendor vendor_urlsrf _in_containerdefault_scl_prefix name_pattern upload_url upload_userdefault_container_runtime sos_pkg_name sos_bin_pathr# classmethodr=rEr-rcrh __classcell__r5s@r6rr$s F F;<KHM"LJK (LL>B!>  0@ 4r7ra[ Any information provided to %(vendor)s will be treated in accordance with the published support policies at: %(vendor_urls)s The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party. No changes will be made to system configuration. zhttps://api.access.redhat.comzsftp://sftp.access.redhat.comceZdZdZeZdZedezdzZ e Z dZ dfd Z eddZfdZd Zd Zd Zd Zfd ZfdZdZdZxZS)rHat The RHEL policy is used specifically for Red Hat Enterprise Linux, of any release, and not forks or derivative distributions. For example, this policy will be loaded for any RHEL 8 installation, but will not be loaded for CentOS Stream 8 or Red Hat CoreOS, for which there are separate policies. Plugins activated by installed packages will only be activated if those packages are installed via RPM (dnf/yum inclusive). Packages installed by other means are not considered by this policy. By default, --upload will be directed to using the SFTP location provided by Red Hat for technical support cases. Users who provide login credentials for their Red Hat Customer Portal account will have their archives uploaded to a user-specific directory. If users provide those credentials as well as a case number, --upload will instead attempt to directly upload archives to the referenced case, thus streamlining the process of providing data to technical support engineers. If either or both of the credentials or case number are omitted or are incorrect, then a temporary anonymous user will be used for upload to the SFTP server, and users will need to provide that information to their technical support engineer. This information will be printed at the end of the upload process for any sos report execution. raThis command will collect diagnostic and configuration information from this %(distro)s system and installed applications. An archive containing the collected information will be generated in %(tmpdir)s and may be provided to a %(vendor)s support representative. %(vendor_text)s postc^tt| |||||jtyNr)r"rHr#register_presetsrr3s r6r#zRHELPolicy.__init__s2 j$(t7D5@ ) B l+r7c~|r|j|vStjjtsyt td5}|D]^}|j ds|jd\}}|jd}|j |jsVdddy dddy#1swYyxYw)aTest to see if the running host is a RHEL installation. Checks for the presence of the "Red Hat Enterprise Linux" release string at the beginning of the NAME field in the `/etc/os-release` file and returns ``True`` if it is found, and ``False`` otherwise. :returns: ``True`` if the host is running RHEL or ``False`` otherwise. FrNAME=z"'NT) rLr/rUexists OS_RELEASEopen startswithsplitstrip)r;r<rblinenamevalues r6r=zRHELPolicy.checks ::' 'ww~~j) *c " $a $??6*$(JJsOMT5!KK.E'' 3#  $ $ $ $ $sB3AB3B3(B33B<c~|jdjry|jdjrtt|y|j sf|jrttd|_yt|_|jjdttd|_yy)N cmdlineoptszVEnter your Red Hat Customer Portal username for uploading [empty for anonymous SFTP]: z&No case id provided, uploading to SFTPzYEnter your Red Hat Customer Portal username for uploading to SFTP [empty for anonymous]: ) commonsrurtr"rHprompt_for_upload_userget_upload_usercase_idinput_ RH_SFTP_HOSTui_loginfo)r4r5s r6rz!RHELPolicy.prompt_for_upload_users << & 2 2  << & 1 1 *d : < ##%||#(=*>$ #/   !IJ#(@*A$ &r7c |jr |jS|jdjr|jdjS|jdjdk(rtSd}t||j zzS)Nrsftpz /support/v1/cases/%s/attachments)rtrupload_protocolr RH_API_HOSTr)r4 rh_case_apis r6get_upload_urlzRHELPolicy.get_upload_urlsp ???? " \\- ( 3 3<< .99 9 \\- ( 8 8F B E r7cNtjdd|jvrtt|St s tdd}d}tdz}|jr|jr|j}tj||d}|jdk(r3|j}tj |j"d }nT|j$j'd |jd |j|j$j)d |sd di}tj|tj*|d}|jdk(rRtj |j"}|d}|d }|j$j-t/d|dn9|j$j'd|jd |j|r|rtt|||Std)zOverride the base upload_sftp to allow for setting an on-demand generated anonymous login for the RH SFTP server if a username and password are not given z//r!zPpython3-requests is not installed and is required for obtaining SFTP auth token.Nz/support/v2/sftp/token )authtimeouttokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous. isAnonymousT)datarusernamezUser z^ used for anonymous upload. Please inform your support engineer so they may retrieve the data.z)DEBUG: anonymous request failed (status: )userpasswordz1Could not retrieve valid or anonymous credentials)rrrr"rH upload_sftpREQUESTS_LOADED Exceptionrrget_upload_passwordget_upload_https_authrequestsr~ status_codejsonloadstextrdebugerrordumpsrr) r4_token_userurlrretadataanonrespr5s r6rzRHELPolicy.upload_sftp=s   d #A &d.A.A.C CT68 8>? ?44    !d&>&>&@--/D--$;C#%,,.CHH-g6 !!:3??:K3xxzl$ !!7 "D)E==4::e+B!,6* <  5Mn, &r7rHceZdZdZdZdgZy)rGCentOSCommunity Websitezhttps://www.centos.org/NrlrmrnrLrorpr9r7r6rGrGs F FCDKr7rGc~eZdZdZedezdzZdZdZdZ dZ dZ dfd Z e dd Zd Zdd Zd ZxZS)RedHatAtomicPolicyzRed Hat Atomic HostThis command will collect diagnostic and configuration information from this %(distro)s system. An archive containing the collected information will be generated in %(tmpdir)s and may be provided to a %(vendor)s support representative. r}Tdockerz.registry.access.redhat.com/rhel7/support-tools/host rpm -q sosc^tt| |||||jtyr)r"rr#rrr3s r6r#zRedHatAtomicPolicy.__init__s3  $0t?L=H 1 J n-r7cj|r|j|vSd}ttjvr|Stjttz}tj j |sy t|djjD] }|t|vz} |S#t$rY|SwxYw)NFr) rLrr/environrrUrrread splitlinesATOMIC_RELEASE_STRIOError)r;r<atomic host_releasers r6r=zRedHatAtomicPolicy.checks ::' ' 2:: -Mzz"23j@ ww~~l+ \3/446AAC 5,44 5     s*8B%% B21B2cx|jdr|jtS|jtS)Nzatomic-openshift)rrr r rs r6rzRedHatAtomicPolicy.probe_presets3   . /##E* *''r7cd}|xs |j}|rdnd}|j|j|j|||xsdSNa{runtime} run -di --name {name} --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME={name} -e IMAGE={image} {pull} -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host {auth} {image}z --pull=alwaysrk)runtimerimagepullrcontainer_imagerKcontainer_runtimesos_container_namer4rr force_pull_cmd_image_pulls r6create_sos_containerz'RedHatAtomicPolicy.create_sos_containerYJ .$..#-2{{4#9#9 $ 7 7!' % $  , ,r7cy)Nz#docker rm --force sos-collector-tmpr9rs r6set_cleanup_cmdz"RedHatAtomicPolicy.set_cleanup_cmds4r7rirjNNF)rlrmrnrLrrr containerzedrrsos_path_stripcontainer_version_commandr#ryr=rr rrzr{s@r6rrsv "F   , , -CL FON ,>B!.$( ,5r7rceZdZdZdZedezdzZdZdZ dZ dZ d Z d Z dfd Zedd Zd ZddZdZxZS)rIaB Red Hat CoreOS is a containerized host built upon Red Hat Enterprise Linux and as such this policy is built on top of the RHEL policy. For users, this should be entirely transparent as any behavior exhibited or influenced on RHEL systems by that policy will be seen on RHCOS systems as well. The one change is that this policy ensures that sos collect will deploy a container on RHCOS systems in order to facilitate sos report collection, as RHCOS discourages non-default package installation via rpm-ostree which is used to maintain atomicity for RHCOS nodes. The default container image used by this policy is the support-tools image maintained by Red Hat on registry.redhat.io. Note that this policy is only loaded when sos is directly run on an RHCOS node - if sos collect uses the `oc` transport (the default transport that will be attempted by the ocp cluster profile), then the policy loaded inside the launched pod will be RHEL. Again, this is expected and will not impact how sos report collections are performed. zRed Hat CoreOSrr}Trz®istry.redhat.io/rhel8/support-toolsrrz/var/lib/kubelet/config.jsonc4tt| ||||yr)r"rIr#r3s r6r#zRedHatCoreOSPolicy.__init__s#  $0t?L=H 1 Jr7c|rd|vSd}ttjvr|Stjttz} t |dj j D] }|d|vz}  |S#t$rY|SwxYw)NCoreOSFrzRed Hat Enterprise Linux CoreOS)rr/rrrrrr)r;r<coreosrrs r6r=zRedHatCoreOSPolicy.checks v% % 2:: -Mzz"23j@  \3/446AAC D;tCC D     s4A77 BBc,|jtSre)rr rs r6rzRedHatCoreOSPolicy.probe_preset0s&&r7cd}|xs |j}|rdnd}|j|j|j|||xsdSrrrs r6r z'RedHatCoreOSPolicy.create_sos_container5r r7c d|jzS)Nzpodman rm --force %s)rrs r6rz"RedHatCoreOSPolicy.set_cleanup_cmdCs%(?(???r7rirjr)rlrmrnrrLrrr containerizedrrrrcontainer_authfiler#ryr=rr rrzr{s@r6rIrIs(F   , , -CM >ON ,7>B!J  ' ,@r7rIceZdZdZdZdgZy)CentOsAtomicPolicyzCentOS Atomic HostrrNrr9r7r6rrGs !F FCDKr7rcPeZdZdZdZdZddgZ d fd Zed dZ dZ xZ S) rJaj The policy for Fedora based systems, regardless of spin/edition. This policy is based on the parent Red Hat policy, and thus will only check for RPM packages when considering packaged-based plugin enablement. Packages installed by other sources are not considered. There is no default --upload location for this policy. If users need to upload an sos report archive from a Fedora system, they will need to provide the location via --upload-url, and optionally login credentials for that location via --upload-user and --upload-pass (or the appropriate environment variables). Fedorazthe Fedora Project)rzhttps://fedoraproject.org/)zCommunity Forumsz%https://discussion.fedoraproject.org/c4tt| ||||yr)r"rJr#r3s r6r#zFedoraPolicy.__init__bs" lD*79F7B + Dr7c`|r|j|vStjjdS)zXThis method checks to see if we are running on Fedora. It returns True or False.z/etc/fedora-release)rLr/rUisfiler:s r6r=zFedoraPolicy.checkhs* ::' 'ww~~344r7cl|jdxs|jdd}t|dS)Nzfedora-releasezfedora-release-.*rrS)rrr)r4pkgs r6fedora_versionzFedoraPolicy.fedora_versionrs?/0A  ' '(; ""r7rirj) rlrmrnrrLrorpr#ryr=r&rzr{s@r6rJrJMsI F !F;EK ?C!D 55#r7rJ)+rr/r)r[sos.report.pluginsrsos.presets.redhatrrrrrr r r r r sos.policies.distrosrr!sos.policies.package_managers.rpmr sos.utilitiesrrrrrr ImportErrorrrrrrrrrHrGrrIrrJr9r7r6r-s +(((??O -B;BL . . m&m&`E:E @5@5FQ@Q@hE+E (#<(#cOs B**B43B4