Beispiel #1
0
 def test_update_resource_class_uuid(self, mock_ins, mock_write, mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     resource_class = utils.create_test_resource_class(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_resource_class, self.context,
                       resource_class.uuid, {'uuid': ''})
    def test_container_actions_get_by_container(self, mock_db_inst,
                                                mock_write, mock_read):
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        uuid1 = uuidutils.generate_uuid()

        expected = []

        action_values = self._create_action_values(uuid1)
        action = dbapi.action_start(self.context, action_values)
        action['start_time'] = datetime.isoformat(action['start_time'])
        expected.append(action)

        action_values['action'] = 'test-action'
        action = dbapi.action_start(self.context, action_values)
        action['start_time'] = datetime.isoformat(action['start_time'])
        expected.append(action)

        # Create an other container action.
        uuid2 = uuidutils.generate_uuid()
        action_values = self._create_action_values(uuid2, 'test-action')
        dbapi.action_start(self.context, action_values)

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
            expected)
        actions = dbapi.actions_get(self.context, uuid1)
        self._assertEqualListsOfObjects(expected, actions)
Beispiel #3
0
    def test_list_capsules_with_filters(self, mock_db_inst, mock_write,
                                        mock_read):
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound

        capsule1 = utils.create_test_capsule(name='capsule1',
                                             uuid=uuidutils.generate_uuid(),
                                             context=self.context)
        capsule2 = utils.create_test_capsule(name='capsule2',
                                             uuid=uuidutils.generate_uuid(),
                                             context=self.context)

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
            [capsule1.as_dict(), capsule2.as_dict()])

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

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

        res = dbapi.list_capsules(self.context,
                                  filters={'uuid': 'unknow-uuid'})
        self.assertEqual([], [r.id for r in res])
Beispiel #4
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_container_action_event_start(self, mock_db_inst,
                                          mock__action_get_by_request_id,
                                          mock_write, mock_read):
        """Create a container action event."""
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        uuid = uuidutils.generate_uuid()

        action_values = self._create_action_values(uuid)
        action = dbapi.action_start(self.context, action_values)

        event_values = self._create_event_values(uuid)

        mock__action_get_by_request_id.return_value = action
        mock_read.side_effect = etcd.EtcdKeyNotFound
        event = dbapi.action_event_start(self.context, event_values)

        ignored_keys = self.IGNORED_FIELDS + ['finish_time', 'traceback',
                                              'result', 'action_uuid',
                                              'request_id', 'container_uuid',
                                              'uuid']
        self._assertEqualObjects(event_values, event, ignored_keys)

        event['start_time'] = datetime.isoformat(event['start_time'])
        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([event])
        self._assertActionEventSaved(event, action['uuid'])
Beispiel #6
0
    def test_list_containers_with_filters(self, mock_db_inst, mock_write,
                                          mock_read):
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound

        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
            [container1.as_dict(), container2.as_dict()])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-one'})
        self.assertEqual([container1.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-two'})
        self.assertEqual([container2.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-three'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': container1.name})
        self.assertEqual([container1.id], [r.id for r in res])
Beispiel #7
0
 def test_get_capsule_by_uuid(self, mock_db_inst, mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     capsule = utils.create_test_capsule(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(capsule.as_dict())
     res = dbapi.get_capsule_by_uuid(self.context, capsule.uuid)
     self.assertEqual(capsule.id, res.id)
     self.assertEqual(capsule.uuid, res.uuid)
Beispiel #8
0
 def test_destroy_capsule_by_uuid(self, mock_db_inst, mock_delete,
                                  mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     capsule = utils.create_test_capsule(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(capsule.as_dict())
     dbapi.destroy_capsule(self.context, capsule.uuid)
     mock_delete.assert_called_once_with('/capsules/%s' % capsule.uuid)
Beispiel #9
0
 def test_get_resource_class_by_name(self, mock_db_inst, mock_write,
                                     mock_read):
     mock_db_inst.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     rcs = utils.create_test_resource_class(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         [rcs.as_dict()])
     res = dbapi.get_resource_class(self.context, rcs.name)
     self.assertEqual(rcs.uuid, res.uuid)
Beispiel #10
0
 def test_get_container_by_name(self, mock_inst, mock_write, mock_read):
     mock_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     container = utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         [container.as_dict()])
     res = dbapi.get_container_by_name(self.context, container.name)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
Beispiel #11
0
 def test_get_compute_node_by_name(self, mock_db_inst,
                                   mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     node = utils.create_test_compute_node(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(
         node.as_dict())
     res = dbapi.get_compute_node(self.context, node.hostname)
     self.assertEqual(node.uuid, res.uuid)
Beispiel #12
0
 def test_get_volume_mapping_by_uuid(self, mock_ins, mock_write, mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     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)
Beispiel #13
0
 def test_destroy_volume_mapping_by_uuid(self, mock_ins, mock_delete,
                                         mock_write, mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     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)
Beispiel #14
0
 def test_destroy_resource_class(self, mock_ins, mock_delete, mock_write,
                                 mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     resource_class = utils.create_test_resource_class(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(resource_class.
                                                          as_dict())
     dbapi.destroy_resource_class(self.context, resource_class.uuid)
     mock_delete.assert_called_once_with('/resource_classes/%s' %
                                         resource_class.uuid)
 def test_get_zun_service(self, mock_ins, mock_write, mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     zun_service = utils.create_test_zun_service()
     mock_read.side_effect = lambda *args: FakeEtcdResult(zun_service.
                                                          as_dict())
     res = dbapi.get_zun_service(self.context, zun_service.host,
                                 zun_service.binary)
     self.assertEqual(zun_service.host, res.host)
     self.assertEqual(zun_service.binary, res.binary)
Beispiel #16
0
 def test_get_quota(self, mock_db_inst,
                    mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     quota = utils.create_test_quota(context=self.context)
     mock_read.side_effect = lambda *args: utils.FakeEtcdResult(
         quota.as_dict())
     res = dbapi.quota_get(self.context, quota.project_id,
                           quota.resource)
     self.assertEqual(quota.hard_limit, res.hard_limit)
 def test_list_zun_services(self, mock_ins, mock_write, mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     service_1 = utils.create_test_zun_service(host='host_1')
     service_2 = utils.create_test_zun_service(host='host_2')
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         [service_1.as_dict(), service_2.as_dict()])
     res = dbapi.list_zun_services(self.context)
     self.assertEqual(2, len(res))
     self.assertEqual('host_1', res[0].host)
     self.assertEqual('host_2', res[1].host)
Beispiel #18
0
 def test_destroy_quota(self, mock_db_inst, mock_delete,
                        mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     quota = utils.create_test_quota(context=self.context)
     mock_read.side_effect = lambda *args: utils.FakeEtcdResult(
         quota.as_dict())
     dbapi.quota_destroy(
         self.context, quota.project_id, quota.resource)
     mock_delete.assert_called_once_with(
         '/quotas/{}/{}' . format(quota.project_id, quota.resource))
 def test_destroy_zun_service(self, mock_ins, mock_delete, mock_write,
                              mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     zun_service = utils.create_test_zun_service()
     mock_read.side_effect = lambda *args: FakeEtcdResult(zun_service.
                                                          as_dict())
     dbapi.destroy_zun_service(zun_service.host, zun_service.binary)
     mock_delete.assert_called_once_with('/zun_services/%s' %
                                         zun_service.host + '_' +
                                         zun_service.binary)
Beispiel #20
0
    def setUp(self):
        super(DbTestCase, self).setUp()

        self.dbapi = (db_api._get_dbdriver_instance() if CONF.database.backend
                      == "sqlalchemy" else etcd_api.get_backend())

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 migration,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)
Beispiel #21
0
    def setUp(self):
        super(DbTestCase, self).setUp()

        self.dbapi = (db_api._get_dbdriver_instance()
                      if CONF.database.backend == "sqlalchemy"
                      else etcd_api.get_backend())

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api, migration,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)
Beispiel #22
0
 def test_update_quota(self, mock_db_inst, mock_update,
                       mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     quota = utils.create_test_quota(context=self.context)
     new_hard_limit = 60
     mock_read.side_effect = lambda *args: utils.FakeEtcdResult(
         quota.as_dict())
     dbapi.quota_update(self.context, quota.project_id, quota.resource,
                        new_hard_limit)
     self.assertEqual(new_hard_limit,
                      json.loads(mock_update.call_args_list[0][0][0].
                                 value.decode('utf-8'))['hard_limit'])
    def test_update_zun_service(self, mock_ins, mock_update, mock_write,
                                mock_read):
        mock_ins.return_value = etcd_api.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        service = utils.create_test_zun_service()
        new_host = 'new-host'

        mock_read.side_effect = lambda *args: FakeEtcdResult(service.as_dict())
        dbapi.update_zun_service(service.host, service.binary,
                                 {'host': new_host})
        self.assertEqual(
            new_host,
            json.loads(mock_update.call_args_list[0][0][0].value)['host'])
Beispiel #24
0
    def test_update_capsule(self, mock_db_inst, mock_update, mock_write,
                            mock_read):
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        capsule = utils.create_test_capsule(context=self.context)
        new_meta_name = 'new_meta_name'

        mock_read.side_effect = lambda *args: FakeEtcdResult(capsule.as_dict())
        dbapi.update_capsule(self.context, capsule.uuid,
                             {'meta_name': new_meta_name})
        self.assertEqual(
            new_meta_name,
            json.loads(mock_update.call_args_list[0][0][0].value.decode(
                'utf-8'))['meta_name'])
Beispiel #25
0
    def test_update_container(self, mock_inst, mock_update, mock_write,
                              mock_read):
        mock_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        container = utils.create_test_container(context=self.context)
        new_image = 'new-image'

        mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
        ))
        dbapi.update_container(self.context, container.uuid,
                               {'image': new_image})
        self.assertEqual(
            new_image,
            json.loads(mock_update.call_args_list[0][0][0].value)['image'])
Beispiel #26
0
    def test_update_volume_mapping(self, mock_ins, mock_update, mock_write,
                                   mock_read):
        mock_ins.return_value = etcd_api.get_backend()
        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'])
Beispiel #27
0
 def test_list_compute_nodes(self, mock_db_inst, mock_write, mock_read):
     hostnames = []
     compute_nodes = []
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(1, 6):
         res_class = utils.create_test_compute_node(
             context=self.context, hostname='class' + str(i))
         compute_nodes.append(res_class.as_dict())
         hostnames.append(six.text_type(res_class['hostname']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         compute_nodes)
     res = dbapi.list_compute_nodes(self.context)
     res_names = [r.hostname for r in res]
     self.assertEqual(sorted(hostnames), sorted(res_names))
Beispiel #28
0
 def test_update_compute_node(self, mock_db_inst, mock_update,
                              mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(
         context=self.context)
     old_name = compute_node.hostname
     new_name = 'new-name'
     self.assertNotEqual(old_name, new_name)
     mock_read.side_effect = lambda *args: FakeEtcdResult(
         compute_node.as_dict())
     dbapi.update_compute_node(
         self.context, compute_node.uuid, {'hostname': new_name})
     self.assertEqual(new_name, json.loads(
         mock_update.call_args_list[0][0][0].value)['hostname'])
Beispiel #29
0
 def test_list_capsules(self, mock_db_inst, mock_write, mock_read):
     uuids = []
     capsules = []
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(1, 6):
         capsule = utils.create_test_capsule(uuid=uuidutils.generate_uuid(),
                                             context=self.context,
                                             name='capsule' + str(i))
         capsules.append(capsule.as_dict())
         uuids.append(six.text_type(capsule['uuid']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(capsules)
     res = dbapi.list_capsules(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Beispiel #30
0
 def test_list_resource_classes(self, mock_ins, mock_write, mock_read):
     names = []
     resource_classes = []
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(1, 6):
         res_class = utils.create_test_resource_class(context=self.context,
                                                      name='class' + str(i))
         resource_classes.append(res_class.as_dict())
         names.append(six.text_type(res_class['name']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         resource_classes)
     res = dbapi.list_resource_classes(self.context)
     res_names = [r.name for r in res]
     self.assertEqual(sorted(names), sorted(res_names))
Beispiel #31
0
 def test_update_resource_class(self, mock_ins, mock_update, mock_write,
                                mock_read):
     mock_ins.return_value = etcd_api.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     resource_class = utils.create_test_resource_class(context=self.context)
     old_name = resource_class.name
     new_name = 'new-name'
     self.assertNotEqual(old_name, new_name)
     mock_read.side_effect = lambda *args: FakeEtcdResult(resource_class.
                                                          as_dict())
     dbapi.update_resource_class(self.context, resource_class.uuid,
                                 {'name': new_name})
     self.assertEqual(
         new_name,
         json.loads(mock_update.call_args_list[0][0][0].value)['name'])
Beispiel #32
0
def _get_dbapi():
    if CONF.database.backend == 'sqlalchemy':
        dbapi = db_api._get_dbdriver_instance()
    else:
        dbapi = etcd_api.get_backend()
    return dbapi