From c10ff07e5ee21ca4db42853ac3031146da7b632b Mon Sep 17 00:00:00 2001 From: wangsong Date: Tue, 23 Apr 2024 21:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=80=E6=9C=89=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=BF=81=E7=A7=BB=E5=88=B0/etc=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=E3=80=81=E6=94=AF=E6=8C=81=E4=BF=9D=E5=AD=98=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemUpdater/Core/UpdaterConfigParser.py | 16 +++-- backend-immutable/SystemUpdater/Core/enums.py | 8 +-- .../SystemUpdater/UpdateManager.py | 21 +++--- .../SystemUpdater/UpdateManagerDbus.py | 13 ++-- .../backend/BackendOstreeNext.py | 29 ++++++-- .../data/system-updater-coverable.conf | 18 ----- .../data/system-updater-defaults.conf | 12 ++-- .../tests/test-admin-upgrade-endoflife.sh | 71 ++++++++++--------- debian/changelog | 9 +++ debian/kylin-system-updater-immutable.install | 14 ++-- 10 files changed, 114 insertions(+), 97 deletions(-) delete mode 100644 backend-immutable/data/system-updater-coverable.conf diff --git a/backend-immutable/SystemUpdater/Core/UpdaterConfigParser.py b/backend-immutable/SystemUpdater/Core/UpdaterConfigParser.py index 0842c1e..1c14dc1 100755 --- a/backend-immutable/SystemUpdater/Core/UpdaterConfigParser.py +++ b/backend-immutable/SystemUpdater/Core/UpdaterConfigParser.py @@ -12,14 +12,14 @@ import os import logging class UpgradeConfig(SafeConfigParser): - def __init__(self, datadir="/var/lib/kylin-system-updater/", name="system-updater.conf",defaults_dir=None): + def __init__(self, datadir="/var/lib/kylin-system-updater/", name="system-updater.conf",defaults_conf=None): SafeConfigParser.__init__(self) self.datadir = datadir maincfg = os.path.join(datadir, name) # defaults are read first self.config_files = [] - if defaults_dir: - self.config_files.append(os.path.join(datadir, defaults_dir)) + if defaults_conf: + self.config_files.append(defaults_conf) # our config file self.config_files += [maincfg] for conf in self.config_files: @@ -34,6 +34,10 @@ class UpgradeConfig(SafeConfigParser): def reRead(self): self.read(self.config_files, encoding='iso-8859-1') + def _write(self): + with open(self.config_files[-1], 'w+') as configfile: + self.write(configfile) + def setValue(self, section, option, value=None,is_write = True): logging.info("SetValue Section:%s Option:%s Value:%s",section, option, value) try: @@ -44,8 +48,7 @@ class UpgradeConfig(SafeConfigParser): logging.error(str(e)) return False if is_write == True: - with open(self.config_files[-1], 'w+') as configfile: - self.write(configfile) + self._write() return True def getWithDefault(self, section, option, default,re_read=False): @@ -85,8 +88,7 @@ class UpgradeConfig(SafeConfigParser): logging.error(str(e)) return if is_write == True: - with open(self.config_files[-1], 'w+') as configfile: - self.write(configfile) + self._write() def getListFromFile(self, section, option): try: diff --git a/backend-immutable/SystemUpdater/Core/enums.py b/backend-immutable/SystemUpdater/Core/enums.py index a5ef765..2b7aeaa 100644 --- a/backend-immutable/SystemUpdater/Core/enums.py +++ b/backend-immutable/SystemUpdater/Core/enums.py @@ -5,7 +5,7 @@ __all__ = ( #错误枚举 "ERROR_OTHER_PROGRESS_OCCUPATION","ERROR_NETWORK_FAILED","ERROR_CANCELLED","ERROR_NOT_ROLLBAK_DEPLOYMENT", - "ERROR_ORIGIN_IS_NONE", + "ERROR_ORIGIN_IS_NONE","INSTALL_FAILED_FALG","INSTALL_SUCCESS_FLAG","INSTALL_DEFAULT_FLAG", # 方法 "get_error_description_from_enum" ) @@ -17,7 +17,9 @@ _ = gettext.gettext #系统更新的所有枚举 PRIORITY_UPGRADE_SUCCCESSED = "priority-upgrade-successed" - +INSTALL_DEFAULT_FLAG = 'none' +INSTALL_FAILED_FALG = 'failed' +INSTALL_SUCCESS_FLAG = 'success' #apt update阶段出现的错误解析 @@ -42,8 +44,6 @@ ERROR_NOT_ROLLBAK_DEPLOYMENT = "#0300" GLIB_ERROR_NETWORK_FAILED = "While fetching mirrorlist" - - _DESCS_ERROR = { ERROR_OTHER_PROGRESS_OCCUPATION: _("Other tasks are being updated and upgraded, please try again later."), ERROR_NETWORK_FAILED: _("Network anomaly, can't check for updates!"), diff --git a/backend-immutable/SystemUpdater/UpdateManager.py b/backend-immutable/SystemUpdater/UpdateManager.py index a44f441..d5c889d 100644 --- a/backend-immutable/SystemUpdater/UpdateManager.py +++ b/backend-immutable/SystemUpdater/UpdateManager.py @@ -25,10 +25,11 @@ class UpdateManager(): def __init__(self,options): try: self.options = options + self._check_conf_dir() self.cache = MyCache() self.trans = UpdatesAvailable() self.sqlite3_server = Sqlite3Server(self) - self.configs_uncover = UpgradeConfig(defaults_dir="system-updater-defaults.conf") + self.configs_uncover = UpgradeConfig(defaults_conf="/etc/kylin-system-updater/system-updater-defaults.conf") self.bus = dbus.SystemBus() self.dbus_send = self._setup_dbus(self.bus) @@ -101,6 +102,10 @@ class UpdateManager(): self.dbus_send.DeployUpdatFinishedNext(parent.exit,[SYSTEM_UPDATE_GROUPS],trans.available_metadata,parent.error_code) trans.deployable = False + if parent.exit: + self.configs_uncover.setValue("statusForFinishPrompt","finished_status",INSTALL_SUCCESS_FLAG) + else: + self.configs_uncover.setValue("statusForFinishPrompt","finished_status",parent.error_code) if parent.exit and self.options.sysroot == None: self._system_reboot_shutdown(device_status,self.options.prohibit_shutdown) @@ -134,15 +139,6 @@ class UpdateManager(): logging.info('making the ConfigPath(%s) is complete...',output_path) output_config_name = output_path + SYSTEM_UPDATE_GROUPS + '.json' - - # groups_base_info.update({"package":SYSTEM_UPDATE_GROUPS}) - # groups_base_info.update({"new_version":data.setdefault("new_version","")}) - # groups_base_info.update({"name":data.setdefault("name","")}) - # groups_base_info.update({"description":data.setdefault("description","")}) - # groups_base_info.update({"icon":data.setdefault("icon","")}) - # groups_base_info.update({"total_download_size":data.setdefault("total_download_size","")}) - # groups_base_info.update({"total_install_size":data.setdefault("total_install_size","")}) - # groups_base_info.update({"changelog":data.setdefault("changelog","")}) groups_base_info.update({"version":data.setdefault("version","")}) groups_base_info.update({"update-type":data.setdefault("update-type",SYSTEM_UPDATE_GROUPS)}) @@ -162,6 +158,11 @@ class UpdateManager(): logging.info("Generate Jsonfile(%s) to complete... ",output_config_name) except Exception as e: logging.error(e) + def _check_conf_dir(): + # 检查var配置目录是否存在 不存在时进行创建 + VAR_CONFG_DIR = '/var/lib/kylin-system-updater' + if not os.path.exists(VAR_CONFG_DIR): + os.makedirs(VAR_CONFG_DIR) def _system_reboot_shutdown(self,status="reboot",prohibit_shutdown=False): if status == "shutdown": diff --git a/backend-immutable/SystemUpdater/UpdateManagerDbus.py b/backend-immutable/SystemUpdater/UpdateManagerDbus.py index ebab561..0df6a65 100755 --- a/backend-immutable/SystemUpdater/UpdateManagerDbus.py +++ b/backend-immutable/SystemUpdater/UpdateManagerDbus.py @@ -107,7 +107,7 @@ class UpdateManagerDbusController(dbus.service.Object): self.cache = parent.cache self.bus = bus self.prohibit_list = [] - + self.configs_uncover = parent.configs_uncover self.database = self.parent.sqlite3_server self.now_working = self.ACTION_DEFUALT_STATUS @@ -294,17 +294,20 @@ class UpdateManagerDbusController(dbus.service.Object): logging.error(str(e)) return self.now_working - #更新的dbus + #更新完成后的弹窗 @dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='s',sender_keyword='sender') def CheckPopupOnPoweroffInstalled(self,sender=None): try: sender_name = get_proc_from_dbus_name(sender) - logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' ChcekPopupOnPoweroffInstalled sender:%s...',sender_name) - return "none" + status = self.configs_uncover.getWithDefault("statusForFinishPrompt", "finished_status",INSTALL_DEFAULT_FLAG) + logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' ChcekPopupOnPoweroffInstalled sender:%s status:%s ...',sender_name,status) + if status != INSTALL_DEFAULT_FLAG: + self.configs_uncover.setValue("statusForFinishPrompt","finished_status",INSTALL_DEFAULT_FLAG) + return status except Exception as e: logging.error(str(e)) - return "none" + return INSTALL_DEFAULT_FLAG # 获取系统版本号 @dbus.service.method(UPDATER_DBUS_INTERFACE, out_signature='ss',sender_keyword='sender') diff --git a/backend-immutable/SystemUpdater/backend/BackendOstreeNext.py b/backend-immutable/SystemUpdater/backend/BackendOstreeNext.py index c2c8282..1557d9f 100644 --- a/backend-immutable/SystemUpdater/backend/BackendOstreeNext.py +++ b/backend-immutable/SystemUpdater/backend/BackendOstreeNext.py @@ -280,13 +280,34 @@ class DeployBackend(BackendBaseOstree): self._progress_to_plymouth(60) - # 最终完成阶段在关机的时候 logging.info("start deploy available_refs:%s new_revision:%s...",refs,new_revision) ret,new_deployment = sysroot.deploy_tree(self.osname,new_revision,self.origin,self.merge_deployment,None,None) - sysroot.simple_write_deployment(self.osname,new_deployment,self.merge_deployment,0,None) + + # 进行部署时 保留历史部署 + flags = OSTree.SysrootSimpleWriteDeploymentFlags.RETAIN + sysroot.simple_write_deployment(self.osname,new_deployment,self.merge_deployment,flags,None) self._progress_to_plymouth(90) - # ret,new_deployment = sysroot.stage_tree(self.osname,new_revision,self.origin,self.merge_deployment,None,None) + + # 获取当前部署 数量 + cur_deployment = [] + cur_deployment.append(new_deployment) + old_deployments = sysroot.get_deployments() + + # 部署的列表 + for deploys in old_deployments: + # 对为hotfix和pin的部署进行过滤 + if deploys.get_unlocked() == OSTree.DeploymentUnlockedState.HOTFIX and deploys.is_pinned(): + continue + + if not new_deployment.equal(deploys): + cur_deployment.append(deploys) + + logging.info("Number of current deployments:%d and all:%d",len(cur_deployment),len(old_deployments)) + if len(cur_deployment) > 5: + logging.info("The number of deployments exceed 5 and delete the 5 after the depoyment...") + ret = sysroot.write_deployments(cur_deployment[:5],None) + self._progress_to_plymouth(95) # 健全性检查 # rootfs_path = sysroot.get_deployment_dirpath(new_deployment) @@ -349,7 +370,7 @@ class RollbackBackend(BackendBaseOstree): # 部署的列表 for deploys in old_deployments: - if out_rollback.equal(deploys) != True: + if not out_rollback.equal(deploys): new_deployments.append(deploys) logging.info("start reollback checksum:%s...",rollback_csum) diff --git a/backend-immutable/data/system-updater-coverable.conf b/backend-immutable/data/system-updater-coverable.conf deleted file mode 100644 index 729f3c6..0000000 --- a/backend-immutable/data/system-updater-coverable.conf +++ /dev/null @@ -1,18 +0,0 @@ -#此配置文件内的所有配置项,在重新安装时会被替换掉 - -[AutoUpgradeConfig] -upgradeInterval = 7 -downloadRandom = 180 - -[TestsConfig] -check_device_power = True -force_dist_upgrade = False - -[ShutdownInstall] -# 包含的类型: "success":安装成功 "failed":安装失败 "none":不弹窗,默认状态 -finished_status = none - -[main debian archive] -Origin=Debian -Label=Debian -delta_uri=http://10.41.116.28 diff --git a/backend-immutable/data/system-updater-defaults.conf b/backend-immutable/data/system-updater-defaults.conf index 03b54ff..0f25af2 100644 --- a/backend-immutable/data/system-updater-defaults.conf +++ b/backend-immutable/data/system-updater-defaults.conf @@ -16,13 +16,11 @@ finished_status = success update_version = update_content = -# 保存上次安装的状态: - #1、在升级完成时刷新成功或者失败 - #2、在检查更新阶段 若推送内容不为空 检查不需要更新 判断为系统为最新 也刷新状态 -# last_install 字符串类型,"success":上次更新成功 非success时都认为失败例如 "#0202" 错误码 -[statusForProperties] -last_install = success -uuid = +[statusForFinishPrompt] +#statusForFinishPrompt +# 更新完成之后 开机弹窗提示更新状态的标志 ,控制面板的弹窗程序使用,记录安装的状态 +# 包含的类型: "success":安装成功 "none":不弹窗,默认状态,其他情况均为安装失败,例如#0201 +finished_status = none # 前端使用配置文件 [UpdateFrontendConf] diff --git a/backend-immutable/tests/test-admin-upgrade-endoflife.sh b/backend-immutable/tests/test-admin-upgrade-endoflife.sh index 059d8d1..4c4de90 100755 --- a/backend-immutable/tests/test-admin-upgrade-endoflife.sh +++ b/backend-immutable/tests/test-admin-upgrade-endoflife.sh @@ -28,6 +28,38 @@ moniter_signal_success () { done } +test_deploy_limit() { + for ((i=1; i<=$1; i++)) + do + y=$((i - 1)) + + if [ $y -eq 0 ]; then + y="" + fi + os_repository_new_commit 1 1 testos/buildmaster/newbranch$i + + mkdir empty$i + echo -n "Refs:testos/buildmaster/x86_64-runtime and new commit revision:" + ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --tree=dir=$(pwd)/empty$i --add-metadata-string "ostree.endoflife-rebase=testos/buildmaster/newbranch$i" -b testos/buildmaster/newbranch$y -s "EOL redirect to new branch" + + echo "" + echo "Ostree test environment is deployed, Start System update Fuction tested" + echo "" + + # 检查更新 + sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$update_method > /dev/null + moniter_signal_success $update_finished_signal + + # 下载过程 + sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$download_method > /dev/null + moniter_signal_success $download_finished_signal + + # 部署 + sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$deploy_method > /dev/null + moniter_signal_success $deploy_finished_signal + done +} + # 创建仓库 仓库类型 and boot类型 setup_os_repository "archive" "syslinux" @@ -43,44 +75,17 @@ assert_has_dir sysroot/boot/ostree/testos-${bootcsum} echo "Frist deploy refs:testos/buildmaster/x86_64-runtime to success" -os_repository_new_commit 1 1 testos/buildmaster/newbranch - -mkdir empty -echo -n "Refs:testos/buildmaster/x86_64-runtime and new commit revision:" -${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --tree=dir=$(pwd)/empty --add-metadata-string "ostree.endoflife-rebase=testos/buildmaster/newbranch" -b testos/buildmaster/x86_64-runtime -s "EOL redirect to new branch" - -echo "" -echo "Ostree test environment is deployed, Start System update Fuction tested" -echo "" - -sleep 600 - exec 3< <(/home/x/share/ostree/kylin-system-updater/backend/kylin-system-updater -r -d --sysroot=$test_tmpdir/sysroot --os=testos 2>&1) - # 等待dbus服务启动 sleep 3 -# 检查更新 -sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$update_method > /dev/null -moniter_signal_success $update_finished_signal - -# 下载过程 -sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$download_method > /dev/null -moniter_signal_success $download_finished_signal - -# 部署 -sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$deploy_method > /dev/null -moniter_signal_success $deploy_finished_signal +test_deploy_limit 1 # 部署完成后的检查 -assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf "${bootcsum}" -rev=$(${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo rev-parse testos/buildmaster/newbranch) -assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.0/usr/bin/content-iteration "1" +# assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf "${bootcsum}" +# rev=$(${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo rev-parse testos/buildmaster/newbranch) +# assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.0/usr/bin/content-iteration "1" -assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.0.origin "newbranch" +# assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.0.origin "newbranch" -echo "ok update and redirect" - -# 检查更新 -sudo gdbus call --system --dest $bus_name --object-path $object_path --method $interface_name.$update_method > /dev/null -moniter_signal_success $update_finished_signal \ No newline at end of file +echo "ok update and redirect" \ No newline at end of file diff --git a/debian/changelog b/debian/changelog index 2a3fd1f..4e6ae4d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +kylin-system-updater (3.0.0.0-ok18) v101; urgency=medium + + * BUG: 无 + * 需求号: 无 + * 其他改动说明: 支持所有配置迁移到/etc目录下、支持保存历史回滚 + * 其他改动影响域:无 + + -- wangsong Tue, 23 Apr 2024 21:00:01 +0800 + kylin-system-updater (3.0.0.0-ok17) v101; urgency=medium * BUG: 无 diff --git a/debian/kylin-system-updater-immutable.install b/debian/kylin-system-updater-immutable.install index ef0eff8..2c78c98 100644 --- a/debian/kylin-system-updater-immutable.install +++ b/debian/kylin-system-updater-immutable.install @@ -1,5 +1,5 @@ #!/usr/bin/dh-exec -#backend-immutable +#backend backend-immutable/data/kylin-system-updater.db /usr/share/kylin-system-updater/ backend-immutable/report-updater-bug /usr/bin backend-immutable/data/30kylin-system-updater /etc/apt/apt.conf.d/ @@ -15,9 +15,8 @@ backend-immutable/SystemUpdater/*.py /usr/share/kylin-system-updater/SystemUpdat backend-immutable/SystemUpdater/backend/*.py /usr/share/kylin-system-updater/SystemUpdater/backend/ backend-immutable/SystemUpdater/Core/*.py /usr/share/kylin-system-updater/SystemUpdater/Core/ backend-immutable/build/mo/* /usr/share/locale/ -backend-immutable/data/system-updater-defaults.conf /var/lib/kylin-system-updater/ -backend-immutable/data/system-updater-coverable.conf /var/lib/kylin-system-updater/ -backend-immutable/data/inhibit-sleep.conf /var/lib/kylin-system-updater/ + +backend-immutable/data/system-updater-defaults.conf /etc/kylin-system-updater/ backend-immutable/data/unattended-upgrades-policy.conf /var/lib/unattended-upgrades/ backend-immutable/data/unattended-upgrades-timestamp /var/lib/unattended-upgrades/ backend-immutable/data/cn.kylinos.KylinSystemUpdater.policy /usr/share/polkit-1/actions/ @@ -32,10 +31,7 @@ backend-immutable/data/kylin-system-updater /etc/logrotate.d #uu unattended-upgrades/*.service /lib/systemd/system/ -unattended-upgrades/notify /usr/bin/ -unattended-upgrades/*.desktop /etc/xdg/autostart/ -unattended-upgrades/kylin-unattended-upgrade /usr/bin unattended-upgrades/kylin-unattended-upgrade-shutdown /usr/bin -unattended-upgrades/kylin-unattended-upgrades /etc/apt/apt.conf.d/ +unattended-upgrades/kylin-unattended-upgrade /usr/bin unattended-upgrades/logrotate.d/* /etc/logrotate.d/ - +unattended-upgrades/mo/* /usr/share/locale/ \ No newline at end of file