~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/fake_network.py

  • Committer: Tarmac
  • Author(s): Jason Koelker
  • Date: 2011-09-19 20:16:49 UTC
  • mfrom: (1558.1.54 network_refactor)
  • Revision ID: tarmac-20110919201649-9em4fa4tdwe91oic
* Remove the foreign key and backrefs tying vif<->instance
* Update instance filtering to pass ip related filters to the network manager
* move/update tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# under the License.
17
17
 
18
18
from nova import db
 
19
from nova import exception
19
20
from nova import flags
20
 
from nova import test
 
21
from nova import utils
21
22
from nova.network import manager as network_manager
22
23
 
23
24
 
64
65
            return self[name]
65
66
 
66
67
 
 
68
class FakeNetworkManager(network_manager.NetworkManager):
 
69
    """This NetworkManager doesn't call the base class so we can bypass all
 
70
    inherited service cruft and just perform unit tests.
 
71
    """
 
72
 
 
73
    class FakeDB:
 
74
        def fixed_ip_get_by_instance(self, context, instance_id):
 
75
            return [dict(address='10.0.0.0'),  dict(address='10.0.0.1'),
 
76
                    dict(address='10.0.0.2')]
 
77
 
 
78
        def network_get_by_cidr(self, context, cidr):
 
79
            raise exception.NetworkNotFoundForCidr()
 
80
 
 
81
        def network_create_safe(self, context, net):
 
82
            fakenet = dict(net)
 
83
            fakenet['id'] = 999
 
84
            return fakenet
 
85
 
 
86
        def network_get_all(self, context):
 
87
            raise exception.NoNetworksFound()
 
88
 
 
89
        def virtual_interface_get_all(self, context):
 
90
            floats = [{'address': '172.16.1.1'},
 
91
                      {'address': '172.16.1.2'},
 
92
                      {'address': '173.16.1.2'}]
 
93
 
 
94
            vifs = [{'instance_id': 0,
 
95
                     'fixed_ipv6': '2001:db8::dcad:beff:feef:1',
 
96
                     'fixed_ips': [{'address': '172.16.0.1',
 
97
                                    'floating_ips': [floats[0]]}]},
 
98
                    {'instance_id': 20,
 
99
                     'fixed_ipv6': '2001:db8::dcad:beff:feef:2',
 
100
                     'fixed_ips': [{'address': '172.16.0.2',
 
101
                                    'floating_ips': [floats[1]]}]},
 
102
                    {'instance_id': 30,
 
103
                     'fixed_ipv6': '2002:db8::dcad:beff:feef:2',
 
104
                     'fixed_ips': [{'address': '173.16.0.2',
 
105
                                    'floating_ips': [floats[2]]}]}]
 
106
            return vifs
 
107
 
 
108
        def instance_get_uuids_by_ids(self, context, ids):
 
109
            # NOTE(jkoelker): This is just here until we can rely on UUIDs
 
110
            return [{'uuid': str(utils.gen_uuid()),
 
111
                     'id': id} for id in ids]
 
112
 
 
113
    def __init__(self):
 
114
        self.db = self.FakeDB()
 
115
        self.deallocate_called = None
 
116
 
 
117
    def deallocate_fixed_ip(self, context, address):
 
118
        self.deallocate_called = address
 
119
 
 
120
    def _create_fixed_ips(self, context, network_id):
 
121
        pass
 
122
 
 
123
 
67
124
flavor = {'id': 0,
68
125
          'name': 'fake_flavor',
69
126
          'memory_mb': 2048,