对优先升级做出优化,可进行升级时,可不需要重启代码或者重启控制面板增加标志位来确定

This commit is contained in:
wangsong 2022-06-16 20:34:52 +08:00
parent 3dda6f799d
commit 0eabb53912
6 changed files with 73 additions and 51 deletions

View File

@ -18,6 +18,7 @@ import datetime
import threading
from email import message
from datetime import datetime
from binascii import a2b_hex
from Crypto.PublicKey import RSA
from urllib import parse, request

View File

@ -7,7 +7,7 @@ __all__ = (
"ERROR_NOT_INIT_PACKAGESINFIO","ERROR_READ_IMPORTANTLIST_FAILED","ERROR_RESOLVER_FAILED","ERROR_NOT_UPGRADE_PACKAGES",
"ERROR_REMOVE_ESSENTIAL_PACKAGES","ERROR_NOT_DISK_SPACE",
"ERROR_UPDATE_KEY_SIGNATURES","ERROR_UPDATE_NET_AUTHENTICATION","ERROR_UPDATE_NOTREAD_SOURCES",
"ERROR_UPDATE_KEY_SIGNATURES","ERROR_UPDATE_NET_AUTHENTICATION","ERROR_UPDATE_NOTREAD_SOURCES","PRIORITY_UPGRADE_SUCCCESSED",
"get_error_description_from_enum", "get_error_string_from_enum", "get_source_name_from_enum")
@ -16,6 +16,8 @@ gettext.bindtextdomain('kylin-system-updater', '/usr/share/locale')
gettext.textdomain('kylin-system-updater')
_ = gettext.gettext
PRIORITY_UPGRADE_SUCCCESSED = "priority-upgrade-successed"
#更新阶段
ERROR_UPDATE_KEY_SIGNATURES = "The following signatures"
ERROR_UPDATE_NET_AUTHENTICATION ="does the network require authentication?"
@ -34,6 +36,7 @@ ERROR_REMOVE_ESSENTIAL_PACKAGES = "error-remove-essential-packages"
ERROR_NOT_DISK_SPACE = "error-not-disk-space"
_STRINGS_ERROR = {
PRIORITY_UPGRADE_SUCCCESSED: _("Update Manager upgrade is complete, please restart the control panel before performing the system update"),
ERROR_UPDATE_SOURCE_FAILED: _("Unable to access the source management server"),
ERROR_NETWORK_FAILED: _("Please check your network connection and retry."),
ERROR_NOT_GROUPS_CONFIG: _("Unable to get group configuration package, please contact administrator to solve"),

View File

@ -306,7 +306,7 @@ class UpdateManager():
def _check_self_upgrade(self,cache):
need_upgrade = False
self_upgrade = []
with open(UpdateList.IMPORTANT_LIST_PATH, 'r') as f:
data = f.read()
important_list = data.split()
@ -322,6 +322,7 @@ class UpdateManager():
logging.info("Check: (%s) start upgrading From %s to %s...",pkg_name,\
self_pkg.installed.source_version,self_pkg.candidate.source_version)
self_pkg.mark_install()
self_upgrade.append(pkg_name)
need_upgrade = True
except SystemError:
logging.error("Check: mark %s to upgrade Failed...",pkg_name)
@ -340,20 +341,28 @@ class UpdateManager():
self.dbusController.UpdateDetectStatusChanged(95,_("Group configuration being updated"))
logging.info("Check: groups JSON ConfigPkgs(%s) start upgrading From %s to %s...",self.GROUPS_PKG_NAME,\
pkg_json.installed.source_version,pkg_json.candidate.source_version)
pkg_json.mark_install()
need_upgrade = True
try:
pkg_json.mark_install()
self_upgrade.append(self.GROUPS_PKG_NAME)
need_upgrade = True
except SystemError:
logging.error("Check: mark %s to upgrade Failed...",pkg_name)
else:
logging.info("Check: ConfigPkgs(%s:%s) No need to upgrade...",self.GROUPS_PKG_NAME,pkg_json.installed.source_version)
else:
self.dbusController.UpdateDetectStatusChanged(95,_("Group configuration being updated"))
logging.info("Check: groups JSON ConfigPkgs(%s) start new installing...",self.GROUPS_PKG_NAME)
pkg_json.mark_install()
need_upgrade = True
try:
pkg_json.mark_install()
self_upgrade.append(self.GROUPS_PKG_NAME)
need_upgrade = True
except SystemError:
logging.error("Check: mark %s to upgrade Failed...",pkg_name)
else:
raise UpdateBaseError(ERROR_NOT_GROUPS_CONFIG)
if need_upgrade == True:
self.start_install(InstallBackend.MODE_INSTALL_SINGLE,True)
self.start_install(InstallBackend.MODE_INSTALL_SINGLE,True,upgrade_content=self_upgrade)
raise UpdateProgressExit()
def _check_system_broken(self,cache):

View File

@ -295,8 +295,7 @@ class InstallBackendAptdaemon(InstallBackend):
return
self.aptd_base.progress = progress
self._dist_status_changed(action,self.now_upgrade.upgrade_groups+self.now_upgrade.single_pkgs,\
self.aptd_base.progress,self.aptd_base.status,self.aptd_base.details)
self._dist_status_changed(action,self.now_upgrade.upgrade_content,self.aptd_base.progress,self.aptd_base.status,self.aptd_base.details)
#同步状态回调
@ -309,7 +308,7 @@ class InstallBackendAptdaemon(InstallBackend):
if self.aptd_base.status == None:
return
self._dist_status_changed(action,self.now_upgrade.upgrade_groups+self.now_upgrade.single_pkgs,\
self._dist_status_changed(action,self.now_upgrade.upgrade_content,\
self.aptd_base.progress,self.aptd_base.status,self.aptd_base.details)
#分发进度状态和细节信息

View File

@ -64,8 +64,12 @@ class NowUpgradeMeta:
return groups_list,pkg_list
def make_upgrade_content(self,content):
self.upgrade_groups,self.single_pkgs = self._make_groups_list(self.parent.upgrade_data,self.parent.action_mode,content)
self.upgrade_content = self.upgrade_groups + self.single_pkgs
if self.parent.action_mode != self.parent.MODE_INSTALL_SINGLE:
self.upgrade_groups,self.single_pkgs = self._make_groups_list(self.parent.upgrade_data,self.parent.action_mode,content)
self.upgrade_content = self.upgrade_groups + self.single_pkgs
else:
self.single_pkgs = content
self.upgrade_content = self.upgrade_groups + self.single_pkgs
class AptdBaseInformation:
@ -141,9 +145,8 @@ class InstallBackend():
try:
#安装升级包 首先必须调用ACTION_CHECK_RESOLVER 计算依赖解决方便 标记cache 进行升级
if self.action == self.ACTION_INSTALL or self.action == self.ACTION_DOWNLOADONLY:
if self.action_mode != self.MODE_INSTALL_SINGLE:
#拿到升级列表
self.now_upgrade.make_upgrade_content(partial_upgrade_list)
#拿到升级列表
self.now_upgrade.make_upgrade_content(partial_upgrade_list)
pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,self.upgrade_data.adjust_pkgs,self.action_mode)
logging.info("INSTALL install:%d , upgrade:%d remove:%d",len(pkgs_install),len(pkgs_upgrade),len(pkgs_remove))
@ -157,8 +160,8 @@ class InstallBackend():
if len(pkgs_install) == 0 and len(pkgs_upgrade) == 0 and len(pkgs_remove) == 0:
raise UpdateBaseError(ERROR_NOT_UPGRADE_PACKAGES)
if self.action_mode == self.MODE_INSTALL_SINGLE:
logging.warning("MODE_INSTALL_SINGLE install:%s , upgrade:%s remove:%s",str(pkgs_install),str(pkgs_upgrade),str(pkgs_remove))
# if self.action_mode == self.MODE_INSTALL_SINGLE:
# logging.warning("MODE_INSTALL_SINGLE install:%s , upgrade:%s remove:%s",str(pkgs_install),str(pkgs_upgrade),str(pkgs_remove))
self.window_main.update_essential.check(pkgs_remove)
@ -495,6 +498,45 @@ class InstallBackend():
if error_code == ERROR_NOT_DISK_SPACE:
self.window_main.dbusController.InstallDetectStatus(False,error_code)
def _self_upgrade_finished(self,success,error_string='',error_desc=''):
if success:
error_string = get_error_string_from_enum(PRIORITY_UPGRADE_SUCCCESSED)
if self.window_main.configs.getWithDefault("SystemStatus", "priority_upgrade_restart", False) == True:
if self.window_main.APTD_PKG_NAME in self.now_upgrade.upgrade_content:
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
self.window_main.dbusController.make_aptdeamon_restart()
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.FRONTEND_PKG_NAME in self.now_upgrade.upgrade_content:
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.BACKEND_PKG_NAME in self.now_upgrade.upgrade_content:
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
#升级本身完成后 退出 有systemd 来进行重启服务
self.window_main.dbusController.Quit(None)
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.GROUPS_PKG_NAME in self.now_upgrade.upgrade_content:
#只有安装配置文件包 才会走到此处
self.window_main.update_essential.update()
self.window_main.start_available()
else:
#只有安装配置文件包 才会走到此处
self.window_main.update_essential.update()
self.window_main.start_available()
return
else:
#当更新过程中安装配置包时 失败时发送错误信号
# 防止错误结果太长导致出现控制面板显示太多 目前最多20字符
if len(error_string + error_desc) > 20:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string,error_desc)
else:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string,error_desc)
return
#调用aptdeamon结束之后处理的地方 不管是出错还是正常都在此处理
def _action_done(self, action, is_cancelled,success, error_string,error_desc,error_code=''):
#后端的状态 到空闲状态
@ -505,41 +547,8 @@ class InstallBackend():
self._release_install_lock()
self._send_error_code(error_code)
#单包安装模式 单独处理 目前 更新配置包和升级本身使用
if self.action_mode == self.MODE_INSTALL_SINGLE:
if success:
if self.window_main.APTD_PKG_NAME in self.cache and self.cache[self.window_main.APTD_PKG_NAME] in self.cache.get_changes():
error_string = _("Update Manager upgrade is complete, please restart the control panel before performing the system update")
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
self.window_main.dbusController.make_aptdeamon_restart()
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.FRONTEND_PKG_NAME in self.cache and self.cache[self.window_main.FRONTEND_PKG_NAME] in self.cache.get_changes():
error_string = _("Update Manager upgrade is complete, please restart the control panel before performing the system update")
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.BACKEND_PKG_NAME in self.cache and self.cache[self.window_main.BACKEND_PKG_NAME] in self.cache.get_changes():
error_string = _("Update Manager upgrade is complete, please restart the control panel before performing the system update")
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.BACKEND_PKG_NAME],error_string,error_desc)
#升级本身完成后 退出 有systemd 来进行重启服务
self.window_main.dbusController.Quit(None)
#当单包升级的时候 升级本身时,让程序退出,再重新启动
if self.window_main.GROUPS_PKG_NAME in self.cache and self.cache[self.window_main.GROUPS_PKG_NAME] in self.cache.get_changes():
#只有安装配置文件包 才会走到此处
self.window_main.update_essential.update()
self.window_main.start_available()
return
else:
#当更新过程中安装配置包时 失败时发送错误信号
# 防止错误结果太长导致出现控制面板显示太多 目前最多20字符
if len(error_string + error_desc) > 20:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string,error_desc)
else:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string,error_desc)
return
self._self_upgrade_finished()
else:
if self.now_upgrade.version_upgrade == True and self.now_upgrade.need_retry == True and success == False:
#增加重试次数的限制

View File

@ -2,6 +2,7 @@
abnormal_reboot = False
close_source_filter = False
upload_upgrade_log = False
priority_upgrade_restart = True
[ConfigPkgStatus]
check_resover_remove = False