From 0a520bac6461dcd910399f2e10f45aba7020254c Mon Sep 17 00:00:00 2001 From: Betsy Luzader Date: Mon, 19 Jan 2015 13:44:54 -0600 Subject: [PATCH] Server Pool Storage Clean Up Dropped the Server table and deleted all associated code. This completes the server-pools-storage blueprint. Implements:blueprint server-pools-storage Change-Id: I67c3b8e3a27a91e8f5ba0af325be780c32ed2063 --- designate/storage/base.py | 52 ------------------- designate/storage/impl_sqlalchemy/__init__.py | 35 ------------- .../migrate_repo/versions/050_drop_servers.py | 37 +++++++++++++ designate/storage/impl_sqlalchemy/tables.py | 12 ----- designate/tests/test_storage/__init__.py | 10 ++-- 5 files changed, 42 insertions(+), 104 deletions(-) create mode 100644 designate/storage/impl_sqlalchemy/migrate_repo/versions/050_drop_servers.py diff --git a/designate/storage/base.py b/designate/storage/base.py index 6274780f3..8312bdda9 100644 --- a/designate/storage/base.py +++ b/designate/storage/base.py @@ -88,58 +88,6 @@ class Storage(DriverPlugin): :param quota_id: Delete a Quota via ID """ - @abc.abstractmethod - def create_server(self, context, server): - """ - Create a Server. - - :param context: RPC Context. - :param server: Server object with the values to be created. - """ - - @abc.abstractmethod - def find_servers(self, context, criterion=None, marker=None, - limit=None, sort_key=None, sort_dir=None): - """ - Find Servers. - - :param context: RPC Context. - :param criterion: Criteria to filter by. - :param marker: Resource ID from which after the requested page will - start after - :param limit: Integer limit of objects of the page size after the - marker - :param sort_key: Key from which to sort after. - :param sort_dir: Direction to sort after using sort_key. - """ - - @abc.abstractmethod - def get_server(self, context, server_id): - """ - Get a Server via ID. - - :param context: RPC Context. - :param server_id: Server ID to get. - """ - - @abc.abstractmethod - def update_server(self, context, server): - """ - Update a Server - - :param context: RPC Context. - :param server: Server object - """ - - @abc.abstractmethod - def delete_server(self, context, server_id): - """ - Delete a Server via ID. - - :param context: RPC Context. - :param server_id: Delete a Server via ID - """ - @abc.abstractmethod def create_tld(self, context, tld): """ diff --git a/designate/storage/impl_sqlalchemy/__init__.py b/designate/storage/impl_sqlalchemy/__init__.py index ff267e86e..ed184a002 100644 --- a/designate/storage/impl_sqlalchemy/__init__.py +++ b/designate/storage/impl_sqlalchemy/__init__.py @@ -97,41 +97,6 @@ class SQLAlchemyStorage(sqlalchemy_base.SQLAlchemy, storage_base.Storage): return self._delete(context, tables.quotas, quota, exceptions.QuotaNotFound) - # Server Methods - def _find_servers(self, context, criterion, one=False, marker=None, - limit=None, sort_key=None, sort_dir=None): - return self._find( - context, tables.servers, objects.Server, objects.ServerList, - exceptions.ServerNotFound, criterion, one, marker, limit, - sort_key, sort_dir) - - def create_server(self, context, server): - return self._create( - tables.servers, server, exceptions.DuplicateServer) - - def get_server(self, context, server_id): - return self._find_servers(context, {'id': server_id}, one=True) - - def find_servers(self, context, criterion=None, marker=None, limit=None, - sort_key=None, sort_dir=None): - return self._find_servers(context, criterion, marker=marker, - limit=limit, sort_key=sort_key, - sort_dir=sort_dir) - - def find_server(self, context, criterion): - return self._find_servers(context, criterion, one=True) - - def update_server(self, context, server): - return self._update( - context, tables.servers, server, exceptions.DuplicateServer, - exceptions.ServerNotFound) - - def delete_server(self, context, server_id): - # Fetch the existing server, we'll need to return it. - server = self._find_servers(context, {'id': server_id}, one=True) - return self._delete(context, tables.servers, server, - exceptions.ServerNotFound) - # TLD Methods def _find_tlds(self, context, criterion, one=False, marker=None, limit=None, sort_key=None, sort_dir=None): diff --git a/designate/storage/impl_sqlalchemy/migrate_repo/versions/050_drop_servers.py b/designate/storage/impl_sqlalchemy/migrate_repo/versions/050_drop_servers.py new file mode 100644 index 000000000..8db6204ad --- /dev/null +++ b/designate/storage/impl_sqlalchemy/migrate_repo/versions/050_drop_servers.py @@ -0,0 +1,37 @@ +# Copyright (c) 2015 Rackspace Hosting +# +# Author: Betsy Luzader +# +# 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 Table, MetaData + +meta = MetaData() + +# No downgrade is possible because once the table is dropped, because there is +# no way to recreate the table with the original data. All data was migrated +# to the PoolAttributes table in the previous migration, however a database +# backup should still be done before the migration + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + + # Load the database tables + servers_table = Table('servers', meta, autoload=True) + servers_table.drop() + + +def downgrade(migrate_engine): + pass \ No newline at end of file diff --git a/designate/storage/impl_sqlalchemy/tables.py b/designate/storage/impl_sqlalchemy/tables.py index 1dc119680..43f0b4c52 100644 --- a/designate/storage/impl_sqlalchemy/tables.py +++ b/designate/storage/impl_sqlalchemy/tables.py @@ -51,18 +51,6 @@ quotas = Table('quotas', metadata, mysql_charset='utf8', ) -servers = Table('servers', metadata, - Column('id', UUID, default=utils.generate_uuid, primary_key=True), - Column('version', Integer(), default=1, nullable=False), - Column('created_at', DateTime, default=lambda: timeutils.utcnow()), - Column('updated_at', DateTime, onupdate=lambda: timeutils.utcnow()), - - Column('name', String(255), nullable=False, unique=True), - - mysql_engine='InnoDB', - mysql_charset='utf8', -) - tlds = Table('tlds', metadata, Column('id', UUID, default=utils.generate_uuid, primary_key=True), Column('version', Integer(), default=1, nullable=False), diff --git a/designate/tests/test_storage/__init__.py b/designate/tests/test_storage/__init__.py index f3ea3b78b..84d28a6ac 100644 --- a/designate/tests/test_storage/__init__.py +++ b/designate/tests/test_storage/__init__.py @@ -75,27 +75,27 @@ class StorageTestCase(object): def test_paging_marker_not_found(self): with testtools.ExpectedException(exceptions.MarkerNotFound): - self.storage.find_servers( + self.storage.find_pool_attributes( self.admin_context, marker=str(uuid.uuid4()), limit=5) def test_paging_marker_invalid(self): with testtools.ExpectedException(exceptions.InvalidMarker): - self.storage.find_servers( + self.storage.find_pool_attributes( self.admin_context, marker='4') def test_paging_limit_invalid(self): with testtools.ExpectedException(exceptions.ValueError): - self.storage.find_servers( + self.storage.find_pool_attributes( self.admin_context, limit='z') def test_paging_sort_dir_invalid(self): with testtools.ExpectedException(exceptions.ValueError): - self.storage.find_servers( + self.storage.find_pool_attributes( self.admin_context, sort_dir='invalid_sort_dir') def test_paging_sort_key_invalid(self): with testtools.ExpectedException(exceptions.InvalidSortKey): - self.storage.find_servers( + self.storage.find_pool_attributes( self.admin_context, sort_key='invalid_sort_key') # Interface Tests