Example #1
0
 def test_wont_zap_non_block_device(self,
                                    _zap_disk,):
     """Will not zap a disk that isn't a block device"""
     def side_effect(arg):
         return {
             'devices': '/dev/vdb',
             'i-really-mean-it': True,
         }.get(arg)
     self.hookenv.action_get.side_effect = side_effect
     self.is_block_device.return_value = False
     zap_disk.zap()
     _zap_disk.assert_not_called()
     self.hookenv.action_fail.assert_called_with(
         "1 devices are not block devices: /dev/vdb")
Example #2
0
 def test_wont_zap__mapped_luks_device(self, _zap_disk):
     """Will not zap a disk that has a LUKS header"""
     def side_effect(arg):
         return {
             'devices': '/dev/vdb',
             'i-really-mean-it': True,
         }.get(arg)
     self.hookenv.action_get.side_effect = side_effect
     self.is_active_bluestore_device.return_value = False
     self.is_mapped_luks_device.return_value = True
     zap_disk.zap()
     _zap_disk.assert_not_called()
     self.hookenv.action_fail.assert_called_with(
         "1 devices are mounted: /dev/vdb")
Example #3
0
 def test_wont_zap_mounted_block_device(self,
                                        _zap_disk):
     """Will not zap a disk that is mounted"""
     def side_effect(arg):
         return {
             'devices': '/dev/vdb',
             'i-really-mean-it': True,
         }.get(arg)
     self.hookenv.action_get.side_effect = side_effect
     self.is_device_mounted.return_value = True
     zap_disk.zap()
     _zap_disk.assert_not_called()
     self.hookenv.action_fail.assert_called_with(
         "1 devices are mounted: /dev/vdb")
Example #4
0
    def test_wont_zap_not_abs_path(self, _zap_disk):
        """Won't zap not absolute path"""
        def side_effect(arg):
            return {
                'devices': 'not-absolute',
                'i-really-mean-it': True,
            }.get(arg)

        self.hookenv.action_get.side_effect = side_effect
        zap_disk.zap()
        _zap_disk.assert_not_called()
        self.hookenv.action_fail.assert_called_with(
            'Failed due to: not-absolute: Not absolute path.')
        self.hookenv.action_set.assert_not_called()
Example #5
0
    def test_wont_zap_non_existent_device(self, _zap_disk):
        """Won't zap non-existent disk"""
        def side_effect(arg):
            return {
                'devices': '/dev/not-valid-disk',
                'i-really-mean-it': True,
            }.get(arg)

        self.hookenv.action_get.side_effect = side_effect
        zap_disk.zap()
        _zap_disk.assert_not_called()
        self.hookenv.action_fail.assert_called_with(
            'Failed due to: /dev/not-valid-disk: Device does not exist.')
        self.hookenv.action_set.assert_not_called()
Example #6
0
 def test_authorized_zap_single_disk(self,
                                     _zap_disk):
     """Will zap disk with extra config set"""
     def side_effect(arg):
         return {
             'devices': '/dev/vdb',
             'i-really-mean-it': True,
         }.get(arg)
     self.hookenv.action_get.side_effect = side_effect
     self.kv.get.return_value = ['/dev/vdb', '/dev/vdz']
     zap_disk.zap()
     _zap_disk.assert_called_with('/dev/vdb')
     self.kv.get.assert_called_with('osd-devices', [])
     self.kv.set.assert_called_with('osd-devices', ['/dev/vdz'])
     self.hookenv.action_set.assert_called_with({
         'message': "1 disk(s) have been zapped, to use "
                    "them as OSDs, run: \njuju "
                    "run-action ceph-osd-test/0 add-disk "
                    "osd-devices=\"/dev/vdb\""
     })