Remove redundant Connection Class in zun/db/api.py

Closes-bug: #1655835

Change-Id: I719502c9f93343d56eafb5d057f48616246b1986
Signed-off-by: Kevin Zhao <kevin.zhao@linaro.org>
This commit is contained in:
Kevin Zhao 2017-01-12 15:15:33 +08:00 committed by Hongbin Lu
parent 8e68e204ce
commit 9ba37ffcfd
7 changed files with 320 additions and 332 deletions

View File

@ -15,10 +15,7 @@
Base API for Database
"""
import abc
from oslo_db import api as db_api
import six
from zun.common import exception
from zun.common.i18n import _
@ -46,262 +43,253 @@ def get_instance():
"must be sql or etcd") % CONF.db_type)
@six.add_metaclass(abc.ABCMeta)
class Connection(object):
"""Base class for storage system connections."""
def __init__(self):
"""Constructor."""
pass
@classmethod
def list_container(cls, context, filters=None,
limit=None, marker=None,
sort_key=None, sort_dir=None):
"""List matching containers.
Return a list of the specified columns for all containers that match
the specified filters.
:param context: The security context
:param filters: Filters to apply. Defaults to None.
:param limit: Maximum number of containers to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_container(
context, filters, limit, marker, sort_key, sort_dir)
@classmethod
def create_container(cls, context, values):
"""Create a new container.
:param values: A dict containing several items used to identify
and track the container, and several dicts which are
passed
into the Drivers when managing this container. For
example:
::
{
'uuid': uuidutils.generate_uuid(),
'name': 'example',
'type': 'virt'
}
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.create_container(context, values)
@classmethod
def get_container_by_id(cls, context, container_id):
"""Return a container.
:param context: The security context
:param container_uuid: The uuid of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_id(context, container_id)
@classmethod
def get_container_by_uuid(cls, context, container_uuid):
"""Return a container.
:param context: The security context
:param container_uuid: The uuid of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_uuid(context, container_uuid)
@classmethod
def get_container_by_name(cls, context, container_name):
"""Return a container.
:param context: The security context
:param container_name: The name of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_name(context, container_name)
@classmethod
def destroy_container(cls, context, container_id):
"""Destroy a container and all associated interfaces.
:param context: Request context
:param container_id: The id or uuid of a container.
"""
dbdriver = get_instance()
return dbdriver.destroy_container(context, container_id)
@classmethod
def update_container(cls, context, container_id, values):
"""Update properties of a container.
:context: Request context
:param container_id: The id or uuid of a container.
:values: The properties to be updated
:returns: A container.
:raises: ContainerNotFound
"""
dbdriver = get_instance()
return dbdriver.update_container(context, container_id, values)
@classmethod
def destroy_zun_service(cls, host, binary):
"""Destroys a zun_service record.
:param host: The host on which the service resides.
:param binary: The binary file name of the service.
:returns: A zun service record.
"""
dbdriver = get_instance()
return dbdriver.destroy_zun_service(host, binary)
@classmethod
def update_zun_service(cls, host, binary, values):
"""Update properties of a zun_service.
:param host: The host on which the service resides.
:param binary: The binary file name of the service.
:param values: The attributes to be updated.
:returns: A zun service record.
"""
dbdriver = get_instance()
return dbdriver.update_zun_service(host, binary, values)
@classmethod
def get_zun_service(cls, context, host, binary):
"""Return a zun_service record.
:param context: The security context
:param host: The host where the binary is located.
:param binary: The name of the binary.
:returns: A zun_service record.
"""
dbdriver = get_instance()
return dbdriver.get_zun_service(host, binary)
@classmethod
def create_zun_service(cls, values):
"""Create a new zun_service record.
:param values: A dict containing several items used to identify
and define the zun_service record.
:returns: A zun_service record.
"""
dbdriver = get_instance()
return dbdriver.create_zun_service(values)
@classmethod
def list_zun_service(cls, context, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
"""Get matching zun_service records.
Return a list of the specified columns for all zun_services
those match the specified filters.
:param context: The security context
:param disabled: Filters disbaled services. Defaults to None.
:param limit: Maximum number of zun_services to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
:param sort_dir: direction in which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_zun_service(filters, limit,
marker, sort_key, sort_dir)
@classmethod
def list_zun_service_by_binary(cls, context, binary):
"""List matching zun services.
Return a list of the specified binary.
:param context: The security context
:param binary: The name of the binary.
:returns: A list of tuples of the specified binary.
"""
dbdriver = get_instance()
return dbdriver.list_zun_service_by_binary(binary)
@classmethod
def pull_image(cls, context, values):
"""Create a new image.
:param context: The security context
:param values: A dict containing several items used to identify
and track the image, and several dicts which are
passed
into the Drivers when managing this image. For
example:
::
{
'uuid': uuidutils.generate_uuid(),
'repo': 'hello-world',
'tag': 'latest'
}
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.pull_image(context, values)
@classmethod
def update_image(cls, image_id, values):
"""Update properties of an image.
:param container_id: The id or uuid of an image.
:returns: An Image.
:raises: ImageNotFound
"""
dbdriver = get_instance()
return dbdriver.update_image(image_id, values)
@classmethod
def list_image(cls, context, filters=None,
def list_container(context, filters=None,
limit=None, marker=None,
sort_key=None, sort_dir=None):
"""Get matching images.
"""List matching containers.
Return a list of the specified columns for all images that
match the specified filters.
:param context: The security context
:param filters: Filters to apply. Defaults to None.
:param limit: Maximum number of images to return.
:param marker: the last item of the previous page; we
return the next
:param sort_key: Attribute by which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_image(context, filters, limit, marker,
sort_key, sort_dir)
Return a list of the specified columns for all containers that match
the specified filters.
:param context: The security context
:param filters: Filters to apply. Defaults to None.
:param limit: Maximum number of containers to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_container(
context, filters, limit, marker, sort_key, sort_dir)
@classmethod
def get_image_by_id(cls, context, image_id):
"""Return an image.
:param context: The security context
:param image_id: The id of an image.
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.get_image_by_id(context, image_id)
def create_container(context, values):
"""Create a new container.
@classmethod
def get_image_by_uuid(cls, context, image_uuid):
"""Return an image.
:param values: A dict containing several items used to identify
and track the container, and several dicts which are
passed
into the Drivers when managing this container. For
example:
::
{
'uuid': uuidutils.generate_uuid(),
'name': 'example',
'type': 'virt'
}
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.create_container(context, values)
:param context: The security context
:param image_uuid: The uuid of an image.
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.get_image_by_uuid(context, image_uuid)
def get_container_by_id(context, container_id):
"""Return a container.
:param context: The security context
:param container_uuid: The uuid of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_id(context, container_id)
def get_container_by_uuid(context, container_uuid):
"""Return a container.
:param context: The security context
:param container_uuid: The uuid of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_uuid(context, container_uuid)
def get_container_by_name(context, container_name):
"""Return a container.
:param context: The security context
:param container_name: The name of a container.
:returns: A container.
"""
dbdriver = get_instance()
return dbdriver.get_container_by_name(context, container_name)
def destroy_container(context, container_id):
"""Destroy a container and all associated interfaces.
:param context: Request context
:param container_id: The id or uuid of a container.
"""
dbdriver = get_instance()
return dbdriver.destroy_container(context, container_id)
def update_container(context, container_id, values):
"""Update properties of a container.
:context: Request context
:param container_id: The id or uuid of a container.
:values: The properties to be updated
:returns: A container.
:raises: ContainerNotFound
"""
dbdriver = get_instance()
return dbdriver.update_container(context, container_id, values)
def destroy_zun_service(host, binary):
"""Destroys a zun_service record.
:param host: The host on which the service resides.
:param binary: The binary file name of the service.
:returns: A zun service record.
"""
dbdriver = get_instance()
return dbdriver.destroy_zun_service(host, binary)
def update_zun_service(host, binary, values):
"""Update properties of a zun_service.
:param host: The host on which the service resides.
:param binary: The binary file name of the service.
:param values: The attributes to be updated.
:returns: A zun service record.
"""
dbdriver = get_instance()
return dbdriver.update_zun_service(host, binary, values)
def get_zun_service(context, host, binary):
"""Return a zun_service record.
:param context: The security context
:param host: The host where the binary is located.
:param binary: The name of the binary.
:returns: A zun_service record.
"""
dbdriver = get_instance()
return dbdriver.get_zun_service(host, binary)
def create_zun_service(values):
"""Create a new zun_service record.
:param values: A dict containing several items used to identify
and define the zun_service record.
:returns: A zun_service record.
"""
dbdriver = get_instance()
return dbdriver.create_zun_service(values)
def list_zun_service(context, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
"""Get matching zun_service records.
Return a list of the specified columns for all zun_services
those match the specified filters.
:param context: The security context
:param disabled: Filters disbaled services. Defaults to None.
:param limit: Maximum number of zun_services to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
:param sort_dir: direction in which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_zun_service(filters, limit,
marker, sort_key, sort_dir)
def list_zun_service_by_binary(context, binary):
"""List matching zun services.
Return a list of the specified binary.
:param context: The security context
:param binary: The name of the binary.
:returns: A list of tuples of the specified binary.
"""
dbdriver = get_instance()
return dbdriver.list_zun_service_by_binary(binary)
def pull_image(context, values):
"""Create a new image.
:param context: The security context
:param values: A dict containing several items used to identify
and track the image, and several dicts which are
passed
into the Drivers when managing this image. For
example:
::
{
'uuid': uuidutils.generate_uuid(),
'repo': 'hello-world',
'tag': 'latest'
}
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.pull_image(context, values)
def update_image(image_id, values):
"""Update properties of an image.
:param container_id: The id or uuid of an image.
:returns: An Image.
:raises: ImageNotFound
"""
dbdriver = get_instance()
return dbdriver.update_image(image_id, values)
def list_image(context, filters=None,
limit=None, marker=None,
sort_key=None, sort_dir=None):
"""Get matching images.
Return a list of the specified columns for all images that
match the specified filters.
:param context: The security context
:param filters: Filters to apply. Defaults to None.
:param limit: Maximum number of images to return.
:param marker: the last item of the previous page; we
return the next
:param sort_key: Attribute by which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
dbdriver = get_instance()
return dbdriver.list_image(context, filters, limit, marker,
sort_key, sort_dir)
def get_image_by_id(context, image_id):
"""Return an image.
:param context: The security context
:param image_id: The id of an image.
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.get_image_by_id(context, image_id)
def get_image_by_uuid(context, image_uuid):
"""Return an image.
:param context: The security context
:param image_uuid: The uuid of an image.
:returns: An image.
"""
dbdriver = get_instance()
return dbdriver.get_image_by_uuid(context, image_uuid)

View File

@ -27,7 +27,6 @@ from sqlalchemy.sql import func
from zun.common import exception
from zun.common.i18n import _
import zun.conf
from zun.db import api
from zun.db.sqlalchemy import models
CONF = zun.conf.CONF
@ -103,7 +102,7 @@ def _paginate_query(model, limit=None, marker=None, sort_key=None,
return query.all()
class Connection(api.Connection):
class Connection(object):
"""SqlAlchemy connection."""
def __init__(self):

View File

@ -77,7 +77,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
:param context: Security context
:returns: a :class:`Container` object.
"""
db_container = dbapi.Connection.get_container_by_uuid(context, uuid)
db_container = dbapi.get_container_by_uuid(context, uuid)
container = Container._from_db_object(cls(context), db_container)
return container
@ -89,7 +89,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
:param context: Security context
:returns: a :class:`Container` object.
"""
db_container = dbapi.Connection.get_container_by_name(context, name)
db_container = dbapi.get_container_by_name(context, name)
container = Container._from_db_object(cls(context), db_container)
return container
@ -109,7 +109,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
:returns: a list of :class:`Container` object.
"""
db_containers = dbapi.Connection.list_container(
db_containers = dbapi.list_container(
context, limit=limit, marker=marker, sort_key=sort_key,
sort_dir=sort_dir, filters=filters)
return Container._from_db_object_list(db_containers, cls, context)
@ -127,7 +127,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
"""
values = self.obj_get_changes()
db_container = dbapi.Connection.create_container(context, values)
db_container = dbapi.create_container(context, values)
self._from_db_object(self, db_container)
@base.remotable
@ -141,7 +141,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
A context should be set when instantiating the
object, e.g.: Container(context)
"""
dbapi.Connection.destroy_container(context, self.uuid)
dbapi.destroy_container(context, self.uuid)
self.obj_reset_changes()
@base.remotable
@ -159,7 +159,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
object, e.g.: Container(context)
"""
updates = self.obj_get_changes()
dbapi.Connection.update_container(context, self.uuid, updates)
dbapi.update_container(context, self.uuid, updates)
self.obj_reset_changes()

View File

@ -55,7 +55,7 @@ class Image(base.ZunPersistentObject, base.ZunObject):
:param context: Security context
:returns: a :class:`Image` object.
"""
db_image = dbapi.Connection.get_image_by_uuid(context, uuid)
db_image = dbapi.get_image_by_uuid(context, uuid)
image = Image._from_db_object(cls(context), db_image)
return image
@ -74,11 +74,12 @@ class Image(base.ZunPersistentObject, base.ZunObject):
:returns: a list of :class:`Image` object.
"""
db_images = dbapi.Connection.list_image(context, limit=limit,
marker=marker,
sort_key=sort_key,
sort_dir=sort_dir,
filters=filters)
db_images = dbapi.list_image(context,
limit=limit,
marker=marker,
sort_key=sort_key,
sort_dir=sort_dir,
filters=filters)
return Image._from_db_object_list(db_images, cls, context)
@base.remotable
@ -94,7 +95,7 @@ class Image(base.ZunPersistentObject, base.ZunObject):
"""
values = self.obj_get_changes()
db_image = dbapi.Connection.pull_image(context, values)
db_image = dbapi.pull_image(context, values)
self._from_db_object(self, db_image)
@base.remotable
@ -112,5 +113,5 @@ class Image(base.ZunPersistentObject, base.ZunObject):
object, e.g.: Image(context)
"""
updates = self.obj_get_changes()
dbapi.Connection.update_image(self.uuid, updates)
dbapi.update_image(self.uuid, updates)
self.obj_reset_changes()

View File

@ -57,7 +57,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
:param context: Security context.
:returns: a :class:`ZunService` object.
"""
db_zun_service = dbapi.Connection.get_zun_service(
db_zun_service = dbapi.get_zun_service(
context, host, binary)
if db_zun_service is None:
return None
@ -78,7 +78,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
:returns: a list of :class:`ZunService` object.
"""
db_zun_services = dbapi.Connection.list_zun_service(
db_zun_services = dbapi.list_zun_service(
context, limit=limit, marker=marker, sort_key=sort_key,
sort_dir=sort_dir)
return ZunService._from_db_object_list(db_zun_services, cls,
@ -86,7 +86,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
@base.remotable_classmethod
def list_by_binary(cls, context, binary):
db_zun_services = dbapi.Connection.list_zun_service_by_binary(
db_zun_services = dbapi.list_zun_service_by_binary(
context, binary)
return ZunService._from_db_object_list(db_zun_services, cls, context)
@ -102,7 +102,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
object, e.g.: ZunService(context)
"""
values = self.obj_get_changes()
db_zun_service = dbapi.Connection.create_zun_service(values)
db_zun_service = dbapi.create_zun_service(values)
self._from_db_object(self, db_zun_service)
@base.remotable
@ -116,7 +116,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
A context should be set when instantiating the
object, e.g.: ZunService(context)
"""
dbapi.Connection.destroy_zun_service(self.host, self.binary)
dbapi.destroy_zun_service(self.host, self.binary)
self.obj_reset_changes()
@base.remotable
@ -134,7 +134,7 @@ class ZunService(base.ZunPersistentObject, base.ZunObject):
object, e.g.: ZunService(context)
"""
updates = self.obj_get_changes()
dbapi.Connection.update_zun_service(self.host, self.binary, updates)
dbapi.update_zun_service(self.host, self.binary, updates)
self.obj_reset_changes()
@base.remotable

View File

@ -52,7 +52,7 @@ class DbContainerTestCase(base.DbTestCase):
def test_get_container_by_id(self):
container = utils.create_test_container(context=self.context)
res = dbapi.Connection.get_container_by_id(self.context, container.id)
res = dbapi.get_container_by_id(self.context, container.id)
self.assertEqual(container.id, res.id)
self.assertEqual(container.uuid, res.uuid)
@ -104,24 +104,24 @@ class DbContainerTestCase(base.DbTestCase):
def test_get_container_by_uuid(self):
container = utils.create_test_container(context=self.context)
res = dbapi.Connection.get_container_by_uuid(self.context,
container.uuid)
res = dbapi.get_container_by_uuid(self.context,
container.uuid)
self.assertEqual(container.id, res.id)
self.assertEqual(container.uuid, res.uuid)
def test_get_container_by_name(self):
container = utils.create_test_container(context=self.context)
res = dbapi.Connection.get_container_by_name(
res = dbapi.get_container_by_name(
self.context, container.name)
self.assertEqual(container.id, res.id)
self.assertEqual(container.uuid, res.uuid)
def test_get_container_that_does_not_exist(self):
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.get_container_by_id,
dbapi.get_container_by_id,
self.context, 99)
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.get_container_by_uuid,
dbapi.get_container_by_uuid,
self.context,
uuidutils.generate_uuid())
@ -133,7 +133,7 @@ class DbContainerTestCase(base.DbTestCase):
context=self.context,
name='container'+str(i))
uuids.append(six.text_type(container['uuid']))
res = dbapi.Connection.list_container(self.context)
res = dbapi.list_container(self.context)
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), sorted(res_uuids))
@ -145,12 +145,12 @@ class DbContainerTestCase(base.DbTestCase):
context=self.context,
name='container'+str(i))
uuids.append(six.text_type(container.uuid))
res = dbapi.Connection.list_container(self.context, sort_key='uuid')
res = dbapi.list_container(self.context, sort_key='uuid')
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), res_uuids)
self.assertRaises(exception.InvalidParameterValue,
dbapi.Connection.list_container,
dbapi.list_container,
self.context,
sort_key='foo')
@ -164,40 +164,40 @@ class DbContainerTestCase(base.DbTestCase):
uuid=uuidutils.generate_uuid(),
context=self.context)
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'container-one'})
self.assertEqual([container1.id], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'container-two'})
self.assertEqual([container2.id], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'bad-container'})
self.assertEqual([], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context,
filters={'name': container1.name})
self.assertEqual([container1.id], [r.id for r in res])
def test_destroy_container(self):
container = utils.create_test_container(context=self.context)
dbapi.Connection.destroy_container(self.context, container.id)
dbapi.destroy_container(self.context, container.id)
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.get_container_by_id,
dbapi.get_container_by_id,
self.context, container.id)
def test_destroy_container_by_uuid(self):
container = utils.create_test_container(context=self.context)
dbapi.Connection.destroy_container(self.context, container.uuid)
dbapi.destroy_container(self.context, container.uuid)
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.get_container_by_uuid,
dbapi.get_container_by_uuid,
self.context, container.uuid)
def test_destroy_container_that_does_not_exist(self):
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.destroy_container, self.context,
dbapi.destroy_container, self.context,
uuidutils.generate_uuid())
def test_update_container(self):
@ -206,8 +206,8 @@ class DbContainerTestCase(base.DbTestCase):
new_image = 'new-image'
self.assertNotEqual(old_image, new_image)
res = dbapi.Connection.update_container(self.context, container.id,
{'image': new_image})
res = dbapi.update_container(self.context, container.id,
{'image': new_image})
self.assertEqual(new_image, res.image)
def test_update_container_with_the_same_name(self):
@ -220,23 +220,23 @@ class DbContainerTestCase(base.DbTestCase):
uuid=uuidutils.generate_uuid(),
context=self.context)
new_name = 'new_name'
dbapi.Connection.update_container(self.context, container1.id,
{'name': new_name})
dbapi.update_container(self.context, container1.id,
{'name': new_name})
self.assertRaises(exception.ContainerAlreadyExists,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container2.id, {'name': new_name})
def test_update_container_not_found(self):
container_uuid = uuidutils.generate_uuid()
new_image = 'new-image'
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container_uuid, {'image': new_image})
def test_update_container_uuid(self):
container = utils.create_test_container(context=self.context)
self.assertRaises(exception.InvalidParameterValue,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container.id, {'uuid': ''})
@ -288,8 +288,8 @@ class EtcdDbContainerTestCase(base.DbTestCase):
container = utils.create_test_container(context=self.context)
mock_read.side_effect = lambda *args: FakeEtcdResult(
container.as_dict())
res = dbapi.Connection.get_container_by_uuid(self.context,
container.uuid)
res = dbapi.get_container_by_uuid(self.context,
container.uuid)
self.assertEqual(container.id, res.id)
self.assertEqual(container.uuid, res.uuid)
@ -300,7 +300,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
container = utils.create_test_container(context=self.context)
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
[container.as_dict()])
res = dbapi.Connection.get_container_by_name(
res = dbapi.get_container_by_name(
self.context, container.name)
self.assertEqual(container.id, res.id)
self.assertEqual(container.uuid, res.uuid)
@ -309,7 +309,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
def test_get_container_that_does_not_exist(self, mock_read):
mock_read.side_effect = etcd.EtcdKeyNotFound
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.get_container_by_uuid,
dbapi.get_container_by_uuid,
self.context,
uuidutils.generate_uuid())
@ -328,7 +328,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
uuids.append(six.text_type(container['uuid']))
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
containers)
res = dbapi.Connection.list_container(self.context)
res = dbapi.list_container(self.context)
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), sorted(res_uuids))
@ -347,12 +347,12 @@ class EtcdDbContainerTestCase(base.DbTestCase):
uuids.append(six.text_type(container.uuid))
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
containers)
res = dbapi.Connection.list_container(self.context, sort_key='uuid')
res = dbapi.list_container(self.context, sort_key='uuid')
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), res_uuids)
self.assertRaises(exception.InvalidParameterValue,
dbapi.Connection.list_container,
dbapi.list_container,
self.context,
sort_key='foo')
@ -373,19 +373,19 @@ class EtcdDbContainerTestCase(base.DbTestCase):
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
[container1.as_dict(), container2.as_dict()])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'container-one'})
self.assertEqual([container1.id], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'container-two'})
self.assertEqual([container2.id], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context, filters={'name': 'container-three'})
self.assertEqual([], [r.id for r in res])
res = dbapi.Connection.list_container(
res = dbapi.list_container(
self.context,
filters={'name': container1.name})
self.assertEqual([container1.id], [r.id for r in res])
@ -398,7 +398,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
container = utils.create_test_container(context=self.context)
mock_read.side_effect = lambda *args: FakeEtcdResult(
container.as_dict())
dbapi.Connection.destroy_container(self.context, container.uuid)
dbapi.destroy_container(self.context, container.uuid)
mock_delete.assert_called_once_with('/containers/%s' % container.uuid)
@mock.patch.object(etcd_client, 'read')
@ -410,14 +410,14 @@ class EtcdDbContainerTestCase(base.DbTestCase):
container = utils.create_test_container(context=self.context)
mock_read.side_effect = lambda *args: FakeEtcdResult(
container.as_dict())
dbapi.Connection.destroy_container(self.context, container.uuid)
dbapi.destroy_container(self.context, container.uuid)
mock_delete.assert_called_once_with('/containers/%s' % container.uuid)
@mock.patch.object(etcd_client, 'read')
def test_destroy_container_that_does_not_exist(self, mock_read):
mock_read.side_effect = etcd.EtcdKeyNotFound
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.destroy_container, self.context,
dbapi.destroy_container, self.context,
uuidutils.generate_uuid())
@mock.patch.object(etcd_client, 'read')
@ -430,8 +430,8 @@ class EtcdDbContainerTestCase(base.DbTestCase):
mock_read.side_effect = lambda *args: FakeEtcdResult(
container.as_dict())
dbapi.Connection.update_container(self.context, container.uuid,
{'image': new_image})
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'])
@ -453,7 +453,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
[container1.as_dict(), container2.as_dict()])
self.assertRaises(exception.ContainerAlreadyExists,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container2.uuid, {'name': 'container-one'})
@mock.patch.object(etcd_client, 'read')
@ -462,7 +462,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
new_image = 'new-image'
mock_read.side_effect = etcd.EtcdKeyNotFound
self.assertRaises(exception.ContainerNotFound,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container_uuid, {'image': new_image})
@mock.patch.object(etcd_client, 'read')
@ -471,7 +471,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
mock_read.side_effect = etcd.EtcdKeyNotFound
container = utils.create_test_container(context=self.context)
self.assertRaises(exception.InvalidParameterValue,
dbapi.Connection.update_container, self.context,
dbapi.update_container, self.context,
container.id, {'uuid': ''})
@mock.patch.object(etcd_client, 'read')

View File

@ -154,7 +154,7 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
zun_service = utils.create_test_zun_service()
mock_read.side_effect = lambda *args: FakeEtcdResult(
zun_service.as_dict())
res = dbapi.Connection.get_zun_service(
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)
@ -164,7 +164,7 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
def test_get_zun_service_not_found(self, mock_write, mock_read):
mock_read.side_effect = etcd.EtcdKeyNotFound
zun_service = utils.create_test_zun_service()
res = dbapi.Connection.get_zun_service(
res = dbapi.get_zun_service(
self.context, 'wrong_host_name', zun_service.binary)
self.assertIsNone(res)
@ -176,7 +176,7 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
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.Connection.list_zun_service(self.context)
res = dbapi.list_zun_service(self.context)
self.assertEqual(2, len(res))
self.assertEqual('host_1', res[0].host)
self.assertEqual('host_2', res[1].host)
@ -191,13 +191,13 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
host='host_2', binary='binary_2')
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
[service_1.as_dict(), service_2.as_dict()])
res = dbapi.Connection.list_zun_service_by_binary(
res = dbapi.list_zun_service_by_binary(
self.context, 'binary_1')
self.assertEqual(1, len(res))
self.assertEqual('host_1', res[0].host)
self.assertEqual('binary_1', res[0].binary)
res = dbapi.Connection.list_zun_service_by_binary(
res = dbapi.list_zun_service_by_binary(
self.context, 'fake-binary')
self.assertEqual(0, len(res))
@ -209,8 +209,8 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
zun_service = utils.create_test_zun_service()
mock_read.side_effect = lambda *args: FakeEtcdResult(
zun_service.as_dict())
dbapi.Connection.destroy_zun_service(zun_service.host,
zun_service.binary)
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)
@ -218,7 +218,7 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
def test_destroy_zun_service_not_exist(self, mock_delete):
mock_delete.side_effect = etcd.EtcdKeyNotFound
self.assertRaises(exception.ZunServiceNotFound,
dbapi.Connection.destroy_zun_service,
dbapi.destroy_zun_service,
'host_1', 'binary_1')
@mock.patch.object(etcd_client, 'read')
@ -231,8 +231,8 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
mock_read.side_effect = lambda *args: FakeEtcdResult(
service.as_dict())
dbapi.Connection.update_zun_service(service.host, service.binary,
{'host': new_host})
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'])
@ -240,5 +240,5 @@ class EtcdDbZunServiceTestCase(base.DbTestCase):
def test_update_zun_service_not_exist(self, mock_read):
mock_read.side_effect = etcd.EtcdKeyNotFound
self.assertRaises(exception.ZunServiceNotFound,
dbapi.Connection.update_zun_service,
dbapi.update_zun_service,
'host_1', 'binary_1', {'host': 'new-host'})