Repository: canonical/operator
Pull request #493 (2021-03-23 21:27:00)

Update Pebble layer field from "default" to "startup"
Matches Pebble change https://github.com/canonical/pebble/pull/20


Patch:
diff --git a/ops/model.py b/ops/model.py
index cfd7a05..4c57663 100644
--- a/ops/model.py
+++ b/ops/model.py
@@ -1036,7 +1036,7 @@ class Container:
         return self._pebble
 
     def autostart(self):
-        """Autostart all default services."""
+        """Autostart all services marked as startup: enabled."""
         self._pebble.autostart_services()
 
     def start(self, *service_names: str):
diff --git a/ops/pebble.py b/ops/pebble.py
index 5d20949..38b894f 100644
--- a/ops/pebble.py
+++ b/ops/pebble.py
@@ -459,7 +459,7 @@ class Service:
         raw = raw or {}
         self.summary = raw.get('summary', '')
         self.description = raw.get('description', '')
-        self.default = raw.get('default', '')
+        self.startup = raw.get('startup', '')
         self.override = raw.get('override', '')
         self.command = raw.get('command', '')
         self.after = list(raw.get('after', []))
@@ -483,7 +483,7 @@ class Service:
         fields = [
             ('summary', self.summary),
             ('description', self.description),
-            ('default', self.default),
+            ('startup', self.startup),
             ('override', self.override),
             ('command', self.command),
             ('after', self.after),
@@ -655,7 +655,7 @@ class Client:
         return Change.from_dict(result['result'])
 
     def autostart_services(self, timeout: float = 30.0, delay: float = 0.1) -> ChangeID:
-        """Start the autostart services and wait (poll) for them to be started.
+        """Start the startup-enabled services and wait (poll) for them to be started.
 
         Raises ChangeError if one or more of the services didn't start. If
         timeout is 0, submit the action but don't wait; just return the change


Test patch:
diff --git a/test/test_pebble.py b/test/test_pebble.py
index 1e966db..bfc2c69 100644
--- a/test/test_pebble.py
+++ b/test/test_pebble.py
@@ -448,7 +448,7 @@ class TestService(unittest.TestCase):
         self.assertEqual(service.name, name)
         self.assertEqual(service.summary, '')
         self.assertEqual(service.description, '')
-        self.assertEqual(service.default, '')
+        self.assertEqual(service.startup, '')
         self.assertEqual(service.override, '')
         self.assertEqual(service.command, '')
         self.assertEqual(service.after, [])
@@ -468,7 +468,7 @@ class TestService(unittest.TestCase):
         d = {
             'summary': 'Sum Mary',
             'description': 'The lazy quick brown',
-            'default': 'Dee Fault',
+            'startup': 'Start Up',
             'override': 'override',
             'command': 'echo sum mary',
             'after': ['a1', 'a2'],
@@ -479,7 +479,7 @@ class TestService(unittest.TestCase):
         s = pebble.Service('Name 2', d)
         self.assertEqual(s.name, 'Name 2')
         self.assertEqual(s.description, 'The lazy quick brown')
-        self.assertEqual(s.default, 'Dee Fault')
+        self.assertEqual(s.startup, 'Start Up')
         self.assertEqual(s.override, 'override')
         self.assertEqual(s.command, 'echo sum mary')
         self.assertEqual(s.after, ['a1', 'a2'])