Add some tests for os_update_readonly_flag
There is no test for os_update_readonly_flag api,
so add some for it.
Change-Id: Ice9a6ffea47dbaa492067f746edddcfbfc4eac4a
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 30c2c74..8581d16 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -140,6 +140,35 @@
self.assertEqual(200, resp.status)
self.assertIn('available', body['status'])
+ def _is_true(self, val):
+ return val in ['true', 'True', True]
+
+ @attr(type='gate')
+ def test_volume_readonly_update(self):
+ # Update volume readonly true
+ readonly = True
+ resp, body = self.client.update_volume_readonly(self.volume['id'],
+ readonly)
+ self.assertEqual(202, resp.status)
+
+ # Get Volume information
+ resp, fetched_volume = self.client.get_volume(self.volume['id'])
+ bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
+ self.assertEqual(200, resp.status)
+ self.assertEqual(True, bool_flag)
+
+ # Update volume readonly false
+ readonly = False
+ resp, body = self.client.update_volume_readonly(self.volume['id'],
+ readonly)
+ self.assertEqual(202, resp.status)
+
+ # Get Volume information
+ resp, fetched_volume = self.client.get_volume(self.volume['id'])
+ bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
+ self.assertEqual(200, resp.status)
+ self.assertEqual(False, bool_flag)
+
class VolumesActionsTestXML(VolumesActionsTest):
_interface = "xml"
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index 93b28a2..b4a1a68 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -246,3 +246,13 @@
resp, body = self.post(url, post_body, self.headers)
body = json.loads(body)
return resp, body['transfer']
+
+ def update_volume_readonly(self, volume_id, readonly):
+ """Update the Specified Volume readonly."""
+ post_body = {
+ 'readonly': readonly
+ }
+ post_body = json.dumps({'os-update_readonly_flag': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
diff --git a/tempest/services/volume/xml/volumes_client.py b/tempest/services/volume/xml/volumes_client.py
index b1e54ed..21254aa 100644
--- a/tempest/services/volume/xml/volumes_client.py
+++ b/tempest/services/volume/xml/volumes_client.py
@@ -337,3 +337,13 @@
resp, body = self.post(url, str(Document(post_body)), self.headers)
volume = xml_to_json(etree.fromstring(body))
return resp, volume
+
+ def update_volume_readonly(self, volume_id, readonly):
+ """Update the Specified Volume readonly."""
+ post_body = Element("os-update_readonly_flag",
+ readonly=readonly)
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body