Merge "add share server update to manila-manage share update_host"
This commit is contained in:
commit
3b19c3ff25
@ -375,7 +375,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
|
||||
@ -389,6 +389,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,
|
||||
|
@ -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)
|
||||
|
||||
|
||||
##################
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -426,13 +426,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)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
The ``manila-manage share update_host`` command now updates the host
|
||||
attribute of share servers in addition to shares.
|
Loading…
Reference in New Issue
Block a user