Skip to content

Commit f64c154

Browse files
committed
feat(tools): adds an update scenario for all targets
This change adds a new function that describes the main update scenario. It handles multiple hosts and then runs an update on each of them. Basically, it is the kind of function that can be called directly from a CLI. Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent fb8a02c commit f64c154

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

lib/tools/tasks/update.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,56 @@
22
33
This module is intended for performing update actions on existing remote targets.
44
"""
5+
import sys
6+
from concurrent.futures import ThreadPoolExecutor
57

8+
from lib.common import HostAddress
69
from lib.host import Host
10+
from lib.pool import Pool
711

812
from .. import logger
913

1014
from typing import List
1115

16+
def update_all(hosts: List[HostAddress], enablerepos: List[str]):
17+
"""Updates all targets scenario.
18+
19+
This function describes the update scenario for a set of remote targets. Those targets used for
20+
running xcp-ng tests suite. See below.
21+
22+
The scenario
23+
------------
24+
25+
* Receives a list of master host, :py:class:`lib.common.HostAddress` (either hostname or ip address)
26+
27+
.. note:: Host must be a master
28+
29+
If provided hosts are not master (or main), an error :py:exc:`AssertionError` will be thrown
30+
and then exits the program.
31+
32+
* Optionally receives a list of repositories to enabled (related to `yum`). *Repo(s) will be enabled for each host.*
33+
* Creates a list of :py:class:`lib.pool.Pool`
34+
* Updates are done using multithreading
35+
36+
:param :py:class:`List[lib.common.HostAddress]`: A list of host for the update scenario.
37+
:param List[str] enablerepos: Enable one or more repo(s) when updating.
38+
"""
39+
logger.debug(f"[{hosts}] enablerepos: {enablerepos}")
40+
# init related pools
41+
try:
42+
pools = [Pool(h) for h in hosts]
43+
logger.info("Preparing Pools...")
44+
except AssertionError as ae:
45+
logger.critical(ae)
46+
sys.exit(1)
47+
48+
with ThreadPoolExecutor() as executor:
49+
for p in pools:
50+
executor.submit(update_host, p.master, enablerepos)
51+
52+
logger.info(pools)
53+
54+
1255
def update_host(host: Host, enablerepos: List[str] = []):
1356
"""Updates the target.
1457

0 commit comments

Comments
 (0)