Use run() wrapper instead of connection.execute()
The sqlalchemy driver uses a run() wrapper instead of directly using the connection.execute() method. I changed the other use of connection.execute() to run() for consistency. Closes-Bug: #1469207 Change-Id: I0cfe043f31e8bebe26c983c734e0db754e122fbe
This commit is contained in:
parent
c3ebf0d12c
commit
e007e474e6
@ -43,14 +43,14 @@ class CatalogueController(base.CatalogueBase):
|
||||
stmt = sa.sql.select([tables.Catalogue]).where(
|
||||
tables.Catalogue.c.project == project
|
||||
)
|
||||
cursor = self.driver.connection.execute(stmt)
|
||||
cursor = self.driver.run(stmt)
|
||||
return (_normalize(v) for v in cursor)
|
||||
|
||||
def get(self, project, queue):
|
||||
stmt = sa.sql.select([tables.Catalogue]).where(
|
||||
_match(project, queue)
|
||||
)
|
||||
entry = self.driver.connection.execute(stmt).fetchone()
|
||||
entry = self.driver.run(stmt).fetchone()
|
||||
|
||||
if entry is None:
|
||||
raise errors.QueueNotMapped(queue, project)
|
||||
@ -68,7 +68,7 @@ class CatalogueController(base.CatalogueBase):
|
||||
stmt = sa.sql.insert(tables.Catalogue).values(
|
||||
project=project, queue=queue, pool=pool
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
except sa.exc.IntegrityError:
|
||||
self._update(project, queue, pool)
|
||||
@ -77,13 +77,13 @@ class CatalogueController(base.CatalogueBase):
|
||||
stmt = sa.sql.delete(tables.Catalogue).where(
|
||||
_match(project, queue)
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
def _update(self, project, queue, pool):
|
||||
stmt = sa.sql.update(tables.Catalogue).where(
|
||||
_match(project, queue)
|
||||
).values(pool=pool)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
def update(self, project, queue, pool=None):
|
||||
if pool is None:
|
||||
@ -96,7 +96,7 @@ class CatalogueController(base.CatalogueBase):
|
||||
|
||||
def drop_all(self):
|
||||
stmt = sa.sql.expression.delete(tables.Catalogue)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
|
||||
def _normalize(entry):
|
||||
|
@ -45,7 +45,7 @@ class FlavorsController(base.FlavorsBase):
|
||||
|
||||
if limit > 0:
|
||||
stmt = stmt.limit(limit)
|
||||
cursor = self.driver.connection.execute(stmt)
|
||||
cursor = self.driver.run(stmt)
|
||||
|
||||
marker_name = {}
|
||||
|
||||
@ -64,7 +64,7 @@ class FlavorsController(base.FlavorsBase):
|
||||
tables.Flavors.c.project == project)
|
||||
)
|
||||
|
||||
flavor = self.driver.connection.execute(stmt).fetchone()
|
||||
flavor = self.driver.run(stmt).fetchone()
|
||||
if flavor is None:
|
||||
raise errors.FlavorDoesNotExist(name)
|
||||
|
||||
@ -79,7 +79,7 @@ class FlavorsController(base.FlavorsBase):
|
||||
name=name, pool_group=pool_group, project=project,
|
||||
capabilities=cap
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
except sa.exc.IntegrityError:
|
||||
if not self._pools_ctrl.get_pools_by_group(pool_group):
|
||||
raise errors.PoolGroupDoesNotExist(pool_group)
|
||||
@ -96,7 +96,7 @@ class FlavorsController(base.FlavorsBase):
|
||||
sa.and_(tables.Flavors.c.name == name,
|
||||
tables.Flavors.c.project == project)
|
||||
).limit(1)
|
||||
return self.driver.connection.execute(stmt).fetchone() is not None
|
||||
return self.driver.run(stmt).fetchone() is not None
|
||||
|
||||
@utils.raises_conn_error
|
||||
def update(self, name, project=None, pool_group=None, capabilities=None):
|
||||
@ -116,7 +116,7 @@ class FlavorsController(base.FlavorsBase):
|
||||
sa.and_(tables.Flavors.c.name == name,
|
||||
tables.Flavors.c.project == project)).values(**fields)
|
||||
|
||||
res = self.driver.connection.execute(stmt)
|
||||
res = self.driver.run(stmt)
|
||||
if res.rowcount == 0:
|
||||
raise errors.FlavorDoesNotExist(name)
|
||||
|
||||
@ -126,12 +126,12 @@ class FlavorsController(base.FlavorsBase):
|
||||
sa.and_(tables.Flavors.c.name == name,
|
||||
tables.Flavors.c.project == project)
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
@utils.raises_conn_error
|
||||
def drop_all(self):
|
||||
stmt = sa.sql.expression.delete(tables.Flavors)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
|
||||
def _normalize(flavor, detailed=False):
|
||||
|
@ -42,7 +42,7 @@ class PoolsController(base.PoolsBase):
|
||||
)
|
||||
if limit > 0:
|
||||
stmt = stmt.limit(limit)
|
||||
cursor = self.driver.connection.execute(stmt)
|
||||
cursor = self.driver.run(stmt)
|
||||
|
||||
marker_name = {}
|
||||
|
||||
@ -59,7 +59,7 @@ class PoolsController(base.PoolsBase):
|
||||
stmt = sa.sql.select([tables.Pools]).where(
|
||||
tables.Pools.c.group == group
|
||||
)
|
||||
cursor = self.driver.connection.execute(stmt)
|
||||
cursor = self.driver.run(stmt)
|
||||
|
||||
normalizer = functools.partial(_normalize, detailed=detailed)
|
||||
return (normalizer(v) for v in cursor)
|
||||
@ -70,7 +70,7 @@ class PoolsController(base.PoolsBase):
|
||||
tables.Pools.c.name == name
|
||||
)
|
||||
|
||||
pool = self.driver.connection.execute(stmt).fetchone()
|
||||
pool = self.driver.run(stmt).fetchone()
|
||||
if pool is None:
|
||||
raise errors.PoolDoesNotExist(name)
|
||||
|
||||
@ -79,7 +79,7 @@ class PoolsController(base.PoolsBase):
|
||||
def _ensure_group_exists(self, name):
|
||||
try:
|
||||
stmt = sa.sql.expression.insert(tables.PoolGroup).values(name=name)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
return True
|
||||
except sa.exc.IntegrityError:
|
||||
return False
|
||||
@ -96,7 +96,7 @@ class PoolsController(base.PoolsBase):
|
||||
stmt = sa.sql.expression.insert(tables.Pools).values(
|
||||
name=name, weight=weight, uri=uri, group=group, options=opts
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
except sa.exc.IntegrityError:
|
||||
# TODO(cpp-cabrera): merge update/create into a single
|
||||
@ -109,7 +109,7 @@ class PoolsController(base.PoolsBase):
|
||||
stmt = sa.sql.select([tables.Pools.c.name]).where(
|
||||
tables.Pools.c.name == name
|
||||
).limit(1)
|
||||
return self.driver.connection.execute(stmt).fetchone() is not None
|
||||
return self.driver.run(stmt).fetchone() is not None
|
||||
|
||||
@utils.raises_conn_error
|
||||
def _update(self, name, **kwargs):
|
||||
@ -132,7 +132,7 @@ class PoolsController(base.PoolsBase):
|
||||
stmt = sa.sql.update(tables.Pools).where(
|
||||
tables.Pools.c.name == name).values(**fields)
|
||||
|
||||
res = self.driver.connection.execute(stmt)
|
||||
res = self.driver.run(stmt)
|
||||
if res.rowcount == 0:
|
||||
raise errors.PoolDoesNotExist(name)
|
||||
|
||||
@ -141,14 +141,14 @@ class PoolsController(base.PoolsBase):
|
||||
stmt = sa.sql.expression.delete(tables.Pools).where(
|
||||
tables.Pools.c.name == name
|
||||
)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
@utils.raises_conn_error
|
||||
def _drop_all(self):
|
||||
stmt = sa.sql.expression.delete(tables.Pools)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
stmt = sa.sql.expression.delete(tables.PoolGroup)
|
||||
self.driver.connection.execute(stmt)
|
||||
self.driver.run(stmt)
|
||||
|
||||
|
||||
def _normalize(pool, detailed=False):
|
||||
|
Loading…
x
Reference in New Issue
Block a user