Last active
August 16, 2022 14:45
-
-
Save happz/39828287a47fd983c8db14a2e3700459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tmt/steps/provision/__init__.py b/tmt/steps/provision/__init__.py | |
index 772013f..a77ed61 100644 | |
--- a/tmt/steps/provision/__init__.py | |
+++ b/tmt/steps/provision/__init__.py | |
@@ -255,6 +255,16 @@ class GuestData(tmt.utils.SerializableContainer): | |
# hostname or ip address | |
guest: Optional[str] = None | |
+ def from_input(self, obj: tmt.steps.BasePlugin) -> None: | |
+ for field in dataclasses.fields(self): | |
+ value = obj.get(field.name) | |
+ normalize_callback = getattr(self, f'_normalize_{field.name}', None) | |
+ | |
+ if normalize_callback: | |
+ value = normalize_callback(value) | |
+ | |
+ setattr(self, field.name, value) | |
+ | |
class Guest(tmt.utils.Common): | |
""" | |
@@ -621,6 +631,12 @@ class GuestSshData(GuestData): | |
# password | |
password: Optional[str] = None | |
+ def _normalize_port(self, value: Optional[str]) -> Optional[int]: | |
+ if value is None: | |
+ return None | |
+ | |
+ return int(value) | |
+ | |
class GuestSsh(Guest): | |
""" | |
diff --git a/tmt/steps/provision/testcloud.py b/tmt/steps/provision/testcloud.py | |
index 43df098..c51c9d6 100644 | |
--- a/tmt/steps/provision/testcloud.py | |
+++ b/tmt/steps/provision/testcloud.py | |
@@ -176,6 +176,12 @@ class TestcloudGuestData( | |
image_url: Optional[str] = None | |
instance_name: Optional[str] = None | |
+ def _normalize_memory(self, value: Optional[str]) -> int: | |
+ if value is None: | |
+ return DEFAULT_MEMORY | |
+ | |
+ return int(value) | |
+ | |
@tmt.steps.provides_method('virtual.testcloud') | |
class ProvisionTestcloud(tmt.steps.provision.ProvisionPlugin): | |
@@ -278,10 +284,8 @@ class ProvisionTestcloud(tmt.steps.provision.ProvisionPlugin): | |
super().go() | |
# Give info about provided data | |
- data = TestcloudGuestData(**{ | |
- key: self.get(key) | |
- for key in TestcloudGuestData.keys() | |
- }) | |
+ data = TestcloudGuestData().from_input(self) | |
+ | |
for key, value in data.to_dict().items(): | |
if key == 'memory': | |
self.info('memory', f"{value} MB", 'green') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment