Browse Source

Request appropriate Ceph application name for pools created

Change-Id: I33107f4266f481cf79bc8fe9d29428185b52e4c8
changes/70/643070/2
Frode Nordahl 2 months ago
parent
commit
abefc9a358
No account linked to committer's email address
2 changed files with 25 additions and 11 deletions
  1. 1
    1
      hooks/cinder_backup_hooks.py
  2. 24
    10
      unit_tests/test_cinder_backup_hooks.py

+ 1
- 1
hooks/cinder_backup_hooks.py View File

@@ -81,7 +81,7 @@ def get_ceph_request():
81 81
     service = service_name()
82 82
     rq = CephBrokerRq()
83 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 85
     return rq
86 86
 
87 87
 

+ 24
- 10
unit_tests/test_cinder_backup_hooks.py View File

@@ -12,9 +12,9 @@
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14 14
 
15
-from mock import patch
15
+import mock
16 16
 
17
-with patch('cinder_backup_utils.register_configs'):
17
+with mock.patch('cinder_backup_utils.register_configs'):
18 18
     import cinder_backup_hooks as hooks
19 19
 
20 20
 from test_utils import (
@@ -52,16 +52,16 @@ class TestCinderBackupHooks(CharmTestCase):
52 52
         super(TestCinderBackupHooks, self).setUp(hooks, TO_PATCH)
53 53
         self.config.side_effect = self.test_config.get
54 54
 
55
-    @patch('charmhelpers.core.hookenv.config')
56
-    @patch('os.mkdir')
55
+    @mock.patch('charmhelpers.core.hookenv.config')
56
+    @mock.patch('os.mkdir')
57 57
     def test_ceph_joined(self, mkdir, mock_config):
58 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 60
             isdir.return_value = False
61 61
             hooks.hooks.execute(['hooks/ceph-relation-joined'])
62 62
             mkdir.assert_called_with('/etc/ceph')
63 63
 
64
-    @patch('charmhelpers.core.hookenv.config')
64
+    @mock.patch('charmhelpers.core.hookenv.config')
65 65
     def test_ceph_changed_no_key(self, mock_config):
66 66
         """It does nothing when ceph key is not available"""
67 67
         self.CONFIGS.complete_contexts.return_value = ['']
@@ -69,7 +69,7 @@ class TestCinderBackupHooks(CharmTestCase):
69 69
         m = 'ceph relation incomplete. Peer not ready?'
70 70
         self.log.assert_called_with(m)
71 71
 
72
-    @patch('charmhelpers.core.hookenv.config')
72
+    @mock.patch('charmhelpers.core.hookenv.config')
73 73
     def test_ceph_changed(self, mock_config):
74 74
         """It ensures ceph assets created on ceph changed"""
75 75
         self.is_request_complete.return_value = True
@@ -83,8 +83,8 @@ class TestCinderBackupHooks(CharmTestCase):
83 83
         self.assertTrue(self.CONFIGS.write_all.called)
84 84
         self.set_ceph_env_variables.assert_called_with(service='cinder-backup')
85 85
 
86
-    @patch.object(hooks, 'get_ceph_request')
87
-    @patch('charmhelpers.core.hookenv.config')
86
+    @mock.patch.object(hooks, 'get_ceph_request')
87
+    @mock.patch('charmhelpers.core.hookenv.config')
88 88
     def test_ceph_changed_newrq(self, mock_config, mock_get_ceph_request):
89 89
         """It ensures ceph assets created on ceph changed"""
90 90
         mock_get_ceph_request.return_value = 'cephreq'
@@ -98,7 +98,7 @@ class TestCinderBackupHooks(CharmTestCase):
98 98
                                                     group='cinder')
99 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 102
     def test_ceph_changed_no_keys(self, mock_config):
103 103
         """It ensures ceph assets created on ceph changed"""
104 104
         self.CONFIGS.complete_contexts.return_value = ['ceph']
@@ -110,3 +110,17 @@ class TestCinderBackupHooks(CharmTestCase):
110 110
         # the hook should just exit 0 and return.
111 111
         self.assertTrue(self.log.called)
112 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')

Loading…
Cancel
Save