Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 18 | from nose.plugins.attrib import attr |
rajalakshmi-ganesan | 5894d51 | 2012-05-31 19:00:36 +0530 | [diff] [blame] | 19 | from nose.tools import raises |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 20 | |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame^] | 22 | from tempest import exceptions |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 23 | from tempest.tests.compute import base |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 24 | |
| 25 | |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 26 | class VolumesNegativeTestBase(object): |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 27 | |
| 28 | @attr(type='negative') |
| 29 | def test_volume_get_nonexistant_volume_id(self): |
| 30 | """Negative: Should not be able to get details of nonexistant volume""" |
| 31 | #Creating a nonexistant volume id |
| 32 | volume_id_list = list() |
| 33 | resp, body = self.client.list_volumes() |
| 34 | for i in range(len(body)): |
| 35 | volume_id_list.append(body[i]['id']) |
| 36 | while True: |
| 37 | non_exist_id = rand_name('999') |
| 38 | if non_exist_id not in volume_id_list: |
| 39 | break |
| 40 | #Trying to GET a non existant volume |
| 41 | try: |
| 42 | resp, body = self.client.get_volume(non_exist_id) |
| 43 | except exceptions.NotFound: |
| 44 | pass |
| 45 | else: |
| 46 | self.fail('Should not be able to GET the details from a ' |
| 47 | 'nonexistant volume') |
| 48 | |
| 49 | @attr(type='negative') |
| 50 | def test_volume_delete_nonexistant_volume_id(self): |
| 51 | """Negative: Should not be able to delete nonexistant Volume""" |
| 52 | #Creating nonexistant volume id |
| 53 | volume_id_list = list() |
| 54 | resp, body = self.client.list_volumes() |
| 55 | for i in range(len(body)): |
| 56 | volume_id_list.append(body[i]['id']) |
| 57 | while True: |
| 58 | non_exist_id = rand_name('999') |
| 59 | if non_exist_id not in volume_id_list: |
| 60 | break |
| 61 | #Trying to DELETE a non existant volume |
| 62 | try: |
| 63 | resp, body = self.client.delete_volume(non_exist_id) |
| 64 | except exceptions.NotFound: |
| 65 | pass |
| 66 | else: |
| 67 | self.fail('Should not be able to DELETE a nonexistant volume') |
rajalakshmi-ganesan | 5894d51 | 2012-05-31 19:00:36 +0530 | [diff] [blame] | 68 | |
rajalakshmi-ganesan | 5894d51 | 2012-05-31 19:00:36 +0530 | [diff] [blame] | 69 | @raises(exceptions.BadRequest) |
| 70 | @attr(type='negative') |
| 71 | def test_create_volume_with_invalid_size(self): |
| 72 | """ |
| 73 | Negative: Should not be able to create volume with invalid size |
| 74 | in request |
| 75 | """ |
| 76 | v_name = rand_name('Volume-') |
| 77 | metadata = {'Type': 'work'} |
| 78 | resp, volume = self.client.create_volume(size='#$%', |
| 79 | display_name=v_name, |
| 80 | metadata=metadata) |
| 81 | |
rajalakshmi-ganesan | 5894d51 | 2012-05-31 19:00:36 +0530 | [diff] [blame] | 82 | @raises(exceptions.BadRequest) |
| 83 | @attr(type='negative') |
| 84 | def test_create_volume_with_out_passing_size(self): |
| 85 | """ |
| 86 | Negative: Should not be able to create volume without passing size |
| 87 | in request |
| 88 | """ |
| 89 | v_name = rand_name('Volume-') |
| 90 | metadata = {'Type': 'work'} |
| 91 | resp, volume = self.client.create_volume(size='', |
| 92 | display_name=v_name, |
| 93 | metadata=metadata) |
| 94 | |
rajalakshmi-ganesan | 5894d51 | 2012-05-31 19:00:36 +0530 | [diff] [blame] | 95 | @raises(exceptions.BadRequest) |
| 96 | @attr(type='negative') |
| 97 | def test_create_volume_with_size_zero(self): |
| 98 | """ |
| 99 | Negative: Should not be able to create volume with size zero |
| 100 | """ |
| 101 | v_name = rand_name('Volume-') |
| 102 | metadata = {'Type': 'work'} |
| 103 | resp, volume = self.client.create_volume(size='0', |
| 104 | display_name=v_name, |
| 105 | metadata=metadata) |
| 106 | |
| 107 | @raises(exceptions.NotFound) |
| 108 | @attr(type='negative') |
| 109 | def test_get_invalid_volume_id(self): |
| 110 | """ |
| 111 | Negative: Should not be able to get volume with invalid id |
| 112 | """ |
| 113 | resp, volume = self.client.get_volume('#$%%&^&^') |
| 114 | |
| 115 | @raises(exceptions.NotFound) |
| 116 | @attr(type='negative') |
| 117 | def test_get_volume_without_passing_volume_id(self): |
| 118 | """ |
| 119 | Negative: Should not be able to get volume when empty ID is passed |
| 120 | """ |
| 121 | resp, volume = self.client.get_volume('') |
| 122 | |
| 123 | @raises(exceptions.NotFound) |
| 124 | @attr(type='negative') |
| 125 | def test_delete_invalid_volume_id(self): |
| 126 | """ |
| 127 | Negative: Should not be able to delete volume when invalid ID is passed |
| 128 | """ |
| 129 | resp, volume = self.client.delete_volume('!@#$%^&*()') |
| 130 | |
| 131 | @raises(exceptions.NotFound) |
| 132 | @attr(type='negative') |
| 133 | def test_delete_volume_without_passing_volume_id(self): |
| 134 | """ |
| 135 | Negative: Should not be able to delete volume when empty ID is passed |
| 136 | """ |
| 137 | resp, volume = self.client.delete_volume('') |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 138 | |
| 139 | |
| 140 | class VolumesNegativeTestXML(base.BaseComputeTestXML, |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 141 | VolumesNegativeTestBase): |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 142 | @classmethod |
| 143 | def setUpClass(cls): |
| 144 | cls._interface = "xml" |
| 145 | super(VolumesNegativeTestXML, cls).setUpClass() |
| 146 | cls.client = cls.volumes_extensions_client |
| 147 | |
| 148 | |
| 149 | class VolumesNegativeTestJSON(base.BaseComputeTestJSON, |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 150 | VolumesNegativeTestBase): |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 151 | @classmethod |
| 152 | def setUpClass(cls): |
| 153 | cls._interface = "json" |
| 154 | super(VolumesNegativeTestJSON, cls).setUpClass() |
| 155 | cls.client = cls.volumes_extensions_client |