Skip to content
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
23 changes: 12 additions & 11 deletions aws_lambda_builders/workflows/dotnet_clipackage/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ def execute(self):
LOG.info("Skipping to update Amazon.Lambda.Tools install/update, since it is updated recently")
return

try:
LOG.debug("Checking if Amazon.Lambda.Tools is already installed")
output = self.subprocess_dotnet.run(["tool", "list", "-g"])
if "amazon.lambda.tools" in output.lower():
LOG.info("Amazon.Lambda.Tools already installed. Skipping install.")
GlobalToolInstallAction.__tools_installed = True
return
except DotnetCLIExecutionError:
pass

try:
LOG.debug("Installing Amazon.Lambda.Tools Global Tool")
self.subprocess_dotnet.run(["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"])
GlobalToolInstallAction.__tools_installed = True
except DotnetCLIExecutionError:
LOG.debug("Error installing probably due to already installed. Attempt to update to latest version.")
try:
self.subprocess_dotnet.run(
["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
)
GlobalToolInstallAction.__tools_installed = True
except DotnetCLIExecutionError as ex:
raise ActionFailedError(
"Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex)
)
except DotnetCLIExecutionError as ex:
raise ActionFailedError("Error installing the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex))


class RunPackageAction(BaseAction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ def run(self, args, cwd=None):

if p.returncode != 0:
raise DotnetCLIExecutionError(message=decode(err))

return decode(out)
30 changes: 17 additions & 13 deletions tests/unit/workflows/dotnet_clipackage/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ def tearDown(self):
self.subprocess_dotnet.reset_mock()

def test_global_tool_install(self):
self.subprocess_dotnet.run.return_value = ""
action = GlobalToolInstallAction(self.subprocess_dotnet)
action.execute()
self.subprocess_dotnet.run.assert_called_once_with(
self.subprocess_dotnet.run.assert_any_call(["tool", "list", "-g"])
self.subprocess_dotnet.run.assert_any_call(
["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
)

def test_global_tool_update(self):
self.subprocess_dotnet.run.side_effect = [DotnetCLIExecutionError(message="Already Installed"), None]
def test_global_tool_already_installed(self):
self.subprocess_dotnet.run.return_value = (
"Package Id Version Commands\n"
"--------------------------------------------------------------\n"
"amazon.lambda.tools 5.3.0 dotnet-lambda\n"
)
action = GlobalToolInstallAction(self.subprocess_dotnet)
action.execute()
self.subprocess_dotnet.run.assert_any_call(
["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
)
self.subprocess_dotnet.run.assert_any_call(
["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
)
self.subprocess_dotnet.run.assert_called_once_with(["tool", "list", "-g"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also assert below this that the actual install is not done?


def test_global_tool_update_failed(self):
def test_global_tool_install_failed(self):
self.subprocess_dotnet.run.side_effect = [
DotnetCLIExecutionError(message="Already Installed"),
DotnetCLIExecutionError(message="Updated Failed"),
"", # tool list returns empty (not installed)
DotnetCLIExecutionError(message="Install Failed"),
]
action = GlobalToolInstallAction(self.subprocess_dotnet)
self.assertRaises(ActionFailedError, action.execute)

def test_global_tool_parallel(self):
self.subprocess_dotnet.run.return_value = ""
actions = [
GlobalToolInstallAction(self.subprocess_dotnet),
GlobalToolInstallAction(self.subprocess_dotnet),
Expand All @@ -58,9 +60,11 @@ def test_global_tool_parallel(self):
for action in actions:
executor.submit(action.execute)

self.subprocess_dotnet.run.assert_called_once_with(
self.subprocess_dotnet.run.assert_any_call(["tool", "list", "-g"])
self.subprocess_dotnet.run.assert_any_call(
["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
)
self.assertEqual(self.subprocess_dotnet.run.call_count, 2)


class TestRunPackageAction(TestCase):
Expand Down
Loading