Retrieve compatible share servers using subnet id
When searching for compatible share servers, the share manager now looks for share servers that matches the destination host and the related share network subnet id. Change-Id: I62b80e24df443789359bb8d7ceaaf3d704366bc9
This commit is contained in:
parent
09f5813078
commit
914fa7fdcb
@ -960,12 +960,12 @@ def share_server_search_by_identifier(context, identifier, session=None):
|
|||||||
context, identifier, session=session)
|
context, identifier, session=session)
|
||||||
|
|
||||||
|
|
||||||
def share_server_get_all_by_host_and_share_net_valid(context, host,
|
def share_server_get_all_by_host_and_share_subnet_valid(context, host,
|
||||||
share_net_id,
|
share_subnet_id,
|
||||||
session=None):
|
session=None):
|
||||||
"""Get share server DB records by host and share net not error."""
|
"""Get share server DB records by host and share net not error."""
|
||||||
return IMPL.share_server_get_all_by_host_and_share_net_valid(
|
return IMPL.share_server_get_all_by_host_and_share_subnet_valid(
|
||||||
context, host, share_net_id, session=session)
|
context, host, share_subnet_id, session=session)
|
||||||
|
|
||||||
|
|
||||||
def share_server_get_all(context):
|
def share_server_get_all(context):
|
||||||
|
@ -42,7 +42,7 @@ from oslo_utils import uuidutils
|
|||||||
import six
|
import six
|
||||||
from sqlalchemy import MetaData
|
from sqlalchemy import MetaData
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
from sqlalchemy.orm import joinedload, load_only
|
from sqlalchemy.orm import joinedload
|
||||||
from sqlalchemy.sql.expression import literal
|
from sqlalchemy.sql.expression import literal
|
||||||
from sqlalchemy.sql.expression import true
|
from sqlalchemy.sql.expression import true
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
@ -3719,30 +3719,19 @@ def share_server_search_by_identifier(context, identifier, session=None):
|
|||||||
|
|
||||||
|
|
||||||
@require_context
|
@require_context
|
||||||
def share_server_get_all_by_host_and_share_net_valid(context, host,
|
def share_server_get_all_by_host_and_share_subnet_valid(context, host,
|
||||||
share_net_id,
|
share_subnet_id,
|
||||||
session=None):
|
session=None):
|
||||||
# Get subnets by share_net_id
|
result = (_server_get_query(context, session).filter_by(host=host)
|
||||||
subnets = (_network_subnet_get_query(context, session)
|
.filter_by(share_network_subnet_id=share_subnet_id)
|
||||||
.filter_by(share_network_id=share_net_id)
|
|
||||||
.options(load_only("id"))
|
|
||||||
.all())
|
|
||||||
subnet_ids = [s.id for s in subnets]
|
|
||||||
|
|
||||||
# Retrieve servers by the retrieved subnet ids
|
|
||||||
result = (_server_get_query(context, session)
|
|
||||||
.filter_by(host=host)
|
|
||||||
.filter(models.ShareServer.share_network_subnet_id.in_(
|
|
||||||
subnet_ids))
|
|
||||||
.filter(models.ShareServer.status.in_(
|
.filter(models.ShareServer.status.in_(
|
||||||
(constants.STATUS_CREATING,
|
(constants.STATUS_CREATING,
|
||||||
constants.STATUS_ACTIVE))).all())
|
constants.STATUS_ACTIVE))).all())
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
filters_description = ('share_network_id is "%(share_net_id)s",'
|
filters_description = ('share_network_subnet_id is "%(share_net_id)s",'
|
||||||
' host is "%(host)s" and status in'
|
' host is "%(host)s" and status in'
|
||||||
' "%(status_cr)s" or "%(status_act)s"') % {
|
' "%(status_cr)s" or "%(status_act)s"') % {
|
||||||
'share_net_id': share_net_id,
|
'share_net_id': share_subnet_id,
|
||||||
'host': host,
|
'host': host,
|
||||||
'status_cr': constants.STATUS_CREATING,
|
'status_cr': constants.STATUS_CREATING,
|
||||||
'status_act': constants.STATUS_ACTIVE,
|
'status_act': constants.STATUS_ACTIVE,
|
||||||
|
@ -566,17 +566,15 @@ class ShareManager(manager.SchedulerDependentManager):
|
|||||||
elif parent_share_server:
|
elif parent_share_server:
|
||||||
share_network_subnet_id = (
|
share_network_subnet_id = (
|
||||||
parent_share_server['share_network_subnet_id'])
|
parent_share_server['share_network_subnet_id'])
|
||||||
share_network_subnet = self.db.share_network_subnet_get(
|
|
||||||
context, share_network_subnet_id)
|
|
||||||
share_network_id = share_network_subnet['share_network_id']
|
|
||||||
|
|
||||||
def get_available_share_servers():
|
def get_available_share_servers():
|
||||||
if parent_share_server:
|
if parent_share_server:
|
||||||
return [parent_share_server]
|
return [parent_share_server]
|
||||||
else:
|
else:
|
||||||
return (
|
return (
|
||||||
self.db.share_server_get_all_by_host_and_share_net_valid(
|
self.db
|
||||||
context, self.host, share_network_id)
|
.share_server_get_all_by_host_and_share_subnet_valid(
|
||||||
|
context, self.host, share_network_subnet_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
@utils.synchronized("share_manager_%s" % share_network_subnet_id,
|
@utils.synchronized("share_manager_%s" % share_network_subnet_id,
|
||||||
@ -751,8 +749,9 @@ class ShareManager(manager.SchedulerDependentManager):
|
|||||||
def _wrapped_provide_share_server_for_share_group():
|
def _wrapped_provide_share_server_for_share_group():
|
||||||
try:
|
try:
|
||||||
available_share_servers = (
|
available_share_servers = (
|
||||||
self.db.share_server_get_all_by_host_and_share_net_valid(
|
self.db
|
||||||
context, self.host, share_network_id))
|
.share_server_get_all_by_host_and_share_subnet_valid(
|
||||||
|
context, self.host, share_network_subnet_id))
|
||||||
except exception.ShareServerNotFound:
|
except exception.ShareServerNotFound:
|
||||||
available_share_servers = None
|
available_share_servers = None
|
||||||
|
|
||||||
|
@ -2681,17 +2681,17 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
|
|||||||
db_utils.create_share_server(**invalid)
|
db_utils.create_share_server(**invalid)
|
||||||
db_utils.create_share_server(**other)
|
db_utils.create_share_server(**other)
|
||||||
|
|
||||||
servers = db_api.share_server_get_all_by_host_and_share_net_valid(
|
servers = db_api.share_server_get_all_by_host_and_share_subnet_valid(
|
||||||
self.ctxt,
|
self.ctxt,
|
||||||
host='host1',
|
host='host1',
|
||||||
share_net_id='1')
|
share_subnet_id='1')
|
||||||
self.assertEqual(valid['id'], servers[0]['id'])
|
self.assertEqual(valid['id'], servers[0]['id'])
|
||||||
|
|
||||||
def test_get_all_by_host_and_share_net_not_found(self):
|
def test_get_all_by_host_and_share_net_not_found(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.ShareServerNotFound,
|
exception.ShareServerNotFound,
|
||||||
db_api.share_server_get_all_by_host_and_share_net_valid,
|
db_api.share_server_get_all_by_host_and_share_subnet_valid,
|
||||||
self.ctxt, host='fake', share_net_id='fake'
|
self.ctxt, host='fake', share_subnet_id='fake'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all(self):
|
def test_get_all(self):
|
||||||
|
@ -2096,7 +2096,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
raise exception.ManilaException()
|
raise exception.ManilaException()
|
||||||
|
|
||||||
self.mock_object(db,
|
self.mock_object(db,
|
||||||
'share_server_get_all_by_host_and_share_net_valid',
|
'share_server_get_all_by_host_and_share_subnet_valid',
|
||||||
mock.Mock(side_effect=raise_share_server_not_found))
|
mock.Mock(side_effect=raise_share_server_not_found))
|
||||||
self.mock_object(self.share_manager, '_setup_server',
|
self.mock_object(self.share_manager, '_setup_server',
|
||||||
mock.Mock(side_effect=raise_manila_exception))
|
mock.Mock(side_effect=raise_manila_exception))
|
||||||
@ -2107,11 +2107,11 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
self.context,
|
self.context,
|
||||||
fake_share.instance['id'],
|
fake_share.instance['id'],
|
||||||
)
|
)
|
||||||
(db.share_server_get_all_by_host_and_share_net_valid.
|
(db.share_server_get_all_by_host_and_share_subnet_valid.
|
||||||
assert_called_once_with(
|
assert_called_once_with(
|
||||||
utils.IsAMatcher(context.RequestContext),
|
utils.IsAMatcher(context.RequestContext),
|
||||||
self.share_manager.host,
|
self.share_manager.host,
|
||||||
fake_share['share_network_id'],
|
share_net_subnet['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)
|
||||||
@ -2386,7 +2386,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
db, 'share_network_subnet_get_by_availability_zone_id',
|
db, 'share_network_subnet_get_by_availability_zone_id',
|
||||||
mock.Mock(return_value=fake_share_net_subnet))
|
mock.Mock(return_value=fake_share_net_subnet))
|
||||||
self.mock_object(db,
|
self.mock_object(db,
|
||||||
'share_server_get_all_by_host_and_share_net_valid',
|
'share_server_get_all_by_host_and_share_subnet_valid',
|
||||||
mock.Mock(return_value=[fake_share_server]))
|
mock.Mock(return_value=[fake_share_server]))
|
||||||
self.mock_object(
|
self.mock_object(
|
||||||
self.share_manager.driver,
|
self.share_manager.driver,
|
||||||
@ -2468,7 +2468,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
sg = db_utils.create_share_group()
|
sg = db_utils.create_share_group()
|
||||||
|
|
||||||
self.mock_object(db,
|
self.mock_object(db,
|
||||||
'share_server_get_all_by_host_and_share_net_valid',
|
'share_server_get_all_by_host_and_share_subnet_valid',
|
||||||
mock.Mock(return_value=[fake_share_server]))
|
mock.Mock(return_value=[fake_share_server]))
|
||||||
self.mock_object(
|
self.mock_object(
|
||||||
self.share_manager.driver,
|
self.share_manager.driver,
|
||||||
|
Loading…
Reference in New Issue
Block a user