add share server update to manila-manage share update_host

Change-Id: Ifb19d926a84fae986b8d296959cfce71bf0c2e9e
Closes-Bug: #1881098
This commit is contained in:
Maurice Escher 2020-05-26 18:22:54 +02:00
parent 82f01bd17f
commit 365cfa3516
No known key found for this signature in database
GPG Key ID: CC56DEC23EE46750
5 changed files with 40 additions and 5 deletions

View File

@ -364,7 +364,7 @@ class ShareCommands(object):
@args('--force', required=False, type=bool, default=False,
help="Ignore validations.")
def update_host(self, current_host, new_host, force=False):
"""Modify the host name associated with a share.
"""Modify the host name associated with a share and share server.
Particularly to recover from cases where one has moved
their Manila Share node, or modified their 'host' opt
@ -378,6 +378,11 @@ class ShareCommands(object):
"to %(nhost)s." % {'count': updated, 'chost': current_host,
'nhost': new_host})
servers = db.share_servers_host_update(ctxt, current_host, new_host)
print("Updated host of %(count)s share servers on %(chost)s "
"to %(nhost)s." % {'count': servers, 'chost': current_host,
'nhost': new_host})
CATEGORIES = {
'config': ConfigCommands,

View File

@ -991,6 +991,11 @@ def share_server_backend_details_set(context, share_server_id, server_details):
server_details)
def share_servers_host_update(context, current_host, new_host):
"""Update the host attr of all share servers that are on current_host."""
return IMPL.share_servers_host_update(context, current_host, new_host)
##################

View File

@ -3867,6 +3867,20 @@ def share_server_backend_details_delete(context, share_server_id,
item.soft_delete(session)
@require_admin_context
def share_servers_host_update(context, current_host, new_host):
session = get_session()
host_field = models.ShareServer.host
with session.begin():
query = model_query(
context, models.ShareServer, session=session, read_deleted="no",
).filter(host_field.like('{}%'.format(current_host)))
result = query.update(
{host_field: func.replace(host_field, current_host, new_host)},
synchronize_session=False)
return result
###################
def _driver_private_data_query(session, context, entity_id, key=None,

View File

@ -392,13 +392,19 @@ class ManilaCmdManageTestCase(test.TestCase):
mock.Mock(return_value='admin_ctxt'))
self.mock_object(db, 'share_instances_host_update',
mock.Mock(return_value=20))
self.mock_object(db, 'share_servers_host_update',
mock.Mock(return_value=5))
with mock.patch('sys.stdout', new=six.StringIO()) as intercepted_op:
self.share_cmds.update_host(current_host, new_host, force)
expected_op = ("Updated host of 20 share instances on "
"%(chost)s to %(nhost)s." %
{'chost': current_host, 'nhost': new_host})
self.assertEqual(expected_op, intercepted_op.getvalue().strip())
expected_op_si = ("Updated host of 20 share instances on "
"%(chost)s to %(nhost)s." %
{'chost': current_host, 'nhost': new_host})
expected_op_sv = ("Updated host of 5 share servers on "
"%(chost)s to %(nhost)s." %
{'chost': current_host, 'nhost': new_host})
self.assertEqual(expected_op_si + "\n" + expected_op_sv,
intercepted_op.getvalue().strip())
db.share_instances_host_update.assert_called_once_with(
'admin_ctxt', current_host, new_host)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
The ``manila-manage share update_host`` command now updates the host
attribute of share servers in addition to shares.