a >hz;@sddlZddlZddlZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZmZddlmZmZmZddlmZddlmZddlmZddlmZdd lmZd ZGd d d eZ d Z!dZ"dZ#Gddde Z$Gddde$Z%Gddde$Z&Gddde Z'dS)N) RedHatPlugin) RHEL_PRESETSRHVRHELCBRHOSPRHOCPRH_CFME RH_SATELLITEAAPEDA AAPCONTROLLER) LinuxPolicyENV_HOST_SYSROOT OS_RELEASE)RpmPackageManager)FlatpakPackageManager)MultiPackageManager)bold)_soszRed Hat Enterprise LinuxcszeZdZdZddgZdZdZdZdZdZ dZ d Z d Z d Z d Zdfdd ZefddZddZddZddZZS) RedHatPolicyRed Hat)zDistribution Websitezhttps://www.redhat.com/)zCommercial Supportzhttps://access.redhat.com/z/var/tmpFZfriendlyNpodmansosz /usr/sbinzVhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth/devicezPhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/tokenTcstj||||dd|_tttg|j|d|_|jt g7_|jj |_ |j sft j dt d||j |_|jrd|_nd|_|jtjd7_|jtjd 7_|js||dS) Nsysrootinit probe_runtime remote_execF)ZprimaryZ fallbackschrootrz'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)super__init__usrmoverrrrpackage_managerZvalid_subclassesrZpackagespkgssysstderrwriteexit check_usrmovePATHospathseprZ set_exec_pathZ load_presetsselfrrrr __class__?/usr/lib/python3.9/site-packages/sos/policies/distros/redhat.pyr!1s2    zRedHatPolicy.__init__csz|turtt||dS|dttttd}|D]8\}}t d|}|jdd|d|j ddd q8z<35z<30F)newline) rr display_distro_helpadd_text CentOsPolicy RHELPolicyRedHatCoreOSPolicy FedoraPolicyitemsros_release_name)clssectionZsubsZsubcvalueZsublnr/r1r2r8Ss"z RedHatPolicy.display_distro_helpcCs8d|vr tjdotjdS|dd}|ddkS)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 Z filesystemz/binz/sbinversionr3)r+pathislink)r.r$Zfilesys_versionr1r1r2r)ls  zRedHatPolicy.check_usrmovecCs2g}dd}|jr.|D]}|||q|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 cSs:ddg}||vr*|tjd|ddfStdd|fS)Nz/bin/rpmz /bin/mailxz/usrrz (^)(/s?bin)z\1/usr\2)r+rEjoinresub)rEZ skip_pathsr1r1r2transform_pathsz8RedHatPolicy.mangle_package_path..transform_path)r"extend)r.filespathsrJfr1r1r2mangle_package_path{s z RedHatPolicy.mangle_package_pathcCs|s |jS|SN)_tmp_dir)r.Z opt_tmp_dirr1r1r2 get_tmp_dirszRedHatPolicy.get_tmp_dir)NNTN)__name__ __module__ __qualname__vendor vendor_urlsrQZ _in_containerZ name_patternZ upload_urlZ upload_userZdefault_container_runtimeZ sos_pkg_name sos_bin_pathZclient_identifier_urlZtoken_endpointr! classmethodr8r)rOrR __classcell__r1r1r/r2rs,"ra[ 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.comcsbeZdZdZdZdZeZdZe de dZ e Z dZdZd Zdfd d Zd dZddZZS)r;at 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. rz/etc/redhat-releaser4aThis command will collect diagnostic and configuration information from this %(os_release_name)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 ZpostNi@Tcs"tj||||d|tdSNr)r r!Zregister_presetsrr-r/r1r2r!s  zRHELPolicy.__init__cCsDz,|jd}|j|dd}t|dWSty>Yn0dS)Nzredhat-release*rrCF)r#all_pkgs_by_name_regexr$int Exception)r.ZrrZpkgnamer1r1r2 dist_versions  zRHELPolicy.dist_versioncCsdD]&}|j|ddr|tSq|ddurD|tS|ddur\|tS|ddurt|tS|ddus|ddur|tS|d dur|t Sd D] }||dur|t Sq|t S) N)ZrescueZ emergencyz.targetFzsatellite-commonz rhosp-releaseZcfmez ovirt-engineZvdsmzautomation-controller-server)zautomation-eda-controllerz automation-eda-controller-server) Z init_systemZ is_running find_presetr pkg_by_namer rr rr r r)r.targetpkgr1r1r2 probe_presets&      zRHELPolicy.probe_preset)NNTN)rSrTrU__doc__rVos_release_fileRHEL_RELEASE_STRr? os_release_id_disclaimer_textmsg RH_SFTP_HOSTZ _upload_urlZ_upload_methodZ _device_tokenZ_max_size_requestr!r`rerZr1r1r/r2r;s&  r;c@s"eZdZdZdgZdZdZdZdS)r:ZCentOS)Community Websitezhttps://www.centos.org/z/etc/centos-releasez CentOS Linuxr3N)rSrTrUrVrWrgr?rir1r1r1r2r:s r:csveZdZdZdZededZdZdZ dZ dZ d Z d Z dfd d ZedddZddZdddZddZZS)r<aB 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 Enterprise Linux CoreOSzThis command will collect diagnostic and configuration information from this %(os_release_name)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[Trz®istry.redhat.io/rhel8/support-toolsz/hostz rpm -q sosz/var/lib/kubelet/config.jsonNcstj||||ddSr\r r!r-r/r1r2r!4s zRedHatCoreOSPolicy.__init__cCs|r d|vSd}ttjvr|Stjtt}zRt|ddd0}|D]}||j|vO}qJWdn1sr0YWntyYn0|S)NZCoreOSFrzutf-8)encoding) rr+environropenread splitlinesr?IOError)r@ZremoteZcoreosZ host_releaseZhfileliner1r1r2check:s 2 zRedHatCoreOSPolicy.checkcCs |tSrP)rarr.r1r1r2reMszRedHatCoreOSPolicy.probe_presetFc CsL|p|j}|rdnd}|jd|jd|jd|d|d|p@dd| S)Nz --pull=alwaysrpz run -di --name zE --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=z -e IMAGE=r6zr -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host )container_imagecontainer_runtimesos_container_name)r.ZimageZauthZ force_pullZ_imageZ_pullr1r1r2create_sos_containerRs     z'RedHatCoreOSPolicy.create_sos_containercCs d|jS)Nzpodman rm --force )r}rzr1r1r2set_cleanup_cmdbsz"RedHatCoreOSPolicy.set_cleanup_cmd)NNTN)rp)NNF)rSrTrUrfr?rjrkrlZ containerizedr|r{Zsos_path_stripZcontainer_version_commandZcontainer_authfiler!rYryrer~rrZr1r1r/r2r<s*   r<csFeZdZdZdZddgZdZdZdZdZ dfd d Z d dZ Z S)r=aj 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). zthe Fedora Project)rnzhttps://fedoraproject.org/)zCommunity Forumsz%https://discussion.fedoraproject.org/z/etc/fedora-releasez Fedora Linuxr5z/usr/binNTcstj||||ddSr\ror-r/r1r2r!}s zFedoraPolicy.__init__cCs&|dp|jdd}t|dS)Nzfedora-releasezfedora-release-.*rC)rbr#r]r^)r.rdr1r1r2fedora_versions zFedoraPolicy.fedora_version)NNTN) rSrTrUrfrVrWrgr?rirXr!rrZr1r1r/r2r=fs r=)(r+r%rHZsos.report.pluginsrZsos.presets.redhatrrrrrrr r r r Zsos.policies.distrosr rrZ!sos.policies.package_managers.rpmrZ%sos.policies.package_managers.flatpakrZsos.policies.package_managersrZ sos.utilitiesrrrrjrhrrkZ RH_API_HOSTrmr;r:r<r=r1r1r1r2 s& 0     } [X