Skip to content
Merged
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
6 changes: 5 additions & 1 deletion mchub/models/magic_castle/magic_castle.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,18 @@ def get_progress(self):
@property
def state(self):
config = self.applied_config if self.applied_config else self.config
# Reading the status of a successfully destroyed cluster deletes its ORM
# instance. Preserve project metadata before that commit detaches the
# instance, so the final DESTROY_SUCCESS state can still be serialized.
cloud = {"name": self.project.name, "id": self.project.id}
return {
**config,
"hostname": self.hostname,
"status": self.status,
"freeipa_passwd": self.freeipa_passwd,
"age": self.age,
"expiration_date": self.expiration_date,
"cloud": {"name": self.project.name, "id": self.project.id},
"cloud": cloud,
"hieradata_entries": _hieradata_to_entries(config.get("hieradata", "")),
}

Expand Down
7 changes: 5 additions & 2 deletions tests/unit/magic_castle/test_magic_castle.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_get_status_valid(app):
assert valid1.orm.status == ClusterStatusCode.PROVISIONING_SUCCESS


def test_destroyed_cluster_archives_github_repo(app, mocker):
def test_destroyed_cluster_state_archives_github_repo(app, mocker):
from mchub.database import db
from mchub.models.magic_castle.cluster_status_code import ClusterStatusCode
from mchub.models.magic_castle.magic_castle import MagicCastle, MagicCastleORM
Expand All @@ -130,7 +130,10 @@ def test_destroyed_cluster_archives_github_repo(app, mocker):
archive_repo = mocker.spy(get_github_storage(), "archive_repo")
cluster.orm.status = ClusterStatusCode.DESTROY_SUCCESS

assert cluster.status == ClusterStatusCode.DESTROY_SUCCESS
state = cluster.state

assert state["status"] == ClusterStatusCode.DESTROY_SUCCESS
assert state["cloud"] == {"name": "project-alice", "id": 1}
archive_repo.assert_called_once_with("valid1.magic-castle.cloud")


Expand Down