Merge "Transform share and share servers statuses to lowercase"

This commit is contained in:
Jenkins 2015-06-03 15:27:27 +00:00 committed by Gerrit Code Review
commit 2d1dacfdaf
18 changed files with 326 additions and 221 deletions

View File

@ -125,7 +125,7 @@ class ManageNFSShareTest(base.BaseSharesAdminTest):
def test_manage_retry(self): def test_manage_retry(self):
# Manage share with invalid parameters # Manage share with invalid parameters
share = None share = None
parameters = [(self.st_invalid['share_type']['id'], 'MANAGE_ERROR'), parameters = [(self.st_invalid['share_type']['id'], 'manage_error'),
(self.st['share_type']['id'], 'available')] (self.st['share_type']['id'], 'available')]
for share_type_id, status in parameters: for share_type_id, status in parameters:

View File

@ -18,6 +18,7 @@ from webob import exc
from manila.api import extensions from manila.api import extensions
from manila.api.openstack import wsgi from manila.api.openstack import wsgi
from manila.common import constants
from manila import db from manila import db
from manila import exception from manila import exception
from manila import share from manila import share
@ -31,11 +32,11 @@ class AdminController(wsgi.Controller):
collection = None collection = None
valid_status = set([ valid_status = set([
'creating', constants.STATUS_CREATING,
'available', constants.STATUS_AVAILABLE,
'deleting', constants.STATUS_DELETING,
'error', constants.STATUS_ERROR,
'error_deleting', constants.STATUS_ERROR_DELETING,
]) ])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -85,7 +86,7 @@ class AdminController(wsgi.Controller):
@wsgi.action('os-force_delete') @wsgi.action('os-force_delete')
def _force_delete(self, req, id, body): def _force_delete(self, req, id, body):
"""Delete a resource, bypassing the check that it must be available.""" """Delete a resource, bypassing the check for status."""
context = req.environ['manila.context'] context = req.environ['manila.context']
self.authorize(context, 'force_delete') self.authorize(context, 'force_delete')
try: try:

View File

@ -50,9 +50,7 @@ class ShareUnmanageController(wsgi.Controller):
"that are created on top of share servers " "that are created on top of share servers "
"(created with share-networks).") "(created with share-networks).")
raise exc.HTTPForbidden(explanation=msg) raise exc.HTTPForbidden(explanation=msg)
# NOTE(vponomaryov): use 'upper' translation because share elif share['status'] in constants.TRANSITIONAL_STATUSES:
# statuses not always used from common place yet.
elif share['status'].upper() in constants.TRANSITIONAL_STATUSES:
msg = _("Share with transitional state can not be unmanaged. " msg = _("Share with transitional state can not be unmanaged. "
"Share '%(s_id)s' is in '%(state)s' state.") % dict( "Share '%(s_id)s' is in '%(state)s' state.") % dict(
state=share['status'], s_id=share['id']) state=share['status'], s_id=share['id'])

View File

@ -13,28 +13,25 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
STATUS_NEW = 'NEW' STATUS_NEW = 'new'
STATUS_CREATING = 'CREATING' STATUS_CREATING = 'creating'
STATUS_DELETING = 'DELETING' STATUS_DELETING = 'deleting'
STATUS_DELETED = 'DELETED' STATUS_DELETED = 'deleted'
STATUS_ERROR = 'ERROR' STATUS_ERROR = 'error'
STATUS_ERROR_DELETING = 'ERROR_DELETING' STATUS_ERROR_DELETING = 'error_deleting'
STATUS_AVAILABLE = 'AVAILABLE' STATUS_AVAILABLE = 'available'
STATUS_ACTIVE = 'ACTIVE' STATUS_ACTIVE = 'active'
STATUS_INACTIVE = 'INACTIVE' STATUS_INACTIVE = 'inactive'
STATUS_ACTIVATING = 'ACTIVATING' STATUS_MANAGING = 'manage_starting'
STATUS_DEACTIVATING = 'DEACTIVATING' STATUS_MANAGE_ERROR = 'manage_error'
STATUS_MANAGING = 'MANAGE_STARTING' STATUS_UNMANAGING = 'unmanage_starting'
STATUS_MANAGE_ERROR = 'MANAGE_ERROR' STATUS_UNMANAGE_ERROR = 'unmanage_error'
STATUS_UNMANAGING = 'UNMANAGE_STARTING' STATUS_UNMANAGED = 'unmanaged'
STATUS_UNMANAGE_ERROR = 'UNMANAGE_ERROR' STATUS_EXTENDING = 'extending'
STATUS_UNMANAGED = 'UNMANAGED' STATUS_EXTENDING_ERROR = 'extending_error'
STATUS_EXTENDING = 'EXTENDING'
STATUS_EXTENDING_ERROR = 'EXTENDING_ERROR'
TRANSITIONAL_STATUSES = ( TRANSITIONAL_STATUSES = (
STATUS_CREATING, STATUS_DELETING, STATUS_CREATING, STATUS_DELETING,
STATUS_ACTIVATING, STATUS_DEACTIVATING,
STATUS_MANAGING, STATUS_UNMANAGING, STATUS_MANAGING, STATUS_UNMANAGING,
STATUS_EXTENDING, STATUS_EXTENDING,
) )

View File

@ -0,0 +1,53 @@
# Copyright 2015 Mirantis Inc.
# All Rights Reserved.
#
# 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.
"""Transform statuses to lowercase
Revision ID: 3db9992c30f3
Revises: 533646c7af38
Create Date: 2015-05-28 19:30:35.645773
"""
# revision identifiers, used by Alembic.
revision = '3db9992c30f3'
down_revision = '533646c7af38'
from alembic import op
import sqlalchemy as sa
from manila.db.sqlalchemy import models
def upgrade():
# NOTE(vponomaryov): shares has some statuses as uppercase, so
# transform them in addition to statuses of share servers.
for model in (models.Share, models.ShareServer):
_transform_case(model, make_upper=False)
def downgrade():
# NOTE(vponomaryov): transform share server statuses to uppercase and
# leave share statuses as is.
_transform_case(models.ShareServer, make_upper=True)
def _transform_case(model, make_upper):
connection = op.get_bind()
session = sa.orm.Session(bind=connection.connect())
case = sa.func.upper if make_upper else sa.func.lower
session.query(model).update(
{model.status: case(model.status)}, synchronize_session='fetch')
session.commit()

View File

@ -284,11 +284,11 @@ class ShareMetadata(BASE, ManilaBase):
class ShareAccessMapping(BASE, ManilaBase): class ShareAccessMapping(BASE, ManilaBase):
"""Represents access to NFS.""" """Represents access to NFS."""
STATE_NEW = 'new' STATE_NEW = constants.STATUS_NEW
STATE_ACTIVE = 'active' STATE_ACTIVE = constants.STATUS_ACTIVE
STATE_DELETING = 'deleting' STATE_DELETING = constants.STATUS_DELETING
STATE_DELETED = 'deleted' STATE_DELETED = constants.STATUS_DELETED
STATE_ERROR = 'error' STATE_ERROR = constants.STATUS_ERROR
__tablename__ = 'share_access_map' __tablename__ = 'share_access_map'
id = Column(String(36), primary_key=True) id = Column(String(36), primary_key=True)

View File

@ -73,8 +73,8 @@ class API(base.Base):
self._check_metadata_properties(context, metadata) self._check_metadata_properties(context, metadata)
if snapshot is not None: if snapshot is not None:
if snapshot['status'] != 'available': if snapshot['status'] != constants.STATUS_AVAILABLE:
msg = _("status must be 'available'") msg = _("status must be '%s'") % constants.STATUS_AVAILABLE
raise exception.InvalidShareSnapshot(reason=msg) raise exception.InvalidShareSnapshot(reason=msg)
if not size: if not size:
size = snapshot['size'] size = snapshot['size']
@ -175,7 +175,7 @@ class API(base.Base):
'share_network_id': share_network_id, 'share_network_id': share_network_id,
'availability_zone': availability_zone, 'availability_zone': availability_zone,
'metadata': metadata, 'metadata': metadata,
'status': "creating", 'status': constants.STATUS_CREATING,
'scheduled_at': timeutils.utcnow(), 'scheduled_at': timeutils.utcnow(),
'display_name': name, 'display_name': name,
'display_description': description, 'display_description': description,
@ -306,8 +306,10 @@ class API(base.Base):
QUOTAS.commit(context, reservations, project_id=project_id) QUOTAS.commit(context, reservations, project_id=project_id)
return return
if not (force or share['status'] in ["available", "error"]): statuses = (constants.STATUS_AVAILABLE, constants.STATUS_ERROR)
msg = _("Share status must be available or error") if not (force or share['status'] in statuses):
msg = _("Share status must be one of %(statuses)s") % {
"statuses": statuses}
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
snapshots = self.db.share_snapshot_get_all_for_share(context, share_id) snapshots = self.db.share_snapshot_get_all_for_share(context, share_id)
@ -316,8 +318,9 @@ class API(base.Base):
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
now = timeutils.utcnow() now = timeutils.utcnow()
share = self.db.share_update(context, share_id, {'status': 'deleting', share = self.db.share_update(
'terminated_at': now}) context, share_id, {'status': constants.STATUS_DELETING,
'terminated_at': now})
self.share_rpcapi.delete_share(context, share) self.share_rpcapi.delete_share(context, share)
@ -350,8 +353,9 @@ class API(base.Base):
force=False): force=False):
policy.check_policy(context, 'share', 'create_snapshot', share) policy.check_policy(context, 'share', 'create_snapshot', share)
if ((not force) and (share['status'] != "available")): if ((not force) and (share['status'] != constants.STATUS_AVAILABLE)):
msg = _("must be available") msg = _("Source share status must be "
"%s") % constants.STATUS_AVAILABLE
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
size = share['size'] size = share['size']
@ -388,7 +392,7 @@ class API(base.Base):
'size': share['size'], 'size': share['size'],
'user_id': context.user_id, 'user_id': context.user_id,
'project_id': context.project_id, 'project_id': context.project_id,
'status': "creating", 'status': constants.STATUS_CREATING,
'progress': '0%', 'progress': '0%',
'share_size': share['size'], 'share_size': share['size'],
'display_name': name, 'display_name': name,
@ -410,12 +414,14 @@ class API(base.Base):
@policy.wrap_check_policy('share') @policy.wrap_check_policy('share')
def delete_snapshot(self, context, snapshot, force=False): def delete_snapshot(self, context, snapshot, force=False):
if not (force or snapshot['status'] in ["available", "error"]): statuses = (constants.STATUS_AVAILABLE, constants.STATUS_ERROR)
msg = _("Share Snapshot status must be 'available' or 'error'.") if not (force or snapshot['status'] in statuses):
msg = _("Share Snapshot status must be one of %(statuses)s.") % {
"statuses": statuses}
raise exception.InvalidShareSnapshot(reason=msg) raise exception.InvalidShareSnapshot(reason=msg)
self.db.share_snapshot_update(context, snapshot['id'], self.db.share_snapshot_update(context, snapshot['id'],
{'status': 'deleting'}) {'status': constants.STATUS_DELETING})
share = self.db.share_get(context, snapshot['share_id']) share = self.db.share_get(context, snapshot['share_id'])
self.share_rpcapi.delete_snapshot(context, snapshot, share['host']) self.share_rpcapi.delete_snapshot(context, snapshot, share['host'])
@ -557,8 +563,8 @@ class API(base.Base):
if not share['host']: if not share['host']:
msg = _("Share host is None") msg = _("Share host is None")
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
if share['status'] not in ["available"]: if share['status'] != constants.STATUS_AVAILABLE:
msg = _("Share status must be available") msg = _("Share status must be %s") % constants.STATUS_AVAILABLE
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
policy.check_policy(ctx, 'share', 'allow_access') policy.check_policy(ctx, 'share', 'allow_access')
values = { values = {
@ -567,11 +573,11 @@ class API(base.Base):
'access_to': access_to, 'access_to': access_to,
'access_level': access_level, 'access_level': access_level,
} }
access = [a for a in self.db.share_access_get_all_by_type_and_access( for access in self.db.share_access_get_all_by_type_and_access(
ctx, share['id'], access_type, access_to) if a['state'] != 'error'] ctx, share['id'], access_type, access_to):
if access: if access['state'] != constants.STATUS_ERROR:
raise exception.ShareAccessExists(access_type=access_type, raise exception.ShareAccessExists(access_type=access_type,
access=access_to) access=access_to)
if access_level not in constants.ACCESS_LEVELS + (None, ): if access_level not in constants.ACCESS_LEVELS + (None, ):
msg = _("Invalid share access level: %s.") % access_level msg = _("Invalid share access level: %s.") % access_level
raise exception.InvalidShareAccess(reason=msg) raise exception.InvalidShareAccess(reason=msg)
@ -586,8 +592,8 @@ class API(base.Base):
if not share['host']: if not share['host']:
msg = _("Share host is None") msg = _("Share host is None")
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
if share['status'] not in ["available"]: if share['status'] != constants.STATUS_AVAILABLE:
msg = _("Share status must be available") msg = _("Share status must be %s") % constants.STATUS_AVAILABLE
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
# Then check state of the access rule # Then check state of the access rule
@ -598,7 +604,9 @@ class API(base.Base):
{'state': access.STATE_DELETING}) {'state': access.STATE_DELETING})
self.share_rpcapi.deny_access(ctx, share, access) self.share_rpcapi.deny_access(ctx, share, access)
else: else:
msg = _("Access policy should be active or in error state") msg = _("Access policy should be %(active)s or in %(error)s "
"state") % {"active": constants.STATUS_ACTIVE,
"error": constants.STATUS_ERROR}
raise exception.InvalidShareAccess(reason=msg) raise exception.InvalidShareAccess(reason=msg)
# update share state and send message to manager # update share state and send message to manager
@ -679,13 +687,11 @@ class API(base.Base):
def extend(self, context, share, new_size): def extend(self, context, share, new_size):
policy.check_policy(context, 'share', 'extend') policy.check_policy(context, 'share', 'extend')
status = six.text_type(share['status']).upper() if share['status'] != constants.STATUS_AVAILABLE:
if status != constants.STATUS_AVAILABLE:
msg_params = { msg_params = {
'valid_status': constants.STATUS_AVAILABLE, 'valid_status': constants.STATUS_AVAILABLE,
'share_id': share['id'], 'share_id': share['id'],
'status': status, 'status': share['status'],
} }
msg = _("Share %(share_id)s status must be '%(valid_status)s' " msg = _("Share %(share_id)s status must be '%(valid_status)s' "
"to extend, but current status is: " "to extend, but current status is: "

View File

@ -439,7 +439,8 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
t = time.time() t = time.time()
while time.time() - t < self.configuration.max_time_to_attach: while time.time() - t < self.configuration.max_time_to_attach:
volume = self.volume_api.get(context, volume['id']) volume = self.volume_api.get(context, volume['id'])
if volume['status'] in ('available', 'error'): if volume['status'] in (const.STATUS_AVAILABLE,
const.STATUS_ERROR):
break break
time.sleep(1) time.sleep(1)
else: else:
@ -467,9 +468,9 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
t = time.time() t = time.time()
while time.time() - t < self.configuration.max_time_to_create_volume: while time.time() - t < self.configuration.max_time_to_create_volume:
if volume['status'] == 'available': if volume['status'] == const.STATUS_AVAILABLE:
break break
if volume['status'] == 'error': if volume['status'] == const.STATUS_ERROR:
raise exception.ManilaException(_('Failed to create volume')) raise exception.ManilaException(_('Failed to create volume'))
time.sleep(1) time.sleep(1)
volume = self.volume_api.get(context, volume['id']) volume = self.volume_api.get(context, volume['id'])
@ -562,9 +563,9 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
self.admin_context, volume['id'], volume_snapshot_name, '') self.admin_context, volume['id'], volume_snapshot_name, '')
t = time.time() t = time.time()
while time.time() - t < self.configuration.max_time_to_create_volume: while time.time() - t < self.configuration.max_time_to_create_volume:
if volume_snapshot['status'] == 'available': if volume_snapshot['status'] == const.STATUS_AVAILABLE:
break break
if volume_snapshot['status'] == 'error': if volume_snapshot['status'] == const.STATUS_ERROR:
raise exception.ManilaException(_('Failed to create volume ' raise exception.ManilaException(_('Failed to create volume '
'snapshot')) 'snapshot'))
time.sleep(1) time.sleep(1)

View File

@ -155,7 +155,7 @@ class ShareManager(manager.SchedulerDependentManager):
shares = self.db.share_get_all_by_host(ctxt, self.host) shares = self.db.share_get_all_by_host(ctxt, self.host)
LOG.debug("Re-exporting %s shares", len(shares)) LOG.debug("Re-exporting %s shares", len(shares))
for share in shares: for share in shares:
if share['status'] != 'available': if share['status'] != constants.STATUS_AVAILABLE:
LOG.info( LOG.info(
_LI("Share %(name)s: skipping export, because it has " _LI("Share %(name)s: skipping export, because it has "
"'%(status)s' status."), "'%(status)s' status."),
@ -279,7 +279,8 @@ class ShareManager(manager.SchedulerDependentManager):
share_network_id = share_ref.get('share_network_id', None) share_network_id = share_ref.get('share_network_id', None)
if share_network_id and not self.driver.driver_handles_share_servers: if share_network_id and not self.driver.driver_handles_share_servers:
self.db.share_update(context, share_id, {'status': 'error'}) self.db.share_update(
context, share_id, {'status': constants.STATUS_ERROR})
raise exception.ManilaException( raise exception.ManilaException(
"Driver does not expect share-network to be provided " "Driver does not expect share-network to be provided "
"with current configuration.") "with current configuration.")
@ -304,7 +305,7 @@ class ShareManager(manager.SchedulerDependentManager):
LOG.error(_LE("Share server %s does not exist."), LOG.error(_LE("Share server %s does not exist."),
parent_share_server_id) parent_share_server_id)
self.db.share_update(context, share_id, self.db.share_update(context, share_id,
{'status': 'error'}) {'status': constants.STATUS_ERROR})
elif share_network_id: elif share_network_id:
try: try:
share_server, share_ref = self._provide_share_server_for_share( share_server, share_ref = self._provide_share_server_for_share(
@ -314,7 +315,7 @@ class ShareManager(manager.SchedulerDependentManager):
LOG.error(_LE("Failed to get share server" LOG.error(_LE("Failed to get share server"
" for share creation.")) " for share creation."))
self.db.share_update(context, share_id, self.db.share_update(context, share_id,
{'status': 'error'}) {'status': constants.STATUS_ERROR})
else: else:
share_server = None share_server = None
@ -351,11 +352,12 @@ class ShareManager(manager.SchedulerDependentManager):
'can not be written to db because it ' 'can not be written to db because it '
'contains %s and it is not a dictionary.'), 'contains %s and it is not a dictionary.'),
detail_data) detail_data)
self.db.share_update(context, share_id, {'status': 'error'}) self.db.share_update(
context, share_id, {'status': constants.STATUS_ERROR})
else: else:
LOG.info(_LI("Share created successfully.")) LOG.info(_LI("Share created successfully."))
self.db.share_update(context, share_id, self.db.share_update(context, share_id,
{'status': 'available', {'status': constants.STATUS_AVAILABLE,
'launched_at': timeutils.utcnow()}) 'launched_at': timeutils.utcnow()})
def manage_share(self, context, share_id, driver_options): def manage_share(self, context, share_id, driver_options):
@ -382,7 +384,7 @@ class ShareManager(manager.SchedulerDependentManager):
}) })
share_update.update({ share_update.update({
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'launched_at': timeutils.utcnow(), 'launched_at': timeutils.utcnow(),
}) })
@ -490,8 +492,10 @@ class ShareManager(manager.SchedulerDependentManager):
share_server=share_server) share_server=share_server)
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.db.share_update(context, share_id, self.db.share_update(
{'status': 'error_deleting'}) context,
share_id,
{'status': constants.STATUS_ERROR_DELETING})
try: try:
reservations = QUOTAS.reserve(context, reservations = QUOTAS.reserve(context,
project_id=project_id, project_id=project_id,
@ -552,13 +556,14 @@ class ShareManager(manager.SchedulerDependentManager):
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.db.share_snapshot_update(context, self.db.share_snapshot_update(
snapshot_ref['id'], context,
{'status': 'error'}) snapshot_ref['id'],
{'status': constants.STATUS_ERROR})
self.db.share_snapshot_update(context, self.db.share_snapshot_update(context,
snapshot_ref['id'], snapshot_ref['id'],
{'status': 'available', {'status': constants.STATUS_AVAILABLE,
'progress': '100%'}) 'progress': '100%'})
return snapshot_id return snapshot_id
@ -579,12 +584,16 @@ class ShareManager(manager.SchedulerDependentManager):
self.driver.delete_snapshot(context, snapshot_ref, self.driver.delete_snapshot(context, snapshot_ref,
share_server=share_server) share_server=share_server)
except exception.ShareSnapshotIsBusy: except exception.ShareSnapshotIsBusy:
self.db.share_snapshot_update(context, snapshot_ref['id'], self.db.share_snapshot_update(
{'status': 'available'}) context,
snapshot_ref['id'],
{'status': constants.STATUS_AVAILABLE})
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.db.share_snapshot_update(context, snapshot_ref['id'], self.db.share_snapshot_update(
{'status': 'error_deleting'}) context,
snapshot_ref['id'],
{'status': constants.STATUS_ERROR_DELETING})
else: else:
self.db.share_snapshot_destroy(context, snapshot_id) self.db.share_snapshot_destroy(context, snapshot_id)
try: try:

View File

@ -17,6 +17,7 @@ from oslo_config import cfg
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import webob import webob
from manila.common import constants
from manila import context from manila import context
from manila import db from manila import db
from manila import exception from manila import exception
@ -47,12 +48,14 @@ class AdminActionsTest(test.TestCase):
def test_reset_status_as_admin(self): def test_reset_status_as_admin(self):
# current status is available # current status is available
share = db.share_create(self.admin_context, {'status': 'available'}) share = db.share_create(
self.admin_context, {'status': constants.STATUS_AVAILABLE})
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
# request status of 'error' # request status of 'error'
req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}}) req.body = jsonutils.dumps(
{'os-reset_status': {'status': constants.STATUS_ERROR}})
# attach admin context to request # attach admin context to request
req.environ['manila.context'] = self.admin_context req.environ['manila.context'] = self.admin_context
resp = req.get_response(app()) resp = req.get_response(app())
@ -60,18 +63,18 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 202) self.assertEqual(resp.status_int, 202)
share = db.share_get(self.admin_context, share['id']) share = db.share_get(self.admin_context, share['id'])
# status changed to 'error' # status changed to 'error'
self.assertEqual(share['status'], 'error') self.assertEqual(share['status'], constants.STATUS_ERROR)
def test_reset_status_as_non_admin(self): def test_reset_status_as_non_admin(self):
# current status is 'error' # current status is 'error'
share = db.share_create(context.get_admin_context(), share = db.share_create(context.get_admin_context(),
{'status': 'error'}) {'status': constants.STATUS_ERROR})
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
# request changing status to available # request changing status to available
req.body = jsonutils.dumps({'os-reset_status': {'status': req.body = jsonutils.dumps(
'available'}}) {'os-reset_status': {'status': constants.STATUS_AVAILABLE}})
# non-admin context # non-admin context
req.environ['manila.context'] = self.member_context req.environ['manila.context'] = self.member_context
resp = req.get_response(app()) resp = req.get_response(app())
@ -79,11 +82,12 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 403) self.assertEqual(resp.status_int, 403)
share = db.share_get(context.get_admin_context(), share['id']) share = db.share_get(context.get_admin_context(), share['id'])
# status is still 'error' # status is still 'error'
self.assertEqual(share['status'], 'error') self.assertEqual(share['status'], constants.STATUS_ERROR)
def test_malformed_reset_status_body(self): def test_malformed_reset_status_body(self):
# current status is available # current status is available
share = db.share_create(self.admin_context, {'status': 'available'}) share = db.share_create(
self.admin_context, {'status': constants.STATUS_AVAILABLE})
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
@ -96,11 +100,12 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
share = db.share_get(self.admin_context, share['id']) share = db.share_get(self.admin_context, share['id'])
# status is still 'available' # status is still 'available'
self.assertEqual(share['status'], 'available') self.assertEqual(share['status'], constants.STATUS_AVAILABLE)
def test_invalid_status_for_share(self): def test_invalid_status_for_share(self):
# current status is available # current status is available
share = db.share_create(self.admin_context, {'status': 'available'}) share = db.share_create(
self.admin_context, {'status': constants.STATUS_AVAILABLE})
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
@ -113,7 +118,7 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
share = db.share_get(self.admin_context, share['id']) share = db.share_get(self.admin_context, share['id'])
# status is still 'available' # status is still 'available'
self.assertEqual(share['status'], 'available') self.assertEqual(share['status'], constants.STATUS_AVAILABLE)
def test_reset_status_for_missing_share(self): def test_reset_status_for_missing_share(self):
# missing-share-id # missing-share-id
@ -122,8 +127,8 @@ class AdminActionsTest(test.TestCase):
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
# malformed request body # malformed request body
req.body = jsonutils.dumps({'os-reset_status': {'status': req.body = jsonutils.dumps(
'available'}}) {'os-reset_status': {'status': constants.STATUS_AVAILABLE}})
# attach admin context to request # attach admin context to request
req.environ['manila.context'] = self.admin_context req.environ['manila.context'] = self.admin_context
resp = req.get_response(app()) resp = req.get_response(app())
@ -137,17 +142,17 @@ class AdminActionsTest(test.TestCase):
def test_snapshot_reset_status(self): def test_snapshot_reset_status(self):
# snapshot in 'error_deleting' # snapshot in 'error_deleting'
share = db.share_create(self.admin_context, {}) share = db.share_create(self.admin_context, {})
snapshot = db.share_snapshot_create(self.admin_context, snapshot = db.share_snapshot_create(
{ self.admin_context,
'status': 'error_deleting', {'status': constants.STATUS_ERROR_DELETING,
'share_id': share['id'] 'share_id': share['id']})
})
req = webob.Request.blank('/v1/fake/snapshots/%s/action' % req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
snapshot['id']) snapshot['id'])
req.method = 'POST' req.method = 'POST'
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
# request status of 'error' # request status of 'error'
req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}}) req.body = jsonutils.dumps(
{'os-reset_status': {'status': constants.STATUS_ERROR}})
# attach admin context to request # attach admin context to request
req.environ['manila.context'] = self.admin_context req.environ['manila.context'] = self.admin_context
resp = req.get_response(app()) resp = req.get_response(app())
@ -155,16 +160,14 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 202) self.assertEqual(resp.status_int, 202)
snapshot = db.share_snapshot_get(self.admin_context, snapshot['id']) snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
# status changed to 'error' # status changed to 'error'
self.assertEqual(snapshot['status'], 'error') self.assertEqual(snapshot['status'], constants.STATUS_ERROR)
def test_invalid_status_for_snapshot(self): def test_invalid_status_for_snapshot(self):
# snapshot in 'available' # snapshot in 'available'
share = db.share_create(self.admin_context, {}) share = db.share_create(self.admin_context, {})
snapshot = db.share_snapshot_create(self.admin_context, snapshot = db.share_snapshot_create(
{ self.admin_context,
'status': 'available', {'status': constants.STATUS_AVAILABLE, 'share_id': share['id']})
'share_id': share['id']
})
req = webob.Request.blank('/v1/fake/snapshots/%s/action' % req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
snapshot['id']) snapshot['id'])
req.method = 'POST' req.method = 'POST'
@ -179,7 +182,7 @@ class AdminActionsTest(test.TestCase):
self.assertEqual(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
snapshot = db.share_snapshot_get(self.admin_context, snapshot['id']) snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
# status is still 'available' # status is still 'available'
self.assertEqual(snapshot['status'], 'available') self.assertEqual(snapshot['status'], constants.STATUS_AVAILABLE)
def test_admin_force_delete_share(self): def test_admin_force_delete_share(self):
share = db.share_create(self.admin_context, {'size': 1}) share = db.share_create(self.admin_context, {'size': 1})

View File

@ -15,6 +15,7 @@
import datetime import datetime
from manila.common import constants
from manila import exception as exc from manila import exception as exc
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
@ -106,7 +107,7 @@ def stub_volume_get_all_by_project(self, context, search_opts=None):
def stub_snapshot(id, **kwargs): def stub_snapshot(id, **kwargs):
snapshot = {'id': id, snapshot = {'id': id,
'volume_id': 12, 'volume_id': 12,
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'volume_size': 100, 'volume_size': 100,
'created_at': None, 'created_at': None,
'display_name': 'Default name', 'display_name': 'Default name',

View File

@ -22,6 +22,7 @@ import webob
from manila.api import common from manila.api import common
from manila.api.v1 import shares from manila.api.v1 import shares
from manila.common import constants
from manila import context from manila import context
from manila import exception from manila import exception
from manila.share import api as share_api from manila.share import api as share_api
@ -368,7 +369,7 @@ class ShareApiTest(test.TestCase):
def _share_list_summary_with_search_opts(self, use_admin_context): def _share_list_summary_with_search_opts(self, use_admin_context):
search_opts = { search_opts = {
'name': 'fake_name', 'name': 'fake_name',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'share_server_id': 'fake_share_server_id', 'share_server_id': 'fake_share_server_id',
'share_type_id': 'fake_share_type_id', 'share_type_id': 'fake_share_type_id',
'snapshot_id': 'fake_snapshot_id', 'snapshot_id': 'fake_snapshot_id',
@ -457,7 +458,7 @@ class ShareApiTest(test.TestCase):
def _share_list_detail_with_search_opts(self, use_admin_context): def _share_list_detail_with_search_opts(self, use_admin_context):
search_opts = { search_opts = {
'name': 'fake_name', 'name': 'fake_name',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'share_server_id': 'fake_share_server_id', 'share_server_id': 'fake_share_server_id',
'share_type_id': 'fake_share_type_id', 'share_type_id': 'fake_share_type_id',
'snapshot_id': 'fake_snapshot_id', 'snapshot_id': 'fake_snapshot_id',
@ -482,7 +483,7 @@ class ShareApiTest(test.TestCase):
{ {
'id': 'id2', 'id': 'id2',
'display_name': 'n2', 'display_name': 'n2',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'snapshot_id': 'fake_snapshot_id', 'snapshot_id': 'fake_snapshot_id',
'share_type_id': 'fake_share_type_id', 'share_type_id': 'fake_share_type_id',
'host': 'fake_host', 'host': 'fake_host',

View File

@ -26,6 +26,7 @@ import ddt
import mock import mock
from oslo_config import cfg from oslo_config import cfg
from manila.common import constants
from manila import context from manila import context
from manila import exception from manila import exception
from manila.share import configuration as config from manila.share import configuration as config
@ -83,10 +84,10 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self.glusterfs_server2_volumes = 'manila-share-2-2G\nshare2' self.glusterfs_server2_volumes = 'manila-share-2-2G\nshare2'
self.share1 = new_share( self.share1 = new_share(
export_location=self.glusterfs_target1, export_location=self.glusterfs_target1,
status="available") status=constants.STATUS_AVAILABLE)
self.share2 = new_share( self.share2 = new_share(
export_location=self.glusterfs_target2, export_location=self.glusterfs_target2,
status="available") status=constants.STATUS_AVAILABLE)
gmgr = glusterfs.GlusterManager gmgr = glusterfs.GlusterManager
self.gmgr1 = gmgr(self.glusterfs_server1, self._execute, None, None, self.gmgr1 = gmgr(self.glusterfs_server1, self._execute, None, None,
has_volume=False) has_volume=False)

View File

@ -109,25 +109,25 @@ def fake_access(id, **kwargs):
_FAKE_LIST_OF_ALL_SHARES = [ _FAKE_LIST_OF_ALL_SHARES = [
{ {
'name': 'foo', 'name': 'foo',
'status': 'active', 'status': constants.STATUS_AVAILABLE,
'project_id': 'fake_pid_1', 'project_id': 'fake_pid_1',
'share_server_id': 'fake_server_1', 'share_server_id': 'fake_server_1',
}, },
{ {
'name': 'bar', 'name': 'bar',
'status': 'error', 'status': constants.STATUS_ERROR,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_server_id': 'fake_server_2', 'share_server_id': 'fake_server_2',
}, },
{ {
'name': 'foo', 'name': 'foo',
'status': 'active', 'status': constants.STATUS_AVAILABLE,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_server_id': 'fake_server_3', 'share_server_id': 'fake_server_3',
}, },
{ {
'name': 'bar', 'name': 'bar',
'status': 'error', 'status': constants.STATUS_ERROR,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_server_id': 'fake_server_3', 'share_server_id': 'fake_server_3',
}, },
@ -137,25 +137,25 @@ _FAKE_LIST_OF_ALL_SHARES = [
_FAKE_LIST_OF_ALL_SNAPSHOTS = [ _FAKE_LIST_OF_ALL_SNAPSHOTS = [
{ {
'name': 'foo', 'name': 'foo',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'project_id': 'fake_pid_1', 'project_id': 'fake_pid_1',
'share_id': 'fake_server_1', 'share_id': 'fake_server_1',
}, },
{ {
'name': 'bar', 'name': 'bar',
'status': 'error', 'status': constants.STATUS_ERROR,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_id': 'fake_server_2', 'share_id': 'fake_server_2',
}, },
{ {
'name': 'foo', 'name': 'foo',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_id': 'fake_share_id_3', 'share_id': 'fake_share_id_3',
}, },
{ {
'name': 'bar', 'name': 'bar',
'status': 'error', 'status': constants.STATUS_ERROR,
'project_id': 'fake_pid_2', 'project_id': 'fake_pid_2',
'share_id': 'fake_share_id_3', 'share_id': 'fake_share_id_3',
}, },
@ -276,7 +276,7 @@ class ShareAPITestCase(test.TestCase):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.mock_object(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'status': 'active'}) shares = self.api.get_all(ctx, {'status': constants.STATUS_AVAILABLE})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
]) ])
@ -290,7 +290,8 @@ class ShareAPITestCase(test.TestCase):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.mock_object(db_driver, 'share_get_all', self.mock_object(db_driver, 'share_get_all',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES)) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
shares = self.api.get_all(ctx, {'status': 'error', 'all_tenants': 1}) shares = self.api.get_all(
ctx, {'status': constants.STATUS_ERROR, 'all_tenants': 1})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
]) ])
@ -317,7 +318,8 @@ class ShareAPITestCase(test.TestCase):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False)
self.mock_object(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'name': 'bar', 'status': 'error'}) shares = self.api.get_all(
ctx, {'name': 'bar', 'status': constants.STATUS_ERROR})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
]) ])
@ -330,7 +332,8 @@ class ShareAPITestCase(test.TestCase):
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2]) self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2])
# one item expected, two filtered # one item expected, two filtered
shares = self.api.get_all(ctx, {'name': 'foo', 'status': 'active'}) shares = self.api.get_all(
ctx, {'name': 'foo', 'status': constants.STATUS_AVAILABLE})
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2::4]) self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2::4])
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -466,7 +469,8 @@ class ShareAPITestCase(test.TestCase):
share = fake_share('fakeid', share = fake_share('fakeid',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
status='creating', is_public=is_public) status=constants.STATUS_CREATING,
is_public=is_public)
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
@ -491,7 +495,7 @@ class ShareAPITestCase(test.TestCase):
share = fake_share('fakeid', share = fake_share('fakeid',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
status='creating') status=constants.STATUS_CREATING)
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
@ -515,8 +519,10 @@ class ShareAPITestCase(test.TestCase):
None, '', 'fake', 'nfsfake', 'cifsfake', 'glusterfsfake', 'hdfsfake') None, '', 'fake', 'nfsfake', 'cifsfake', 'glusterfsfake', 'hdfsfake')
def test_create_share_invalid_protocol(self, proto): def test_create_share_invalid_protocol(self, proto):
options = fake_share( options = fake_share(
'fakeid', user_id=self.context.user_id, 'fakeid',
project_id=self.context.project_id, status='creating') user_id=self.context.user_id,
project_id=self.context.project_id,
status=constants.STATUS_CREATING)
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
options.pop(name, None) options.pop(name, None)
@ -542,7 +548,7 @@ class ShareAPITestCase(test.TestCase):
share = fake_share('fakeid', share = fake_share('fakeid',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
status='creating') status=constants.STATUS_CREATING)
self.mock_object(db_driver, 'share_create', self.mock_object(db_driver, 'share_create',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.mock_object(db_driver, 'share_export_locations_update') self.mock_object(db_driver, 'share_export_locations_update')
@ -619,7 +625,7 @@ class ShareAPITestCase(test.TestCase):
'id': 'fakeid', 'id': 'fakeid',
'host': 'fake', 'host': 'fake',
'size': '1', 'size': '1',
'status': 'available', 'status': constants.STATUS_AVAILABLE,
'user_id': self.context.user_id, 'user_id': self.context.user_id,
'project_id': self.context.project_id, 'project_id': self.context.project_id,
} }
@ -638,17 +644,17 @@ class ShareAPITestCase(test.TestCase):
def test_create_snapshot(self): def test_create_snapshot(self):
date = datetime.datetime(1, 1, 1, 1, 1, 1) date = datetime.datetime(1, 1, 1, 1, 1, 1)
timeutils.utcnow.return_value = date timeutils.utcnow.return_value = date
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=share['id'], share_id=share['id'],
status='creating') status=constants.STATUS_CREATING)
fake_name = 'fakename' fake_name = 'fakename'
fake_desc = 'fakedesc' fake_desc = 'fakedesc'
options = { options = {
'share_id': share['id'], 'share_id': share['id'],
'user_id': self.context.user_id, 'user_id': self.context.user_id,
'project_id': self.context.project_id, 'project_id': self.context.project_id,
'status': "creating", 'status': constants.STATUS_CREATING,
'progress': '0%', 'progress': '0%',
'share_size': share['size'], 'share_size': share['size'],
'size': 1, 'size': 1,
@ -702,7 +708,7 @@ class ShareAPITestCase(test.TestCase):
share = fake_share('fakeid') share = fake_share('fakeid')
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=share['id'], share_id=share['id'],
status='available') status=constants.STATUS_AVAILABLE)
with mock.patch.object(db_driver, 'share_get', with mock.patch.object(db_driver, 'share_get',
mock.Mock(return_value=share)): mock.Mock(return_value=share)):
self.api.delete_snapshot(self.context, snapshot) self.api.delete_snapshot(self.context, snapshot)
@ -711,14 +717,16 @@ class ShareAPITestCase(test.TestCase):
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
self.context, 'share', 'delete_snapshot', snapshot) self.context, 'share', 'delete_snapshot', snapshot)
db_driver.share_snapshot_update.assert_called_once_with( db_driver.share_snapshot_update.assert_called_once_with(
self.context, snapshot['id'], {'status': 'deleting'}) self.context,
snapshot['id'],
{'status': constants.STATUS_DELETING})
db_driver.share_get.assert_called_once_with( db_driver.share_get.assert_called_once_with(
self.context, snapshot['share_id']) self.context, snapshot['share_id'])
def test_delete_snapshot_wrong_status(self): def test_delete_snapshot_wrong_status(self):
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id='fakeshareid', share_id='fakeshareid',
status='creating') status=constants.STATUS_CREATING)
self.assertRaises(exception.InvalidShareSnapshot, self.assertRaises(exception.InvalidShareSnapshot,
self.api.delete_snapshot, self.api.delete_snapshot,
self.context, self.context,
@ -727,7 +735,7 @@ class ShareAPITestCase(test.TestCase):
self.context, 'share', 'delete_snapshot', snapshot) self.context, 'share', 'delete_snapshot', snapshot)
def test_create_snapshot_if_share_not_available(self): def test_create_snapshot_if_share_not_available(self):
share = fake_share('fakeid', status='error') share = fake_share('fakeid', status=constants.STATUS_ERROR)
self.assertRaises(exception.InvalidShare, self.assertRaises(exception.InvalidShare,
self.api.create_snapshot, self.api.create_snapshot,
self.context, self.context,
@ -747,15 +755,15 @@ class ShareAPITestCase(test.TestCase):
original_share = fake_share('fake_original_id', original_share = fake_share('fake_original_id',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
status='available') status=constants.STATUS_AVAILABLE)
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=original_share['id'], share_id=original_share['id'],
status='available') status=constants.STATUS_AVAILABLE)
share = fake_share('fakeid', share = fake_share('fakeid',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
snapshot_id=snapshot['id'], snapshot_id=snapshot['id'],
status='creating') status=constants.STATUS_CREATING)
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
@ -804,15 +812,15 @@ class ShareAPITestCase(test.TestCase):
original_share = fake_share('fake_original_id', original_share = fake_share('fake_original_id',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
status='available') status=constants.STATUS_AVAILABLE)
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=original_share['id'], share_id=original_share['id'],
status='available') status=constants.STATUS_AVAILABLE)
share = fake_share('fakeid', share = fake_share('fakeid',
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
snapshot_id=snapshot['id'], snapshot_id=snapshot['id'],
status='creating') status=constants.STATUS_CREATING)
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
@ -862,11 +870,12 @@ class ShareAPITestCase(test.TestCase):
share_id = 'fake_share_id' share_id = 'fake_share_id'
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=share_id, share_id=share_id,
status='available') status=constants.STATUS_AVAILABLE)
share_type = {'id': 'fake_share_type'} share_type = {'id': 'fake_share_type'}
share = fake_share(share_id, user_id=self.context.user_id, share = fake_share(share_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
snapshot_id=snapshot['id'], status='creating', snapshot_id=snapshot['id'],
status=constants.STATUS_CREATING,
share_type_id=share_type['id']) share_type_id=share_type['id'])
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
@ -919,11 +928,12 @@ class ShareAPITestCase(test.TestCase):
share_id = 'fake_share_id' share_id = 'fake_share_id'
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=share_id, share_id=share_id,
status='available') status=constants.STATUS_AVAILABLE)
share_type = {'id': 'fake_share_type'} share_type = {'id': 'fake_share_type'}
share = fake_share(share_id, user_id=self.context.user_id, share = fake_share(share_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
snapshot_id=snapshot['id'], status='creating', snapshot_id=snapshot['id'],
status=constants.STATUS_CREATING,
share_type_id=share_type['id'][1:]) share_type_id=share_type['id'][1:])
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
@ -963,14 +973,15 @@ class ShareAPITestCase(test.TestCase):
user_id=self.context.user_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
share_type_id='fake_share_type_id', share_type_id='fake_share_type_id',
status='available') status=constants.STATUS_AVAILABLE)
share_id = 'fake_share_id' share_id = 'fake_share_id'
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id=original_share['id'], share_id=original_share['id'],
status='available') status=constants.STATUS_AVAILABLE)
share = fake_share(share_id, user_id=self.context.user_id, share = fake_share(share_id, user_id=self.context.user_id,
project_id=self.context.project_id, project_id=self.context.project_id,
snapshot_id=snapshot['id'], status='creating', snapshot_id=snapshot['id'],
status=constants.STATUS_CREATING,
share_type_id=original_share['share_type_id']) share_type_id=original_share['share_type_id'])
options = share.copy() options = share.copy()
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
@ -1030,14 +1041,15 @@ class ShareAPITestCase(test.TestCase):
def test_create_from_snapshot_not_available(self): def test_create_from_snapshot_not_available(self):
snapshot = fake_snapshot('fakesnapshotid', snapshot = fake_snapshot('fakesnapshotid',
share_id='fakeshare_id', share_id='fakeshare_id',
status='error') status=constants.STATUS_ERROR)
self.assertRaises(exception.InvalidShareSnapshot, self.api.create, self.assertRaises(exception.InvalidShareSnapshot, self.api.create,
self.context, 'nfs', '1', 'fakename', self.context, 'nfs', '1', 'fakename',
'fakedesc', snapshot=snapshot, 'fakedesc', snapshot=snapshot,
availability_zone='fakeaz') availability_zone='fakeaz')
def test_create_from_snapshot_larger_size(self): def test_create_from_snapshot_larger_size(self):
snapshot = fake_snapshot(1, size=100, status='available') snapshot = fake_snapshot(
1, size=100, status=constants.STATUS_AVAILABLE)
self.assertRaises(exception.InvalidInput, self.api.create, self.assertRaises(exception.InvalidInput, self.api.create,
self.context, 'nfs', 1, 'fakename', 'fakedesc', self.context, 'nfs', 1, 'fakename', 'fakedesc',
availability_zone='fakeaz', snapshot=snapshot) availability_zone='fakeaz', snapshot=snapshot)
@ -1057,7 +1069,7 @@ class ShareAPITestCase(test.TestCase):
timeutils.utcnow.return_value = date timeutils.utcnow.return_value = date
share = fake_share('fakeid', status=status, share = fake_share('fakeid', status=status,
share_server_id=share_server_id) share_server_id=share_server_id)
options = {'status': 'deleting', 'terminated_at': date} options = {'status': constants.STATUS_DELETING, 'terminated_at': date}
deleting_share = share.copy() deleting_share = share.copy()
deleting_share.update(options) deleting_share.update(options)
self.mock_object(db_driver, 'share_update', self.mock_object(db_driver, 'share_update',
@ -1066,7 +1078,7 @@ class ShareAPITestCase(test.TestCase):
return share, deleting_share, options return share, deleting_share, options
@ddt.data('available', 'error') @ddt.data(constants.STATUS_AVAILABLE, constants.STATUS_ERROR)
def test_delete(self, status): def test_delete(self, status):
share_server_id = 'fake-ss-id' share_server_id = 'fake-ss-id'
share, deleting_share, options = self._setup_delete_mocks( share, deleting_share, options = self._setup_delete_mocks(
@ -1083,7 +1095,7 @@ class ShareAPITestCase(test.TestCase):
def test_delete_share_without_share_server(self): def test_delete_share_without_share_server(self):
share, deleting_share, options = self._setup_delete_mocks( share, deleting_share, options = self._setup_delete_mocks(
'available', share_server_id=None) constants.STATUS_AVAILABLE, share_server_id=None)
self.api.delete(self.context, share) self.api.delete(self.context, share)
@ -1207,7 +1219,7 @@ class ShareAPITestCase(test.TestCase):
@ddt.data(None, 'rw', 'ro') @ddt.data(None, 'rw', 'ro')
def test_allow_access(self, level): def test_allow_access(self, level):
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
values = { values = {
'share_id': share['id'], 'share_id': share['id'],
'access_type': 'fakeacctype', 'access_type': 'fakeacctype',
@ -1228,13 +1240,13 @@ class ShareAPITestCase(test.TestCase):
self.context, 'share', 'allow_access') self.context, 'share', 'allow_access')
def test_allow_access_invalid_access_level(self): def test_allow_access_invalid_access_level(self):
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
self.assertRaises(exception.InvalidShareAccess, self.api.allow_access, self.assertRaises(exception.InvalidShareAccess, self.api.allow_access,
self.context, share, 'fakeacctype', 'fakeaccto', self.context, share, 'fakeacctype', 'fakeaccto',
'ab') 'ab')
def test_allow_access_status_not_available(self): def test_allow_access_status_not_available(self):
share = fake_share('fakeid', status='error') share = fake_share('fakeid', status=constants.STATUS_ERROR)
self.assertRaises(exception.InvalidShare, self.api.allow_access, self.assertRaises(exception.InvalidShare, self.api.allow_access,
self.context, share, 'fakeacctype', 'fakeaccto') self.context, share, 'fakeacctype', 'fakeaccto')
@ -1245,7 +1257,7 @@ class ShareAPITestCase(test.TestCase):
@mock.patch.object(db_driver, 'share_access_delete', mock.Mock()) @mock.patch.object(db_driver, 'share_access_delete', mock.Mock())
def test_deny_access_error(self): def test_deny_access_error(self):
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
access = fake_access('fakaccid', state='fakeerror') access = fake_access('fakaccid', state='fakeerror')
self.api.deny_access(self.context, share, access) self.api.deny_access(self.context, share, access)
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
@ -1255,7 +1267,7 @@ class ShareAPITestCase(test.TestCase):
@mock.patch.object(db_driver, 'share_access_update', mock.Mock()) @mock.patch.object(db_driver, 'share_access_update', mock.Mock())
def test_deny_access_active(self): def test_deny_access_active(self):
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
access = fake_access('fakaccid', state='fakeactive') access = fake_access('fakaccid', state='fakeactive')
self.api.deny_access(self.context, share, access) self.api.deny_access(self.context, share, access)
db_driver.share_access_update.assert_called_once_with( db_driver.share_access_update.assert_called_once_with(
@ -1266,7 +1278,7 @@ class ShareAPITestCase(test.TestCase):
self.context, share, access) self.context, share, access)
def test_deny_access_not_active_not_error(self): def test_deny_access_not_active_not_error(self):
share = fake_share('fakeid', status='available') share = fake_share('fakeid', status=constants.STATUS_AVAILABLE)
access = fake_access('fakaccid', state='fakenew') access = fake_access('fakaccid', state='fakenew')
self.assertRaises(exception.InvalidShareAccess, self.api.deny_access, self.assertRaises(exception.InvalidShareAccess, self.api.deny_access,
self.context, share, access) self.context, share, access)
@ -1274,7 +1286,7 @@ class ShareAPITestCase(test.TestCase):
self.context, 'share', 'deny_access') self.context, 'share', 'deny_access')
def test_deny_access_status_not_available(self): def test_deny_access_status_not_available(self):
share = fake_share('fakeid', status='error') share = fake_share('fakeid', status=constants.STATUS_ERROR)
self.assertRaises(exception.InvalidShare, self.api.deny_access, self.assertRaises(exception.InvalidShare, self.api.deny_access,
self.context, share, 'fakeacc') self.context, share, 'fakeacc')
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(

View File

@ -38,9 +38,9 @@ from manila import utils
class FakeAccessRule(object): class FakeAccessRule(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.STATE_ACTIVE = 'active' self.STATE_ACTIVE = constants.STATUS_ACTIVE
self.STATE_NEW = 'new' self.STATE_NEW = constants.STATUS_NEW
self.STATE_ERROR = 'error' self.STATE_ERROR = constants.STATUS_ERROR
self.access_type = 'fake_type' self.access_type = 'fake_type'
self.id = 'fake_id' self.id = 'fake_id'
for k, v in kwargs.items(): for k, v in kwargs.items():
@ -105,13 +105,13 @@ class ShareManagerTestCase(test.TestCase):
return db.share_access_create(context.get_admin_context(), access) return db.share_access_create(context.get_admin_context(), access)
@staticmethod @staticmethod
def _create_share_server(state='ACTIVE', share_network_id=None, host=None, def _create_share_server(state=None, share_network_id=None, host=None,
backend_details=None): backend_details=None):
"""Create a share server object.""" """Create a share server object."""
srv = {} srv = {}
srv['host'] = host srv['host'] = host
srv['share_network_id'] = share_network_id srv['share_network_id'] = share_network_id
srv['status'] = state srv['status'] = state or constants.STATUS_ACTIVE
share_srv = db.share_server_create(context.get_admin_context(), srv) share_srv = db.share_server_create(context.get_admin_context(), srv)
if backend_details: if backend_details:
db.share_server_backend_details_set( db.share_server_backend_details_set(
@ -180,13 +180,15 @@ class ShareManagerTestCase(test.TestCase):
access_type='fake_access_type', access='fake_access') access_type='fake_access_type', access='fake_access')
shares = [ shares = [
{'id': 'fake_id_1', 'status': 'available', }, {'id': 'fake_id_1', 'status': constants.STATUS_AVAILABLE},
{'id': 'fake_id_2', 'status': 'error', 'name': 'fake_name_2'}, {'id': 'fake_id_2',
{'id': 'fake_id_3', 'status': 'in-use', 'name': 'fake_name_3'}, 'status': constants.STATUS_ERROR,
'name': 'fake_name_2'},
{'id': 'fake_id_3', 'status': 'fake', 'name': 'fake_name_3'},
] ]
rules = [ rules = [
FakeAccessRule(state='active'), FakeAccessRule(state=constants.STATUS_ACTIVE),
FakeAccessRule(state='error'), FakeAccessRule(state=constants.STATUS_ERROR),
] ]
fake_export_locations = ['fake/path/1', 'fake/path'] fake_export_locations = ['fake/path/1', 'fake/path']
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
@ -244,9 +246,15 @@ class ShareManagerTestCase(test.TestCase):
raise exception.ManilaException(message="Fake raise") raise exception.ManilaException(message="Fake raise")
shares = [ shares = [
{'id': 'fake_id_1', 'status': 'available', 'name': 'fake_name_1'}, {'id': 'fake_id_1',
{'id': 'fake_id_2', 'status': 'error', 'name': 'fake_name_2'}, 'status': constants.STATUS_AVAILABLE,
{'id': 'fake_id_3', 'status': 'available', 'name': 'fake_name_3'}, 'name': 'fake_name_1'},
{'id': 'fake_id_2',
'status': constants.STATUS_ERROR,
'name': 'fake_name_2'},
{'id': 'fake_id_3',
'status': constants.STATUS_AVAILABLE,
'name': 'fake_name_3'},
] ]
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
self.mock_object(self.share_manager.db, self.mock_object(self.share_manager.db,
@ -297,13 +305,19 @@ class ShareManagerTestCase(test.TestCase):
raise exception.ManilaException(message="Fake raise") raise exception.ManilaException(message="Fake raise")
shares = [ shares = [
{'id': 'fake_id_1', 'status': 'available', 'name': 'fake_name_1'}, {'id': 'fake_id_1',
{'id': 'fake_id_2', 'status': 'error', 'name': 'fake_name_2'}, 'status': constants.STATUS_AVAILABLE,
{'id': 'fake_id_3', 'status': 'available', 'name': 'fake_name_3'}, 'name': 'fake_name_1'},
{'id': 'fake_id_2',
'status': constants.STATUS_ERROR,
'name': 'fake_name_2'},
{'id': 'fake_id_3',
'status': constants.STATUS_AVAILABLE,
'name': 'fake_name_3'},
] ]
rules = [ rules = [
FakeAccessRule(state='active'), FakeAccessRule(state=constants.STATUS_ACTIVE),
FakeAccessRule(state='error'), FakeAccessRule(state=constants.STATUS_ERROR),
] ]
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
self.mock_object(self.share_manager.db, self.mock_object(self.share_manager.db,
@ -383,7 +397,7 @@ class ShareManagerTestCase(test.TestCase):
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'available') self.assertEqual(shr['status'], constants.STATUS_AVAILABLE)
self.assertEqual(shr['share_server_id'], server['id']) self.assertEqual(shr['share_server_id'], server['id'])
def test_create_share_from_snapshot_with_server_not_found(self): def test_create_share_from_snapshot_with_server_not_found(self):
@ -403,7 +417,7 @@ class ShareManagerTestCase(test.TestCase):
) )
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'error') self.assertEqual(shr['status'], constants.STATUS_ERROR)
def test_create_share_from_snapshot(self): def test_create_share_from_snapshot(self):
"""Test share can be created from snapshot.""" """Test share can be created from snapshot."""
@ -418,7 +432,7 @@ class ShareManagerTestCase(test.TestCase):
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'available') self.assertEqual(shr['status'], constants.STATUS_AVAILABLE)
self.assertTrue(len(shr['export_location']) > 0) self.assertTrue(len(shr['export_location']) > 0)
self.assertEqual(2, len(shr['export_locations'])) self.assertEqual(2, len(shr['export_locations']))
@ -444,7 +458,7 @@ class ShareManagerTestCase(test.TestCase):
snapshot_id).share_id) snapshot_id).share_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], 'available') self.assertEqual(snap['status'], constants.STATUS_AVAILABLE)
self.share_manager.delete_snapshot(self.context, snapshot_id) self.share_manager.delete_snapshot(self.context, snapshot_id)
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
@ -473,14 +487,15 @@ class ShareManagerTestCase(test.TestCase):
self.context, share_id, snapshot_id) self.context, share_id, snapshot_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], 'error') self.assertEqual(snap['status'], constants.STATUS_ERROR)
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.delete_snapshot, self.share_manager.delete_snapshot,
self.context, snapshot_id) self.context, snapshot_id)
self.assertEqual('error_deleting', db.share_snapshot_get( self.assertEqual(
self.context, snapshot_id).status) constants.STATUS_ERROR_DELETING,
db.share_snapshot_get(self.context, snapshot_id).status)
self.share_manager.driver.create_snapshot.assert_called_once_with( self.share_manager.driver.create_snapshot.assert_called_once_with(
self.context, utils.IsAMatcher(models.ShareSnapshot), self.context, utils.IsAMatcher(models.ShareSnapshot),
share_server=None) share_server=None)
@ -497,14 +512,14 @@ class ShareManagerTestCase(test.TestCase):
self.mock_object(self.share_manager.driver, "delete_snapshot", self.mock_object(self.share_manager.driver, "delete_snapshot",
mock.Mock(side_effect=_raise_share_snapshot_is_busy)) mock.Mock(side_effect=_raise_share_snapshot_is_busy))
share = self._create_share(status='ACTIVE') share = self._create_share(status=constants.STATUS_ACTIVE)
snapshot = self._create_snapshot(share_id=share['id']) snapshot = self._create_snapshot(share_id=share['id'])
snapshot_id = snapshot['id'] snapshot_id = snapshot['id']
self.share_manager.delete_snapshot(self.context, snapshot_id) self.share_manager.delete_snapshot(self.context, snapshot_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], 'available') self.assertEqual(snap['status'], constants.STATUS_AVAILABLE)
self.share_manager.driver.delete_snapshot.assert_called_once_with( self.share_manager.driver.delete_snapshot.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
utils.IsAMatcher(models.ShareSnapshot), utils.IsAMatcher(models.ShareSnapshot),
@ -531,7 +546,7 @@ class ShareManagerTestCase(test.TestCase):
utils.IsAMatcher(context.RequestContext), share_id) utils.IsAMatcher(context.RequestContext), share_id)
self.share_manager.db.share_update.assert_called_once_with( self.share_manager.db.share_update.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), share_id, utils.IsAMatcher(context.RequestContext), share_id,
{'status': 'error'}) {'status': constants.STATUS_ERROR})
def test_create_share_with_share_network_server_not_exists(self): def test_create_share_with_share_network_server_not_exists(self):
"""Test share can be created without share server.""" """Test share can be created without share server."""
@ -598,7 +613,7 @@ class ShareManagerTestCase(test.TestCase):
mock.call( mock.call(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
fake_share['id'], fake_share['id'],
{'status': 'error'}, {'status': constants.STATUS_ERROR},
) )
]) ])
self.share_manager._setup_server.assert_called_once_with( self.share_manager._setup_server.assert_called_once_with(
@ -616,7 +631,7 @@ class ShareManagerTestCase(test.TestCase):
share_id share_id
) )
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'error') self.assertEqual(shr['status'], constants.STATUS_ERROR)
def test_create_share_with_share_network_server_exists(self): def test_create_share_with_share_network_server_exists(self):
"""Test share can be created with existing share server.""" """Test share can be created with existing share server."""
@ -635,7 +650,7 @@ class ShareManagerTestCase(test.TestCase):
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'available') self.assertEqual(shr['status'], constants.STATUS_AVAILABLE)
self.assertEqual(shr['share_server_id'], share_srv['id']) self.assertEqual(shr['share_server_id'], share_srv['id'])
self.assertTrue(len(shr['export_location']) > 0) self.assertTrue(len(shr['export_location']) > 0)
self.assertEqual(1, len(shr['export_locations'])) self.assertEqual(1, len(shr['export_locations']))
@ -665,7 +680,7 @@ class ShareManagerTestCase(test.TestCase):
share = self._create_share(share_network_id=share_net['id']) share = self._create_share(share_network_id=share_net['id'])
self._create_share_server( self._create_share_server(
share_network_id=share_net['id'], host=self.share_manager.host, share_network_id=share_net['id'], host=self.share_manager.host,
state='ERROR') state=constants.STATUS_ERROR)
share_id = share['id'] share_id = share['id']
fake_server = {'id': 'fake_srv_id'} fake_server = {'id': 'fake_srv_id'}
self.mock_object(db, 'share_server_create', self.mock_object(db, 'share_server_create',
@ -678,7 +693,7 @@ class ShareManagerTestCase(test.TestCase):
self.assertEqual(share_id, db.share_get(context.get_admin_context(), self.assertEqual(share_id, db.share_get(context.get_admin_context(),
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'available') self.assertEqual(shr['status'], constants.STATUS_AVAILABLE)
self.assertEqual(shr['share_server_id'], 'fake_srv_id') self.assertEqual(shr['share_server_id'], 'fake_srv_id')
db.share_server_create.assert_called_once_with( db.share_server_create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), mock.ANY) utils.IsAMatcher(context.RequestContext), mock.ANY)
@ -704,14 +719,14 @@ class ShareManagerTestCase(test.TestCase):
share_id) share_id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'error') self.assertEqual(shr['status'], constants.STATUS_ERROR)
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.delete_share, self.share_manager.delete_share,
self.context, self.context,
share_id) share_id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], 'error_deleting') self.assertEqual(shr['status'], constants.STATUS_ERROR_DELETING)
self.share_manager.driver.create_share.assert_called_once_with( self.share_manager.driver.create_share.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
utils.IsAMatcher(models.Share), utils.IsAMatcher(models.Share),
@ -844,7 +859,8 @@ class ShareManagerTestCase(test.TestCase):
else: else:
self.assertFalse( self.assertFalse(
self.share_manager.db.share_export_locations_update.called) self.share_manager.db.share_export_locations_update.called)
valid_share_data = {'status': 'available', 'launched_at': mock.ANY} valid_share_data = {
'status': constants.STATUS_AVAILABLE, 'launched_at': mock.ANY}
valid_share_data.update(driver_data) valid_share_data.update(driver_data)
self.share_manager.db.share_update.assert_called_once_with( self.share_manager.db.share_update.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
@ -1138,7 +1154,7 @@ class ShareManagerTestCase(test.TestCase):
access_id) access_id)
acs = db.share_access_get(self.context, access_id) acs = db.share_access_get(self.context, access_id)
self.assertEqual(acs['state'], 'error') self.assertEqual(acs['state'], constants.STATUS_ERROR)
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.deny_access, self.share_manager.deny_access,
@ -1146,7 +1162,7 @@ class ShareManagerTestCase(test.TestCase):
access_id) access_id)
acs = db.share_access_get(self.context, access_id) acs = db.share_access_get(self.context, access_id)
self.assertEqual(acs['state'], 'error') self.assertEqual(acs['state'], constants.STATUS_ERROR)
def test_setup_server(self): def test_setup_server(self):
# Setup required test data # Setup required test data
@ -1373,13 +1389,16 @@ class ShareManagerTestCase(test.TestCase):
for k, v in details.items()] for k, v in details.items()]
self.assertEqual(expected, details_mock.call_args_list) self.assertEqual(expected, details_mock.call_args_list)
self.share_manager.db.share_server_update.assert_called_once_with( self.share_manager.db.share_server_update.assert_called_once_with(
self.context, share_server['id'], {'status': 'ERROR'}) self.context,
share_server['id'],
{'status': constants.STATUS_ERROR})
self.share_manager.driver.deallocate_network.assert_called_once_with( self.share_manager.driver.deallocate_network.assert_called_once_with(
self.context, share_server['id'] self.context, share_server['id']
) )
def test_ensure_share_has_pool_with_only_host(self): def test_ensure_share_has_pool_with_only_host(self):
fake_share = {'status': 'available', 'host': 'host1', 'id': 1} fake_share = {
'status': constants.STATUS_AVAILABLE, 'host': 'host1', 'id': 1}
host = self.share_manager._ensure_share_has_pool(context. host = self.share_manager._ensure_share_has_pool(context.
get_admin_context(), get_admin_context(),
fake_share) fake_share)
@ -1387,7 +1406,7 @@ class ShareManagerTestCase(test.TestCase):
def test_ensure_share_has_pool_with_full_pool_name(self): def test_ensure_share_has_pool_with_full_pool_name(self):
fake_share = {'host': 'host1#pool0', 'id': 1, fake_share = {'host': 'host1#pool0', 'id': 1,
'status': 'available'} 'status': constants.STATUS_AVAILABLE}
fake_share_expected_value = 'pool0' fake_share_expected_value = 'pool0'
host = self.share_manager._ensure_share_has_pool(context. host = self.share_manager._ensure_share_has_pool(context.
get_admin_context(), get_admin_context(),
@ -1396,7 +1415,7 @@ class ShareManagerTestCase(test.TestCase):
def test_ensure_share_has_pool_unable_to_fetch_share(self): def test_ensure_share_has_pool_unable_to_fetch_share(self):
fake_share = {'host': 'host@backend', 'id': 1, fake_share = {'host': 'host@backend', 'id': 1,
'status': 'available'} 'status': constants.STATUS_AVAILABLE}
with mock.patch.object(self.share_manager.driver, 'get_pool', with mock.patch.object(self.share_manager.driver, 'get_pool',
side_effect=Exception): side_effect=Exception):
with mock.patch.object(manager, 'LOG') as mock_LOG: with mock.patch.object(manager, 'LOG') as mock_LOG:

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six import six
from manila.common import constants
from manila import context from manila import context
from manila import db from manila import db
from manila.share import rpcapi as share_rpcapi from manila.share import rpcapi as share_rpcapi
@ -38,7 +39,7 @@ class ShareRpcAPITestCase(test.TestCase):
shr = {} shr = {}
shr['host'] = 'fake_host' shr['host'] = 'fake_host'
shr['availability_zone'] = CONF.storage_availability_zone shr['availability_zone'] = CONF.storage_availability_zone
shr['status'] = "available" shr['status'] = constants.STATUS_AVAILABLE
share = db.share_create(self.context, shr) share = db.share_create(self.context, shr)
acs = {} acs = {}
acs['access_type'] = "ip" acs['access_type'] = "ip"

View File

@ -17,6 +17,7 @@
from oslo_utils import uuidutils from oslo_utils import uuidutils
from manila.common import constants
from manila import context from manila import context
from manila import db from manila import db
from manila import exception from manila import exception
@ -36,7 +37,7 @@ class ShareServerTableTestCase(test.TestCase):
values = { values = {
'share_network_id': uuidutils.generate_uuid(), 'share_network_id': uuidutils.generate_uuid(),
'host': 'host1', 'host': 'host1',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
return db.share_server_create(self.ctxt, values) return db.share_server_create(self.ctxt, values)
@ -44,7 +45,7 @@ class ShareServerTableTestCase(test.TestCase):
values = { values = {
'share_network_id': 'fake-share-net-id', 'share_network_id': 'fake-share-net-id',
'host': 'hostname', 'host': 'hostname',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE
} }
expected = self._create_share_server(values) expected = self._create_share_server(values)
server = db.share_server_get(self.ctxt, expected['id']) server = db.share_server_get(self.ctxt, expected['id'])
@ -62,7 +63,7 @@ class ShareServerTableTestCase(test.TestCase):
values = { values = {
'share_network_id': 'fake-share-net-id', 'share_network_id': 'fake-share-net-id',
'host': 'hostname', 'host': 'hostname',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
server = self._create_share_server(values) server = self._create_share_server(values)
self.assertTrue(server['id']) self.assertTrue(server['id'])
@ -87,7 +88,7 @@ class ShareServerTableTestCase(test.TestCase):
update = { update = {
'share_network_id': 'update_net', 'share_network_id': 'update_net',
'host': 'update_host', 'host': 'update_host',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
server = self._create_share_server() server = self._create_share_server()
updated_server = db.share_server_update(self.ctxt, server['id'], updated_server = db.share_server_update(self.ctxt, server['id'],
@ -108,17 +109,17 @@ class ShareServerTableTestCase(test.TestCase):
valid = { valid = {
'share_network_id': '1', 'share_network_id': '1',
'host': 'host1', 'host': 'host1',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
invalid = { invalid = {
'share_network_id': '1', 'share_network_id': '1',
'host': 'host1', 'host': 'host1',
'status': 'ERROR' 'status': constants.STATUS_ERROR,
} }
other = { other = {
'share_network_id': '2', 'share_network_id': '2',
'host': 'host2', 'host': 'host2',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
valid = self._create_share_server(valid) valid = self._create_share_server(valid)
self._create_share_server(invalid) self._create_share_server(invalid)
@ -139,17 +140,17 @@ class ShareServerTableTestCase(test.TestCase):
srv1 = { srv1 = {
'share_network_id': '1', 'share_network_id': '1',
'host': 'host1', 'host': 'host1',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
srv2 = { srv2 = {
'share_network_id': '1', 'share_network_id': '1',
'host': 'host1', 'host': 'host1',
'status': 'ERROR' 'status': constants.STATUS_ERROR,
} }
srv3 = { srv3 = {
'share_network_id': '2', 'share_network_id': '2',
'host': 'host2', 'host': 'host2',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
servers = db.share_server_get_all(self.ctxt) servers = db.share_server_get_all(self.ctxt)
self.assertEqual(len(servers), 0) self.assertEqual(len(servers), 0)
@ -188,7 +189,7 @@ class ShareServerTableTestCase(test.TestCase):
values = { values = {
'share_network_id': 'fake-share-net-id', 'share_network_id': 'fake-share-net-id',
'host': 'hostname', 'host': 'hostname',
'status': 'ACTIVE' 'status': constants.STATUS_ACTIVE,
} }
details = { details = {
'value1': '1', 'value1': '1',

View File

@ -21,6 +21,7 @@ from oslo_config import cfg
from oslo_utils import timeutils from oslo_utils import timeutils
import testtools import testtools
from manila.common import constants
from manila import context from manila import context
from manila import db from manila import db
from manila.db.sqlalchemy import api as sqa_api from manila.db.sqlalchemy import api as sqa_api
@ -51,7 +52,7 @@ class QuotaIntegrationTestCase(test.TestCase):
share['user_id'] = self.user_id share['user_id'] = self.user_id
share['project_id'] = self.project_id share['project_id'] = self.project_id
share['size'] = size share['size'] = size
share['status'] = 'available' share['status'] = constants.STATUS_AVAILABLE
share['host'] = 'fake_host' share['host'] = 'fake_host'
return db.share_create(self.context, share) return db.share_create(self.context, share)
@ -62,7 +63,7 @@ class QuotaIntegrationTestCase(test.TestCase):
snapshot['share_id'] = share['id'] snapshot['share_id'] = share['id']
snapshot['share_size'] = share['size'] snapshot['share_size'] = share['size']
snapshot['host'] = share['host'] snapshot['host'] = share['host']
snapshot['status'] = 'available' snapshot['status'] = constants.STATUS_AVAILABLE
return db.share_snapshot_create(self.context, snapshot) return db.share_snapshot_create(self.context, snapshot)
@testtools.skip("SQLAlchemy sqlite insert bug") @testtools.skip("SQLAlchemy sqlite insert bug")