Merge "Introducing new forced_down field for a Service object"

This commit is contained in:
Jenkins 2015-07-14 13:54:15 +00:00 committed by Gerrit Code Review
commit 104d5b8202
8 changed files with 55 additions and 6 deletions

View File

@ -0,0 +1,24 @@
# 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 sqlalchemy import Boolean, Column, MetaData, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
services = Table('services', meta, autoload=True)
shadow_services = Table('shadow_services', meta, autoload=True)
services.create_column(Column('forced_down', Boolean, default=False))
shadow_services.create_column(Column('forced_down', Boolean,
default=False))

View File

@ -101,6 +101,7 @@ class Service(BASE, NovaBase):
disabled = Column(Boolean, default=False)
disabled_reason = Column(String(255))
last_seen_up = Column(DateTime, nullable=True)
forced_down = Column(Boolean, default=False)
class ComputeNode(BASE, NovaBase):

View File

@ -44,7 +44,8 @@ class Service(base.NovaPersistentObject, base.NovaObject,
# Version 1.11: Added get_by_host_and_binary
# Version 1.12: ComputeNode version 1.11
# Version 1.13: Added last_seen_up
VERSION = '1.13'
# Version 1.14: Added forced_down
VERSION = '1.14'
fields = {
'id': fields.IntegerField(read_only=True),
@ -57,6 +58,7 @@ class Service(base.NovaPersistentObject, base.NovaObject,
'availability_zone': fields.StringField(nullable=True),
'compute_node': fields.ObjectField('ComputeNode'),
'last_seen_up': fields.DateTimeField(nullable=True),
'forced_down': fields.BooleanField(),
}
obj_relationships = {
@ -67,6 +69,8 @@ class Service(base.NovaPersistentObject, base.NovaObject,
def obj_make_compatible(self, primitive, target_version):
_target_version = utils.convert_version_to_tuple(target_version)
if _target_version < (1, 14) and 'forced_down' in primitive:
del primitive['forced_down']
if _target_version < (1, 13) and 'last_seen_up' in primitive:
del primitive['last_seen_up']
if _target_version < (1, 10):
@ -199,7 +203,8 @@ class ServiceList(base.ObjectListBase, base.NovaObject):
# Version 1.9: Added get_by_binary() and Service version 1.11
# Version 1.10: Service version 1.12
# Version 1.11: Service version 1.13
VERSION = '1.11'
# Version 1.12: Service version 1.14
VERSION = '1.12'
fields = {
'objects': fields.ListOfObjectsField('Service'),
@ -218,6 +223,7 @@ class ServiceList(base.ObjectListBase, base.NovaObject):
'1.9': '1.11',
'1.10': '1.12',
'1.11': '1.13',
'1.12': '1.14',
}
@base.remotable_classmethod

View File

@ -292,6 +292,7 @@ class BaseTestCase(test.TestCase):
'deleted_at': None,
'deleted': False,
'last_seen_up': None,
'forced_down': False
}
return service

View File

@ -2814,7 +2814,8 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
'binary': 'fake_binary',
'topic': 'fake_topic',
'report_count': 3,
'disabled': False
'disabled': False,
'forced_down': False
}
def _create_service(self, values):
@ -2861,6 +2862,18 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
self.assertRaises(exception.ServiceNotFound,
db.service_update, self.ctxt, 100500, {})
def test_service_update_with_set_forced_down(self):
service = self._create_service({})
db.service_update(self.ctxt, service['id'], {'forced_down': True})
updated_service = db.service_get(self.ctxt, service['id'])
self.assertTrue(updated_service['forced_down'])
def test_service_update_with_unset_forced_down(self):
service = self._create_service({'forced_down': True})
db.service_update(self.ctxt, service['id'], {'forced_down': False})
updated_service = db.service_get(self.ctxt, service['id'])
self.assertFalse(updated_service['forced_down'])
def test_service_get(self):
service1 = self._create_service({})
self._create_service({'host': 'some_other_fake_host'})

View File

@ -758,6 +758,9 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
fkey_names = [fkey['name'] for fkey in fkeys]
self.assertIn('fk_instance_extra_instance_uuid', fkey_names)
def _check_297(self, engine, data):
self.assertColumnExists(engine, 'services', 'forced_down')
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
test_base.DbTestCase,

View File

@ -1123,8 +1123,8 @@ object_data = {
'SecurityGroupList': '1.0-a3bb51998e7d2a95b3e613111e853817',
'SecurityGroupRule': '1.1-ae1da17b79970012e8536f88cb3c6b29',
'SecurityGroupRuleList': '1.1-521f1aeb7b0cc00d026175509289d020',
'Service': '1.13-bc6c9671a91439e08224c2652da5fc4c',
'ServiceList': '1.11-d1728430a30700c143e542b7c75f65b0',
'Service': '1.14-1d5c9a16f47da93e82082c4fce31588a',
'ServiceList': '1.12-02c9aec8f075cfa8d6cb4da0507a60e7',
'TaskLog': '1.0-78b0534366f29aa3eebb01860fbe18fe',
'TaskLogList': '1.0-2378c0e2afdbbfaf392f31c1dffa4d25',
'Tag': '1.1-8b8d7d5b48887651a0e01241672e2963',
@ -1188,7 +1188,7 @@ object_relationships = {
'SecurityGroupRule': {'SecurityGroup': '1.1'},
'SecurityGroupRuleList': {'SecurityGroupRule': '1.1'},
'Service': {'ComputeNode': '1.11'},
'ServiceList': {'Service': '1.13'},
'ServiceList': {'Service': '1.14'},
'TagList': {'Tag': '1.1'},
'TaskLogList': {'TaskLog': '1.0'},
'VirtCPUModel': {'VirtCPUFeature': '1.0', 'VirtCPUTopology': '1.0'},

View File

@ -35,6 +35,7 @@ fake_service = {
'binary': 'fake-service',
'topic': 'fake-service-topic',
'report_count': 1,
'forced_down': False,
'disabled': False,
'disabled_reason': None,
'last_seen_up': None,