Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [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 | |
| 18 | from nose.plugins.attrib import attr |
| 19 | from nose.tools import raises |
| 20 | |
| 21 | from tempest import exceptions |
| 22 | from tempest.common.utils.data_utils import rand_name |
| 23 | from tempest.tests.volume.base import BaseVolumeTest |
| 24 | |
| 25 | |
| 26 | class VolumesNegativeTest(BaseVolumeTest): |
| 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
| 30 | super(VolumesNegativeTest, cls).setUpClass() |
| 31 | cls.client = cls.volumes_client |
| 32 | |
| 33 | @raises(exceptions.NotFound) |
| 34 | @attr(type='negative') |
| 35 | def test_volume_get_nonexistant_volume_id(self): |
| 36 | """Should not be able to get a nonexistant volume""" |
| 37 | #Creating a nonexistant volume id |
| 38 | volume_id_list = [] |
| 39 | resp, volumes = self.client.list_volumes() |
| 40 | for i in range(len(volumes)): |
| 41 | volume_id_list.append(volumes[i]['id']) |
| 42 | while True: |
| 43 | non_exist_id = rand_name('999') |
| 44 | if non_exist_id not in volume_id_list: |
| 45 | break |
| 46 | #Trying to Get a non existant volume |
| 47 | resp, volume = self.client.get_volume(non_exist_id) |
| 48 | |
| 49 | @raises(exceptions.NotFound) |
| 50 | @attr(type='negative') |
| 51 | def test_volume_delete_nonexistant_volume_id(self): |
| 52 | """Should not be able to delete a nonexistant Volume""" |
| 53 | # Creating nonexistant volume id |
| 54 | volume_id_list = [] |
| 55 | resp, volumes = self.client.list_volumes() |
| 56 | for i in range(len(volumes)): |
| 57 | volume_id_list.append(volumes[i]['id']) |
| 58 | while True: |
| 59 | non_exist_id = '12345678-abcd-4321-abcd-123456789098' |
| 60 | if non_exist_id not in volume_id_list: |
| 61 | break |
| 62 | # Try to Delete a non existant volume |
| 63 | resp, body = self.client.delete_volume(non_exist_id) |
| 64 | |
| 65 | @raises(exceptions.BadRequest) |
| 66 | @attr(type='negative') |
| 67 | def test_create_volume_with_invalid_size(self): |
| 68 | """ |
| 69 | Should not be able to create volume with invalid size |
| 70 | in request |
| 71 | """ |
| 72 | v_name = rand_name('Volume-') |
| 73 | metadata = {'Type': 'work'} |
| 74 | resp, volume = self.client.create_volume(size='#$%', |
| 75 | display_name=v_name, |
| 76 | metadata=metadata) |
| 77 | |
| 78 | @raises(exceptions.BadRequest) |
| 79 | @attr(type='negative') |
| 80 | def test_create_volume_with_out_passing_size(self): |
| 81 | """ |
| 82 | Should not be able to create volume without passing size |
| 83 | in request |
| 84 | """ |
| 85 | v_name = rand_name('Volume-') |
| 86 | metadata = {'Type': 'work'} |
| 87 | resp, volume = self.client.create_volume(size='', |
| 88 | display_name=v_name, |
| 89 | metadata=metadata) |
| 90 | |
| 91 | @raises(exceptions.BadRequest) |
| 92 | @attr(type='negative') |
| 93 | def test_create_volume_with_size_zero(self): |
| 94 | """ |
| 95 | Should not be able to create volume with size zero |
| 96 | """ |
| 97 | v_name = rand_name('Volume-') |
| 98 | metadata = {'Type': 'work'} |
| 99 | resp, volume = self.client.create_volume(size='0', |
| 100 | display_name=v_name, |
| 101 | metadata=metadata) |
| 102 | |
| 103 | @raises(exceptions.NotFound) |
| 104 | @attr(type='negative') |
| 105 | def test_get_invalid_volume_id(self): |
| 106 | """ |
| 107 | Should not be able to get volume with invalid id |
| 108 | """ |
| 109 | resp, volume = self.client.get_volume('#$%%&^&^') |
| 110 | |
| 111 | @raises(exceptions.NotFound) |
| 112 | @attr(type='negative') |
| 113 | def test_get_volume_without_passing_volume_id(self): |
| 114 | """ |
| 115 | Should not be able to get volume when empty ID is passed |
| 116 | """ |
| 117 | resp, volume = self.client.get_volume('') |
| 118 | |
| 119 | @raises(exceptions.NotFound) |
| 120 | @attr(type='negative') |
| 121 | def test_delete_invalid_volume_id(self): |
| 122 | """ |
| 123 | Should not be able to delete volume when invalid ID is passed |
| 124 | """ |
| 125 | resp, volume = self.client.delete_volume('!@#$%^&*()') |
| 126 | |
| 127 | @raises(exceptions.NotFound) |
| 128 | @attr(type='negative') |
| 129 | def test_delete_volume_without_passing_volume_id(self): |
| 130 | """ |
| 131 | Should not be able to delete volume when empty ID is passed |
| 132 | """ |
| 133 | resp, volume = self.client.delete_volume('') |