From 4f3ab586870600201400f2aaf49895afcc377142 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 6 Jun 2016 13:38:24 -0400 Subject: [PATCH] Implement Instance Upgrade This change includes a new "trove upgrade" CLI command and a new "Instances.upgrade" python API method to implement the new Instance Upgrade feature. Change-Id: I6ec2ebb78019c014f87ba5d8cbfd284686c64f30 Implements: blueprint image-upgrade --- .../notes/image-upgrade-dfa20861d756532d.yaml | 5 +++++ troveclient/tests/test_instances.py | 10 ++++++++++ troveclient/tests/test_v1_shell.py | 4 ++++ troveclient/v1/instances.py | 12 ++++++++++++ troveclient/v1/shell.py | 14 ++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 releasenotes/notes/image-upgrade-dfa20861d756532d.yaml diff --git a/releasenotes/notes/image-upgrade-dfa20861d756532d.yaml b/releasenotes/notes/image-upgrade-dfa20861d756532d.yaml new file mode 100644 index 00000000..2a885752 --- /dev/null +++ b/releasenotes/notes/image-upgrade-dfa20861d756532d.yaml @@ -0,0 +1,5 @@ +--- +features: + - Add a new trove upgrade CLI command and a new + Instances.upgrade python API method to implement + the new Instance Upgrade feature. diff --git a/troveclient/tests/test_instances.py b/troveclient/tests/test_instances.py index 67453d87..89028fc0 100644 --- a/troveclient/tests/test_instances.py +++ b/troveclient/tests/test_instances.py @@ -238,6 +238,16 @@ class InstancesTest(testtools.TestCase): resp.status_code = 500 self.assertRaises(Exception, self.instances.edit, 'instance1') + def test_upgrade(self): + resp = mock.Mock() + resp.status_code = 200 + body = None + self.instances.api.client.patch = mock.Mock(return_value=(resp, body)) + self.instances.upgrade(self.instance_with_id, "5.6") + resp.status_code = 500 + self.assertRaises(Exception, self.instances.upgrade, + 'instance1') + def test_configuration(self): def side_effect_func(path, inst): return path, inst diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 00896f7f..eabd2149 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -608,6 +608,10 @@ class ShellTest(utils.TestCase): self.run_command('configuration-detach 1234') self.assert_called('PUT', '/instances/1234') + def test_upgrade(self): + self.run_command('upgrade 1234 c-123') + self.assert_called('PATCH', '/instances/1234') + def test_metadata_edit(self): self.run_command('metadata-edit 1234 key-123 value-123') self.assert_called('PATCH', '/instances/1234/metadata/key-123') diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index 54738c19..53946706 100644 --- a/troveclient/v1/instances.py +++ b/troveclient/v1/instances.py @@ -167,6 +167,18 @@ class Instances(base.ManagerWithFind): resp, body = self.api.client.patch(url, body=body) common.check_for_exceptions(resp, body, url) + def upgrade(self, instance, datastore_version): + """Upgrades an instance with a new datastore version.""" + body = { + "instance": { + "datastore_version": datastore_version + } + } + + url = "/instances/%s" % base.getid(instance) + resp, body = self.api.client.patch(url, body=body) + common.check_for_exceptions(resp, body, url) + def list(self, limit=None, marker=None, include_clustered=False): """Get a list of all instances. diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 6eca9507..695a122a 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -759,6 +759,20 @@ def do_resize_instance(cs, args): cs.instances.resize_instance(instance, flavor_id) +@utils.arg('instance', + metavar='', + type=str, + help='ID or name of the instance.') +@utils.arg('datastore_version', + metavar='', + help='A datastore version name or ID.') +@utils.service_type('database') +def do_upgrade(cs, args): + """Upgrades an instance to a new datastore version.""" + instance = _find_instance(cs, args.instance) + cs.instances.upgrade(instance, args.datastore_version) + + @utils.arg('instance', metavar='', type=str,