diff --git a/tempest/openstack.py b/tempest/openstack.py index 862b517a38..1830aa8536 100644 --- a/tempest/openstack.py +++ b/tempest/openstack.py @@ -10,6 +10,7 @@ from tempest.services.nova.json.security_groups_client \ import SecurityGroupsClient from tempest.services.nova.json.floating_ips_client import FloatingIPsClient from tempest.services.nova.json.keypairs_client import KeyPairsClient +from tempest.services.nova.json.volumes_client import VolumesClient class Manager(object): @@ -42,6 +43,7 @@ class Manager(object): self.keypairs_client = KeyPairsClient(*client_args) self.security_groups_client = SecurityGroupsClient(*client_args) self.floating_ips_client = FloatingIPsClient(*client_args) + self.volumes_client = VolumesClient(*client_args) class ServiceManager(object): diff --git a/tempest/services/nova/json/volumes_client.py b/tempest/services/nova/json/volumes_client.py new file mode 100644 index 0000000000..95131f2449 --- /dev/null +++ b/tempest/services/nova/json/volumes_client.py @@ -0,0 +1,36 @@ +from tempest.common import rest_client +import json + + +class VolumesClient(object): + + def __init__(self, config, username, key, auth_url, tenant_name=None): + self.config = config + catalog_type = self.config.compute.catalog_type + self.client = rest_client.RestClient(config, username, key, auth_url, + catalog_type, tenant_name) + + def list_volumes(self, params=None): + """List all the volumes created""" + url = 'os-volumes' + if params != None: + param_list = [] + for param, value in params.iteritems(): + param_list.append("%s=%s&" % (param, value)) + + url += '?' + ' '.join(param_list) + + resp, body = self.client.get(url) + body = json.loads(body) + return resp, body['volumes'] + + def get_volume(self, volume_id): + """Returns the details of a single volume""" + url = "os-volumes/%s" % str(volume_id) + resp, body = self.client.get(url) + body = json.loads(body) + return resp, body['volume'] + + def delete_volume(self, volume_id): + """Deletes the Specified Volume""" + return self.client.delete("os-volumes/%s" % str(volume_id)) diff --git a/tempest/tests/test_volumes_negative.py b/tempest/tests/test_volumes_negative.py new file mode 100644 index 0000000000..83eef52780 --- /dev/null +++ b/tempest/tests/test_volumes_negative.py @@ -0,0 +1,54 @@ +from nose.plugins.attrib import attr +import unittest2 as unittest +from tempest import openstack +from tempest.common.utils.data_utils import rand_name +from tempest import exceptions + + +class VolumesTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.os = openstack.Manager() + cls.client = cls.os.volumes_client + + @attr(type='negative') + def test_volume_get_nonexistant_volume_id(self): + """Negative: Should not be able to get details of nonexistant volume""" + #Creating a nonexistant volume id + volume_id_list = list() + resp, body = self.client.list_volumes() + for i in range(len(body)): + volume_id_list.append(body[i]['id']) + while True: + non_exist_id = rand_name('999') + if non_exist_id not in volume_id_list: + break + #Trying to GET a non existant volume + try: + resp, body = self.client.get_volume(non_exist_id) + except exceptions.NotFound: + pass + else: + self.fail('Should not be able to GET the details from a ' + 'nonexistant volume') + + @attr(type='negative') + def test_volume_delete_nonexistant_volume_id(self): + """Negative: Should not be able to delete nonexistant Volume""" + #Creating nonexistant volume id + volume_id_list = list() + resp, body = self.client.list_volumes() + for i in range(len(body)): + volume_id_list.append(body[i]['id']) + while True: + non_exist_id = rand_name('999') + if non_exist_id not in volume_id_list: + break + #Trying to DELETE a non existant volume + try: + resp, body = self.client.delete_volume(non_exist_id) + except exceptions.NotFound: + pass + else: + self.fail('Should not be able to DELETE a nonexistant volume')