Browse Source

Use '_stored' not 'state'

As per issue 7 *1, switch to variable name '_stored'

*1 https://github.com/openstack-charmers/charm-ceph-iscsi/issues/7

Change-Id: I52513ce2c25b03f2015835b96cccb3766806bceb
changes/56/749456/2
Liam Young 2 years ago
parent
commit
288e712c0a
  1. 26
      ops_openstack/core.py
  2. 38
      unit_tests/test_ops_openstack.py

26
ops_openstack/core.py

@ -41,7 +41,7 @@ logger = logging.getLogger(__name__)
class OSBaseCharm(CharmBase):
state = StoredState()
_stored = StoredState()
PACKAGES = []
@ -51,9 +51,9 @@ class OSBaseCharm(CharmBase):
def __init__(self, framework):
super().__init__(framework)
self.state.set_default(is_started=False)
self.state.set_default(is_paused=False)
self.state.set_default(series_upgrade=False)
self._stored.set_default(is_started=False)
self._stored.set_default(is_paused=False)
self._stored.set_default(series_upgrade=False)
self.framework.observe(self.on.install, self.on_install)
self.framework.observe(self.on.update_status, self.on_update_status)
self.framework.observe(self.on.pause_action, self.on_pause_action)
@ -88,12 +88,12 @@ class OSBaseCharm(CharmBase):
return
except NotImplementedError:
pass
if self.state.series_upgrade:
if self._stored.series_upgrade:
self.unit.status = BlockedStatus(
'Ready for do-release-upgrade and reboot. '
'Set complete when finished.')
return
if self.state.is_paused:
if self._stored.is_paused:
self.unit.status = MaintenanceStatus(
"Paused. Use 'resume' action to resume normal service.")
return
@ -105,7 +105,7 @@ class OSBaseCharm(CharmBase):
self.unit.status = BlockedStatus(
'Missing relations: {}'.format(', '.join(missing_relations)))
return
if self.state.is_started:
if self._stored.is_started:
self.unit.status = ActiveStatus('Unit is ready')
else:
self.unit.status = WaitingStatus('Charm configuration in progress')
@ -125,8 +125,8 @@ class OSBaseCharm(CharmBase):
'pause',
services=self.services(),
charm_func=None)
self.state.is_paused = True
self.state.series_upgrade = True
self._stored.is_paused = True
self._stored.series_upgrade = True
self.update_status()
def on_post_series_upgrade(self, event):
@ -134,8 +134,8 @@ class OSBaseCharm(CharmBase):
'resume',
services=self.services(),
charm_func=None)
self.state.is_paused = False
self.state.series_upgrade = False
self._stored.is_paused = False
self._stored.series_upgrade = False
self.update_status()
def on_pause_action(self, event):
@ -143,7 +143,7 @@ class OSBaseCharm(CharmBase):
'pause',
services=self.services(),
charm_func=None)
self.state.is_paused = True
self._stored.is_paused = True
self.update_status()
def on_resume_action(self, event):
@ -151,7 +151,7 @@ class OSBaseCharm(CharmBase):
'resume',
services=self.services(),
charm_func=None)
self.state.is_paused = False
self._stored.is_paused = False
self.update_status()

38
unit_tests/test_ops_openstack.py

@ -97,9 +97,9 @@ class TestOSBaseCharm(CharmTestCase):
def test_init(self):
self.harness.begin()
self.assertFalse(self.harness.charm.state.is_started)
self.assertFalse(self.harness.charm.state.is_paused)
self.assertFalse(self.harness.charm.state.series_upgrade)
self.assertFalse(self.harness.charm._stored.is_started)
self.assertFalse(self.harness.charm._stored.is_paused)
self.assertFalse(self.harness.charm._stored.series_upgrade)
def test_install(self):
print(self.harness._backend)
@ -127,7 +127,7 @@ class TestOSBaseCharm(CharmTestCase):
def test_update_status(self):
self.harness.add_relation('shared-db', 'mysql')
self.harness.begin()
self.harness.charm.state.is_started = True
self.harness.charm._stored.is_started = True
self.harness.charm.on.update_status.emit()
self.assertEqual(
self.harness.charm.unit.status.message,
@ -142,7 +142,7 @@ class TestOSBaseCharm(CharmTestCase):
'custom-check-fail': 'True'})
self.harness.add_relation('shared-db', 'mysql')
self.harness.begin()
self.harness.charm.state.is_started = True
self.harness.charm._stored.is_started = True
self.harness.charm.on.update_status.emit()
self.assertEqual(
self.harness.charm.unit.status.message,
@ -164,7 +164,7 @@ class TestOSBaseCharm(CharmTestCase):
def test_update_status_series_upgrade(self):
self.harness.begin()
self.harness.charm.state.series_upgrade = True
self.harness.charm._stored.series_upgrade = True
self.harness.charm.on_update_status('An Event')
self.assertEqual(
self.harness.charm.unit.status.message,
@ -176,7 +176,7 @@ class TestOSBaseCharm(CharmTestCase):
def test_update_status_series_paused(self):
self.harness.begin()
self.harness.charm.state.is_paused = True
self.harness.charm._stored.is_paused = True
self.harness.charm.on.update_status.emit()
self.assertEqual(
self.harness.charm.unit.status.message,
@ -204,11 +204,11 @@ class TestOSBaseCharm(CharmTestCase):
def test_pre_series_upgrade(self):
self.os_utils.manage_payload_services.return_value = ('a', 'b')
self.harness.begin()
self.assertFalse(self.harness.charm.state.series_upgrade)
self.assertFalse(self.harness.charm.state.is_paused)
self.assertFalse(self.harness.charm._stored.series_upgrade)
self.assertFalse(self.harness.charm._stored.is_paused)
self.harness.charm.on.pre_series_upgrade.emit()
self.assertTrue(self.harness.charm.state.series_upgrade)
self.assertTrue(self.harness.charm.state.is_paused)
self.assertTrue(self.harness.charm._stored.series_upgrade)
self.assertTrue(self.harness.charm._stored.is_paused)
self.os_utils.manage_payload_services.assert_called_once_with(
'pause',
services=['apache2', 'ks-api'],
@ -217,11 +217,11 @@ class TestOSBaseCharm(CharmTestCase):
def test_post_series_upgrade(self):
self.os_utils.manage_payload_services.return_value = ('a', 'b')
self.harness.begin()
self.harness.charm.state.series_upgrade = True
self.harness.charm.state.is_paused = True
self.harness.charm._stored.series_upgrade = True
self.harness.charm._stored.is_paused = True
self.harness.charm.on.post_series_upgrade.emit()
self.assertFalse(self.harness.charm.state.series_upgrade)
self.assertFalse(self.harness.charm.state.is_paused)
self.assertFalse(self.harness.charm._stored.series_upgrade)
self.assertFalse(self.harness.charm._stored.is_paused)
self.os_utils.manage_payload_services.assert_called_once_with(
'resume',
services=['apache2', 'ks-api'],
@ -230,9 +230,9 @@ class TestOSBaseCharm(CharmTestCase):
def test_pause(self):
self.os_utils.manage_payload_services.return_value = ('a', 'b')
self.harness.begin()
self.assertFalse(self.harness.charm.state.is_paused)
self.assertFalse(self.harness.charm._stored.is_paused)
self.harness.charm.on_pause_action('An Event')
self.assertTrue(self.harness.charm.state.is_paused)
self.assertTrue(self.harness.charm._stored.is_paused)
self.os_utils.manage_payload_services.assert_called_once_with(
'pause',
services=['apache2', 'ks-api'],
@ -241,9 +241,9 @@ class TestOSBaseCharm(CharmTestCase):
def test_resume(self):
self.os_utils.manage_payload_services.return_value = ('a', 'b')
self.harness.begin()
self.harness.charm.state.is_paused = True
self.harness.charm._stored.is_paused = True
self.harness.charm.on_resume_action('An Event')
self.assertFalse(self.harness.charm.state.is_paused)
self.assertFalse(self.harness.charm._stored.is_paused)
self.os_utils.manage_payload_services.assert_called_once_with(
'resume',
services=['apache2', 'ks-api'],

Loading…
Cancel
Save