Exemple #1
0
 def test_create_volume_mapping_already_exists(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     utils.create_test_volume_mapping(context=self.context)
     mock_read.side_effect = lambda *args: None
     self.assertRaises(exception.ResourceExists,
                       utils.create_test_volume_mapping,
                       context=self.context)
Exemple #2
0
    def test_list_volume_mappings_with_filters(self, mock_ins, mock_write,
                                               mock_read):
        mock_ins.return_value = etcd_api.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound

        volume_mapping1 = utils.create_test_volume_mapping(
            name='volume_mapping1',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        volume_mapping2 = utils.create_test_volume_mapping(
            name='volume_mapping2',
            uuid=uuidutils.generate_uuid(),
            context=self.context,
        )

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
            [volume_mapping1.as_dict(),
             volume_mapping2.as_dict()])

        res = dbapi.list_volume_mappings(
            self.context, filters={'uuid': volume_mapping1.uuid})
        self.assertEqual([volume_mapping1.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context, filters={'uuid': volume_mapping2.uuid})
        self.assertEqual([volume_mapping2.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(self.context,
                                         filters={'uuid': 'unknow-uuid'})
        self.assertEqual([], [r.id for r in res])
 def test_create_volume_mapping_already_exists(self):
     utils.create_test_volume_mapping(context=self.context,
                                      uuid='123')
     with self.assertRaisesRegex(exception.VolumeMappingAlreadyExists,
                                 'A volume mapping with UUID 123.*'):
         utils.create_test_volume_mapping(context=self.context,
                                          uuid='123')
Exemple #4
0
    def test_list_volume_mappings_with_filters(self):
        volume_mapping1 = utils.create_test_volume_mapping(
            volume_provider='provider-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        volume_mapping2 = utils.create_test_volume_mapping(
            volume_provider='provider-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'provider-one'})
        self.assertEqual([volume_mapping1.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'provider-two'})
        self.assertEqual([volume_mapping2.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'bad-provider'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context,
            filters={'volume_provider': volume_mapping1.volume_provider})
        self.assertEqual([volume_mapping1.id], [r.id for r in res])
    def test_update_volume_mapping(self):
        volume_mapping = utils.create_test_volume_mapping(context=self.context)
        old_path = volume_mapping.container_path
        new_path = 'new-container-path'
        self.assertNotEqual(old_path, new_path)

        res = dbapi.update_volume_mapping(self.context, volume_mapping.id,
                                          {'container_path': new_path})
        self.assertEqual(new_path, res.container_path)
Exemple #6
0
 def test_destroy_volume_mapping_by_uuid(self, mock_delete, mock_write,
                                         mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(volume_mapping.
                                                          as_dict())
     dbapi.destroy_volume_mapping(self.context, volume_mapping.uuid)
     mock_delete.assert_called_once_with('/volume_mappings/%s' %
                                         volume_mapping.uuid)
Exemple #7
0
 def test_get_volume_mapping_by_uuid(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(volume_mapping.
                                                          as_dict())
     res = dbapi.get_volume_mapping_by_uuid(self.context,
                                            volume_mapping.uuid)
     self.assertEqual(volume_mapping.id, res.id)
     self.assertEqual(volume_mapping.uuid, res.uuid)
Exemple #8
0
    def test_update_volume_mapping(self):
        volume_mapping = utils.create_test_volume_mapping(context=self.context)
        old_conn_info = volume_mapping.connection_info
        new_conn_info = 'new-conn-info'
        self.assertNotEqual(old_conn_info, new_conn_info)

        res = dbapi.update_volume_mapping(self.context, volume_mapping.id,
                                          {'connection_info': new_conn_info})
        self.assertEqual(new_conn_info, res.connection_info)
Exemple #9
0
 def test_list_volume_mappings(self):
     uuids = []
     for i in range(1, 6):
         volume_mapping = utils.create_test_volume_mapping(
             uuid=uuidutils.generate_uuid(), context=self.context)
         uuids.append(six.text_type(volume_mapping['uuid']))
     res = dbapi.list_volume_mappings(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Exemple #10
0
    def test_update_volume_mapping(self):
        volume_mapping = utils.create_test_volume_mapping(context=self.context)
        old_path = volume_mapping.container_path
        new_path = 'new-container-path'
        self.assertNotEqual(old_path, new_path)

        res = dbapi.update_volume_mapping(self.context, volume_mapping.id,
                                          {'container_path': new_path})
        self.assertEqual(new_path, res.container_path)
Exemple #11
0
    def test_update_volume_mapping(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        volume_mapping = utils.create_test_volume_mapping(context=self.context)
        new_conn_info = 'new-conn-info'

        mock_read.side_effect = lambda *args: FakeEtcdResult(volume_mapping.
                                                             as_dict())
        dbapi.update_volume_mapping(self.context, volume_mapping.uuid,
                                    {'container_info': new_conn_info})
        self.assertEqual(
            new_conn_info,
            json.loads(mock_update.call_args_list[0][0][0].value.decode(
                'utf-8'))['container_info'])
    def test_list_volume_mappings_with_filters(self):
        volume1 = utils.create_test_volume(
            id=1,
            volume_provider='provider-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        volume_mapping1 = utils.create_test_volume_mapping(
            id=1,
            volume_id=volume1.id,
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        volume2 = utils.create_test_volume(
            id=2,
            volume_provider='provider-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        volume_mapping2 = utils.create_test_volume_mapping(
            id=2,
            uuid=uuidutils.generate_uuid(),
            volume_id=volume2.id,
            context=self.context)

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'provider-one'})
        self.assertEqual([volume_mapping1.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'provider-two'})
        self.assertEqual([volume_mapping2.id], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context, filters={'volume_provider': 'bad-provider'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_volume_mappings(
            self.context,
            filters={'volume_provider': volume1.volume_provider})
        self.assertEqual([volume_mapping1.id], [r.id for r in res])
Exemple #13
0
    def test_list_volume_mappings_sorted(self):
        uuids = []
        for i in range(5):
            volume_mapping = utils.create_test_volume_mapping(
                uuid=uuidutils.generate_uuid(), context=self.context)
            uuids.append(six.text_type(volume_mapping.uuid))
        res = dbapi.list_volume_mappings(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_volume_mappings,
                          self.context,
                          sort_key='foo')
 def test_list_volume_mappings(self):
     uuids = []
     for i in range(1, 6):
         volume = utils.create_test_volume(
             uuid=uuidutils.generate_uuid(),
             context=self.context)
         volume_mapping = utils.create_test_volume_mapping(
             uuid=uuidutils.generate_uuid(),
             volume_id=volume.id,
             context=self.context)
         uuids.append(six.text_type(volume_mapping['uuid']))
     res = dbapi.list_volume_mappings(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Exemple #15
0
 def test_list_volume_mappings(self, mock_write, mock_read):
     uuids = []
     volume_mappings = []
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(0, 6):
         volume_mapping = utils.create_test_volume_mapping(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='volume_mapping' + str(i))
         volume_mappings.append(volume_mapping.as_dict())
         uuids.append(six.text_type(volume_mapping['uuid']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         volume_mappings)
     res = dbapi.list_volume_mappings(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
    def test_list_volume_mappings_sorted(self):
        uuids = []
        for i in range(5):
            volume = utils.create_test_volume(
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            volume_mapping = utils.create_test_volume_mapping(
                uuid=uuidutils.generate_uuid(),
                volume_id=volume.id,
                context=self.context)
            uuids.append(six.text_type(volume_mapping.uuid))
        res = dbapi.list_volume_mappings(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_volume_mappings,
                          self.context,
                          sort_key='foo')
Exemple #17
0
 def test_list_volume_mappings_sorted(self, mock_ins, mock_write,
                                      mock_read):
     uuids = []
     volume_mappings = []
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(0, 6):
         volume_mapping = utils.create_test_volume_mapping(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='volume_mapping' + str(i))
         volume_mappings.append(volume_mapping.as_dict())
         uuids.append(six.text_type(volume_mapping['uuid']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         volume_mappings)
     res = dbapi.list_volume_mappings(self.context, sort_key='uuid')
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), res_uuids)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.list_volume_mappings,
                       self.context,
                       sort_key='wrong_key')
Exemple #18
0
 def test_create_volume_mapping_already_exists(self):
     utils.create_test_volume_mapping(context=self.context, uuid='123')
     with self.assertRaisesRegex(exception.VolumeMappingAlreadyExists,
                                 'A volume mapping with UUID 123.*'):
         utils.create_test_volume_mapping(context=self.context, uuid='123')
Exemple #19
0
 def test_create_volume_mapping(self):
     utils.create_test_volume_mapping(context=self.context)
Exemple #20
0
 def test_update_volume_mapping_uuid(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_volume_mapping, self.context,
                       volume_mapping.uuid, {'uuid': ''})
 def test_destroy_volume_mapping_by_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     dbapi.destroy_volume_mapping(self.context, volume_mapping.uuid)
     self.assertRaises(exception.VolumeMappingNotFound,
                       dbapi.get_volume_mapping_by_uuid,
                       self.context, volume_mapping.uuid)
 def test_update_volume_mapping_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_volume_mapping, self.context,
                       volume_mapping.id, {'uuid': ''})
Exemple #23
0
 def test_get_volume_mapping_by_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     res = dbapi.get_volume_mapping_by_uuid(self.context,
                                            volume_mapping.uuid)
     self.assertEqual(volume_mapping.id, res.id)
     self.assertEqual(volume_mapping.uuid, res.uuid)
 def test_get_volume_mapping_by_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     res = dbapi.get_volume_mapping_by_uuid(self.context,
                                            volume_mapping.uuid)
     self.assertEqual(volume_mapping.id, res.id)
     self.assertEqual(volume_mapping.uuid, res.uuid)
Exemple #25
0
 def test_update_volume_mapping_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_volume_mapping, self.context,
                       volume_mapping.id, {'uuid': ''})
Exemple #26
0
 def test_create_volume_mapping(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     utils.create_test_volume_mapping(context=self.context)
Exemple #27
0
 def test_destroy_volume_mapping_by_uuid(self):
     volume_mapping = utils.create_test_volume_mapping(context=self.context)
     dbapi.destroy_volume_mapping(self.context, volume_mapping.uuid)
     self.assertRaises(exception.VolumeMappingNotFound,
                       dbapi.get_volume_mapping_by_uuid, self.context,
                       volume_mapping.uuid)
 def test_create_volume_mapping(self):
     utils.create_test_volume_mapping(context=self.context)