Skip to content

Commit

Permalink
Add kill-delay to pebble ServiceDict type (#975)
Browse files Browse the repository at this point in the history
Pebble merged/released kill-delay support, but ops did not yet picked that up.
  • Loading branch information
paulomach authored Jul 17, 2023
1 parent 12b2da6 commit dd4865f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'backoff-delay': str,
'backoff-factor': Optional[int],
'backoff-limit': str,
'kill-delay': Optional[str],
},
total=False)

Expand Down Expand Up @@ -824,6 +825,7 @@ def __init__(self, name: str, raw: Optional['ServiceDict'] = None):
self.backoff_delay = dct.get('backoff-delay', '')
self.backoff_factor = dct.get('backoff-factor')
self.backoff_limit = dct.get('backoff-limit', '')
self.kill_delay = dct.get('kill-delay', '')

def to_dict(self) -> 'ServiceDict':
"""Convert this service object to its dict representation."""
Expand All @@ -848,6 +850,7 @@ def to_dict(self) -> 'ServiceDict':
('backoff-delay', self.backoff_delay),
('backoff-factor', self.backoff_factor),
('backoff-limit', self.backoff_limit),
('kill-delay', self.kill_delay),
]
dct = {name: value for name, value in fields if value}
return typing.cast('ServiceDict', dct)
Expand Down
3 changes: 3 additions & 0 deletions test/test_pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def _assert_empty(self, service, name):
self.assertEqual(service.backoff_delay, '')
self.assertIs(service.backoff_factor, None)
self.assertEqual(service.backoff_limit, '')
self.assertIs(service.kill_delay, '')
self.assertEqual(service.to_dict(), {})

def test_name_only(self):
Expand Down Expand Up @@ -719,6 +720,7 @@ def test_dict(self):
'backoff-delay': '1s',
'backoff-factor': 4,
'backoff-limit': '10s',
'kill-delay': '420s',
}
s = pebble.Service('Name 2', d)
self.assertEqual(s.name, 'Name 2')
Expand All @@ -741,6 +743,7 @@ def test_dict(self):
self.assertEqual(s.backoff_delay, '1s')
self.assertEqual(s.backoff_factor, 4)
self.assertEqual(s.backoff_limit, '10s')
self.assertEqual(s.kill_delay, '420s')

self.assertEqual(s.to_dict(), d)

Expand Down

0 comments on commit dd4865f

Please sign in to comment.