summaryrefslogtreecommitdiff
path: root/unit_tests/test_actions_zap_disk.py
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/test_actions_zap_disk.py')
-rw-r--r--unit_tests/test_actions_zap_disk.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/unit_tests/test_actions_zap_disk.py b/unit_tests/test_actions_zap_disk.py
index 47f71e7..61266e3 100644
--- a/unit_tests/test_actions_zap_disk.py
+++ b/unit_tests/test_actions_zap_disk.py
@@ -26,10 +26,12 @@ class ZapDiskActionTests(CharmTestCase):
26 'is_block_device', 26 'is_block_device',
27 'is_device_mounted', 27 'is_device_mounted',
28 'is_active_bluestore_device', 28 'is_active_bluestore_device',
29 'is_mapped_luks_device',
29 'kv']) 30 'kv'])
30 self.is_device_mounted.return_value = False 31 self.is_device_mounted.return_value = False
31 self.is_block_device.return_value = True 32 self.is_block_device.return_value = True
32 self.is_active_bluestore_device.return_value = False 33 self.is_active_bluestore_device.return_value = False
34 self.is_mapped_luks_device.return_value = False
33 self.kv.return_value = self.kv 35 self.kv.return_value = self.kv
34 self.hookenv.local_unit.return_value = "ceph-osd-test/0" 36 self.hookenv.local_unit.return_value = "ceph-osd-test/0"
35 37
@@ -127,3 +129,44 @@ class ZapDiskActionTests(CharmTestCase):
127 _zap_disk.assert_not_called() 129 _zap_disk.assert_not_called()
128 self.hookenv.action_fail.assert_called_with( 130 self.hookenv.action_fail.assert_called_with(
129 "1 devices are mounted: /dev/vdb") 131 "1 devices are mounted: /dev/vdb")
132
133 @mock.patch.object(zap_disk, 'zap_disk')
134 def test_wont_zap__mapped_luks_device(self, _zap_disk):
135 """Will not zap a disk that has a LUKS header"""
136 def side_effect(arg):
137 return {
138 'devices': '/dev/vdb',
139 'i-really-mean-it': True,
140 }.get(arg)
141 self.hookenv.action_get.side_effect = side_effect
142 self.is_active_bluestore_device.return_value = False
143 self.is_mapped_luks_device.return_value = True
144 zap_disk.zap()
145 _zap_disk.assert_not_called()
146 self.hookenv.action_fail.assert_called_with(
147 "1 devices are mounted: /dev/vdb")
148
149 @mock.patch.object(zap_disk, 'zap_disk')
150 def test_zap_luks_not_mapped(self, _zap_disk):
151 """Will zap disk with extra config set"""
152 def side_effect(arg):
153 return {
154 'devices': '/dev/vdb',
155 'i-really-mean-it': True,
156 }.get(arg)
157
158 self.is_active_bluestore_device.return_value = False
159 self.is_mapped_luks_device.return_value = False
160
161 self.hookenv.action_get.side_effect = side_effect
162 self.kv.get.return_value = ['/dev/vdb', '/dev/vdz']
163 zap_disk.zap()
164 _zap_disk.assert_called_with('/dev/vdb')
165 self.kv.get.assert_called_with('osd-devices', [])
166 self.kv.set.assert_called_with('osd-devices', ['/dev/vdz'])
167 self.hookenv.action_set.assert_called_with({
168 'message': "1 disk(s) have been zapped, to use "
169 "them as OSDs, run: \njuju "
170 "run-action ceph-osd-test/0 add-disk "
171 "osd-devices=\"/dev/vdb\""
172 })