-
Notifications
You must be signed in to change notification settings - Fork 17
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
Implement dry-run for install/upgrade process #464
Changes from 5 commits
9562c60
08a43a1
0da5e30
a6de9f8
252b9fc
d101832
3c9f23d
ae564f6
c5f6026
f69796b
1f3c91f
3c28711
8ab2859
c0a038e
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 |
---|---|---|
|
@@ -346,6 +346,35 @@ def do(self: 'NodeGroup', *args, logging_stream_level: int = None, **kwargs): | |
return do | ||
|
||
|
||
def _handle_dry_run(fn: callable) -> callable: | ||
""" | ||
Method is a decorator that handles internal streaming of output (hide=False) of fabric (invoke). | ||
Note! This decorator should be the outermost. | ||
:param fn: Origin function to apply annotation to | ||
:return: Validation wrapper function | ||
""" | ||
def do_dry_run(self: 'NodeGroup', *args, **kwargs): | ||
results = {} | ||
|
||
if kwargs.get("dry_run"): | ||
if fn.__name__ == "put": | ||
self.cluster.log.verbose("Local file \"%s\" is being transferred to remote file \"%s\" on nodes %s with options %s" | ||
% (args[0], args[1], list(self.nodes.keys()), kwargs)) | ||
else: | ||
self.cluster.log.verbose('Performing %s %s on nodes %s with options: %s' % (fn.__name__, args[0], list(self.nodes.keys()), kwargs)) | ||
return NodeGroupResult(self.cluster, results) | ||
elif "dry_run" in kwargs.keys(): | ||
del kwargs["dry_run"] | ||
try: | ||
results = fn(self, *args, **kwargs) | ||
return results | ||
except fabric.group.GroupException as e: | ||
results = e.result | ||
raise | ||
|
||
return do_dry_run | ||
|
||
|
||
class NodeGroup: | ||
|
||
def __init__(self, connections: Connections, cluster): | ||
|
@@ -399,13 +428,16 @@ def _make_result_or_fail(self, results: _HostToResult, | |
return group_result | ||
|
||
@_handle_internal_logging | ||
@_handle_dry_run | ||
def run(self, *args, **kwargs) -> Union[NodeGroupResult, int]: | ||
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 suggest to not call NodeGroup.run/sudo/put for RW operations in dry run at all. The reason is it is difficult to simulate its behaviour. For example, you return empty results, but in fact it returns not empty results in real run. So this can lead to unpredictable changes in behaviour of Kubemarine. Also, put does not return result at all, run/sudo might return |
||
return self.do("run", *args, **kwargs) | ||
|
||
@_handle_internal_logging | ||
@_handle_dry_run | ||
def sudo(self, *args, **kwargs) -> Union[NodeGroupResult, int]: | ||
return self.do("sudo", *args, **kwargs) | ||
|
||
@_handle_dry_run | ||
def put(self, local_file: Union[io.StringIO, str], remote_file: str, **kwargs): | ||
if isinstance(local_file, io.StringIO): | ||
self.cluster.log.verbose("Text is being transferred to remote file \"%s\" on nodes %s with options %s" | ||
|
@@ -441,6 +473,7 @@ def put(self, local_file: Union[io.StringIO, str], remote_file: str, **kwargs): | |
with open(local_file, "rb") as local_stream: | ||
group_to_upload._put(local_stream, remote_file, **kwargs) | ||
|
||
@_handle_dry_run | ||
def _put(self, local_stream: IO, remote_file: str, **kwargs): | ||
hide = kwargs.pop("hide", True) is True | ||
sudo = kwargs.pop("sudo", False) is True | ||
|
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 suggest to not recreate the inventory on the deployer. For example, if you run upgrade, the input cluster.yaml will be changed. This does not seem as "dry-run". I suggest to create separate file in dump/ and reflect the changes there.