update_manager: handle system package init

Force refresh requests after server initializaton.  Update
package state after installation.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-12-04 11:08:27 -05:00
parent e8c1798a13
commit 13bc4c5b9b
2 changed files with 8 additions and 5 deletions

View File

@ -773,8 +773,6 @@ class PackageDeploy(BaseDeploy):
storage = self._load_storage() storage = self._load_storage()
self.available_packages: List[str] = storage.get('packages', []) self.available_packages: List[str] = storage.get('packages', [])
self.refresh_evt: Optional[asyncio.Event] = None self.refresh_evt: Optional[asyncio.Event] = None
# Initialze to current time so an update is not performed on init
self.last_apt_update_time: float = time.time()
self.mutex: asyncio.Lock = asyncio.Lock() self.mutex: asyncio.Lock = asyncio.Lock()
async def refresh(self) -> None: async def refresh(self) -> None:
@ -785,7 +783,9 @@ class PackageDeploy(BaseDeploy):
async with self.mutex: async with self.mutex:
self.refresh_evt = asyncio.Event() self.refresh_evt = asyncio.Event()
try: try:
await self._update_apt() # Do not force a refresh until the server has started
force = self.server.is_running()
await self._update_apt(force=force)
res = await self.cmd_helper.run_cmd_with_response( res = await self.cmd_helper.run_cmd_with_response(
"apt list --upgradable", timeout=60.) "apt list --upgradable", timeout=60.)
pkg_list = [p.strip() for p in res.split("\n") if p.strip()] pkg_list = [p.strip() for p in res.split("\n") if p.strip()]
@ -822,6 +822,7 @@ class PackageDeploy(BaseDeploy):
except Exception: except Exception:
raise self.server.error("Error updating system packages") raise self.server.error("Error updating system packages")
self.available_packages = [] self.available_packages = []
self._save_state()
self.cmd_helper.notify_update_response( self.cmd_helper.notify_update_response(
"Package update finished...", is_complete=True) "Package update finished...", is_complete=True)
return True return True
@ -831,12 +832,11 @@ class PackageDeploy(BaseDeploy):
notify: bool = False notify: bool = False
) -> None: ) -> None:
curtime = time.time() curtime = time.time()
if force or curtime > self.last_apt_update_time + 3600.: if force or curtime > self.last_refresh_time + 3600.:
# Don't update if a request was done within the last hour # Don't update if a request was done within the last hour
await self.cmd_helper.run_cmd( await self.cmd_helper.run_cmd(
f"{self.APT_CMD} update --allow-releaseinfo-change", f"{self.APT_CMD} update --allow-releaseinfo-change",
timeout=300., notify=notify) timeout=300., notify=notify)
self.last_apt_update_time = time.time()
async def install_packages(self, async def install_packages(self,
package_list: List[str], package_list: List[str],

View File

@ -157,6 +157,9 @@ class Server:
def get_event_loop(self) -> EventLoop: def get_event_loop(self) -> EventLoop:
return self.event_loop return self.event_loop
def is_running(self) -> bool:
return self.server_running
async def _start_server(self): async def _start_server(self):
optional_comps: List[Coroutine] = [] optional_comps: List[Coroutine] = []
for name, component in self.components.items(): for name, component in self.components.items():