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