~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/compute/contrib/test_floating_ips.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman, Yolanda Robla, James Page
  • Date: 2013-01-11 13:06:56 UTC
  • mfrom: (1.1.67)
  • Revision ID: package-import@ubuntu.com-20130111130656-7n7fkevy03stm3mv
Tags: 2013.1~g2-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/ubuntu-show-tests.patch: Dropped no longer needed.
* debian/nova-xcp-plugins.install: Fix xcp-plugins empty packages
* debian/control: Drop python-nose in favor or testrepository
* debian/control: Add python-coverage as a build dep.
* debian/rules, debian/control: Run pep8 tests.
* debian/*.init: Remove they are not needed and take up space
* debian/control, debian/nova-cells.{install, logrotate, upstart}: Add
  cells support.
* debian/patches/fix-ubuntu-tests.patch: temporarily disable failing tests.
* debian/control, debian/nova-baremetal.{install, logrotate, upstart}: Add
  nova baremetal support.
* debian/control: Remove python-support.

[ Adam Gandelman ]
* debian/*.manpages: Install Sphinx-generated manpages instead of
  our own.
* debian/nova-compute-*.conf: Specify the newly required compute_driver
  flag in addition to libvirt_type.
* debian/control:  Specify required python-webob and python-stevedore
  versions.

[ Yolanda Robla ]
* debian/*.upstart: Use start-stop-daemon instead of su for chuid
  (LP: #1086833).
* debian/rules: Remove override of dh_installinit for discriminating
  between Debian and Ubuntu.
* debian/nova-common.docs: Installing changelogs from rules
* debian/rules: Replacing perms in /etc/nova/logging.conf for 0644
* debian/control: adduser dependency on nova-compute.
* debian/control: added section oldlibs and priority extra on
  nova-ajax-console-proxy.
* debian/nova-xvpvncproxy.postrm: removing because of duplicates.

[ James Page ]
* d/control: Add ~ to python-sqlalchemy-ext versioned dependencies to
  make backporting easier.
* d/control: Updated nova-volume description and depdendencies to
  mark it as a transitional package, moved to oldlibs/extra.
* d/p/fix-libvirt-tests.patch: Dropped; accepted upstream.
* d/control: Added python-stevedore to BD's.
* d/*.postrm: Dropped postrm's that just run update-rc.d; this is not
  required when deploying upstart configurations only.
* d/nova-scheduler.manpages: Add man page for nova-rpc-zmq-receiver.
* d/rules: Install upstream changelog with a policy compliant name.
* d/control: Mark nova-compute-xcp as virtual package.
* d/control: nova-api-os-volume; Depend on cinder-api and mark as
  transitional package.
* d/nova-api-os-volume.lintian-overrides: Dropped - no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from nova import exception
28
28
from nova import network
29
29
from nova.openstack.common import jsonutils
 
30
from nova.openstack.common import rpc
30
31
from nova import test
31
32
from nova.tests.api.openstack import fakes
32
33
from nova.tests import fake_network
35
36
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
36
37
 
37
38
 
 
39
def network_api_get_fixed_ip(self, context, id):
 
40
    if id is None:
 
41
        return None
 
42
    return {'address': '10.0.0.1', 'id': id, 'instance_uuid': 1}
 
43
 
 
44
 
38
45
def network_api_get_floating_ip(self, context, id):
39
46
    return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
40
47
            'fixed_ip_id': None}
49
56
    return [{'id': 1,
50
57
             'address': '10.10.10.10',
51
58
             'pool': 'nova',
52
 
             'fixed_ip': {'address': '10.0.0.1',
53
 
                          'instance': {'uuid': FAKE_UUID}}},
 
59
             'fixed_ip_id': 20},
54
60
            {'id': 2,
55
61
             'pool': 'nova', 'interface': 'eth0',
56
62
             'address': '10.10.10.11',
57
 
             'fixed_ip': None}]
 
63
             'fixed_ip_id': None}]
58
64
 
59
65
 
60
66
def compute_api_get(self, context, instance_id):
125
131
 
126
132
    def setUp(self):
127
133
        super(FloatingIpTest, self).setUp()
 
134
        self.stubs.Set(network.api.API, "get_fixed_ip",
 
135
                       network_api_get_fixed_ip)
128
136
        self.stubs.Set(compute.api.API, "get",
129
137
                       compute_api_get)
130
138
        self.stubs.Set(network.api.API, "get_floating_ip",
165
173
        floating_ip_address = self.floating_ip
166
174
        floating_ip = db.floating_ip_get_by_address(self.context,
167
175
                                                    floating_ip_address)
168
 
        # NOTE(vish): network_get uses the id not the address
169
 
        floating_ip = db.floating_ip_get(self.context, floating_ip['id'])
170
 
        self.controller._normalize_ip(floating_ip)
 
176
        floating_ip['fixed_ip'] = None
 
177
        floating_ip['instance'] = None
171
178
        view = floating_ips._translate_floating_ip_view(floating_ip)
172
179
        self.assertTrue('floating_ip' in view)
173
180
        self.assertTrue(view['floating_ip']['id'])
178
185
    def test_translate_floating_ip_view_dict(self):
179
186
        floating_ip = {'id': 0, 'address': '10.0.0.10', 'pool': 'nova',
180
187
                       'fixed_ip': None}
181
 
        self.controller._normalize_ip(floating_ip)
182
188
        view = floating_ips._translate_floating_ip_view(floating_ip)
183
189
        self.assertTrue('floating_ip' in view)
184
190
 
239
245
    def test_show_associated_floating_ip(self):
240
246
        def get_floating_ip(self, context, id):
241
247
            return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
242
 
                    'fixed_ip': {'address': '10.0.0.1',
243
 
                                 'instance': {'uuid': FAKE_UUID}}}
 
248
                    'fixed_ip_id': 11}
 
249
 
 
250
        def get_fixed_ip(self, context, id):
 
251
            return {'address': '10.0.0.1', 'instance_uuid': 1}
244
252
 
245
253
        self.stubs.Set(network.api.API, "get_floating_ip", get_floating_ip)
 
254
        self.stubs.Set(network.api.API, "get_fixed_ip", get_fixed_ip)
246
255
 
247
256
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1')
248
257
        res_dict = self.controller.show(req, 1)
249
258
 
250
259
        self.assertEqual(res_dict['floating_ip']['id'], 1)
251
260
        self.assertEqual(res_dict['floating_ip']['ip'], '10.10.10.10')
252
 
        self.assertEqual(res_dict['floating_ip']['fixed_ip'], '10.0.0.1')
253
261
        self.assertEqual(res_dict['floating_ip']['instance_id'], FAKE_UUID)
254
262
 
255
263
    def test_recreation_of_floating_ip(self):
274
282
        self.assertIn(self.floating_ip, ip_list)
275
283
        self.assertNotIn(self.floating_ip_2, ip_list)
276
284
 
 
285
# test floating ip allocate/release(deallocate)
277
286
    def test_floating_ip_allocate_no_free_ips(self):
278
 
        def fake_allocate(*args, **kwargs):
 
287
        def fake_call(*args, **kwargs):
279
288
            raise exception.NoMoreFloatingIps()
280
289
 
281
 
        self.stubs.Set(network.api.API, "allocate_floating_ip", fake_allocate)
 
290
        self.stubs.Set(rpc, "call", fake_call)
282
291
 
283
292
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips')
284
293
        self.assertRaises(exception.NoMoreFloatingIps,
314
323
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1')
315
324
        self.controller.delete(req, 1)
316
325
 
 
326
# test floating ip add/remove -> associate/disassociate
 
327
 
317
328
    def test_floating_ip_associate(self):
318
 
        def fake_associate_floating_ip(*args, **kwargs):
319
 
            pass
320
 
 
321
 
        self.stubs.Set(network.api.API, "associate_floating_ip",
322
 
                       fake_associate_floating_ip)
323
329
        body = dict(addFloatingIp=dict(address=self.floating_ip))
324
330
 
325
331
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
364
370
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
365
371
 
366
372
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
367
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
368
 
                          self.manager._remove_floating_ip,
369
 
                          req, 'test_inst', body)
 
373
        rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
 
374
        self.assertTrue(rsp.status_int == 404)
370
375
 
371
376
    def test_floating_ip_associate_non_existent_ip(self):
372
377
        def fake_network_api_associate(self, context, instance,
375
380
            floating_ips = ["10.10.10.10", "10.10.10.11"]
376
381
            if floating_address not in floating_ips:
377
382
                    raise exception.FloatingIpNotFoundForAddress(
378
 
                            address=floating_address)
379
 
 
380
 
        self.stubs.Set(network.api.API, "associate_floating_ip",
381
 
                       fake_network_api_associate)
382
 
 
383
 
        body = dict(addFloatingIp=dict(address='1.1.1.1'))
384
 
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
385
 
        self.assertRaises(webob.exc.HTTPNotFound,
386
 
                          self.manager._add_floating_ip,
387
 
                          req, 'test_inst', body)
 
383
                            address=flaoting_address)
 
384
 
 
385
            self.stubs.Set(network.api.API, "associate_floating_ip",
 
386
                                             fake_network_api_associate)
 
387
 
 
388
            body = dict(addFloatingIp=dict(address='1.1.1.1'))
 
389
            req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
390
            self.assertRaises(webob.exc.HTTPNotFound,
 
391
                              self.manager._add_floating_ip,
 
392
                              req, 'test_inst', body)
388
393
 
389
394
    def test_floating_ip_disassociate_non_existent_ip(self):
390
395
        def network_api_get_floating_ip_by_address(self, context,
395
400
                            address=floating_address)
396
401
 
397
402
        self.stubs.Set(network.api.API, "get_floating_ip_by_address",
398
 
                       network_api_get_floating_ip_by_address)
 
403
                                        network_api_get_floating_ip_by_address)
399
404
 
400
405
        body = dict(removeFloatingIp=dict(address='1.1.1.1'))
401
406
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
415
420
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
416
421
 
417
422
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
418
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
419
 
                          self.manager._remove_floating_ip,
420
 
                          req, wrong_uuid, body)
 
423
        rsp = self.manager._remove_floating_ip(req, wrong_uuid, body)
 
424
        self.assertTrue(rsp.status_int == 404)
421
425
 
422
426
    def test_floating_ip_disassociate_wrong_instance_id(self):
423
427
        def get_instance_by_floating_ip_addr(self, context, address):
430
434
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
431
435
 
432
436
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
433
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
434
 
                          self.manager._remove_floating_ip,
435
 
                          req, 'test_inst', body)
 
437
        rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
 
438
        self.assertTrue(rsp.status_int == 404)
436
439
 
437
440
    def test_floating_ip_disassociate_auto_assigned(self):
438
441
        def fake_get_floating_ip_addr_auto_assigned(self, context, address):