-
Notifications
You must be signed in to change notification settings - Fork 402
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
Refactor Some Command-Related Methods in aws_ssm.py
#2248
base: main
Are you sure you want to change the base?
Refactor Some Command-Related Methods in aws_ssm.py
#2248
Conversation
Merge Failed. This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset. |
…aries contained in a tuple
…ries containing commands; add type hinting and docstring
…ate_commands() and _exec_transport_commands(); add type hinting and docstring
b46d9dc
to
17a29e9
Compare
Build failed. ❌ ansible-galaxy-importer FAILURE in 4m 42s (non-voting) |
Build failed. ❌ ansible-galaxy-importer FAILURE in 4m 10s (non-voting) |
02cf388
to
6ad3c3d
Compare
6ad3c3d
to
599cb1a
Compare
Build failed. ❌ ansible-galaxy-importer FAILURE in 3m 54s (non-voting) |
Build succeeded. ✔️ ansible-galaxy-importer SUCCESS in 5m 50s (non-voting) |
aws_ssm.py
aws_ssm.py
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.
There is no need to add a test skipped depending on the platform because the is_windows
param is computed from the EC2 instance, not the source computer.
You can combine both tests into a single one.
@patch("ansible_collections.community.aws.plugins.connection.aws_ssm.Connection.is_windows") | ||
def test_generate_commands_windows(self, mock_is_windows): | ||
"""Testing command generation on Windows systems""" | ||
pc = PlayContext() | ||
new_stdin = StringIO() | ||
conn = connection_loader.get("community.aws.aws_ssm", pc, new_stdin) | ||
|
||
mock_is_windows.return_value = 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.
@patch("ansible_collections.community.aws.plugins.connection.aws_ssm.Connection.is_windows") | |
def test_generate_commands_windows(self, mock_is_windows): | |
"""Testing command generation on Windows systems""" | |
pc = PlayContext() | |
new_stdin = StringIO() | |
conn = connection_loader.get("community.aws.aws_ssm", pc, new_stdin) | |
mock_is_windows.return_value = True | |
@pytest.mark.parametrize("is_windows", [True, False]) | |
@patch("ansible_collections.community.aws.plugins.connection.aws_ssm.Connection.is_windows") | |
def test_generate_commands_windows(self, mock_is_windows, is_windows): | |
"""Testing command generation on Windows systems""" | |
pc = PlayContext() | |
new_stdin = StringIO() | |
conn = connection_loader.get("community.aws.aws_ssm", pc, new_stdin) | |
mock_is_windows.return_value = is_windows |
# Check contents of command dictionaries | ||
assert "command" in test_command_generation[0][0] | ||
assert "method" in test_command_generation[0][1] | ||
assert "headers" in test_command_generation[0][1] | ||
assert "Invoke-WebRequest" in test_command_generation[0][1]["command"] | ||
assert test_command_generation[0][1]["method"] == "put" |
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.
# Check contents of command dictionaries | |
assert "command" in test_command_generation[0][0] | |
assert "method" in test_command_generation[0][1] | |
assert "headers" in test_command_generation[0][1] | |
assert "Invoke-WebRequest" in test_command_generation[0][1]["command"] | |
assert test_command_generation[0][1]["method"] == "put" | |
if not is_windows: | |
# Check contents of command dictionaries | |
assert "command" in test_command_generation[0][0] | |
assert "method" in test_command_generation[0][1] | |
assert "headers" in test_command_generation[0][1] | |
assert "Invoke-WebRequest" in test_command_generation[0][1]["command"] | |
assert test_command_generation[0][1]["method"] == "put" | |
else: | |
# Check contents of command dictionaries | |
assert "command" in test_command_generation[0][0] | |
assert "method" in test_command_generation[0][2] | |
assert "headers" in test_command_generation[0][2] | |
assert "curl --request PUT -H" in test_command_generation[0][2]["command"] | |
assert test_command_generation[0][2]["method"] == "put" |
SUMMARY
This work is part of the currently ongoing AWS SSM Connection Refactoring & Plugin Promotion effort and related to ansible-collections/amazon.aws#2394.
Fixes ACA-2095
ISSUE TYPE
TASK LIST
_exec_transport_commands
method is refactored to accept a single structured object (a tuple containing lists of command dictionaries) that contains the necessary command data.Create a custom dataclass to hold command output._generate_commands
function returns a list of typed dictionaries with clear metadata (command strings, method, headers)._exec_transport_commands
accepts a list of typed dictionaries as an argument and returns the customCommandResults
object._generate_commands
method outputs the expected structured command object.