1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Red Hat, Inc.
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
10
# http://www.apache.org/licenses/LICENSE-2.0
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
18
"""Tests for network API"""
20
from nova import context
22
from nova import network
23
from nova.openstack.common import rpc
27
class ApiTestCase(test.TestCase):
29
super(ApiTestCase, self).setUp()
30
self.network_api = network.API()
31
self.context = context.RequestContext('fake-user',
34
def _do_test_associate_floating_ip(self, orig_instance_uuid):
35
"""Test post-association logic"""
37
new_instance = {'uuid': 'new-uuid'}
39
def fake_rpc_call(context, topic, msg):
40
return orig_instance_uuid
42
self.stubs.Set(rpc, 'call', fake_rpc_call)
44
def fake_instance_get_by_uuid(context, instance_uuid):
45
return {'uuid': instance_uuid}
47
self.stubs.Set(self.network_api.db, 'instance_get_by_uuid',
48
fake_instance_get_by_uuid)
50
def fake_get_nw_info(ctxt, instance):
51
class FakeNWInfo(object):
56
self.stubs.Set(self.network_api, '_get_instance_nw_info',
59
if orig_instance_uuid:
60
expected_updated_instances = [new_instance['uuid'],
63
expected_updated_instances = [new_instance['uuid']]
65
def fake_instance_info_cache_update(context, instance_uuid, cache):
66
self.assertEquals(instance_uuid,
67
expected_updated_instances.pop())
69
self.stubs.Set(self.network_api.db, 'instance_info_cache_update',
70
fake_instance_info_cache_update)
72
self.network_api.associate_floating_ip(self.context,
77
def test_associate_preassociated_floating_ip(self):
78
self._do_test_associate_floating_ip('orig-uuid')
80
def test_associate_unassociated_floating_ip(self):
81
self._do_test_associate_floating_ip(None)