From 9e737a2cf8cee4be79f0c8a0efd14ef4d3dbdad0 Mon Sep 17 00:00:00 2001 From: Marcin Piwowarczyk Date: Mon, 2 Jul 2018 08:58:06 +0200 Subject: Support configuration groups for clusters Handles API part implemented in change: I7c0a22c6a0287128d0c37e100589c78173fd9c1a So far passing configuration group was possible only for single instance deployment. As the trove api now already supports configuration attach and detach for clusters, we are able to handle it in client. Configuration will be applied to each cluster instance. Partially implements: blueprint cluster-configuration-groups Change-Id: Ic0840c995cbc34203c76494d7ba522f3e17141a7 Signed-off-by: Marcin Piwowarczyk --- ...ation-groups-for-clusters-6183b0b7b4fb8c9e.yaml | 6 ++++++ troveclient/tests/test_clusters.py | 5 ++++- troveclient/tests/test_v1_shell.py | 22 ++++++++++++++++++++++ troveclient/v1/clusters.py | 4 +++- troveclient/v1/shell.py | 8 +++++++- 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml diff --git a/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml b/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml new file mode 100644 index 0000000..0c559b3 --- /dev/null +++ b/releasenotes/notes/add-configuration-groups-for-clusters-6183b0b7b4fb8c9e.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + A --configuration flag was added to the ``trove cluster-create`` + command, in order to allow a user to attach specific configuration + for cluster. diff --git a/troveclient/tests/test_clusters.py b/troveclient/tests/test_clusters.py index 64e243e..2545083 100644 --- a/troveclient/tests/test_clusters.py +++ b/troveclient/tests/test_clusters.py @@ -79,10 +79,12 @@ class ClustersTest(testtools.TestCase): 'configsvr_volume_type': 'foo_type', 'mongos_volume_size': 12, 'mongos_volume_type': 'bar_type'} + configuration = 'test-config' path, body, resp_key = clusters_test.create("test-name", "datastore", "datastore-version", instances, locality, - extended_properties) + extended_properties, + configuration) self.assertEqual("/clusters", path) self.assertEqual("cluster", resp_key) self.assertEqual("test-name", body["cluster"]["name"]) @@ -93,6 +95,7 @@ class ClustersTest(testtools.TestCase): self.assertEqual(locality, body["cluster"]["locality"]) self.assertEqual(extended_properties, body["cluster"]["extended_properties"]) + self.assertEqual(configuration, body["cluster"]["configuration"]) def test_list(self): page_mock = mock.Mock() diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 03cb725..eb18e48 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -516,6 +516,28 @@ class ShellTest(utils.TestCase): 'name': 'test-clstr2', 'locality': 'affinity'}}) + def test_cluster_create_with_configuration(self): + cmd = ('cluster-create test-clstr2 redis 3.0 ' + '--configuration=config01 ' + '--instance flavor=2,volume=1 ' + '--instance flavor=02,volume=1 ' + '--instance flavor=2,volume=1 ') + self.run_command(cmd) + self.assert_called_anytime( + 'POST', '/clusters', + {'cluster': { + 'instances': [ + {'flavorRef': '2', + 'volume': {'size': '1'}}, + {'flavorRef': '02', + 'volume': {'size': '1'}}, + {'flavorRef': '2', + 'volume': {'size': '1'}}, + ], + 'datastore': {'version': '3.0', 'type': 'redis'}, + 'name': 'test-clstr2', + 'configuration': 'config01'}}) + def test_cluster_create_with_extended_properties(self): cmd = ('cluster-create test-clstr3 mongodb 4.0 ' '--instance flavor=2,volume=1 ' diff --git a/troveclient/v1/clusters.py b/troveclient/v1/clusters.py index ae0380e..caa9d32 100644 --- a/troveclient/v1/clusters.py +++ b/troveclient/v1/clusters.py @@ -37,7 +37,7 @@ class Clusters(base.ManagerWithFind): resource_class = Cluster def create(self, name, datastore, datastore_version, instances=None, - locality=None, extended_properties=None): + locality=None, extended_properties=None, configuration=None): """Create (boot) a new cluster.""" body = {"cluster": { "name": name @@ -53,6 +53,8 @@ class Clusters(base.ManagerWithFind): body["cluster"]["locality"] = locality if extended_properties: body["cluster"]["extended_properties"] = extended_properties + if configuration: + body["cluster"]["configuration"] = configuration return self._create("/clusters", body, "cluster") diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index d5cc927..aef2529 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -894,6 +894,11 @@ def _parse_instance_options(cs, instance_options, for_grow=False): metavar=EXT_PROPS_METAVAR, default=None, help=EXT_PROPS_HELP) +@utils.arg('--configuration', + metavar='', + type=str, + default=None, + help=_('ID of the configuration group to attach to the cluster.')) @utils.service_type('database') def do_cluster_create(cs, args): """Creates a new cluster.""" @@ -908,7 +913,8 @@ def do_cluster_create(cs, args): args.datastore_version, instances=instances, locality=args.locality, - extended_properties=extended_properties) + extended_properties=extended_properties, + configuration=args.configuration) _print_cluster(cluster) -- cgit v1.2.1