16
from testtools import skipIf
16
import swiftclient.client as sc
18
18
from heat.common import template_format
19
from heat.engine import clients
20
19
from heat.engine.resources import swift
21
20
from heat.engine import scheduler
22
from heat.openstack.common.importutils import try_import
23
21
from heat.tests.common import HeatTestCase
24
from heat.tests import fakes
25
22
from heat.tests import utils
27
swiftclient = try_import('swiftclient.client')
29
25
swift_template = '''
70
66
class swiftTest(HeatTestCase):
71
@skipIf(swiftclient is None, 'unable to import swiftclient')
73
68
super(swiftTest, self).setUp()
74
self.m.CreateMock(swiftclient.Connection)
75
self.m.StubOutWithMock(swiftclient.Connection, 'post_account')
76
self.m.StubOutWithMock(swiftclient.Connection, 'put_container')
77
self.m.StubOutWithMock(swiftclient.Connection, 'delete_container')
78
self.m.StubOutWithMock(swiftclient.Connection, 'head_container')
79
self.m.StubOutWithMock(swiftclient.Connection, 'get_auth')
80
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
69
self.m.CreateMock(sc.Connection)
70
self.m.StubOutWithMock(sc.Connection, 'post_account')
71
self.m.StubOutWithMock(sc.Connection, 'put_container')
72
self.m.StubOutWithMock(sc.Connection, 'delete_container')
73
self.m.StubOutWithMock(sc.Connection, 'head_container')
74
self.m.StubOutWithMock(sc.Connection, 'get_auth')
75
self.stub_keystoneclient()
82
77
def create_resource(self, t, stack, resource_name):
83
78
resource_defns = stack.t.resource_definitions(stack)
130
125
"x-container-bytes-used": "17680980",
131
126
"content-type": "text/plain; charset=utf-8"}
133
clients.OpenStackClients.keystone().AndReturn(
134
fakes.FakeKeystoneClient())
135
128
container_name = utils.PhysName('test_stack', 'test_resource')
136
swiftclient.Connection.put_container(
129
sc.Connection.put_container(
137
130
container_name, {}).AndReturn(None)
138
swiftclient.Connection.head_container(
131
sc.Connection.head_container(
139
132
mox.IgnoreArg()).MultipleTimes().AndReturn(headers)
140
swiftclient.Connection.delete_container(container_name).AndReturn(None)
133
sc.Connection.delete_container(container_name).AndReturn(None)
142
135
self.m.ReplayAll()
143
136
t = template_format.parse(swift_template)
162
155
self.m.VerifyAll()
164
157
def test_public_read(self):
165
clients.OpenStackClients.keystone().AndReturn(
166
fakes.FakeKeystoneClient())
167
158
container_name = utils.PhysName('test_stack', 'test_resource')
168
swiftclient.Connection.put_container(
159
sc.Connection.put_container(
170
161
{'X-Container-Read': '.r:*'}).AndReturn(None)
171
swiftclient.Connection.delete_container(container_name).AndReturn(None)
162
sc.Connection.delete_container(container_name).AndReturn(None)
173
164
self.m.ReplayAll()
174
165
t = template_format.parse(swift_template)
180
171
self.m.VerifyAll()
182
173
def test_public_read_write(self):
183
clients.OpenStackClients.keystone().AndReturn(
184
fakes.FakeKeystoneClient())
185
174
container_name = utils.PhysName('test_stack', 'test_resource')
186
swiftclient.Connection.put_container(
175
sc.Connection.put_container(
188
177
{'X-Container-Write': '.r:*',
189
178
'X-Container-Read': '.r:*'}).AndReturn(None)
190
swiftclient.Connection.delete_container(container_name).AndReturn(None)
179
sc.Connection.delete_container(container_name).AndReturn(None)
192
181
self.m.ReplayAll()
193
182
t = template_format.parse(swift_template)
200
189
self.m.VerifyAll()
202
191
def test_container_headers(self):
203
clients.OpenStackClients.keystone().AndReturn(
204
fakes.FakeKeystoneClient())
205
192
container_name = utils.PhysName('test_stack', 'test_resource')
206
swiftclient.Connection.put_container(
193
sc.Connection.put_container(
208
195
{'X-Container-Meta-Web-Error': 'error.html',
209
196
'X-Container-Meta-Web-Index': 'index.html',
210
197
'X-Container-Read': '.r:*'}).AndReturn(None)
211
swiftclient.Connection.delete_container(container_name).AndReturn(None)
198
sc.Connection.delete_container(container_name).AndReturn(None)
213
200
self.m.ReplayAll()
214
201
t = template_format.parse(swift_template)
218
205
self.m.VerifyAll()
220
207
def test_account_headers(self):
221
clients.OpenStackClients.keystone().AndReturn(
222
fakes.FakeKeystoneClient())
223
208
container_name = utils.PhysName('test_stack', 'test_resource')
224
swiftclient.Connection.put_container(container_name, {})
225
swiftclient.Connection.post_account(
209
sc.Connection.put_container(container_name, {})
210
sc.Connection.post_account(
226
211
{'X-Account-Meta-Temp-Url-Key': 'secret'}).AndReturn(None)
227
swiftclient.Connection.delete_container(container_name).AndReturn(None)
212
sc.Connection.delete_container(container_name).AndReturn(None)
229
214
self.m.ReplayAll()
230
215
t = template_format.parse(swift_template)
234
219
self.m.VerifyAll()
236
221
def test_delete_exception(self):
237
clients.OpenStackClients.keystone().AndReturn(
238
fakes.FakeKeystoneClient())
239
222
container_name = utils.PhysName('test_stack', 'test_resource')
240
swiftclient.Connection.put_container(
223
sc.Connection.put_container(
242
225
{}).AndReturn(None)
243
swiftclient.Connection.delete_container(container_name).AndRaise(
244
swiftclient.ClientException('Test delete failure'))
226
sc.Connection.delete_container(container_name).AndRaise(
227
sc.ClientException('Test delete failure'))
246
229
self.m.ReplayAll()
247
230
t = template_format.parse(swift_template)
252
235
self.m.VerifyAll()
254
237
def test_delete_retain(self):
256
clients.OpenStackClients.keystone().AndReturn(
257
fakes.FakeKeystoneClient())
258
238
# first run, with retain policy
259
swiftclient.Connection.put_container(
239
sc.Connection.put_container(
260
240
utils.PhysName('test_stack', 'test_resource'),
261
241
{}).AndReturn(None)
275
255
def test_default_headers_not_none_empty_string(self):
276
256
'''Test that we are not passing None when we have a default
277
empty string or swiftclient will pass them as string None. see
257
empty string or sc will pass them as string None. see
280
clients.OpenStackClients.keystone().AndReturn(
281
fakes.FakeKeystoneClient())
282
260
container_name = utils.PhysName('test_stack', 'test_resource')
283
swiftclient.Connection.put_container(
261
sc.Connection.put_container(
284
262
container_name, {}).AndReturn(None)
285
swiftclient.Connection.delete_container(container_name).AndReturn(None)
263
sc.Connection.delete_container(container_name).AndReturn(None)
287
265
self.m.ReplayAll()
288
266
t = template_format.parse(swift_template)