Merge "Add support for module-reapply command"

This commit is contained in:
Jenkins 2017-01-09 21:39:07 +00:00 committed by Gerrit Code Review
commit e2a2263e19
6 changed files with 75 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- Add module-reapply command to facilitate
applying a module again to all instances
where it was previously applied. Bug 1554903

View File

@ -494,6 +494,9 @@ class FakeHTTPClient(base_client.HTTPClient):
return self.get_instance_counts()
return self.get_instances()
def put_modules_4321_instances(self, **kw):
return (202, {}, None)
def get_instances_modules(self, **kw):
return (200, {}, None)

View File

@ -145,3 +145,13 @@ class TestModules(testtools.TestCase):
def test_instances(self):
expected_query = {'include_clustered': True}
self._test_instances(expected_query)
def test_reapply(self):
resp = mock.Mock()
resp.status_code = 200
body = None
self.modules.api.client.put = mock.Mock(return_value=(resp, body))
self.modules.reapply(self.module_name)
self.modules.reapply(self.module)
resp.status_code = 500
self.assertRaises(Exception, self.modules.reapply, self.module_name)

View File

@ -737,6 +737,12 @@ class ShellTest(utils.TestCase):
'GET', '/modules/4321/instances?count_only=True&'
'include_clustered=True')
def test_module_reapply(self):
with mock.patch.object(troveclient.v1.modules.Module, '__repr__',
mock.Mock(return_value='4321')):
self.run_command('module-reapply 4321 --delay=5')
self.assert_called_anytime('PUT', '/modules/4321/instances')
def test_cluster_modules(self):
self.run_command('cluster-modules cls-1234')
self.assert_called_anytime('GET', '/clusters/cls-1234')

View File

@ -167,3 +167,24 @@ class Modules(base.ManagerWithFind):
query_strings['count_only'] = count_only
return self._paginated(url, "instances", limit, marker,
query_strings=query_strings)
def reapply(self, module, md5=None, include_clustered=None,
batch_size=None, delay=None, force=None):
"""Reapplies the specified module."""
url = "/modules/%s/instances" % base.getid(module)
body = {
"reapply": {
}
}
if md5:
body["reapply"]["md5"] = md5
if include_clustered is not None:
body["reapply"]["include_clustered"] = int(include_clustered)
if batch_size is not None:
body["reapply"]["batch_size"] = batch_size
if delay is not None:
body["reapply"]["batch_delay"] = delay
if force is not None:
body["reapply"]["force"] = int(force)
resp, body = self.api.client.put(url, body=body)
common.check_for_exceptions(resp, body, url)

View File

@ -1799,8 +1799,7 @@ def do_module_show(cs, args):
'Admin only.'))
@utils.arg('--live_update', action='store_true', default=False,
help=_('Allow module to be updated even if it is already applied '
'to a current instance or cluster. Automatically attempt to '
'reapply this module if the contents change.'))
'to a current instance or cluster.'))
@utils.arg('--priority_apply', action='store_true', default=False,
help=_('Sets a priority for applying the module. All priority '
'modules will be applied before non-priority ones. '
@ -1880,9 +1879,7 @@ def do_module_create(cs, args):
help=_('Allow all users to see this module. Admin only.'))
@utils.arg('--live_update', action='store_true', default=None,
help=_('Allow module to be updated or deleted even if it is '
'already applied to a current instance or cluster. '
'Automatically attempt to reapply this module if the '
'contents change.'))
'already applied to a current instance or cluster.'))
@utils.arg('--no_live_update', dest='live_update', action='store_false',
default=None,
help=_('Restricts a module from being updated or deleted if it is '
@ -1925,6 +1922,33 @@ def do_module_update(cs, args):
_print_object(updated_module)
@utils.arg('module', metavar='<module>', type=str,
help=_('Name or ID of the module.'))
@utils.arg('--md5', metavar='<md5>', type=str,
default=None,
help=_('Reapply the module only to instances applied '
'with the specific md5.'))
@utils.arg('--include_clustered', action='store_true', default=False,
help=_('Include instances that are part of a cluster '
'(default %(default)s).'))
@utils.arg('--batch_size', metavar='<batch_size>', type=int,
default=None,
help=_('Number of instances to reapply the module to before '
'sleeping.'))
@utils.arg('--delay', metavar='<delay>', type=int,
default=None,
help=_('Time to sleep in seconds between applying batches.'))
@utils.arg('--force', action='store_true', default=False,
help=_('Force reapply even on modules already having the '
'current MD5'))
@utils.service_type('database')
def do_module_reapply(cs, args):
"""Reapply a module."""
module = _find_module(cs, args.module)
cs.modules.reapply(module, args.md5, args.include_clustered,
args.batch_size, args.delay, args.force)
@utils.arg('module', metavar='<module>',
help=_('ID or name of the module.'))
@utils.service_type('database')