Merge "Remove unused get_not_versions from dbapi"

This commit is contained in:
Zuul 2023-05-25 04:43:49 +00:00 committed by Gerrit Code Review
commit 209e1a70a7
3 changed files with 0 additions and 75 deletions

View File

@ -967,16 +967,6 @@ class Connection(object, metaclass=abc.ABCMeta):
ident does not exist.
"""
@abc.abstractmethod
def get_not_versions(self, model_name, versions):
"""Returns objects with versions that are not the specified versions.
:param model_name: the name of the model (class) of desired objects
:param versions: list of versions of objects not to be returned
:returns: list of the DB objects
:raises: IronicException if there is no class associated with the name
"""
@abc.abstractmethod
def check_versions(self, ignore_models=()):
"""Checks the whole database for incompatible objects.

View File

@ -1747,31 +1747,6 @@ class Connection(api.Connection):
if count == 0:
raise exception.VolumeTargetNotFound(target=ident)
def get_not_versions(self, model_name, versions):
"""Returns objects with versions that are not the specified versions.
This returns objects with versions that are not the specified versions.
Objects with null versions (there shouldn't be any) are also returned.
:param model_name: the name of the model (class) of desired objects
:param versions: list of versions of objects not to be returned
:returns: list of the DB objects
:raises: IronicException if there is no class associated with the name
"""
if not versions:
return []
if model_name == 'Node':
model_name = 'NodeBase'
model = models.get_class(model_name)
# NOTE(rloo): .notin_ does not handle null:
# http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.notin_
query = model_query(model).filter(
sql.or_(model.version == sql.null(),
model.version.notin_(versions)))
return query.all()
def check_versions(self, ignore_models=(), permit_initial_version=False):
"""Checks the whole database for incompatible objects.

View File

@ -16,7 +16,6 @@ from unittest import mock
from oslo_db.sqlalchemy import utils as db_utils
from oslo_utils import uuidutils
import sqlalchemy as sa
from testtools import matchers
from ironic.common import context
from ironic.common import exception
@ -105,45 +104,6 @@ class UpgradingTestCase(base.DbTestCase):
self.assertFalse(self.dbapi.check_versions())
class GetNotVersionsTestCase(base.DbTestCase):
def setUp(self):
super(GetNotVersionsTestCase, self).setUp()
self.dbapi = db_api.get_instance()
def test_get_not_versions(self):
versions = ['1.1', '1.2', '1.3']
node_uuids = []
for v in versions:
node = utils.create_test_node(uuid=uuidutils.generate_uuid(),
version=v)
node_uuids.append(node.uuid)
self.assertEqual([], self.dbapi.get_not_versions('Node', versions))
res = self.dbapi.get_not_versions('Node', ['2.0'])
self.assertThat(res, matchers.HasLength(len(node_uuids)))
res_uuids = [n.uuid for n in res]
self.assertEqual(node_uuids, res_uuids)
res = self.dbapi.get_not_versions('Node', versions[1:])
self.assertThat(res, matchers.HasLength(1))
self.assertEqual(node_uuids[0], res[0].uuid)
def test_get_not_versions_null(self):
node = utils.create_test_node(uuid=uuidutils.generate_uuid(),
version=None)
node = self.dbapi.get_node_by_id(node.id)
self.assertIsNone(node.version)
res = self.dbapi.get_not_versions('Node', ['1.6'])
self.assertThat(res, matchers.HasLength(1))
self.assertEqual(node.uuid, res[0].uuid)
def test_get_not_versions_no_model(self):
utils.create_test_node(uuid=uuidutils.generate_uuid(), version='1.4')
self.assertRaises(exception.IronicException,
self.dbapi.get_not_versions, 'NotExist', ['1.6'])
class UpdateToLatestVersionsTestCase(base.DbTestCase):
def setUp(self):