~ubuntu-branches/ubuntu/quantal/nova/quantal-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
  • 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:
36
36
def network_api_get_fixed_ip(self, context, id):
37
37
    if id is None:
38
38
        return None
39
 
    return {'address': '10.0.0.1', 'id': id, 'instance_id': 1}
 
39
    return {'address': '10.0.0.1', 'id': id, 'instance_uuid': 1}
40
40
 
41
41
 
42
42
def network_api_get_floating_ip(self, context, id):
99
99
    return get_nw_info_for_instance
100
100
 
101
101
 
 
102
def get_instance_by_floating_ip_addr(self, context, address):
 
103
    return None
 
104
 
 
105
 
102
106
class FloatingIpTest(test.TestCase):
103
107
    floating_ip = "10.10.10.10"
 
108
    floating_ip_2 = "10.10.10.11"
104
109
 
105
 
    def _create_floating_ip(self):
 
110
    def _create_floating_ips(self, floating_ips=None):
106
111
        """Create a floating ip object."""
107
 
        host = "fake_host"
108
 
        return db.floating_ip_create(self.context,
109
 
                                     {'address': self.floating_ip,
110
 
                                      'pool': 'nova',
111
 
                                      'host': host})
 
112
        if floating_ips is None:
 
113
            floating_ips = [self.floating_ip]
 
114
        elif not isinstance(floating_ips, (list, tuple)):
 
115
            floating_ips = [floating_ips]
 
116
 
 
117
        def make_ip_dict(ip):
 
118
            """Shortcut for creating floating ip dict."""
 
119
            return
 
120
 
 
121
        dict_ = {'pool': 'nova', 'host': 'fake_host'}
 
122
        return db.floating_ip_bulk_create(
 
123
            self.context, [dict(address=ip, **dict_) for ip in floating_ips],
 
124
        )
112
125
 
113
126
    def _delete_floating_ip(self):
114
127
        db.floating_ip_destroy(self.context, self.floating_ip)
129
142
                       network_api_release)
130
143
        self.stubs.Set(network.api.API, "disassociate_floating_ip",
131
144
                       network_api_disassociate)
 
145
        self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
 
146
                       get_instance_by_floating_ip_addr)
132
147
        self.stubs.Set(compute_utils, "get_nw_info_for_instance",
133
148
                       stub_nw_info(self.stubs))
134
149
 
138
153
                       fake_instance_get)
139
154
 
140
155
        self.context = context.get_admin_context()
141
 
        self._create_floating_ip()
 
156
        self._create_floating_ips()
142
157
 
143
158
        self.controller = floating_ips.FloatingIPController()
144
159
        self.manager = floating_ips.FloatingIPActionController()
148
163
        super(FloatingIpTest, self).tearDown()
149
164
 
150
165
    def test_translate_floating_ip_view(self):
151
 
        floating_ip_address = self._create_floating_ip()
 
166
        floating_ip_address = self.floating_ip
152
167
        floating_ip = db.floating_ip_get_by_address(self.context,
153
168
                                                    floating_ip_address)
154
169
        floating_ip['fixed_ip'] = None
208
223
                    'fixed_ip_id': 11}
209
224
 
210
225
        def get_fixed_ip(self, context, id):
211
 
            return {'address': '10.0.0.1', 'instance_id': 1}
 
226
            return {'address': '10.0.0.1', 'instance_uuid': 1}
212
227
 
213
228
        self.stubs.Set(network.api.API, "get_floating_ip", get_floating_ip)
214
229
        self.stubs.Set(network.api.API, "get_fixed_ip", get_fixed_ip)
220
235
        self.assertEqual(res_dict['floating_ip']['ip'], '10.10.10.10')
221
236
        self.assertEqual(res_dict['floating_ip']['instance_id'], FAKE_UUID)
222
237
 
 
238
    def test_recreation_of_floating_ip(self):
 
239
        self._delete_floating_ip()
 
240
        self._create_floating_ips()
 
241
 
 
242
    def test_floating_ip_in_bulk_creation(self):
 
243
        self._delete_floating_ip()
 
244
 
 
245
        self._create_floating_ips([self.floating_ip, self.floating_ip_2])
 
246
        all_ips = db.floating_ip_get_all(self.context)
 
247
        ip_list = [ip['address'] for ip in all_ips]
 
248
        self.assertIn(self.floating_ip, ip_list)
 
249
        self.assertIn(self.floating_ip_2, ip_list)
 
250
 
 
251
    def test_fail_floating_ip_in_bulk_creation(self):
 
252
        self.assertRaises(exception.FloatingIpExists,
 
253
                          self._create_floating_ips,
 
254
                          [self.floating_ip, self.floating_ip_2])
 
255
        all_ips = db.floating_ip_get_all(self.context)
 
256
        ip_list = [ip['address'] for ip in all_ips]
 
257
        self.assertIn(self.floating_ip, ip_list)
 
258
        self.assertNotIn(self.floating_ip_2, ip_list)
 
259
 
223
260
# test floating ip allocate/release(deallocate)
224
261
    def test_floating_ip_allocate_no_free_ips(self):
225
262
        def fake_call(*args, **kwargs):
228
265
        self.stubs.Set(rpc, "call", fake_call)
229
266
 
230
267
        req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips')
231
 
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
 
268
        self.assertRaises(exception.NoMoreFloatingIps,
 
269
                          self.controller.create,
232
270
                          req)
233
271
 
234
272
    def test_floating_ip_allocate(self):
274
312
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
275
313
        self.manager._remove_floating_ip(req, 'test_inst', body)
276
314
 
 
315
    def test_floating_ip_disassociate_missing(self):
 
316
        body = dict(removeFloatingIp=dict(address='10.10.10.10'))
 
317
 
 
318
        req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
 
319
        rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
 
320
        self.assertTrue(rsp.status_int == 404)
 
321
 
277
322
# these are a few bad param tests
278
323
 
279
324
    def test_bad_address_param_in_remove_floating_ip(self):