Skip to content

Commit 211cf8a

Browse files
committed
tools/update: move update_host into class host
Instead of an external function, update should live inside Host class. Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent 08dfe37 commit 211cf8a

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

lib/host.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,23 @@ def yum_update(self, enablerepos: List[str] = []):
450450

451451
return self.ssh(base_command)
452452

453+
def update(self, enablerepos: list[str] = []):
454+
"""Updates current host.
455+
456+
An helper function that wraps update tasks on current host.
457+
458+
:param list[str] enablerepos:
459+
Repositories to enable when updating.
460+
"""
461+
logging.info(f"[{self}] Updating...")
462+
463+
self.yum_clean_metadata()
464+
self.yum_update(enablerepos=enablerepos)
465+
# Everything's ok, just reboot
466+
self.reboot(verify=True)
467+
468+
logging.info(f"[{self}] Updated successfully!")
469+
453470
def restart_toolstack(self, verify=False):
454471
logging.info("Restart toolstack on host %s" % self)
455472
self.ssh(['xe-toolstack-restart'])

lib/tools/tasks/update.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
from concurrent.futures import ThreadPoolExecutor
66

7-
from lib.host import Host
87
from lib.pool import Pool
98

109
from .. import logger
@@ -25,24 +24,4 @@ def update_all(inventory: dict) -> None:
2524

2625
with ThreadPoolExecutor() as executor:
2726
for p in pools:
28-
executor.submit(update_host, p.master, inventory[p.master.hostname_or_ip]["enablerepos"])
29-
30-
31-
def update_host(host: Host, enablerepos: list[str] = []):
32-
"""Updates the target host.
33-
34-
An helper function that wraps update tasks on specific host.
35-
36-
:param :py:class:`lib.host.Host` host:
37-
Target host to update.
38-
:param list[str] enablerepos:
39-
Repositories to enable when updating.
40-
"""
41-
logger.info(f"[{host}] Updating...")
42-
43-
host.yum_clean_metadata()
44-
host.yum_update(enablerepos=enablerepos)
45-
# Everything's ok, just reboot
46-
host.reboot(verify=True)
47-
48-
logger.info(f"[{host}] Updated successfully!")
27+
executor.submit(p.master.update, inventory[p.master.hostname_or_ip]["enablerepos"])

0 commit comments

Comments
 (0)