Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: support starting and stopping Pebble checks, and the checks enabled field #1560

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

tonyandrewmeyer
Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer commented Feb 3, 2025

Add support for:

  • The startup field in Pebble checks.
  • The start_checks and stop_checks Pebble API calls.

Harness (and Scenario, mostly via re-using the Harness implementation) is adjusted to more closely simulate the Changes implementation of Pebble Checks, so that the 'if the change ID is the empty string, the check is inactive' behaviour can be simulated.

A subtle bug with notices and check-infos is also fixed: previously the mocked Pebble would gather all notices and check-infos from all containers in the state, instead of only those that are in the correct container.

Pebble PR

ops/_private/harness.py Outdated Show resolved Hide resolved
def _render_services(self) -> Dict[str, pebble.Service]:
services: Dict[str, pebble.Service] = {}
for key in sorted(self._layers.keys()):
layer = self._layers[key]
for name, service in layer.services.items():
# TODO: merge existing services https://github.com/canonical/operator/issues/1112
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by: that ticket is closed, and it looks like this is already done.

@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review February 12, 2025 01:17
@tonyandrewmeyer
Copy link
Contributor Author

The pack failure is:

+ sudo snap refresh lxd --channel=5.0/stable
error: unable to contact snap store

I assume this is a temporary problem with the store - I'll retry the job later.

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

This is good work -- thanks especially for updating the testing stuff (and testing the testing stuff!).

A few minor comments, some debatable, and one that would require a Pebble tweak.

ops/pebble.py Outdated Show resolved Hide resolved
ops/pebble.py Outdated Show resolved Hide resolved
ops/pebble.py Outdated Show resolved Hide resolved
@@ -1475,6 +1516,7 @@ def __repr__(self):
'CheckInfo('
f'name={self.name!r}, '
f'level={self.level}, '
f'startup={self.startup}, '
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ben, repeat after me: "dataclasses are good, use them next time". :-)

@@ -2126,7 +2168,9 @@ def autostart_services(self, timeout: float = 30.0, delay: float = 0.1) -> Chang
return self._services_action('autostart', [], timeout, delay)

def replan_services(self, timeout: float = 30.0, delay: float = 0.1) -> ChangeID:
"""Replan by (re)starting changed and startup-enabled services and wait for them to start.
"""Replan by (re)starting changed and startup-enabled services and checks.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a pity I called this replan_services, but oh well, at least it's called just replan for the Container method. Not worth deprecating/aliasing here, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was my thinking as well.

ops/pebble.py Outdated Show resolved Hide resolved
ops/pebble.py Outdated Show resolved Hide resolved
ops/_private/harness.py Outdated Show resolved Hide resolved
ops/_private/harness.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Looks good to me know, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants