-
Notifications
You must be signed in to change notification settings - Fork 6
Replace manual process handling by local_cmd() #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9d306d6
92df3e0
53bb8fc
10fbfb5
7f29d69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -460,6 +460,7 @@ def sign_image(self, image: str) -> str: | |
| Returns path to signed image. | ||
| """ | ||
| assert self._owner_cert is not None | ||
| assert self._owner_cert.key is not None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this change relates to the rest of the commit
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here to please type checking since I added type checking information for local_cmd()
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Probably something to mention in the commit message, as it's not obvious.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| if shutil.which('sbsign'): | ||
| signed = get_signed_name(image) | ||
| commands.local_cmd([ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| import socket | ||
|
|
||
| from lib.commands import local_cmd | ||
| from lib.common import wait_for | ||
|
|
||
| def wait_for_tcp_port(host, port, port_desc, ping=True, host_desc=None): | ||
| if host_desc: | ||
| host_desc = f"({host_desc})" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about getting the formatting space here rather than logging a trailing one when not set? |
||
| if ping: | ||
| wait_for(lambda: local_cmd(['ping', '-c1', host], check=False, simple_output=False).returncode == 0, | ||
| "Wait for host up (ICMP ping)", timeout_secs=10 * 60, retry_delay_secs=10) | ||
| wait_for(lambda: local_cmd(['nc', '-zw5', host, str(port)], check=False, simple_output=False).returncode == 0, | ||
| f"Wait for {port_desc} up on host {host_desc}", timeout_secs=10 * 60, retry_delay_secs=5) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would add timers, retry as defauts params
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do that when/if we need to use a different value IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure i was a just a suggestion at this stage, btw the motivation of values will not hurt if there is any |
||
|
|
||
| def wait_for_ssh(host, host_desc=None, ping=True): | ||
| wait_for_tcp_port(host, 22, "SSH", ping, host_desc) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for port, should't it be a default param ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, but in this why not just wait_for_tcp_port() in this case. The function doesn't bother if it's a real SSH server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well my comment was mostly from API perspective but not a big deal, you could add extra params for ssh if needed, like minimal version requiered etc |
||
|
|
||
| def is_ipv6(ip): | ||
| try: | ||
| socket.inet_pton(socket.AF_INET6, ip) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import pytest | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
| from lib.commands import local_cmd | ||
|
|
||
| # Requirements: | ||
| # - 2 XCP-ng host of same version | ||
|
|
@@ -14,13 +15,11 @@ def test_fs_diff(hosts): | |
|
|
||
| fsdiff = os.path.realpath(f"{os.path.dirname(__file__)}/../../scripts/xcpng-fs-diff.py") | ||
|
|
||
| process = subprocess.Popen( | ||
| [fsdiff, "--reference-host", f"{hosts[0]}", "--test-host", f"{hosts[1]}", "--json-output"], | ||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE | ||
| ) | ||
| stdout, _ = process.communicate() | ||
| res = local_cmd([fsdiff, "--reference-host", f"{hosts[0]}", | ||
| "--test-host", f"{hosts[1]}", | ||
| "--json-output"], simple_output=False) | ||
|
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| if process.returncode != 0: | ||
| print(stdout.decode()) | ||
| if res.returncode != 0: | ||
| print(res.stdout) | ||
|
|
||
| assert process.returncode == 0 | ||
| assert res.returncode == 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import pytest | ||
|
|
||
| import hashlib | ||
| import subprocess | ||
|
|
||
| from lib import commands | ||
|
|
||
|
|
@@ -35,10 +34,10 @@ def test_access_links(host, command_id, url_id): | |
|
|
||
| # Verify the download worked by comparing with local download | ||
| # This ensures the content is accessible and identical from both locations | ||
| local_result = commands.local_cmd(COMMAND) | ||
| local_result = commands.local_cmd(COMMAND, check=False, simple_output=False) | ||
|
|
||
| assert local_result.returncode == 0, ( | ||
| f"Failed to fetch URL locally: {local_result.stderr}" | ||
| f"Failed to fetch URL locally: {local_result.stdout}" | ||
|
Comment on lines
-41
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this and not show
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it there only |
||
| ) | ||
|
|
||
| # Extract checksums | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose there's a reason for not importing at the top level, but such exception should be documented with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid cycling import. Or I should have put the new function in something different than
netutils.Or maybe you prefer that the local import be done in netutils ? It should not make any diffrence.
I will add a comment anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cyclic import could be solved in several ways:
commands.py(yeah, that's a bit meh)local_cmdandsshare not on the same level (but here it is unfortunate the one that would be the best candidate to move out into a new file was the first occupant and most-imported over the repo, ie.sshand friends)Maybe we could have a variant of the 2nd solution, by moving everyone out, into
lib/ssh.pyandlib.command.py(note the lack ofs- or maybelocal.pywould be better? I'm not sure), and letcommands.pyimport the relevant symbols from those as a compatibility lib until we cleanup everything (avoiding to break all those in-flight PRs)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you of moving it to lib.netutil ?
Anyway we could make that in second time, not in that PR, it would change too much files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #366 created for that purpose.