~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, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    License for the specific language governing permissions and limitations
15
15
#    under the License.
16
16
 
 
17
import uuid
 
18
 
17
19
from lxml import etree
18
20
import webob
19
21
 
24
26
from nova import db
25
27
from nova import exception
26
28
from nova import network
 
29
from nova.openstack.common import jsonutils
27
30
from nova.openstack.common import rpc
28
31
from nova import test
29
32
from nova.tests.api.openstack import fakes
30
33
from nova.tests import fake_network
31
 
from nova import utils
 
34
 
32
35
 
33
36
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
34
37
 
87
90
def fake_instance_get(context, instance_id):
88
91
        return {
89
92
        "id": 1,
90
 
        "uuid": utils.gen_uuid(),
 
93
        "uuid": uuid.uuid4(),
91
94
        "name": 'fake',
92
95
        "user_id": 'fakeuser',
93
96
        "project_id": '123'}
146
149
                       get_instance_by_floating_ip_addr)
147
150
        self.stubs.Set(compute_utils, "get_nw_info_for_instance",
148
151
                       stub_nw_info(self.stubs))
 
152
        self.flags(
 
153
            osapi_compute_extension=[
 
154
                'nova.api.openstack.compute.contrib.select_extensions'],
 
155
            osapi_compute_ext_list=['Floating_ips'])
149
156
 
150
157
        fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
151
158
                                                          spectacular=True)
197
204
                                      'id': 2}]}
198
205
        self.assertEqual(res_dict, response)
199
206
 
 
207
    def test_floating_ip_release_nonexisting(self):
 
208
        def fake_get_floating_ip(*args, **kwargs):
 
209
            raise exception.FloatingIpNotFound(id=id)
 
210
 
 
211
        self.stubs.Set(network.api.API, "get_floating_ip",
 
212
                       fake_get_floating_ip)
 
213
 
 
214
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/9876')
 
215
        req.method = 'DELETE'
 
216
        res = req.get_response(fakes.wsgi_app(init_only=('os-floating-ips',)))
 
217
        self.assertEqual(res.status_int, 404)
 
218
        expected_msg = ('{"itemNotFound": {"message": "Floating ip not found '
 
219
                                         'for id 9876", "code": 404}}')
 
220
        self.assertEqual(res.body, expected_msg)
 
221
 
200
222
    def test_floating_ip_show(self):
201
223
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1')
202
224
        res_dict = self.controller.show(req, 1)
214
236
 
215
237
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/9876')
216
238
 
217
 
        self.assertRaises(webob.exc.HTTPNotFound,
218
 
                          self.controller.show, req, 9876)
 
239
        res = req.get_response(fakes.wsgi_app(init_only=('os-floating-ips',)))
 
240
        self.assertEqual(res.status_int, 404)
 
241
        expected_msg = ('{"itemNotFound": {"message": "Floating ip not found '
 
242
                        'for id 9876", "code": 404}}')
 
243
        self.assertEqual(res.body, expected_msg)
219
244
 
220
245
    def test_show_associated_floating_ip(self):
221
246
        def get_floating_ip(self, context, id):
307
332
        rsp = self.manager._add_floating_ip(req, 'test_inst', body)
308
333
        self.assertTrue(rsp.status_int == 202)
309
334
 
 
335
    def test_associate_not_allocated_floating_ip_to_instance(self):
 
336
 
 
337
        def fake_associate_floating_ip(self, context, instance,
 
338
                              floating_address, fixed_address,
 
339
                              affect_auto_assigned=False):
 
340
            raise exception.NotAuthorized()
 
341
        self.stubs.Set(network.api.API, "associate_floating_ip",
 
342
                       fake_associate_floating_ip)
 
343
        floating_ip = '10.10.10.11'
 
344
        body = dict(addFloatingIp=dict(address=floating_ip))
 
345
        req = webob.Request.blank('/v2/fake/servers/test_inst/action')
 
346
        req.method = "POST"
 
347
        req.body = jsonutils.dumps(body)
 
348
        req.headers["content-type"] = "application/json"
 
349
        resp = req.get_response(fakes.wsgi_app(init_only=('servers',)))
 
350
        res_dict = jsonutils.loads(resp.body)
 
351
        self.assertEqual(resp.status_int, 404)
 
352
        self.assertEqual(res_dict['itemNotFound']['message'],
 
353
                       "floating ip not found")
 
354
 
310
355
    def test_floating_ip_disassociate(self):
311
356
        def get_instance_by_floating_ip_addr(self, context, address):
312
357
            if address == '10.10.10.10':
328
373
        rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
329
374
        self.assertTrue(rsp.status_int == 404)
330
375
 
 
376
    def test_floating_ip_associate_non_existent_ip(self):
 
377
        def fake_network_api_associate(self, context, instance,
 
378
                                             floating_address=None,
 
379
                                             fixed_address=None):
 
380
            floating_ips = ["10.10.10.10", "10.10.10.11"]
 
381
            if floating_address not in floating_ips:
 
382
                    raise exception.FloatingIpNotFoundForAddress()
 
383
 
 
384
            self.stubs.Set(network.api.API, "associate_floating_ip",
 
385
                                             fake_network_api_associate)
 
386
 
 
387
            body = dict(addFloatingIp=dict(address='1.1.1.1'))
 
388
            req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
389
            self.assertRaises(webob.exc.HTTPNotFound,
 
390
                              self.manager._add_floating_ip,
 
391
                              req, 'test_inst', body)
 
392
 
 
393
    def test_floating_ip_disassociate_non_existent_ip(self):
 
394
        def network_api_get_floating_ip_by_address(self, context,
 
395
                                                         floating_address):
 
396
            floating_ips = ["10.10.10.10", "10.10.10.11"]
 
397
            if floating_address not in floating_ips:
 
398
                    raise exception.FloatingIpNotFoundForAddress()
 
399
 
 
400
        self.stubs.Set(network.api.API, "get_floating_ip_by_address",
 
401
                                        network_api_get_floating_ip_by_address)
 
402
 
 
403
        body = dict(removeFloatingIp=dict(address='1.1.1.1'))
 
404
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
405
        self.assertRaises(webob.exc.HTTPNotFound,
 
406
                          self.manager._remove_floating_ip,
 
407
                          req, 'test_inst', body)
 
408
 
331
409
    def test_floating_ip_disassociate_wrong_instance_uuid(self):
332
410
        def get_instance_by_floating_ip_addr(self, context, address):
333
411
            if address == '10.10.10.10':
357
435
        rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
358
436
        self.assertTrue(rsp.status_int == 404)
359
437
 
 
438
    def test_floating_ip_disassociate_auto_assigned(self):
 
439
        def fake_get_floating_ip_addr_auto_assigned(self, context, address):
 
440
            return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
 
441
            'fixed_ip_id': 10, 'auto_assigned': 1}
 
442
 
 
443
        def get_instance_by_floating_ip_addr(self, context, address):
 
444
            if address == '10.10.10.10':
 
445
                return 'test_inst'
 
446
 
 
447
        def network_api_disassociate(self, context, instance,
 
448
                                     floating_address):
 
449
            raise exception.CannotDisassociateAutoAssignedFloatingIP()
 
450
 
 
451
        self.stubs.Set(network.api.API, "get_floating_ip_by_address",
 
452
                       fake_get_floating_ip_addr_auto_assigned)
 
453
        self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
 
454
                       get_instance_by_floating_ip_addr)
 
455
        self.stubs.Set(network.api.API, "disassociate_floating_ip",
 
456
                       network_api_disassociate)
 
457
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
 
458
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
459
        self.assertRaises(webob.exc.HTTPForbidden,
 
460
                          self.manager._remove_floating_ip,
 
461
                          req, 'test_inst', body)
 
462
 
 
463
    def test_floating_ip_disassociate_map_authorization_exc(self):
 
464
        def fake_get_floating_ip_addr_auto_assigned(self, context, address):
 
465
            return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
 
466
            'fixed_ip_id': 10, 'auto_assigned': 1}
 
467
 
 
468
        def get_instance_by_floating_ip_addr(self, context, address):
 
469
            if address == '10.10.10.10':
 
470
                return 'test_inst'
 
471
 
 
472
        def network_api_disassociate(self, context, instance, address):
 
473
            raise exception.NotAuthorized()
 
474
 
 
475
        self.stubs.Set(network.api.API, "get_floating_ip_by_address",
 
476
                       fake_get_floating_ip_addr_auto_assigned)
 
477
        self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
 
478
                       get_instance_by_floating_ip_addr)
 
479
        self.stubs.Set(network.api.API, "disassociate_floating_ip",
 
480
                       network_api_disassociate)
 
481
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
 
482
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
483
        self.assertRaises(webob.exc.HTTPForbidden,
 
484
                          self.manager._remove_floating_ip,
 
485
                          req, 'test_inst', body)
 
486
 
360
487
# these are a few bad param tests
361
488
 
362
489
    def test_bad_address_param_in_remove_floating_ip(self):