Merge "Set tempest-ready to False
when the unit start" into main
This commit is contained in:
commit
a994faf61d
@ -118,6 +118,7 @@ class TempestOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
|
||||
self.framework.observe(
|
||||
self.on.get_lists_action, self._on_get_lists_action
|
||||
)
|
||||
self.framework.observe(self.on.start, self._on_start)
|
||||
self.framework.observe(self.on.upgrade_charm, self._on_upgrade_charm)
|
||||
|
||||
@property
|
||||
@ -365,6 +366,19 @@ class TempestOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
|
||||
"""Get the pebble handler."""
|
||||
return self.get_named_pebble_handler(CONTAINER)
|
||||
|
||||
def _on_start(self, event: ops.charm.StartEvent) -> None:
|
||||
"""Called on charm start."""
|
||||
# Mark tempest as being unready when it is started or rebooted. This is
|
||||
# because peer relation data `tempest-ready` persists across a reboot
|
||||
# of the host machine, and this can cause the inconsistency between the
|
||||
# actual pod state and the relation data. For example, relation data
|
||||
# `tempest-ready` can still be `True` before and after the host is
|
||||
# rebooted, but the tempest workspace directory created during tempest
|
||||
# init will be gone because the pod is recreated. So when the host is
|
||||
# rebooted we need to consider tempest to be no longer ready, so that
|
||||
# in the follow up config-changed hook, the charm will re-init tempest.
|
||||
self.set_tempest_ready(False)
|
||||
|
||||
def _on_upgrade_charm(self, event: ops.charm.UpgradeCharmEvent) -> None:
|
||||
"""Called on charm upgrade."""
|
||||
# When a charm is upgraded, consider tempest to no longer be ready,
|
||||
|
@ -35,7 +35,9 @@ sed $'s/\033\[[0-9;]*m//g' -i "$TMP_FILE"
|
||||
# After everything, move it to the actual output.
|
||||
# This ensures we don't have issues with logging libs pushing partial files,
|
||||
# if we were to stream to the final output.
|
||||
mv "$TMP_FILE" "$TEMPEST_OUTPUT"
|
||||
# The `mkdir` is to ensure the tempest workspace directory exists, and the
|
||||
# temp file can be moved to that directory.
|
||||
mkdir -p $TEMPEST_WORKSPACE && mv "$TMP_FILE" "$TEMPEST_OUTPUT"
|
||||
|
||||
SUMMARY="$(awk '/^Totals$/,/Sum of execute/ { print }' < "$TEMPEST_OUTPUT")"
|
||||
if [[ -n "$SUMMARY" ]]; then
|
||||
|
@ -581,6 +581,14 @@ class TestTempestOperatorCharm(test_utils.CharmTestCase):
|
||||
self.harness.charm.init_tempest()
|
||||
self.harness.charm.set_tempest_ready.assert_not_called()
|
||||
|
||||
def test_start(self):
|
||||
"""Test start charm updates things as required."""
|
||||
test_utils.set_all_pebbles_ready(self.harness)
|
||||
|
||||
self.harness.charm.set_tempest_ready = Mock()
|
||||
self.harness.charm._on_start(Mock())
|
||||
self.harness.charm.set_tempest_ready.assert_called_once_with(False)
|
||||
|
||||
def test_upgrade_charm(self):
|
||||
"""Test upgrade charm updates things as required."""
|
||||
test_utils.set_all_pebbles_ready(self.harness)
|
||||
|
Loading…
x
Reference in New Issue
Block a user