3 fh@sdZddlmZmZmZmZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZddlZddlZddlmZddlmZddlZddlmZmZddlZed e jd Ze jd Ze jd Ze jd Z eZ!dZ"edZ#edZ$edZ%dZ&ddZ'ddZ(gfddZ)d7ddZ*ddZ+Gddde,Z-Gdd d e,Z.e.Z/Gd!d"d"ej0j1Z2d#d$Z3d%d&Z4d'd(Z5d)d*Z6d+d,dd-d.gZ7Gd/d0d0ej8Z9Gd1d2d2ej:j;ZdS)8zGsystem_upgrade.py - DNF plugin to handle major-version system upgrades.)callPopen check_outputCalledProcessErrorN)journal)_logger)CliError)ucd)serialize_transactionTransactionReplayzthe color of the skyZ 9348174c5cc74001a71ef26bd79d302eZ fef1cc509d5047268b83a3a553f54b43Z 3e0a5636d16b4ca4bbe5321d06c6aa62Z 8cec00a1566f4d3594f116450395f06cz/usr/bin/plymouthzfprrrr=s   z State._readc CsFtjjtjj|jt|jd}tj |j |dddWdQRXdS)NwT)indent sort_keys) r$r% ensure_dirrrdirnamer;rr@dumpr<)r>Zoutfrrrr5sz State.writecCs&tjj|jrtj|j|jdS)N)rrexistsr;r&r=)r>rrrclears z State.clearcCs|S)Nr)r>rrr __enter__szState.__enter__cCs|dkr|jdS)N)r5)r>exc_type exc_value tracebackrrr__exit__szState.__exit__cs"fdd}fdd}t||S)Ncs||j<dS)N)r<)r>value)optionrrsetpropszState._prop..setpropcs |jjS)N)r<get)r>)rTrrgetpropszState._prop..getprop)property)rTrUrWr)rTr_props  z State._prop state_versiondownload_statusdestdirtarget_releaseversystem_releasevergpgcheckgpgcheck_reposrepo_gpgcheck_reposupgrade_statusupgrade_command distro_syncenable_disable_reposmodule_platform_idN)__name__ __module__ __qualname__r?r=r5rMrNrRrYrZr[r\r]r^r_r`rarbrcrdrerfrrrrr:s(  r:c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)PlymouthOutputzA plymouth output helper class. Filters duplicate calls, and stops calling the plymouth binary if we fail to contact it. cCsd|_t|_d|_dS)NT)alivedict _last_args _last_msg)r>rrrr?szPlymouthOutput.__init__c Gsj||jj|k}|jr| s$|dkrdytt|f|dk|_Wntk rXd|_YnX||j|<|jS)Nz--pingrF)rmrVrkrPLYMOUTHr')r>cmdargsZdupe_cmdrrr _plymouths  zPlymouthOutput._plymouthcCs |jdS)Nz--ping)rr)r>rrrpingszPlymouthOutput.pingcCs4|jr |j|kr |jdd|j||_|jdd|S)Nz hide-messagez--textzdisplay-message)rnrr)r>msgrrrmessageszPlymouthOutput.messagec CsRd}y$ttdg}tjdt|r&d}Wnttfk r@YnX|jdd|S)NZupdatesz--helpz--system-upgradezsystem-upgradez change-modez--)rroresearchr rr'rr)r>modesrrrset_modes zPlymouthOutput.set_modecCs|jddt|S)Nz system-updatez --progress)rrstr)r>ZpercentrrrprogressszPlymouthOutput.progressN) rgrhri__doc__r?rrrsrurzr|rrrrrjs  rjc@s$eZdZddZddZddZdS)PlymouthTransactionProgresscCs|j||||dS)N)_update_plymouth)r>packageactionZti_doneZti_totalZts_doneZts_totalrrrr|sz$PlymouthTransactionProgress.progresscCsd|dkr dS|tjjkr0tjtd||ntjdtd||tj|j||||dS)NgV@Zg$@)r$callbackZ PKG_VERIFYPlymouthr|intru _fmt_event)r>rrcurrenttotalrrrrs  z,PlymouthTransactionProgress._update_plymouthcCs tjjj||}d||||fS)Nz[%d/%d] %s %s...)r$ transactionZACTIONSrV)r>rrrrrrrrsz&PlymouthTransactionProgress._fmt_eventN)rgrhrir|rrrrrrr~sr~ccsJtj}|j|jddd}x(|D] }|d}||kr8q"|}|Vq"WdS)zVFind all boots with this message id. Returns the entries of all found boots. r) MESSAGE_IDZ_UIDN_BOOT_ID)rReaderZ add_matchhex) message_idjZoldbootr)Zbootrrr find_bootss rc Cstttdd }xJtttD]:\}}tdj|d|d|d|jdd|jddqW|d krpttd dS) Nz3The following boots appear to contain upgrade logs:ru){} / {.hex}: {:%Y-%m-%d %H:%M:%S} {}→{}rZ__REALTIME_TIMESTAMPSYSTEM_RELEASEVERz??TARGET_RELEASEVERz-- no logs were found --r)r7r enumeraterID_TO_IDENTIFY_BOOTSformatrV)nr)rrr list_logs s  rc CsZtt|}y(|dkrt|dkr*|d8}||dStk rTttdYnXdS)Nrrrz!Cannot find logs with this index.)listr IndexErrorr r)rrZbootsrrr pick_boot.s  rcCsDtt|}tdd|jg}|j|j}|dkr@tjjt ddS)NZ journalctlz--bootrz%Unable to match systemd journal entry) rrrrwait returncoder$ exceptionsErrorr)rZboot_idZprocessZrcrrrshow_log=s  rZdownloadZcleanupgradelogcs eZdZdZfddZZS)SystemUpgradePluginzsystem-upgradecs8tt|j|||r4|jt|jt|jtdS)N)superrr?Zregister_commandSystemUpgradeCommandOfflineUpgradeCommandOfflineDistrosyncCommand)r>basecli) __class__rrr?Ns   zSystemUpgradePlugin.__init__)rgrhrinamer? __classcell__rr)rrrKsrcs(eZdZdEZedZdZfddZeddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!d9d:Z"d;d<Z#d=d>Z$d?d@Z%dAdBZ&dCdDZ'Z(S)Frsystem-upgradefedupz+Prepare system for upgrade to a new releasezvar/lib/dnf/system-upgradecsjtt|j|tjj|jjj|j |_ tjj|j d|_ tjj|jjjd|_ t tjj|j d|_dS)Nzsystem-upgrade-transaction.jsonz system-updatezsystem-upgrade-state.json)rrr?rrr#rr1r-DATADIRdatadirtransaction_file magic_symlinkr:state)r>r)rrrr?\s zSystemUpgradeCommand.__init__cCsJ|jdddtdd|jddtdd jtd |jd ttd d dS)Nz--no-downgraderdZ store_falsez=keep installed packages if the new release's version is older)destrhelptidrz[%s]|)nargschoicesmetavarz--numberzwhich logs to show)typer) add_argumentrCMDSr#r)parserrrr set_argparserds   z"SystemUpgradeCommand.set_argparsercCs(tj||tj|jj|jjtjjddS)zLog directly to the journal.)rZPRIORITYrrZ DNF_VERSIONN) rsendZ LOG_NOTICErr^r]r$constVERSION)r>rurrrr log_statusns zSystemUpgradeCommand.log_statuscCs|jd|jddS)NZcheck pre_configure) _call_sub)r>rrrrws z"SystemUpgradeCommand.pre_configurecCs|jddS)N configure)r)r>rrrr{szSystemUpgradeCommand.configurecCs|jddS)Nrun)r)r>rrrr~szSystemUpgradeCommand.runcCs|jddS)Nr)r)r>rrrrun_transactionsz$SystemUpgradeCommand.run_transactioncCs|jddS)NZresolved)r)r>rrr run_resolvedsz!SystemUpgradeCommand.run_resolvedcCs.t||d|jjdd}t|r*|dS)Nrr)getattroptsrcallable)r>rZsubfuncrrrrszSystemUpgradeCommand._call_subcCs(|jjtkr$tdj|d}t|dS)NzFIncompatible version of data. Rerun 'dnf {command} download [OPTIONS]')command)rrZ STATE_VERSIONrrr )r>rrtrrr_check_state_versions z)SystemUpgradeCommand._check_state_versioncCs*|j|jj_|jjr|jjnd|jj_dS)N)rrr1cachedirrr\)r>rrr _set_cachedirs z"SystemUpgradeCommand._set_cachedircCsttjjtjjg}ttjj}i}i}xl|jjjD]^}|j |krp|j }|j |j |j jij t|i|j <q6|j |kr6|j |j t|j i|j <q6W||fS)z forward = {repoid:{pkg_nevra: {tsi.action: tsi.reason}} reverse = {pkg_nevra: {tsi.action: tsi.reason}} :return: forward, reverse )setr$rZBACKWARD_ACTIONSlibdnfZ!TransactionItemAction_REINSTALLEDZFORWARD_ACTIONSrrrpkgreason setdefaultrepoidr{)r>Zbackward_actionZforward_actionsZforwardreverseZtsirrrr%_get_forward_reverse_pkg_reason_pairss  & z:SystemUpgradeCommand._get_forward_reverse_pkg_reason_pairscCsb|j|jj_|jjr|jjnd|jj_d|jjkrJ|jj rJtt dnd|jjkr^d|j_dS)Nzoffline-distrosynczFCommand 'offline-distrosync' cannot be used with --no-downgrade optionzoffline-upgradeF) rrr1rrr\rrdr r)r>rrrpre_configure_downloads   z+SystemUpgradeCommand.pre_configure_downloadcCs |jdS)N)r)r>rrrpre_configure_rebootsz)SystemUpgradeCommand.pre_configure_rebootcCs.|j|jjr|jj|j_|jj|jj_dS)N) rrrerrepos_edr]rr1r.)r>rrrpre_configure_upgrades z*SystemUpgradeCommand.pre_configure_upgradecCs |jdS)N)r)r>rrrpre_configure_cleansz(SystemUpgradeCommand.pre_configure_cleancCsd|jjksd|jjkrtjtdt}|rLtd}tj|jt||j j rtd}|j j j s|j j jdj|dj|d rtjtd tjd t|j j |jjd nd |jjkr|jj|jd |jj_d |jj_d |jj_d |jj_d |jj_|j j jdg7_dS)Nzsystem-upgraderz\WARNING: this operation is not supported on the RHEL distribution. Proceed at your own risk.z-Additional information for System Upgrade: {}zyBefore you continue ensure that your system is fully upgraded by running "dnf --refresh upgrade". Do you want to continuez {} [y/N]: z {} [Y/n]: )rtZdefaultyes_msgzOperation aborted.r)r2zoffline-upgradeTZtest)rrrrCrr rrr rZ _promptWantedr1ZassumenooutputZ userconfirmerrorsysexitr3r.rZ _populate_update_security_filterdemands root_user resolvingavailable_repossack_activationZfreshest_metadataZtsflags)r>Zhelp_urlrtrrrconfigure_downloads*        z'SystemUpgradeCommand.configure_downloadcCsd|jj_dS)NT)rrr)r>rrrconfigure_rebootsz%SystemUpgradeCommand.configure_rebootcCsd|jj_d|jj_d|jj_d|jj_|jj|j_|jj dk rN|jj |j j _ |jj dk rx$|j j jD]}|j|jj k|_ qhW|jjdk rx$|j j jD]}|j|jjk|_qW|jj|j j _d|jj_d|j j _t|jj_d|j j _d|j j _dS)NTF)rrrrrrrrdrr_rr1r`reposvaluesrra repo_gpgcheckrfZ cacheonlyZ assumeyesr~Ztransaction_displayZclean_requirements_on_removeZinstall_weak_deps)r>rrrrconfigure_upgrades&            z&SystemUpgradeCommand.configure_upgradecCsd|jj_dS)NT)rrr)r>rrrconfigure_cleansz$SystemUpgradeCommand.configure_cleancCsdS)Nr)r>rrr configure_logsz"SystemUpgradeCommand.configure_logcCs~|jjdksttd|j|jj|jj|jjkrRtdj|jjd}t|t j j |j rlttdt jj|jdS)Ncompletezsystem is not ready for upgradezZthe transaction was not prepared for '{command}'. Rerun 'dnf {command} download [OPTIONS]')rzupgrade is already scheduled)rr[r rrrrrcrrrlexistsrr$r%rIr)r>rtrrr check_reboot s    z!SystemUpgradeCommand.check_rebootcCstjj|js$tjtdtdtj|j|j krLtjtdtdt j j j |j|jj}|sp|jj}|j||jjdkstdj|d}t|dS)Nz-trigger file does not exist. exiting quietly.rz1another upgrade tool is running. exiting quietly.readyz/use 'dnf {command} reboot' to begin the upgrade)r)rrrrrrr SystemExitreadlinkrr$ZyumZmiscZunlink_frrcrrrrbrr )r>rrtrrr check_upgrades  z"SystemUpgradeCommand.check_upgradec Cs,tj|j|j|j }d|_WdQRXdS)Nr)rsymlinkrrrrb)r>rrrr run_prepare,sz SystemUpgradeCommand.run_preparecCs6|j|jjddksdS|jtdttdS)NrrzRebooting to perform upgrade.)rrrrrREBOOT_REQUESTED_IDr)r>rrr run_reboot3s  zSystemUpgradeCommand.run_rebootc sjjrjjn jjjjdkrjjfddjjjD}|r\jj|fddjjj D}|rjj|j $}d|_ jj j |_jj j|_WdQRXdS)Noffline-upgradeoffline-distrosynccs$g|]}jjjj|jr|jqSr)rhistorygrouprVr).0g)r>rr Gsz5SystemUpgradeCommand.run_download..cs$g|]}jjjj|jr|jqSr)rrenvrVr)rr)r>rrrJsZ downloading)rr)rrdrZ upgrade_allrZ read_compscompsgroupsZenv_group_upgradeZ environmentsrr[r1r.r]r\)r>Zinstalled_groupsZinstalled_environmentsrr)r>r run_download=s       z!SystemUpgradeCommand.run_downloadc Csd}|j}d|_|j}WdQRX|dkr4td}n|dkrFtd}ntd}|j|ttjtjdtj |t t |j |j |_|jjdS) NZ incompletezoffline-upgradez1Starting offline upgrade. This will take a while.zoffline-distrosyncz4Starting offline distrosync. This will take a while.z0Starting system upgrade. This will take a while.r)rrbrcrrUPGRADE_STARTED_IDrrzr|rur9r rrreplayr)r>rrrtrrr run_upgradeSs      z SystemUpgradeCommand.run_upgradec Csdtjtdt|jjjtjj |jjjj g|j $}d|_ d|_ d|_d|_d|_WdQRXdS)NzCleaning up downloaded data...)rrrr*rr1rr$Z persistorZTempfilePersistorZdb_pathrr[rZrbrcr\)r>rrrr run_cleanms zSystemUpgradeCommand.run_cleancCs |jjrt|jjntdS)N)rZnumberrr)r>rrrrun_logzszSystemUpgradeCommand.run_logcCs|jjdS)z5Adjust transaction reasons according to stored valuesN)r Zpost_transaction)r>rrrresolved_upgradesz%SystemUpgradeCommand.resolved_upgradecCs|jjj}|js&tjtddSt|}yLt|j d"}t j ||ddd|j dWdQRXt tdj|j Wn<tk r}z tjjtdjt|WYdd}~XnXtjj|jjj}|j}d |_t|_|jj|_|jjj|_d d |jjj D|_!d d |jjj D|_"||_#|jjj$|_%|jjj&|_&|jj'|_(|jjj)|_)|jj*|_+WdQRXt,j|jj*d }tj||j-tdt.dS)NzKThe system-upgrade transaction is empty, your system is already up-to-date.rErFT)rGrH zTransaction saved to {}.zError storing transaction: {}rcSsg|]}|jr|jqSr)r_r)rrrrrrsz=SystemUpgradeCommand.transaction_download..cSsg|]}|jr|jqSr)rr)rrrrrrs)rzDownload finished.)/rrZ get_currentZpackagesrrrr rrr@rKr5r7rr'r$rr r{r+r,r1r-rr[rrZrrdr_rrr`rar^r.r]rfrrer\rrcDOWNLOAD_FINISHED_MSGrDOWNLOAD_FINISHED_ID)r>rdatafr8Z system_verrrtrrrtransaction_downloads: ,       z)SystemUpgradeCommand.transaction_downloadcCs@tjtd|jtdt|j|jjddkrrrrtransaction_upgrades  z(SystemUpgradeCommand.transaction_upgrade)rr))rgrhrialiasesrsummaryrr? staticmethodrrrrrrrrrrrrrrrrrrrrrrrrrr r r rrrrrr)rrrVsF        (rc@seZdZdZedZdS)roffline-upgradez%Prepare offline upgrade of the systemN)r)rgrhrirrrrrrrrsrc@seZdZdZedZdS)roffline-distrosyncz(Prepare offline distrosync of the systemN)r)rgrhrirrrrrrrrsr)N)?r} subprocessrrrrr@rZos.pathrvrZuuidZsystemdrZdnfpluginscorerrr$Zdnf.clir Zdnf.i18nr Zdnf.transactionZdnf.transaction_srr r Z libdnf.confrZUUIDrrr rrror/rr0rrr r*r3r9objectr:rjrrZTransactionProgressr~rrrrrZPluginrrZCommandrrrrrrrsd          @.  e