ohu/xcpng/001 - Tools - adds update scenario#415
ohu/xcpng/001 - Tools - adds update scenario#415olivierh-pro wants to merge 4 commits intomasterfrom
Conversation
d11a9e0 to
0738378
Compare
ydirson
left a comment
There was a problem hiding this comment.
We don't use the "feat(...)" convention in this project. Flexible prefix is much more useful, here that could be something like:
- adds sub package tools for automation scripts
- tools: adds tasks sub packages
- tools/tasks: adds update task
- tools/tasks: adds an update scenario for all targets
lib/tools/tasks/update.py
Outdated
| def update_host(host: Host, enablerepos: List[str] = []): | ||
| """Updates the target. | ||
|
|
||
| Updating a remote host target has the following workflow: | ||
|
|
||
| * Cleans cached metadata | ||
| * Updates packages (with optional repositories enabled or not) | ||
| * Reboots (verifies whether the host is up or not) | ||
|
|
||
| :param :py:class:`lib.host.Host` host: Target host to update. | ||
| :param List[str] enablerepos: Extra repo(s) to enable (default: []). | ||
| """ | ||
| logger.info(f"[{host}] Begin updating target host") | ||
|
|
||
| host.yum_clean_metadata() | ||
| host.yum_update(enablerepos=enablerepos) | ||
| # Everything's ok, just reboot | ||
| host.reboot(verify=True) | ||
|
|
||
| logger.info(f"[{host}] Updated!") |
There was a problem hiding this comment.
This function being essentially a series of calls o Host methods, wouldn't it make sense to be a Host method itself?
There was a problem hiding this comment.
You are completely right, it makes sense, especially with OOP mindset. To be honest I didn't dare to modify Host class 😅 .
The real reason is: I wanted to encapsulate "an update scenario" in a sub package because it is not an "atomic task" as it is suggested by host methods.
Not sure what to do next, anyone else has an opinion here ? @xcp-ng/os-platform-release
There was a problem hiding this comment.
TODO: Quick explanation about role of this func, a wrapper
lib/tools/tasks/update.py
Outdated
| try: | ||
| pools = [Pool(h) for h in hosts] | ||
| logger.info("Preparing Pools...") | ||
| except AssertionError as ae: | ||
| logger.critical(ae) | ||
| sys.exit(1) |
There was a problem hiding this comment.
What does this try/exit bring us over default behavior?
There was a problem hiding this comment.
I really prefer to explicitely exit with code error. By reading this code, I expect to receive error from Pool and then quit the program.
In my opnion, the line that throws AssertionError doesn't completely describe the case. I would have written the code below instead:
if not host.is_maste():
raise EmptyPoolError(f"{master_hostname_or_ip} is not a master host. Required to instantiate a Pool.")There was a problem hiding this comment.
I usually don't like catching AssertionError (or SystemExit). If I need to, I try to keep it in the root function.
I would prefer the Pool constructor sending a more meaningful exception, but I'm fine with the assertion too—this is a test lib after all
There was a problem hiding this comment.
TODO: Remove error handling, let the AssertionError raises anyway
a3dfcb9 to
f64c154
Compare
lib/tools/tasks/update.py
Outdated
| try: | ||
| pools = [Pool(h) for h in hosts] | ||
| logger.info("Preparing Pools...") | ||
| except AssertionError as ae: | ||
| logger.critical(ae) | ||
| sys.exit(1) |
There was a problem hiding this comment.
I usually don't like catching AssertionError (or SystemExit). If I need to, I try to keep it in the root function.
I would prefer the Pool constructor sending a more meaningful exception, but I'm fine with the assertion too—this is a test lib after all
65ea2a4 to
c8c5013
Compare
* instantiates an object logger in `__init__` * logfmt and datefmt match with pytest config found in file `./pytest.ini` at root level Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
This task performs a basic update and takes only one host. It is intended for being used against a list of hosts. Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
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>
c8c5013 to
a8ab52e
Compare
xcpng-539
This PR adds new sub package inside the shared packages
lib. The new sub package provides update actions.update_host: Updates one host with basic actions (clean metadata, yum update and reboot)update_all: Describes a scenario with all logic to perform for updating a set of hostsNote
The code for this PR is based on branch ohu/xcpng-539/000.
Please, consider #413 before this one.