From b98bebfb01b108e77355ff4d4fc763f93474c208 Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Sat, 13 Jul 2013 15:52:17 -0700 Subject: [PATCH] Add service_type to the instances table implements blueprint add-service-type Change-Id: I21147ae1ebe277fc863ec2785ca0e702e8cb0d15 --- .../versions/015_add_service_type.py | 37 +++++++++++++++++++ trove/instance/models.py | 7 +++- trove/tests/api/instances_resize.py | 1 + trove/tests/api/mgmt/instances_actions.py | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 trove/db/sqlalchemy/migrate_repo/versions/015_add_service_type.py diff --git a/trove/db/sqlalchemy/migrate_repo/versions/015_add_service_type.py b/trove/db/sqlalchemy/migrate_repo/versions/015_add_service_type.py new file mode 100644 index 0000000000..ff8d8446cb --- /dev/null +++ b/trove/db/sqlalchemy/migrate_repo/versions/015_add_service_type.py @@ -0,0 +1,37 @@ +# Copyright 2012 OpenStack Foundation +# +# 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.schema import Column +from sqlalchemy.schema import MetaData + +from trove.db.sqlalchemy.migrate_repo.schema import Integer +from trove.db.sqlalchemy.migrate_repo.schema import String +from trove.db.sqlalchemy.migrate_repo.schema import Table + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True) + service_type = Column('service_type', String(36)) + instances.create_column(service_type) + instances.update().values({'service_type': 'mysql'}).execute() + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + # modify column: + instances = Table('instances', meta, autoload=True) + instances.drop_column('service_type') diff --git a/trove/instance/models.py b/trove/instance/models.py index adcdbbcc4e..c2f0b65d84 100644 --- a/trove/instance/models.py +++ b/trove/instance/models.py @@ -221,6 +221,10 @@ class SimpleInstance(object): def volume_size(self): return self.db_info.volume_size + @property + def service_type(self): + return self.db_info.service_type + class DetailInstance(SimpleInstance): """A detailed view of an Instnace. @@ -448,6 +452,7 @@ class Instance(BuiltInstance): db_info = DBInstance.create(name=name, flavor_id=flavor_id, tenant_id=context.tenant, volume_size=volume_size, + service_type=service_type, task_status=InstanceTasks.BUILDING) LOG.debug(_("Tenant %s created new Trove instance %s...") % (context.tenant, db_info.id)) @@ -675,7 +680,7 @@ class DBInstance(dbmodels.DatabaseModelBase): _data_fields = ['name', 'created', 'compute_instance_id', 'task_id', 'task_description', 'task_start_time', - 'volume_id', 'deleted', 'tenant_id'] + 'volume_id', 'deleted', 'tenant_id', 'service_type'] def __init__(self, task_status, **kwargs): kwargs["task_id"] = task_status.code diff --git a/trove/tests/api/instances_resize.py b/trove/tests/api/instances_resize.py index 90caa61b31..b68fd90199 100644 --- a/trove/tests/api/instances_resize.py +++ b/trove/tests/api/instances_resize.py @@ -50,6 +50,7 @@ class ResizeTestBase(TestCase): flavor_id=OLD_FLAVOR_ID, tenant_id=999, volume_size=None, + service_type='mysql', task_status=InstanceTasks.RESIZING) self.server = self.mock.CreateMock(Server) self.instance = models.BuiltInstanceTasks(context, diff --git a/trove/tests/api/mgmt/instances_actions.py b/trove/tests/api/mgmt/instances_actions.py index 737c35ca8a..e4b8fdda8a 100644 --- a/trove/tests/api/mgmt/instances_actions.py +++ b/trove/tests/api/mgmt/instances_actions.py @@ -50,6 +50,7 @@ class MgmtInstanceBase(object): flavor_id=1, tenant_id=self.tenant_id, volume_size=None, + service_type='mysql', task_status=InstanceTasks.NONE) self.server = self.mock.CreateMock(Server) self.instance = imodels.Instance(self.context,