objects: Remove Agent, AgentList

These are no longer used given the removal of the XenAPI driver and
os-agents API. Remove the objects themselves.

Change-Id: Iddb6489e11dea1d3079292caf7848217df706ca6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-08-31 17:00:11 +01:00
parent 7ac52e643c
commit 0fa6f4e7e1
9 changed files with 2 additions and 345 deletions

View File

@ -1102,35 +1102,6 @@ def instance_system_metadata_update(context, instance_uuid, metadata, delete):
####################
def agent_build_create(context, values):
"""Create a new agent build entry."""
return IMPL.agent_build_create(context, values)
def agent_build_get_by_triple(context, hypervisor, os, architecture):
"""Get agent build by hypervisor/OS/architecture triple."""
return IMPL.agent_build_get_by_triple(context, hypervisor, os,
architecture)
def agent_build_get_all(context, hypervisor=None):
"""Get all agent builds."""
return IMPL.agent_build_get_all(context, hypervisor)
def agent_build_destroy(context, agent_update_id):
"""Destroy agent build entry."""
IMPL.agent_build_destroy(context, agent_update_id)
def agent_build_update(context, agent_build_id, values):
"""Update agent build entry."""
IMPL.agent_build_update(context, agent_build_id, values)
####################
def bw_usage_get(context, uuid, start_period, mac):
"""Return bw usage for instance and mac in a given audit period."""
return IMPL.bw_usage_get(context, uuid, start_period, mac)

View File

@ -3402,58 +3402,6 @@ def instance_system_metadata_update(context, instance_uuid, metadata, delete):
return metadata
####################
@pick_context_manager_writer
def agent_build_create(context, values):
agent_build_ref = models.AgentBuild()
agent_build_ref.update(values)
try:
agent_build_ref.save(context.session)
except db_exc.DBDuplicateEntry:
raise exception.AgentBuildExists(hypervisor=values['hypervisor'],
os=values['os'], architecture=values['architecture'])
return agent_build_ref
@pick_context_manager_reader
def agent_build_get_by_triple(context, hypervisor, os, architecture):
return model_query(context, models.AgentBuild, read_deleted="no").\
filter_by(hypervisor=hypervisor).\
filter_by(os=os).\
filter_by(architecture=architecture).\
first()
@pick_context_manager_reader
def agent_build_get_all(context, hypervisor=None):
if hypervisor:
return model_query(context, models.AgentBuild, read_deleted="no").\
filter_by(hypervisor=hypervisor).\
all()
else:
return model_query(context, models.AgentBuild, read_deleted="no").\
all()
@pick_context_manager_writer
def agent_build_destroy(context, agent_build_id):
rows_affected = model_query(context, models.AgentBuild).filter_by(
id=agent_build_id).soft_delete()
if rows_affected == 0:
raise exception.AgentBuildNotFound(id=agent_build_id)
@pick_context_manager_writer
def agent_build_update(context, agent_build_id, values):
rows_affected = model_query(context, models.AgentBuild).\
filter_by(id=agent_build_id).\
update(values)
if rows_affected == 0:
raise exception.AgentBuildNotFound(id=agent_build_id)
####################
@require_context

View File

@ -1209,6 +1209,8 @@ class Aggregate(BASE, NovaBase, models.SoftDeleteMixin):
return self.metadetails['availability_zone']
# TODO(stephenfin): Remove this in the W release or later, once we're sure we
# won't want it back (it's for a XenAPI-only feature)
class AgentBuild(BASE, NovaBase, models.SoftDeleteMixin):
"""Represents an agent build."""
__tablename__ = 'agent_builds'

View File

@ -633,15 +633,6 @@ class NotFound(NovaException):
code = 404
class AgentBuildNotFound(NotFound):
msg_fmt = _("No agent-build associated with id %(id)s.")
class AgentBuildExists(NovaException):
msg_fmt = _("Agent-build with hypervisor %(hypervisor)s os %(os)s "
"architecture %(architecture)s exists.")
class VolumeAttachmentNotFound(NotFound):
msg_fmt = _("Volume attachment %(attachment_id)s could not be found.")

View File

@ -24,7 +24,6 @@ def register_all():
# NOTE(danms): You must make sure your object gets imported in this
# function in order for it to be registered by services that may
# need to receive it via RPC.
__import__('nova.objects.agent')
__import__('nova.objects.aggregate')
__import__('nova.objects.bandwidth_usage')
__import__('nova.objects.block_device')

View File

@ -1,87 +0,0 @@
# Copyright 2014 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.db import api as db
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
# TODO(stephenfin): Remove this object; it's not necessary since the removal of
# XenAPI
@base.NovaObjectRegistry.register
class Agent(base.NovaPersistentObject, base.NovaObject):
VERSION = '1.0'
fields = {
'id': fields.IntegerField(read_only=True),
'hypervisor': fields.StringField(),
'os': fields.StringField(),
'architecture': fields.StringField(),
'version': fields.StringField(),
'url': fields.StringField(),
'md5hash': fields.StringField(),
}
@staticmethod
def _from_db_object(context, agent, db_agent):
for name in agent.fields:
setattr(agent, name, db_agent[name])
agent._context = context
agent.obj_reset_changes()
return agent
@base.remotable_classmethod
def get_by_triple(cls, context, hypervisor, os, architecture):
db_agent = db.agent_build_get_by_triple(context, hypervisor,
os, architecture)
if not db_agent:
return None
return cls._from_db_object(context, objects.Agent(), db_agent)
@base.remotable
def create(self):
updates = self.obj_get_changes()
if 'id' in updates:
raise exception.ObjectActionError(action='create',
reason='Already Created')
db_agent = db.agent_build_create(self._context, updates)
self._from_db_object(self._context, self, db_agent)
@base.remotable
def destroy(self):
db.agent_build_destroy(self._context, self.id)
@base.remotable
def save(self):
updates = self.obj_get_changes()
db.agent_build_update(self._context, self.id, updates)
self.obj_reset_changes()
# TODO(stephenfin): Remove this object; it's not necessary since the removal of
# XenAPI
@base.NovaObjectRegistry.register
class AgentList(base.ObjectListBase, base.NovaObject):
VERSION = '1.0'
fields = {
'objects': fields.ListOfObjectsField('Agent'),
}
@base.remotable_classmethod
def get_all(cls, context, hypervisor=None):
db_agents = db.agent_build_get_all(context, hypervisor=hypervisor)
return base.obj_make_list(context, cls(), objects.Agent, db_agents)

View File

@ -4621,68 +4621,6 @@ class BlockDeviceMappingTestCase(test.TestCase):
self.assertEqual(bdm2['instance_uuid'], self.instance2['uuid'])
class AgentBuildTestCase(test.TestCase, ModelsObjectComparatorMixin):
"""Tests for db.api.agent_build_* methods."""
def setUp(self):
super(AgentBuildTestCase, self).setUp()
self.ctxt = context.get_admin_context()
def test_agent_build_create_and_get_all(self):
self.assertEqual(0, len(db.agent_build_get_all(self.ctxt)))
agent_build = db.agent_build_create(self.ctxt, {'os': 'GNU/HURD'})
all_agent_builds = db.agent_build_get_all(self.ctxt)
self.assertEqual(1, len(all_agent_builds))
self._assertEqualObjects(agent_build, all_agent_builds[0])
def test_agent_build_get_by_triple(self):
agent_build = db.agent_build_create(
self.ctxt, {'hypervisor': 'kvm', 'os': 'FreeBSD',
'architecture': fields.Architecture.X86_64})
self.assertIsNone(db.agent_build_get_by_triple(
self.ctxt, 'kvm', 'FreeBSD', 'i386'))
self._assertEqualObjects(agent_build, db.agent_build_get_by_triple(
self.ctxt, 'kvm', 'FreeBSD', fields.Architecture.X86_64))
def test_agent_build_destroy(self):
agent_build = db.agent_build_create(self.ctxt, {})
self.assertEqual(1, len(db.agent_build_get_all(self.ctxt)))
db.agent_build_destroy(self.ctxt, agent_build.id)
self.assertEqual(0, len(db.agent_build_get_all(self.ctxt)))
def test_agent_build_update(self):
agent_build = db.agent_build_create(self.ctxt, {'os': 'HaikuOS'})
db.agent_build_update(self.ctxt, agent_build.id, {'os': 'ReactOS'})
self.assertEqual('ReactOS', db.agent_build_get_all(self.ctxt)[0].os)
def test_agent_build_destroy_destroyed(self):
agent_build = db.agent_build_create(self.ctxt, {})
db.agent_build_destroy(self.ctxt, agent_build.id)
self.assertRaises(exception.AgentBuildNotFound,
db.agent_build_destroy, self.ctxt, agent_build.id)
def test_agent_build_update_destroyed(self):
agent_build = db.agent_build_create(self.ctxt, {'os': 'HaikuOS'})
db.agent_build_destroy(self.ctxt, agent_build.id)
self.assertRaises(exception.AgentBuildNotFound,
db.agent_build_update, self.ctxt, agent_build.id, {'os': 'OS/2'})
def test_agent_build_exists(self):
values = {'hypervisor': 'kvm', 'os': 'FreeBSD',
'architecture': fields.Architecture.X86_64}
db.agent_build_create(self.ctxt, values)
self.assertRaises(exception.AgentBuildExists, db.agent_build_create,
self.ctxt, values)
def test_agent_build_get_all_by_hypervisor(self):
values = {'hypervisor': 'kvm', 'os': 'FreeBSD',
'architecture': fields.Architecture.X86_64}
created = db.agent_build_create(self.ctxt, values)
actual = db.agent_build_get_all(self.ctxt, hypervisor='kvm')
self._assertEqualListsOfObjects([created], actual)
class VirtualInterfaceTestCase(test.TestCase, ModelsObjectComparatorMixin):
def setUp(self):
super(VirtualInterfaceTestCase, self).setUp()

View File

@ -1,103 +0,0 @@
# Copyright 2014 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from nova import exception
from nova.objects import agent as agent_obj
from nova.tests.unit.objects import test_objects
fake_agent = {
'id': 1,
'hypervisor': 'novavm',
'os': 'linux',
'architecture': 'DISC',
'version': '1.0',
'url': 'http://openstack.org/novavm/agents/novavm_agent_v1.0.rpm',
'md5hash': '8cb151f3adc23a92db8ddbe084796823',
'created_at': None,
'updated_at': None,
'deleted_at': None,
'deleted': False,
}
class _TestAgent(object):
@staticmethod
def _compare(test, db, obj):
for field, value in db.items():
test.assertEqual(db[field], getattr(obj, field))
@mock.patch('nova.db.api.agent_build_get_by_triple')
def test_get_by_triple(self, mock_get):
mock_get.return_value = fake_agent
agent = agent_obj.Agent.get_by_triple(self.context,
'novavm', 'linux', 'DISC')
self._compare(self, fake_agent, agent)
@mock.patch('nova.db.api.agent_build_get_by_triple')
def test_get_by_triple_none(self, mock_get):
mock_get.return_value = None
agent = agent_obj.Agent.get_by_triple(self.context,
'novavm', 'linux', 'DISC')
self.assertIsNone(agent)
@mock.patch('nova.db.api.agent_build_create')
def test_create(self, mock_create):
mock_create.return_value = fake_agent
agent = agent_obj.Agent(context=self.context)
agent.hypervisor = 'novavm'
agent.create()
mock_create.assert_called_once_with(self.context,
{'hypervisor': 'novavm'})
self._compare(self, fake_agent, agent)
@mock.patch('nova.db.api.agent_build_create')
def test_create_with_id(self, mock_create):
agent = agent_obj.Agent(context=self.context, id=123)
self.assertRaises(exception.ObjectActionError, agent.create)
self.assertFalse(mock_create.called)
@mock.patch('nova.db.api.agent_build_destroy')
def test_destroy(self, mock_destroy):
agent = agent_obj.Agent(context=self.context, id=123)
agent.destroy()
mock_destroy.assert_called_once_with(self.context, 123)
@mock.patch('nova.db.api.agent_build_update')
def test_save(self, mock_update):
mock_update.return_value = fake_agent
agent = agent_obj.Agent(context=self.context, id=123)
agent.obj_reset_changes()
agent.hypervisor = 'novavm'
agent.save()
mock_update.assert_called_once_with(self.context, 123,
{'hypervisor': 'novavm'})
@mock.patch('nova.db.api.agent_build_get_all')
def test_get_all(self, mock_get_all):
mock_get_all.return_value = [fake_agent]
agents = agent_obj.AgentList.get_all(self.context, hypervisor='novavm')
self.assertEqual(1, len(agents))
self._compare(self, fake_agent, agents[0])
mock_get_all.assert_called_once_with(self.context, hypervisor='novavm')
class TestAgent(test_objects._LocalTest, _TestAgent):
pass
class TestAgentRemote(test_objects._RemoteTest, _TestAgent):
pass

View File

@ -1045,8 +1045,6 @@ class TestRegistry(test.NoDBTestCase):
# they come with a corresponding version bump in the affected
# objects
object_data = {
'Agent': '1.0-c0c092abaceb6f51efe5d82175f15eba',
'AgentList': '1.0-5a7380d02c3aaf2a32fc8115ae7ca98c',
'Aggregate': '1.3-f315cb68906307ca2d1cca84d4753585',
'AggregateList': '1.3-3ea55a050354e72ef3306adefa553957',
'BandwidthUsage': '1.2-c6e4c779c7f40f2407e3d70022e3cd1c',