~ubuntu-branches/ubuntu/utopic/heat/utopic

« back to all changes in this revision

Viewing changes to heat/tests/test_swift.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Gauvain Pocentek
  • Date: 2014-07-25 10:08:14 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140725100814-86phhyxr90ugg3hr
Tags: 2014.2~b2-0ubuntu1
[ Chuck Short ]
* debian/control: Add python-oslo.messaging 
* debian/tests/heat-daemons: Dropped heat-enginge.
* debian/patches/fix-requirements.patch: Refreshed.
* debian/control: Add python-stevedore
* debian/control: Add python-posix-ipc.
* debian/patches/fix-requirements.patch: Remove routes 2.0 blockage.
* debian/patches/default-sqlite.patch: Refreshed.
* debian/patches/skip-tests.patch: Refreshed.
* debian/control: Add python-requests
* debian/rules: Temporarily disable testsuite.

[ Gauvain Pocentek ]
* debian/patches/default-log-dir.patch: define a default log directory to
  actually get logging to work (LP: #1320013).

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
 
15
15
import mox
16
 
from testtools import skipIf
 
16
import swiftclient.client as sc
17
17
 
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
26
23
 
27
 
swiftclient = try_import('swiftclient.client')
28
24
 
29
25
swift_template = '''
30
26
{
68
64
 
69
65
 
70
66
class swiftTest(HeatTestCase):
71
 
    @skipIf(swiftclient is None, 'unable to import swiftclient')
72
67
    def setUp(self):
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()
81
76
 
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"}
132
127
 
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)
141
134
 
142
135
        self.m.ReplayAll()
143
136
        t = template_format.parse(swift_template)
162
155
        self.m.VerifyAll()
163
156
 
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(
169
160
            container_name,
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)
172
163
 
173
164
        self.m.ReplayAll()
174
165
        t = template_format.parse(swift_template)
180
171
        self.m.VerifyAll()
181
172
 
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(
187
176
            container_name,
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)
191
180
 
192
181
        self.m.ReplayAll()
193
182
        t = template_format.parse(swift_template)
200
189
        self.m.VerifyAll()
201
190
 
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(
207
194
            container_name,
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)
212
199
 
213
200
        self.m.ReplayAll()
214
201
        t = template_format.parse(swift_template)
218
205
        self.m.VerifyAll()
219
206
 
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)
228
213
 
229
214
        self.m.ReplayAll()
230
215
        t = template_format.parse(swift_template)
234
219
        self.m.VerifyAll()
235
220
 
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(
241
224
            container_name,
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'))
245
228
 
246
229
        self.m.ReplayAll()
247
230
        t = template_format.parse(swift_template)
252
235
        self.m.VerifyAll()
253
236
 
254
237
    def test_delete_retain(self):
255
 
 
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)
262
242
 
274
254
 
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
278
258
        bug lp:1259571.
279
259
        '''
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)
286
264
 
287
265
        self.m.ReplayAll()
288
266
        t = template_format.parse(swift_template)