Skip to content

Commit

Permalink
fix: Fix private key getting lost on stack resume failure
Browse files Browse the repository at this point in the history
Starting with v7.7.1, we are fetching the private key from the
database. In case of a resume failure, we need to keep the key
in place when running the cleanup step after the failed resume
so that the learner will not lose access to the lab altogether.
  • Loading branch information
Maari Tamm committed Nov 29, 2023
1 parent 02e96f3 commit f5b45e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
-------------------------
* [Bug fix] Fix private key getting lost after a stack resume failure.
Make sure we keep the stack key in place when running cleanup on
a stack that failed to resume.

Version 7.7.2 (2023-09-15)
-------------------------
* [Bug fix] Fix editing the `stack_key_type` field in Studio; include
Expand Down
2 changes: 1 addition & 1 deletion hastexo/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def run(self, **kwargs):
'error_msg': textwrap.shorten(e.error_msg, width=256),
'ip': None,
'user': "",
'key': "",
'key': self.stack_key if e.suspend else '',
'password': "",
'provider': provider_name
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def test_provider_error_on_cleanup_resume(self):
# Assertions
self.assertEqual(stack.status, "RESUME_FAILED")
self.assertEqual(stack.provider, self.providers[1]["name"])
self.assertEqual(self.stack_key, stack.key)
provider.suspend_stack.assert_called()

def test_undefined_capacity(self):
Expand Down Expand Up @@ -1058,6 +1059,10 @@ def test_resume_suspended_stack_persistent_operational_error(self):
# provider should still be unchanged.
self.assertEqual(stack.provider, self.providers[1]["name"])

# When resume fails, we should still have the private key
# of the stack.
self.assertEqual(self.stack_key, stack.key)

def test_resumed_stack_has_no_ip(self):
# Setup
provider = self.mock_providers[1]
Expand All @@ -1083,6 +1088,7 @@ def test_resumed_stack_has_no_ip(self):
# Assertions
self.assertEqual(stack.status, "RESUME_FAILED")
self.assertEqual(stack.provider, self.providers[1]["name"])
self.assertEqual(self.stack_key, stack.key)
provider.suspend_stack.assert_called()

def test_timeout_resuming_stack(self):
Expand All @@ -1108,6 +1114,7 @@ def test_timeout_resuming_stack(self):
# Assertions
self.assertEqual(stack.status, "LAUNCH_TIMEOUT")
self.assertEqual(stack.provider, self.providers[1]["name"])
self.assertEqual(self.stack_key, stack.key)

def test_resume_hook_empty(self):
# Setup
Expand Down Expand Up @@ -1280,6 +1287,7 @@ def test_delete_stack_on_create_failed(self):

# Assertions
self.assertEqual(stack.status, "CREATE_FAILED")
self.assertEqual('', stack.key)
provider.delete_stack.assert_called_with(
self.stack_name, False
)
Expand All @@ -1304,6 +1312,7 @@ def test_cleanup_timeout_on_create_failed(self):

# Assertions
self.assertEqual(stack.status, "CREATE_FAILED")
self.assertEqual('', stack.key)
provider.delete_stack.assert_called_with(
self.stack_name, False
)
Expand Down

0 comments on commit f5b45e9

Please sign in to comment.