Ejemplo n.º 1
0
    def test_can_cold_success(self, mock_cinder):
        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.cinder.volumes.get.return_value = volume
        result = cinder_util.can_cold(volume)
        self.assertTrue(result)
Ejemplo n.º 2
0
 def test_get_storage_node_list(self, mock_cinder):
     node1 = self.fake_storage_node()
     cinder_util = cinder_helper.CinderHelper()
     cinder_util.cinder.services.list.return_value = [node1]
     cinder_util.get_storage_node_list()
     cinder_util.cinder.services.list.assert_called_once_with(
         binary='cinder-volume')
Ejemplo n.º 3
0
    def test_migrate_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.cinder.volumes.get.return_value = volume

        volume_type = self.fake_volume_type()
        volume_type.name = 'notbackend'
        cinder_util.cinder.volume_types.list.return_value = [volume_type]

        self.assertRaisesRegex(
            exception.Invalid,
            "Volume type must be same for migrating",
            cinder_util.migrate, volume, 'host@backend#pool')

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'migration_status', 'error')
        cinder_util.cinder.volumes.get.return_value = volume

        volume_type = self.fake_volume_type()
        cinder_util.cinder.volume_types.list.return_value = [volume_type]

        result = cinder_util.migrate(volume, 'host@backend#pool')
        self.assertFalse(result)
Ejemplo n.º 4
0
 def test_get_storage_pool_by_name_failure(self, mock_cinder):
     pool1 = self.fake_pool()
     cinder_util = cinder_helper.CinderHelper()
     cinder_util.cinder.services.list.return_value = [pool1]
     self.assertRaisesRegex(exception.PoolNotFound,
                            "The pool failure could not be found",
                            cinder_util.get_storage_pool_by_name, 'failure')
Ejemplo n.º 5
0
    def test_get_storage_node_by_name_success(self, mock_cinder):
        node1 = self.fake_storage_node()
        cinder_util = cinder_helper.CinderHelper()
        cinder_util.cinder.services.list.return_value = [node1]
        node = cinder_util.get_storage_node_by_name('host@backend')

        self.assertEqual(node, node1)
Ejemplo n.º 6
0
 def test_get_storage_node_by_name_failure(self, mock_cinder):
     node1 = self.fake_storage_node()
     cinder_util = cinder_helper.CinderHelper()
     cinder_util.cinder.services.list.return_value = [node1]
     self.assertRaisesRegex(exception.StorageNodeNotFound,
                            "The storage node failure could not be found",
                            cinder_util.get_storage_node_by_name, 'failure')
Ejemplo n.º 7
0
    def test_get_storage_pool_by_name_success(self, mock_cinder):
        pool1 = self.fake_pool()
        cinder_util = cinder_helper.CinderHelper()
        cinder_util.cinder.pools.list.return_value = [pool1]
        pool = cinder_util.get_storage_pool_by_name('host@backend#pool')

        self.assertEqual(pool, pool1)
Ejemplo n.º 8
0
    def test_can_get_volume_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.get_volume = mock.MagicMock(return_value=volume)
        result = cinder_util._can_get_volume(volume.id)
        self.assertTrue(result)
Ejemplo n.º 9
0
    def test_has_snapshot_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        volume.snapshot_id = utils.generate_uuid()
        cinder_util.get_volume = mock.MagicMock(return_value=volume)
        result = cinder_util._has_snapshot(volume)
        self.assertTrue(result)
Ejemplo n.º 10
0
    def test_get_volume_type_by_backendname_with_no_backend_exist(
            self, mock_cinder):
        volume_type1 = self.fake_volume_type()
        cinder_util = cinder_helper.CinderHelper()
        cinder_util.cinder.volume_types.list.return_value = [volume_type1]
        volume_type_name = cinder_util.get_volume_type_by_backendname(
            'nobackend')

        self.assertEqual([], volume_type_name)
Ejemplo n.º 11
0
    def test_has_snapshot_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        volume.snapshot_id = None
        cinder_util.get_volume = mock.MagicMock(return_value=volume)
        result = cinder_util._has_snapshot(volume)
        self.assertFalse(result)
Ejemplo n.º 12
0
    def test_create_volume_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.cinder.volumes.create.return_value = volume
        new_vloume = cinder_util.create_volume(
            cinder_util.cinder, volume, 'fake_type')
        self.assertEqual(new_vloume, volume)
Ejemplo n.º 13
0
    def test_delete_volume_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.cinder.volumes.create.return_value = volume
        cinder_util.check_volume_deleted = mock.MagicMock(return_value=True)
        result = cinder_util.delete_volume(volume)
        self.assertIsNone(result)
Ejemplo n.º 14
0
    def test_retype_success(self, mock_cinder):
        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'migration_status', 'success')
        cinder_util.cinder.volumes.get.return_value = volume

        result = cinder_util.retype(volume, 'notfake_type')
        self.assertTrue(result)
Ejemplo n.º 15
0
    def test_check_volume_deleted_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util._can_get_volume = mock.MagicMock(return_value=volume)
        result = cinder_util.check_volume_deleted(
            volume, retry=2, retry_interval=1)
        self.assertFalse(result)
Ejemplo n.º 16
0
    def test_get_volume_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        side_effect = cinder_exception.NotFound(404)
        cinder_util.cinder.volumes.get.side_effect = side_effect
        cinder_util.cinder.volumes.find.return_value = False
        result = cinder_util.get_volume(volume)
        self.assertFalse(result)
Ejemplo n.º 17
0
    def test_check_migrated_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'migration_status', 'success')
        setattr(volume, 'os-vol-host-attr:host', 'host@backend#pool')
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.check_volume_deleted = mock.MagicMock(return_value=True)
        result = cinder_util.check_migrated(volume)
        self.assertTrue(result)
Ejemplo n.º 18
0
    def test_migrate_success(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'migration_status', 'success')
        cinder_util.cinder.volumes.get.return_value = volume

        volume_type = self.fake_volume_type()
        cinder_util.cinder.volume_types.list.return_value = [volume_type]

        result = cinder_util.migrate(volume, 'host@backend#pool')
        self.assertTrue(result)
Ejemplo n.º 19
0
    def test_create_volume_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'status', 'fake_status')
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.cinder.volumes.create.return_value = volume

        self.assertRaisesRegex(
            Exception,
            "Failed to create volume",
            cinder_util.create_volume, cinder_util.cinder, volume,
            'fake_type', retry=2, retry_interval=1)
Ejemplo n.º 20
0
    def test_delete_volume_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'status', 'fake_status')
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.cinder.volumes.create.return_value = volume
        cinder_util.check_volume_deleted = mock.MagicMock(return_value=False)

        self.assertRaisesRegex(
            Exception,
            "Failed to delete volume",
            cinder_util.delete_volume,
            volume)
Ejemplo n.º 21
0
    def test_can_get_volume_fail(self, mock_cinder):

        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        cinder_util.get_volume = mock.MagicMock()
        cinder_util.get_volume.side_effect = cinder_exception.NotFound(404)
        result = cinder_util._can_get_volume(volume.id)
        self.assertFalse(result)

        cinder_util.get_volume = mock.MagicMock(return_value=None)
        self.assertRaises(
            Exception,
            cinder_util._can_get_volume,
            volume.id)
Ejemplo n.º 22
0
    def test_can_cold_fail(self, mock_cinder):
        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume(status='in-use')
        cinder_util.cinder.volumes.get.return_value = volume
        result = cinder_util.can_cold(volume)
        self.assertFalse(result)

        volume = self.fake_volume(snapshot_id='snapshot_id')
        cinder_util.cinder.volumes.get.return_value = volume
        result = cinder_util.can_cold(volume)
        self.assertFalse(result)

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'host@backend#pool')
        cinder_util.cinder.volumes.get.return_value = volume
        result = cinder_util.can_cold(volume, 'host@backend#pool')
        self.assertFalse(result)
Ejemplo n.º 23
0
    def test_retype_fail(self, mock_cinder):
        cinder_util = cinder_helper.CinderHelper()

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'migration_status', 'success')
        cinder_util.cinder.volumes.get.return_value = volume

        self.assertRaisesRegex(exception.Invalid,
                               "Volume type must be different for retyping",
                               cinder_util.retype, volume, 'fake_type')

        volume = self.fake_volume()
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'migration_status', 'error')
        cinder_util.cinder.volumes.get.return_value = volume

        result = cinder_util.retype(volume, 'notfake_type')
        self.assertFalse(result)
Ejemplo n.º 24
0
    def test_check_migrated_fail(self, mock_cinder):

        def side_effect(volume):
            if isinstance(volume, str):
                volume = self.fake_volume()
                setattr(volume, 'migration_status', 'error')
            elif volume.id is None:
                setattr(volume, 'migration_status', 'fake_status')
                setattr(volume, 'id', utils.generate_uuid())
            return volume

        cinder_util = cinder_helper.CinderHelper()

        # verify that the method check_migrated will return False when the
        # status of migration_status is error.
        volume = self.fake_volume()
        setattr(volume, 'migration_status', 'error')
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        cinder_util.cinder.volumes.get.return_value = volume
        result = cinder_util.check_migrated(volume, retry_interval=1)
        self.assertFalse(result)

        # verify that the method check_migrated will return False when the
        # status of migration_status is in other cases.
        volume = self.fake_volume()
        setattr(volume, 'migration_status', 'success')
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        setattr(volume, 'id', None)
        cinder_util.get_volume = mock.MagicMock()
        cinder_util.get_volume.side_effect = side_effect
        result = cinder_util.check_migrated(volume, retry_interval=1)
        self.assertFalse(result)

        # verify that the method check_migrated will return False when the
        # return_value of method check_volume_deleted is False.
        volume = self.fake_volume()
        setattr(volume, 'migration_status', 'success')
        setattr(volume, 'os-vol-host-attr:host', 'source_node')
        cinder_util.cinder.volumes.get.return_value = volume
        cinder_util.check_volume_deleted = mock.MagicMock(return_value=False)
        cinder_util.get_deleting_volume = mock.MagicMock(return_value=volume)
        result = cinder_util.check_migrated(volume, retry_interval=1)
        self.assertFalse(result)
Ejemplo n.º 25
0
 def __init__(self, osc):
     self.osc = osc
     self.model = model_root.StorageModelRoot()
     self.cinder = osc.cinder()
     self.cinder_helper = cinder_helper.CinderHelper(osc=self.osc)
Ejemplo n.º 26
0
 def cinder(self):
     if self._cinder is None:
         self._cinder = cinder_helper.CinderHelper()
     return self._cinder
Ejemplo n.º 27
0
 def __init__(self, scope, config, osc=None):
     super(StorageScope, self).__init__(scope, config)
     self._osc = osc
     self.wrapper = cinder_helper.CinderHelper(osc=self._osc)
Ejemplo n.º 28
0
 def test_get_storage_pool_list(self, mock_cinder):
     pool = self.fake_pool()
     cinder_util = cinder_helper.CinderHelper()
     cinder_util.cinder.pools.list.return_value = [pool]
     cinder_util.get_storage_pool_list()
     cinder_util.cinder.pools.list.assert_called_once_with(detailed=True)
Ejemplo n.º 29
0
 def cinder(self):
     if not self._cinder:
         self._cinder = cinder_helper.CinderHelper(osc=self.osc)
     return self._cinder
Ejemplo n.º 30
0
 def test_get_volume_type_list(self, mock_cinder):
     volume_type1 = self.fake_volume_type()
     cinder_util = cinder_helper.CinderHelper()
     cinder_util.cinder.volume_types.list.return_value = [volume_type1]
     cinder_util.get_volume_type_list()
     cinder_util.cinder.volume_types.list.assert_called_once_with()