Merge branch 'backend_dev' of gitlab2.kylin.com:kylin-desktop/update-manager-group/kylin-system-updater into backend_dev

This commit is contained in:
wangsong 2021-12-14 21:01:34 +08:00
commit 3d9fb88db0
4 changed files with 93 additions and 18 deletions

View File

@ -2,6 +2,7 @@
# supervisory control and data acquisition
#!/usr/bin/python3
import os
import json
import dbus
import uuid
@ -19,21 +20,23 @@ from json.decoder import JSONDecodeError
from dbus.exceptions import DBusException
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
LOCALTIDPATH = "/var/lib/kylin-system-updater/system-updater.conf"
LOCALTIDDIR = "/var/lib/kylin-system-updater/"
LOCALTIDFILE = "tidfile.conf"
MSGSNDDIR = "/var/lib/kylin-system-updater/sendinfos/"
class UpdateMsgCollector():
def __init__(self, manager):
self.UploadMessage = {}
self.PackageInfo = {}
self.waitSendList = []
self.updateManager = manager
# 转换 & 加密
self.convertor = FormatConvert(self)
# 发送器
self.sender = MessageSend(self)
# 配置文件
self.configs = UpgradeConfig("/var/lib/kylin-system-updater/", name="tidfile.conf")
# self.configs = UpgradeConfig(LOCALTIDDIR, name=LOCALTIDFILE)
def GenUploadMessage(self, dict_message):
UploadMessage = {}
# 获取将要上传的数据,获取东八区时间
@ -59,7 +62,7 @@ class UpdateMsgCollector():
# 获取本地tid
self.sender.GetLocalTid()
PackageInfo["tid"] = str(self.sender.localtid)
# logging.info("Get local tid:(%s).",localtid)
logging.info("Get local tid:(%s).",self.sender.localtid)
json_PackageInfo = self.convertor.dictConvertJson(PackageInfo)
@ -160,9 +163,13 @@ class MessageSend():
ERR_UPLOADMSG_SHA = 4
ERR_UPLOADMSG_CTS = 5
def __init__(self, DataCollector) -> None:
def __init__(self, DataCollector=None) -> None:
# self.convertor = FormatConvert()
self.collector = DataCollector
if DataCollector == None:
self.collector = UpdateMsgCollector()
else:
self.collector = DataCollector
self.ReadFromFile("/var/lib/kylin-system-updater/sendinfos/testMsg.json")
def MsgSendToServer(self, UploadMessage, PackageInfo, encodeMsg):
daqbus = dbus.SystemBus()
@ -202,7 +209,7 @@ class MessageSend():
logging.info("Sent Status: false - packageName: %s : result: %s.", PackageInfo['packageName'], result)
# 上传失败写入本地json
if retval != self.ERR_NO_LOACLTID:
self.WriteToJson()
self.WriteToJson(PackageInfo['messageType'], json_PackageInfo, json_UploadMessage, encodeMsg)
elif retval == 0:
result = "Send to server success"
logging.info("Sent Status: True - packageName: %s : result: %s.", PackageInfo['packageName'], result)
@ -210,7 +217,12 @@ class MessageSend():
def GetLocalTid(self):
# 试图获取本地tid
try:
self.localtid = self.collector.configs.getWithDefault("TID","localtid",default="")
if os.path.exists(LOCALTIDDIR+LOCALTIDFILE):
with open(LOCALTIDDIR+LOCALTIDFILE, "r") as f:
self.localtid = f.readline()
# print(self.localtid)
else:
self.localtid = ""
except Exception as e:
logging.error(str(e))
@ -218,14 +230,40 @@ class MessageSend():
if len(localtid) == 0:
return
try:
self.collector.updateManager.configs.setValue("TID","localtid",value=localtid,is_write=True)
if os.path.exists(LOCALTIDDIR+LOCALTIDFILE):
with open(LOCALTIDDIR+LOCALTIDFILE, "w+") as f:
f.write(str(localtid))
else:
with open(LOCALTIDDIR+LOCALTIDFILE, "w+") as f:
f.write(str(localtid))
except Exception as e:
logging.error(str(e))
def WriteToJson(self, ):
def WriteToJson(self, messageType, json_PackageInfo, json_UploadMessage, encodeMsg):
#发送失败时写入本地json中定时发送
pass
Msg = {}
Msg["PackageInfo"] = json_PackageInfo
Msg["UploadMessage"] = json_UploadMessage
Msg["encodeMsg"] = str(encodeMsg)
json_file = self.collector.convertor.dictConvertJson(Msg)
# 保存信息
try:
if not os.path.exists(MSGSNDDIR):
os.mkdir(MSGSNDDIR)
# 根据messageType保存信息
with open(MSGSNDDIR+messageType+".json","a") as f:
f.write(json_file)
f.write("\n")
except Exception as e:
logging.error(str(e))
def ReadFromFile(self, json_path):
# 从本地文件读取
if not os.path.exists(json_path):
return
# with open(json_path, "w") as f:
# while True:
# line =
class UniqueKey():
keyvalue = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FR\
@ -257,4 +295,10 @@ def get_east_8_time():
# 时间元祖转字符串
now_time = time.strftime("%Y-%m-%d %H:%M:%S",now_time)
now_time = now_time + "." +time_suffix
return now_time
# return now_time
return 0
if __name__ == "__name__":
# 执行定时发送
ms = MessageSend()
ms.ReadFromFile("/var/lib/kylin-system-updater/sendinfos/testMsg.json")

View File

@ -163,8 +163,9 @@ class UpdateManager():
# 是否有破损的包
deb_cache = Cache()
broken_count = deb_cache._depcache.broken_count
if broken_count > 0:
# 走 dpkg 安装流程说明本地apt环境已经损坏
_need_downgrade = self._check_downgrade(deb_cache, debname)
if broken_count > 0 or _need_downgrade == True:
# 走 dpkg 安装流程说明本地apt环境已经损坏,or downgrade
dep_satisfy, header, desc = self._deb_install(deb_cache, deb_path, _check_local_dep)
if dep_satisfy:
self.dbusController.InstalldebFinished(True, header, desc)
@ -608,4 +609,18 @@ class UpdateManager():
except Exception as e:
logging.error(e)
return False, str(e), desc
return True, header, desc
return True, header, desc
def _check_downgrade(self, deb_cache, debname):
if deb_cache == None or debname == "":
return
pkgname = debname.split('_')[0]
pkg_version = debname.split('_')[1]
try:
pkg = deb_cache[pkgname]
if pkg.is_installed and pkg.installed.source_version > pkg_version:
return True
else:
return False
except Exception as e:
logging.error(str(e))

View File

@ -8,5 +8,3 @@ isclosefilter = False
[ConfigPkgStatus]
mustexistconfigpkg = True
[TID]
localtid =

18
debian/changelog vendored
View File

@ -1,3 +1,21 @@
kylin-system-updater (1.2.18.1kord) v101; urgency=medium
* BUG:
* 需求号: 无
* 其他改动说明:
* 其他改动影响域:系统更新
-- luoxueyi <luoxueyi@kylinos.cn> Tue, 14 Dec 2021 16:20:58 +0800
kylin-system-updater (1.2.18kord) v101; urgency=medium
* BUG: #95760: 【更新升级-需求-9002】【系统更新】控制面板更新提示更新失败-软件包错误,实际已经安装成功
* 需求号: 无
* 其他改动说明: 修改大数据采集后端dbus接口
* 其他改动影响域:系统更新多维数据采集
-- luoxueyi <luoxueyi@kylinos.cn> Mon, 13 Dec 2021 10:23:39 +0800
kylin-system-updater (1.2.17.3kord) v101; urgency=medium
* BUG: #95760:  【更新升级-需求-9002】【系统更新】控制面板更新提示更新失败-软件包错误,实际已经安装成功