U (f)@sdZddlZddlZddlZddlmZmZmZmZm Z ddl m Z ddl m Z ddlmZddd d d d d Zee eZe ddddZddZdS)a This function is called from lib/upgrade_lts_contract.py and from lib/reboot_cmds.py This function should be used after running do-release-upgrade in a machine. It will detect any contract deltas between the release before do-release-upgrade and the current release. If we find any differences in the uaclient contract between those releases, we will apply that difference in the upgraded release. For example, suppose we are on Trusty and we are upgrading to Xenial. We found that the apt url for esm services on trusty: https://esm.ubuntu.com/ubuntu While on Xenial, the apt url is: https://esm.ubuntu.com/infra/ubuntu This script will detect differences like that and update the Xenial system to reflect them. N)contractdefaultsmessagessystemutil) _is_attached)UAConfig) machine_tokenZtrustyxenialbionicfocalZlunarjammy)r r r r ZmanticZnoble)cfgreturnc Cs>tdt|js"tddStdtjddgddgd\}}|rTttjt j }t |}t |}|dkrttjj|d td |t td|j|d }|}d}|rtd td tjddgddgd\}}|d7}qtd||ttjtj|||dddtd|ttjdS)Nz%Check whether to upgrade-lts-contractz4Skipping upgrade-lts-contract. Machine is unattachedzStarting upgrade-lts-contract.Zlsofz/var/lib/apt/lists/lockr)Zrcs)releasez?Could not find past release for %s. Current known releases: %r.)seriesz4Detected that apt lock is held. Sleeping 10 seconds. z9upgrade-lts-contract processing contract deltas: %s -> %sTF)rpast_entitlementsnew_entitlementsZ allow_enableZseries_overridesz/upgrade-lts-contract succeeded after %s retries)LOGdebugrZ is_attachedrZsubpprintrZ'RELEASE_UPGRADE_APT_LOCK_HELD_WILL_WAITZget_release_inforr Zget_machine_token_file!current_codename_to_past_codenamegetZRELEASE_UPGRADE_NO_PAST_RELEASEformatZwarningsysexitZ entitlementstimesleepZRELEASE_UPGRADE_STARTINGrZprocess_entitlements_deltaZRELEASE_UPGRADE_SUCCESS) routZ_errZcurrent_releaseZmachine_token_fileZ past_releaserrZ retry_countr!?/usr/lib/python3/dist-packages/uaclient/upgrade_lts_contract.py%process_contract_delta_after_apt_lock4sb                r#cCsttjdS)N)rZensure_folder_absentrZESM_APT_ROOTDIRr!r!r!r"remove_private_esm_apt_cachensr$)__doc__ZloggingrrZuaclientrrrrrZ(uaclient.api.u.pro.status.is_attached.v1rZuaclient.configrZuaclient.filesr rZ getLoggerZreplace_top_level_logger_name__name__rr#r$r!r!r!r"s"    :