Merge " Server Pool Storage Clean Up"

This commit is contained in:
Jenkins 2015-01-21 17:11:17 +00:00 committed by Gerrit Code Review
commit 2df77dccea
5 changed files with 42 additions and 104 deletions

View File

@ -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):
"""

View File

@ -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):

View File

@ -0,0 +1,37 @@
# Copyright (c) 2015 Rackspace Hosting
#
# Author: Betsy Luzader <betsy.luzader@rackspace.com>
#
# 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

View File

@ -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),

View File

@ -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