Rewrite actions/copy_pool into the oeprator framework
In addition to trivial changes (passing `event` into the `copy_pool` function), this change introduces an update to the actions/__init__.py that allows succinct import and use from the main charm.py. An apparently unrelated change is the removal of charm-proof from the lint job, as it fails with the removal of actions/copy-pool. Change-Id: I66a5590ddf0f0bb5ca073a91b451f8c78598609a func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/866
This commit is contained in:

committed by
Luciano Lo Giudice

parent
5656db92df
commit
e60a23ae16
@@ -1 +0,0 @@
|
|||||||
copy_pool.py
|
|
@@ -93,6 +93,8 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
|
|||||||
self.metrics_endpoint = ceph_metrics.CephMetricsEndpointProvider(self)
|
self.metrics_endpoint = ceph_metrics.CephMetricsEndpointProvider(self)
|
||||||
self._observe_action(self.on.change_osd_weight_action,
|
self._observe_action(self.on.change_osd_weight_action,
|
||||||
ops_actions.change_osd_weight.change_osd_weight)
|
ops_actions.change_osd_weight.change_osd_weight)
|
||||||
|
self._observe_action(self.on.copy_pool_action,
|
||||||
|
ops_actions.copy_pool.copy_pool)
|
||||||
|
|
||||||
fw.observe(self.on.install, self.on_install)
|
fw.observe(self.on.install, self.on_install)
|
||||||
fw.observe(self.on.config_changed, self.on_config)
|
fw.observe(self.on.config_changed, self.on_config)
|
||||||
|
@@ -12,4 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from . import change_osd_weight # noqa: F401
|
from . import ( # noqa: F401
|
||||||
|
change_osd_weight,
|
||||||
|
copy_pool,
|
||||||
|
)
|
||||||
|
14
actions/copy_pool.py → src/ops_actions/copy_pool.py
Executable file → Normal file
14
actions/copy_pool.py → src/ops_actions/copy_pool.py
Executable file → Normal file
@@ -16,20 +16,14 @@
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import charmhelpers.core.hookenv as hookenv
|
|
||||||
|
|
||||||
|
def copy_pool(event) -> None:
|
||||||
def copy_pool():
|
|
||||||
try:
|
try:
|
||||||
source = hookenv.action_get("source")
|
source = event.params.get("source")
|
||||||
target = hookenv.action_get("target")
|
target = event.params.get("target")
|
||||||
subprocess.check_call([
|
subprocess.check_call([
|
||||||
'rados', 'cppool',
|
'rados', 'cppool',
|
||||||
source, target
|
source, target
|
||||||
])
|
])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
hookenv.action_fail("Error copying pool: {}".format(str(e)))
|
event.fail("Error copying pool: {}".format(str(e)))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
copy_pool()
|
|
@@ -36,3 +36,4 @@ tests:
|
|||||||
- zaza.openstack.charm_tests.ceph.tests.CephPrometheusTest
|
- zaza.openstack.charm_tests.ceph.tests.CephPrometheusTest
|
||||||
# Tests from quincy.
|
# Tests from quincy.
|
||||||
- zaza.openstack.charm_tests.ceph.tests.CephAuthTest
|
- zaza.openstack.charm_tests.ceph.tests.CephAuthTest
|
||||||
|
- zaza.openstack.charm_tests.ceph.tests.CephMonActionsTest
|
||||||
|
@@ -12,24 +12,24 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
|
from ops.testing import Harness
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import test_utils
|
import test_utils
|
||||||
import create_crush_rule
|
import create_crush_rule
|
||||||
import copy_pool
|
|
||||||
|
with mock.patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
|
||||||
|
mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:
|
||||||
|
lambda *args, **kwargs: f(*args, **kwargs))
|
||||||
|
# src.charm imports ceph_hooks, so we need to workaround the inclusion
|
||||||
|
# of the 'harden' decorator.
|
||||||
|
from src.charm import CephMonCharm
|
||||||
|
|
||||||
|
|
||||||
class CopyPoolTestCase(test_utils.CharmTestCase):
|
class CopyPoolTestCase(test_utils.CharmTestCase):
|
||||||
|
|
||||||
TO_PATCH = [
|
|
||||||
'hookenv',
|
|
||||||
]
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CopyPoolTestCase, self).setUp(
|
self.harness = Harness(CephMonCharm)
|
||||||
copy_pool,
|
|
||||||
self.TO_PATCH
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch.object(create_crush_rule.subprocess, 'check_call')
|
@mock.patch.object(create_crush_rule.subprocess, 'check_call')
|
||||||
def test_copy_pool(self, mock_check_call):
|
def test_copy_pool(self, mock_check_call):
|
||||||
@@ -37,8 +37,9 @@ class CopyPoolTestCase(test_utils.CharmTestCase):
|
|||||||
'source': 'source-pool',
|
'source': 'source-pool',
|
||||||
'target': 'target-pool',
|
'target': 'target-pool',
|
||||||
}
|
}
|
||||||
self.hookenv.action_get.side_effect = lambda k: _action_data.get(k)
|
self.harness.begin()
|
||||||
copy_pool.copy_pool()
|
self.harness.charm.on_copy_pool_action(
|
||||||
|
test_utils.MockActionEvent(_action_data))
|
||||||
mock_check_call.assert_called_with([
|
mock_check_call.assert_called_with([
|
||||||
'rados', 'cppool',
|
'rados', 'cppool',
|
||||||
'source-pool', 'target-pool',
|
'source-pool', 'target-pool',
|
||||||
@@ -50,14 +51,15 @@ class CopyPoolTestCase(test_utils.CharmTestCase):
|
|||||||
'source': 'source-pool',
|
'source': 'source-pool',
|
||||||
'target': 'target-pool',
|
'target': 'target-pool',
|
||||||
}
|
}
|
||||||
self.hookenv.action_get.side_effect = lambda k: _action_data.get(k)
|
self.harness.begin()
|
||||||
mock_check_call.side_effect = subprocess.CalledProcessError(1, 'rados')
|
mock_check_call.side_effect = subprocess.CalledProcessError(1, 'rados')
|
||||||
copy_pool.copy_pool()
|
event = test_utils.MockActionEvent(_action_data)
|
||||||
|
self.harness.charm.on_copy_pool_action(event)
|
||||||
mock_check_call.assert_called_with([
|
mock_check_call.assert_called_with([
|
||||||
'rados', 'cppool',
|
'rados', 'cppool',
|
||||||
'source-pool', 'target-pool',
|
'source-pool', 'target-pool',
|
||||||
])
|
])
|
||||||
self.hookenv.action_fail.assert_called_once_with(mock.ANY)
|
event.fail.assert_called_once_with(mock.ANY)
|
||||||
|
|
||||||
|
|
||||||
class CreateCrushRuleTestCase(test_utils.CharmTestCase):
|
class CreateCrushRuleTestCase(test_utils.CharmTestCase):
|
||||||
|
Reference in New Issue
Block a user