~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/network/test_api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 Red Hat, Inc.
 
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
 
 
18
"""Tests for network API"""
 
19
 
 
20
from nova import context
 
21
from nova import db
 
22
from nova import network
 
23
from nova.openstack.common import rpc
 
24
from nova import test
 
25
 
 
26
 
 
27
class ApiTestCase(test.TestCase):
 
28
    def setUp(self):
 
29
        super(ApiTestCase, self).setUp()
 
30
        self.network_api = network.API()
 
31
        self.context = context.RequestContext('fake-user',
 
32
                                              'fake-project')
 
33
 
 
34
    def _do_test_associate_floating_ip(self, orig_instance_uuid):
 
35
        """Test post-association logic"""
 
36
 
 
37
        new_instance = {'uuid': 'new-uuid'}
 
38
 
 
39
        def fake_rpc_call(context, topic, msg):
 
40
            return orig_instance_uuid
 
41
 
 
42
        self.stubs.Set(rpc, 'call', fake_rpc_call)
 
43
 
 
44
        def fake_instance_get_by_uuid(context, instance_uuid):
 
45
            return {'uuid': instance_uuid}
 
46
 
 
47
        self.stubs.Set(self.network_api.db, 'instance_get_by_uuid',
 
48
                       fake_instance_get_by_uuid)
 
49
 
 
50
        def fake_get_nw_info(ctxt, instance):
 
51
            class FakeNWInfo(object):
 
52
                def json(self):
 
53
                    pass
 
54
            return FakeNWInfo()
 
55
 
 
56
        self.stubs.Set(self.network_api, '_get_instance_nw_info',
 
57
                       fake_get_nw_info)
 
58
 
 
59
        if orig_instance_uuid:
 
60
            expected_updated_instances = [new_instance['uuid'],
 
61
                                          orig_instance_uuid]
 
62
        else:
 
63
            expected_updated_instances = [new_instance['uuid']]
 
64
 
 
65
        def fake_instance_info_cache_update(context, instance_uuid, cache):
 
66
            self.assertEquals(instance_uuid,
 
67
                              expected_updated_instances.pop())
 
68
 
 
69
        self.stubs.Set(self.network_api.db, 'instance_info_cache_update',
 
70
                       fake_instance_info_cache_update)
 
71
 
 
72
        self.network_api.associate_floating_ip(self.context,
 
73
                                               new_instance,
 
74
                                               '172.24.4.225',
 
75
                                               '10.0.0.2')
 
76
 
 
77
    def test_associate_preassociated_floating_ip(self):
 
78
        self._do_test_associate_floating_ip('orig-uuid')
 
79
 
 
80
    def test_associate_unassociated_floating_ip(self):
 
81
        self._do_test_associate_floating_ip(None)