summaryrefslogtreecommitdiff
path: root/saharaclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-11-10 22:02:45 +0000
committerGerrit Code Review <review@openstack.org>2015-11-10 22:02:45 +0000
commite8a7f45825e3ad06e38dcf77bd4c49e3c1a66e5f (patch)
treec6e9e479a7d7b95d4010ceff93eee32cc0c9049a /saharaclient
parent9c4af1eedce044de0e8bd76e37e3995ce5fa2c73 (diff)
parent0ed4f10dfa7b0fb327c26dc3801ade00f3204480 (diff)
downloadpython-saharaclient-e8a7f45825e3ad06e38dcf77bd4c49e3c1a66e5f.tar.gz
Merge "Allowing for shares to be edited on an existing cluster"
Diffstat (limited to 'saharaclient')
-rw-r--r--saharaclient/api/clusters.py5
-rw-r--r--saharaclient/osc/v1/clusters.py18
-rw-r--r--saharaclient/tests/unit/osc/v1/test_clusters.py6
-rw-r--r--saharaclient/tests/unit/test_clusters.py28
4 files changed, 51 insertions, 6 deletions
diff --git a/saharaclient/api/clusters.py b/saharaclient/api/clusters.py
index 3c9941b..ba9130f 100644
--- a/saharaclient/api/clusters.py
+++ b/saharaclient/api/clusters.py
@@ -84,10 +84,11 @@ class ClusterManager(base.ResourceManager):
self._delete('/clusters/%s' % cluster_id)
def update(self, cluster_id, name=None, description=None, is_public=None,
- is_protected=None):
+ is_protected=None, shares=None):
data = {}
self._copy_if_defined(data, name=name, description=description,
- is_public=is_public, is_protected=is_protected)
+ is_public=is_public, is_protected=is_protected,
+ shares=shares)
return self._patch('/clusters/%s' % cluster_id, data)
diff --git a/saharaclient/osc/v1/clusters.py b/saharaclient/osc/v1/clusters.py
index 76250a4..b5c4cfd 100644
--- a/saharaclient/osc/v1/clusters.py
+++ b/saharaclient/osc/v1/clusters.py
@@ -371,6 +371,11 @@ class UpdateCluster(show.ShowOne):
metavar="<description>",
help='Description of the cluster'
)
+ parser.add_argument(
+ '--shares',
+ metavar="<filename>",
+ help='JSON representation of the manila shares'
+ )
public = parser.add_mutually_exclusive_group()
public.add_argument(
'--public',
@@ -410,12 +415,23 @@ class UpdateCluster(show.ShowOne):
cluster_id = utils.get_resource_id(
client.clusters, parsed_args.cluster)
+ shares = None
+ if parsed_args.shares:
+ blob = osc_utils.read_blob_file_contents(parsed_args.shares)
+ try:
+ shares = json.loads(blob)
+ except ValueError as e:
+ raise exceptions.CommandError(
+ 'An error occurred when reading '
+ 'shares from file %s: %s' % (parsed_args.shares, e))
+
data = client.clusters.update(
cluster_id,
name=parsed_args.name,
description=parsed_args.description,
is_public=parsed_args.is_public,
- is_protected=parsed_args.is_protected
+ is_protected=parsed_args.is_protected,
+ shares=shares
).cluster
_format_cluster_output(data)
diff --git a/saharaclient/tests/unit/osc/v1/test_clusters.py b/saharaclient/tests/unit/osc/v1/test_clusters.py
index 687fa74..b88738c 100644
--- a/saharaclient/tests/unit/osc/v1/test_clusters.py
+++ b/saharaclient/tests/unit/osc/v1/test_clusters.py
@@ -333,7 +333,7 @@ class TestUpdateCluster(TestClusters):
# Check that correct arguments were passed
self.cl_mock.update.assert_called_once_with(
'cluster_id', description=None, is_protected=None, is_public=None,
- name=None)
+ name=None, shares=None)
def test_cluster_update_all_options(self):
arglist = ['fake', '--name', 'fake', '--description', 'descr',
@@ -350,7 +350,7 @@ class TestUpdateCluster(TestClusters):
# Check that correct arguments were passed
self.cl_mock.update.assert_called_once_with(
'cluster_id', description='descr', is_protected=True,
- is_public=True, name='fake')
+ is_public=True, name='fake', shares=None)
# Check that columns are correct
expected_columns = ('Anti affinity', 'Cluster template id',
@@ -381,7 +381,7 @@ class TestUpdateCluster(TestClusters):
# Check that correct arguments were passed
self.cl_mock.update.assert_called_once_with(
'cluster_id', description=None, is_protected=False,
- is_public=False, name=None)
+ is_public=False, name=None, shares=None)
class TestScaleCluster(TestClusters):
diff --git a/saharaclient/tests/unit/test_clusters.py b/saharaclient/tests/unit/test_clusters.py
index 18e1c9f..dff755a 100644
--- a/saharaclient/tests/unit/test_clusters.py
+++ b/saharaclient/tests/unit/test_clusters.py
@@ -42,6 +42,14 @@ class ClusterTest(base.BaseTestCase):
"provision_progress": []
}
+ test_shares = [
+ {
+ "id": "bd71d2d5-60a0-4ed9-a3d2-ad312c368880",
+ "path": "/mnt/manila",
+ "access_level": "rw"
+ }
+ ]
+
def test_create_cluster_with_template(self,):
url = self.URL + '/clusters'
self.responses.post(url, status_code=202, json={'cluster': self.body})
@@ -166,3 +174,23 @@ class ClusterTest(base.BaseTestCase):
self.assertIsInstance(resp, cl.Cluster)
self.assertEqual(update_body,
json.loads(self.responses.last_request.body))
+
+ def test_clusters_update_share(self):
+ url = self.URL + '/clusters/id'
+
+ update_body = {
+ 'name': 'new_name',
+ 'description': 'descr',
+ 'shares': self.test_shares
+ }
+
+ self.responses.patch(url, status_code=202, json=update_body)
+
+ resp = self.client.clusters.update('id', name='new_name',
+ description='descr',
+ shares=self.test_shares)
+
+ self.assertEqual(url, self.responses.last_request.url)
+ self.assertIsInstance(resp, cl.Cluster)
+ self.assertEqual(update_body,
+ json.loads(self.responses.last_request.body))