summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrode Nordahl <frode.nordahl@canonical.com>2019-03-13 16:02:50 +0100
committerFrode Nordahl <frode.nordahl@canonical.com>2019-03-13 16:09:01 +0100
commitabefc9a35870106c1cede821bf3e0a9ebe5791fc (patch)
treefa35b16070c57ea4b1634070643298d11833b742
parentadfd6000343b1c2c7a474ee47b3bbacd115cfb0e (diff)
Request appropriate Ceph application name for pools createdHEADmaster
Notes
Notes (review): Code-Review+2: Pete Vander Giessen <pete.vandergiessen@canonical.com> Workflow+1: Pete Vander Giessen <pete.vandergiessen@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 13 Mar 2019 15:33:49 +0000 Reviewed-on: https://review.openstack.org/643070 Project: openstack/charm-cinder-backup Branch: refs/heads/master
-rwxr-xr-xhooks/cinder_backup_hooks.py2
-rw-r--r--unit_tests/test_cinder_backup_hooks.py34
2 files changed, 25 insertions, 11 deletions
diff --git a/hooks/cinder_backup_hooks.py b/hooks/cinder_backup_hooks.py
index aa2ac3e..fc4364c 100755
--- a/hooks/cinder_backup_hooks.py
+++ b/hooks/cinder_backup_hooks.py
@@ -81,7 +81,7 @@ def get_ceph_request():
81 service = service_name() 81 service = service_name()
82 rq = CephBrokerRq() 82 rq = CephBrokerRq()
83 replicas = config('ceph-osd-replication-count') 83 replicas = config('ceph-osd-replication-count')
84 rq.add_op_create_pool(name=service, replica_count=replicas) 84 rq.add_op_create_pool(name=service, replica_count=replicas, app_name='rbd')
85 return rq 85 return rq
86 86
87 87
diff --git a/unit_tests/test_cinder_backup_hooks.py b/unit_tests/test_cinder_backup_hooks.py
index 4f85b13..3d46521 100644
--- a/unit_tests/test_cinder_backup_hooks.py
+++ b/unit_tests/test_cinder_backup_hooks.py
@@ -12,9 +12,9 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15from mock import patch 15import mock
16 16
17with patch('cinder_backup_utils.register_configs'): 17with mock.patch('cinder_backup_utils.register_configs'):
18 import cinder_backup_hooks as hooks 18 import cinder_backup_hooks as hooks
19 19
20from test_utils import ( 20from test_utils import (
@@ -52,16 +52,16 @@ class TestCinderBackupHooks(CharmTestCase):
52 super(TestCinderBackupHooks, self).setUp(hooks, TO_PATCH) 52 super(TestCinderBackupHooks, self).setUp(hooks, TO_PATCH)
53 self.config.side_effect = self.test_config.get 53 self.config.side_effect = self.test_config.get
54 54
55 @patch('charmhelpers.core.hookenv.config') 55 @mock.patch('charmhelpers.core.hookenv.config')
56 @patch('os.mkdir') 56 @mock.patch('os.mkdir')
57 def test_ceph_joined(self, mkdir, mock_config): 57 def test_ceph_joined(self, mkdir, mock_config):
58 """It correctly prepares for a ceph changed hook""" 58 """It correctly prepares for a ceph changed hook"""
59 with patch('os.path.isdir') as isdir: 59 with mock.patch('os.path.isdir') as isdir:
60 isdir.return_value = False 60 isdir.return_value = False
61 hooks.hooks.execute(['hooks/ceph-relation-joined']) 61 hooks.hooks.execute(['hooks/ceph-relation-joined'])
62 mkdir.assert_called_with('/etc/ceph') 62 mkdir.assert_called_with('/etc/ceph')
63 63
64 @patch('charmhelpers.core.hookenv.config') 64 @mock.patch('charmhelpers.core.hookenv.config')
65 def test_ceph_changed_no_key(self, mock_config): 65 def test_ceph_changed_no_key(self, mock_config):
66 """It does nothing when ceph key is not available""" 66 """It does nothing when ceph key is not available"""
67 self.CONFIGS.complete_contexts.return_value = [''] 67 self.CONFIGS.complete_contexts.return_value = ['']
@@ -69,7 +69,7 @@ class TestCinderBackupHooks(CharmTestCase):
69 m = 'ceph relation incomplete. Peer not ready?' 69 m = 'ceph relation incomplete. Peer not ready?'
70 self.log.assert_called_with(m) 70 self.log.assert_called_with(m)
71 71
72 @patch('charmhelpers.core.hookenv.config') 72 @mock.patch('charmhelpers.core.hookenv.config')
73 def test_ceph_changed(self, mock_config): 73 def test_ceph_changed(self, mock_config):
74 """It ensures ceph assets created on ceph changed""" 74 """It ensures ceph assets created on ceph changed"""
75 self.is_request_complete.return_value = True 75 self.is_request_complete.return_value = True
@@ -83,8 +83,8 @@ class TestCinderBackupHooks(CharmTestCase):
83 self.assertTrue(self.CONFIGS.write_all.called) 83 self.assertTrue(self.CONFIGS.write_all.called)
84 self.set_ceph_env_variables.assert_called_with(service='cinder-backup') 84 self.set_ceph_env_variables.assert_called_with(service='cinder-backup')
85 85
86 @patch.object(hooks, 'get_ceph_request') 86 @mock.patch.object(hooks, 'get_ceph_request')
87 @patch('charmhelpers.core.hookenv.config') 87 @mock.patch('charmhelpers.core.hookenv.config')
88 def test_ceph_changed_newrq(self, mock_config, mock_get_ceph_request): 88 def test_ceph_changed_newrq(self, mock_config, mock_get_ceph_request):
89 """It ensures ceph assets created on ceph changed""" 89 """It ensures ceph assets created on ceph changed"""
90 mock_get_ceph_request.return_value = 'cephreq' 90 mock_get_ceph_request.return_value = 'cephreq'
@@ -98,7 +98,7 @@ class TestCinderBackupHooks(CharmTestCase):
98 group='cinder') 98 group='cinder')
99 self.send_request_if_needed.assert_called_with('cephreq') 99 self.send_request_if_needed.assert_called_with('cephreq')
100 100
101 @patch('charmhelpers.core.hookenv.config') 101 @mock.patch('charmhelpers.core.hookenv.config')
102 def test_ceph_changed_no_keys(self, mock_config): 102 def test_ceph_changed_no_keys(self, mock_config):
103 """It ensures ceph assets created on ceph changed""" 103 """It ensures ceph assets created on ceph changed"""
104 self.CONFIGS.complete_contexts.return_value = ['ceph'] 104 self.CONFIGS.complete_contexts.return_value = ['ceph']
@@ -110,3 +110,17 @@ class TestCinderBackupHooks(CharmTestCase):
110 # the hook should just exit 0 and return. 110 # the hook should just exit 0 and return.
111 self.assertTrue(self.log.called) 111 self.assertTrue(self.log.called)
112 self.assertFalse(self.CONFIGS.write_all.called) 112 self.assertFalse(self.CONFIGS.write_all.called)
113
114 @mock.patch.object(hooks, 'CephBrokerRq')
115 @mock.patch.object(hooks, 'config')
116 @mock.patch.object(hooks, 'service_name')
117 def test_ceph_request(self, _service_name, _config, _ceph_broker_rq):
118 _service_name.return_value = 'cinder-backup'
119 _config.return_value = None
120 rq = mock.MagicMock()
121 _ceph_broker_rq.return_value = rq
122 self.assertEqual(hooks.get_ceph_request(), rq)
123 _service_name.assert_called_once_with()
124 _config.assert_called_once_with('ceph-osd-replication-count')
125 rq.add_op_create_pool.assert_called_once_with(
126 name='cinder-backup', replica_count=_config(), app_name='rbd')