Skip to content

Commit

Permalink
plz?
Browse files Browse the repository at this point in the history
  • Loading branch information
SK1Y101 committed Nov 13, 2024
1 parent 5535aa3 commit edaba98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions maas-region/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ def _on_install(self, _event: ops.InstallEvent) -> None:

self._write_snap_version_()
self._write_app_type_(self.unit, "region")
self._ensure_maas_cohort(_event)

_cohort = self.get_cohort()
_cohort = self._ensure_maas_cohort(_event) or self.get_cohort()
if not _cohort:
logger.exception("Snap cohort not found")
return
Expand Down Expand Up @@ -589,7 +587,7 @@ def _on_maas_cluster_data_changed(self, event: ops.RelationChangedEvent) -> None
logger.exception("Awaiting unit refresh")
return

def _ensure_maas_cohort(self, event: ops.InstallEvent) -> None:
def _ensure_maas_cohort(self, event: ops.InstallEvent) -> Union[None, str]:
logger.info(event)
_cohort = self.get_cohort()

Expand All @@ -608,11 +606,12 @@ def _ensure_maas_cohort(self, event: ops.InstallEvent) -> None:

self.set_cohort(_cohort)
logger.debug(_cohort)
return
return _cohort

if not _cohort:
event.defer()
return
return _cohort

def _on_create_admin_action(self, event: ops.ActionEvent):
"""Handle the create-admin action.
Expand Down
2 changes: 2 additions & 0 deletions maas-region/src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,15 @@ def get_or_create_snap_cohort() -> Union[str, None]:

verbose_info = maas._snap("info", ["--verbose"])
if _found_cohort := re.search(r"cohort:\s*([^\n]+)", verbose_info):
logger.debug("Found cohort")
return str(_found_cohort.group(1))
logger.debug("Could not find cohort key in snap info")

cohort_creation = subprocess.check_output(
["sudo", "snap", "create-cohort", maas._name], universal_newlines=True
)
if _created_cohort := re.search(r"cohort-key:\s+([^\n]+)", cohort_creation):
logger.debug("Created cohort")
return str(_created_cohort.group(1))

logger.debug(f"Could not find cohort key in snap create-cohort: {_created_cohort}")
Expand Down

0 comments on commit edaba98

Please sign in to comment.