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:
Douglas Viroel 2019-09-23 17:39:00 -03:00
parent 09f5813078
commit 914fa7fdcb
5 changed files with 30 additions and 42 deletions

View File

@ -960,12 +960,12 @@ def share_server_search_by_identifier(context, identifier, session=None):
context, identifier, session=session)
def share_server_get_all_by_host_and_share_net_valid(context, host,
share_net_id,
session=None):
def share_server_get_all_by_host_and_share_subnet_valid(context, host,
share_subnet_id,
session=None):
"""Get share server DB records by host and share net not error."""
return IMPL.share_server_get_all_by_host_and_share_net_valid(
context, host, share_net_id, session=session)
return IMPL.share_server_get_all_by_host_and_share_subnet_valid(
context, host, share_subnet_id, session=session)
def share_server_get_all(context):

View File

@ -42,7 +42,7 @@ from oslo_utils import uuidutils
import six
from sqlalchemy import MetaData
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 true
from sqlalchemy.sql import func
@ -3719,30 +3719,19 @@ def share_server_search_by_identifier(context, identifier, session=None):
@require_context
def share_server_get_all_by_host_and_share_net_valid(context, host,
share_net_id,
session=None):
# Get subnets by share_net_id
subnets = (_network_subnet_get_query(context, session)
.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))
def share_server_get_all_by_host_and_share_subnet_valid(context, host,
share_subnet_id,
session=None):
result = (_server_get_query(context, session).filter_by(host=host)
.filter_by(share_network_subnet_id=share_subnet_id)
.filter(models.ShareServer.status.in_(
(constants.STATUS_CREATING,
constants.STATUS_ACTIVE))).all())
(constants.STATUS_CREATING,
constants.STATUS_ACTIVE))).all())
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'
' "%(status_cr)s" or "%(status_act)s"') % {
'share_net_id': share_net_id,
'share_net_id': share_subnet_id,
'host': host,
'status_cr': constants.STATUS_CREATING,
'status_act': constants.STATUS_ACTIVE,

View File

@ -566,17 +566,15 @@ class ShareManager(manager.SchedulerDependentManager):
elif 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():
if parent_share_server:
return [parent_share_server]
else:
return (
self.db.share_server_get_all_by_host_and_share_net_valid(
context, self.host, share_network_id)
self.db
.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,
@ -751,8 +749,9 @@ class ShareManager(manager.SchedulerDependentManager):
def _wrapped_provide_share_server_for_share_group():
try:
available_share_servers = (
self.db.share_server_get_all_by_host_and_share_net_valid(
context, self.host, share_network_id))
self.db
.share_server_get_all_by_host_and_share_subnet_valid(
context, self.host, share_network_subnet_id))
except exception.ShareServerNotFound:
available_share_servers = None

View File

@ -2681,17 +2681,17 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
db_utils.create_share_server(**invalid)
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,
host='host1',
share_net_id='1')
share_subnet_id='1')
self.assertEqual(valid['id'], servers[0]['id'])
def test_get_all_by_host_and_share_net_not_found(self):
self.assertRaises(
exception.ShareServerNotFound,
db_api.share_server_get_all_by_host_and_share_net_valid,
self.ctxt, host='fake', share_net_id='fake'
db_api.share_server_get_all_by_host_and_share_subnet_valid,
self.ctxt, host='fake', share_subnet_id='fake'
)
def test_get_all(self):

View File

@ -2096,7 +2096,7 @@ class ShareManagerTestCase(test.TestCase):
raise exception.ManilaException()
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))
self.mock_object(self.share_manager, '_setup_server',
mock.Mock(side_effect=raise_manila_exception))
@ -2107,11 +2107,11 @@ class ShareManagerTestCase(test.TestCase):
self.context,
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(
utils.IsAMatcher(context.RequestContext),
self.share_manager.host,
fake_share['share_network_id'],
share_net_subnet['id'],
))
db.share_server_create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), mock.ANY)
@ -2386,7 +2386,7 @@ class ShareManagerTestCase(test.TestCase):
db, 'share_network_subnet_get_by_availability_zone_id',
mock.Mock(return_value=fake_share_net_subnet))
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]))
self.mock_object(
self.share_manager.driver,
@ -2468,7 +2468,7 @@ class ShareManagerTestCase(test.TestCase):
sg = db_utils.create_share_group()
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]))
self.mock_object(
self.share_manager.driver,