|
2 | 2 |
|
3 | 3 | This module is intended for performing update actions on existing remote targets. |
4 | 4 | """ |
| 5 | +import sys |
| 6 | +from concurrent.futures import ThreadPoolExecutor |
5 | 7 |
|
| 8 | +from lib.common import HostAddress |
6 | 9 | from lib.host import Host |
| 10 | +from lib.pool import Pool |
7 | 11 |
|
8 | 12 | from .. import logger |
9 | 13 |
|
10 | 14 | from typing import List |
11 | 15 |
|
| 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 | + |
12 | 55 | def update_host(host: Host, enablerepos: List[str] = []): |
13 | 56 | """Updates the target. |
14 | 57 |
|
|
0 commit comments