blob: fa146407781b215bcff5830aa9f8aa4beeab6a37 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# 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-ganesanddd9e0e2012-03-21 00:49:22 +053018from nose.plugins.attrib import attr
rajalakshmi-ganesan5894d512012-05-31 19:00:36 +053019from nose.tools import raises
Jay Pipes13b479b2012-06-11 14:52:27 -040020
21from tempest import exceptions
22from tempest.common.utils.data_utils import rand_name
Matthew Treinish9e1eb972012-08-17 17:53:41 -040023from tempest.tests.compute import base
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053024
25
Matthew Treinish9e1eb972012-08-17 17:53:41 -040026class VolumesNegativeTestBase(object):
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053027
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-ganesan5894d512012-05-31 19:00:36 +053068
rajalakshmi-ganesan5894d512012-05-31 19:00:36 +053069 @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-ganesan5894d512012-05-31 19:00:36 +053082 @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-ganesan5894d512012-05-31 19:00:36 +053095 @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 Treinish9e1eb972012-08-17 17:53:41 -0400138
139
140class VolumesNegativeTestXML(base.BaseComputeTestXML,
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800141 VolumesNegativeTestBase):
Matthew Treinish9e1eb972012-08-17 17:53:41 -0400142 @classmethod
143 def setUpClass(cls):
144 cls._interface = "xml"
145 super(VolumesNegativeTestXML, cls).setUpClass()
146 cls.client = cls.volumes_extensions_client
147
148
149class VolumesNegativeTestJSON(base.BaseComputeTestJSON,
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800150 VolumesNegativeTestBase):
Matthew Treinish9e1eb972012-08-17 17:53:41 -0400151 @classmethod
152 def setUpClass(cls):
153 cls._interface = "json"
154 super(VolumesNegativeTestJSON, cls).setUpClass()
155 cls.client = cls.volumes_extensions_client