Skip to content
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

feat: Add cloud version string #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pycloudlib/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def use_key(self, public_key_path, private_key_path=None, name=None):
self._log.debug("using SSH key from %s", public_key_path)
self.key_pair = KeyPair(public_key_path, private_key_path, name)

def version(self) -> Optional[str]:
"""Version string of the platform."""
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a lot of value in us returning None here instead of just an empty string ""? We can then avoid the Optional[str] handling for typing validation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with chad. I don't think there is much benefit to returning a None instead of a falsey/empty string.


def _check_and_set_config(
self,
config_file: Optional[ConfigFile],
Expand Down
4 changes: 4 additions & 0 deletions pycloudlib/lxd/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ def clean(self) -> List[Exception]:
exceptions.append(e)
return exceptions

def version(self):
Copy link
Collaborator

@blackboxsw blackboxsw Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I'd cache this value somehow as it's unlikely to change on the host mid-test.

"""LXD version."""
return subp(["lxd", "--version"]).rstrip()


class LXDContainer(_BaseLXD):
"""LXD Containers Cloud Class."""
Expand Down
9 changes: 9 additions & 0 deletions pycloudlib/qemu/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,12 @@ def clean(self) -> List[Exception]:
exceptions.append(e)

return exceptions

def version(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holmanb We should probably lru_cache this as it's unlikely to change mid integration test run, but it's something we don't want to recalculate any time we call it.

"""Qemu version."""
return (
subprocess.run(self.qemu_binary, capture_output=True)
.stdout.decode()
.splitlines()
.pop(0)
)
2 changes: 2 additions & 0 deletions tests/integration_tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def test_public_api(cloud: BaseCloud):
# Not sure there's a great way to test this other than not raising
cloud.image_serial(image_id)

version = cloud.version()
assert isinstance(version, str) or version is None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert isinstance(version, str) or version is None
assert isinstance(version, str) or version is None

with cloud.launch(image_id=image_id, user_data=cloud_config) as instance:
instance.wait()
exercise_instance(instance)
Expand Down
Loading