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

« back to all changes in this revision

Viewing changes to nova/tests/fake_network.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-01-20 11:54:15 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: package-import@ubuntu.com-20120120115415-h2ujma9o536o1ut6
Tags: upstream-2012.1~e3~20120120.12170
ImportĀ upstreamĀ versionĀ 2012.1~e3~20120120.12170

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# License for the specific language governing permissions and limitations
16
16
# under the License.
17
17
 
 
18
import nova.context
18
19
from nova import db
19
20
from nova import exception
20
21
from nova import flags
71
72
    """
72
73
 
73
74
    class FakeDB:
 
75
        vifs = [{'id': 0,
 
76
                 'instance_id': 0,
 
77
                 'network_id': 1,
 
78
                 'address': 'DC:AD:BE:FF:EF:01'},
 
79
                {'id': 1,
 
80
                 'instance_id': 20,
 
81
                 'network_id': 21,
 
82
                 'address': 'DC:AD:BE:FF:EF:02'},
 
83
                {'id': 2,
 
84
                 'instance_id': 30,
 
85
                 'network_id': 31,
 
86
                 'address': 'DC:AD:BE:FF:EF:03'}]
 
87
 
 
88
        floating_ips = [dict(address='172.16.1.1',
 
89
                             fixed_ip_id=100),
 
90
                        dict(address='172.16.1.2',
 
91
                             fixed_ip_id=200),
 
92
                        dict(address='173.16.1.2',
 
93
                             fixed_ip_id=210)]
 
94
 
 
95
        fixed_ips = [dict(id=100,
 
96
                          address='172.16.0.1',
 
97
                          virtual_interface_id=0),
 
98
                     dict(id=200,
 
99
                          address='172.16.0.2',
 
100
                          virtual_interface_id=1),
 
101
                     dict(id=210,
 
102
                          address='173.16.0.2',
 
103
                          virtual_interface_id=2)]
 
104
 
74
105
        def fixed_ip_get_by_instance(self, context, instance_id):
75
106
            return [dict(address='10.0.0.0'), dict(address='10.0.0.1'),
76
107
                    dict(address='10.0.0.2')]
96
127
            return True
97
128
 
98
129
        def virtual_interface_get_all(self, context):
99
 
            floats = [{'address': '172.16.1.1'},
100
 
                      {'address': '172.16.1.2'},
101
 
                      {'address': '173.16.1.2'}]
102
 
 
103
 
            vifs = [{'instance_id': 0,
104
 
                     'network_id': 1,
105
 
                     'address': 'DC:AD:BE:FF:EF:01',
106
 
                     'fixed_ips': [{'address': '172.16.0.1',
107
 
                                    'floating_ips': [floats[0]]}]},
108
 
                    {'instance_id': 20,
109
 
                     'network_id': 21,
110
 
                     'address': 'DC:AD:BE:FF:EF:02',
111
 
                     'fixed_ips': [{'address': '172.16.0.2',
112
 
                                    'floating_ips': [floats[1]]}]},
113
 
                    {'instance_id': 30,
114
 
                     'network_id': 31,
115
 
                     'address': 'DC:AD:BE:FF:EF:03',
116
 
                     'fixed_ips': [{'address': '173.16.0.2',
117
 
                                    'floating_ips': [floats[2]]}]}]
118
 
            return vifs
 
130
            return self.vifs
119
131
 
120
132
        def instance_get_id_to_uuid_mapping(self, context, ids):
121
133
            # NOTE(jkoelker): This is just here until we can rely on UUIDs
124
136
                mapping[id] = str(utils.gen_uuid())
125
137
            return mapping
126
138
 
 
139
        def fixed_ips_by_virtual_interface(self, context, vif_id):
 
140
            return [ip for ip in self.fixed_ips
 
141
                    if ip['virtual_interface_id'] == vif_id]
 
142
 
127
143
    def __init__(self):
128
144
        self.db = self.FakeDB()
129
145
        self.deallocate_called = None
280
296
    stubs.Set(db, 'network_get', network_get_fake)
281
297
    stubs.Set(db, 'instance_info_cache_update', update_cache_fake)
282
298
 
283
 
    class FakeContext(object):
284
 
        def __init__(self):
285
 
            self.project_id = 1
286
 
 
287
 
    return network.get_instance_nw_info(FakeContext(), 0, 0, 0, None)
 
299
    context = nova.context.RequestContext('testuser', 'testproject',
 
300
                                          is_admin=False)
 
301
    return network.get_instance_nw_info(context, 0, 0, 0, None)
 
302
 
 
303
 
 
304
def stub_out_nw_api_get_instance_nw_info(stubs, func=None):
 
305
    import nova.network
 
306
 
 
307
    def get_instance_nw_info(self, context, instance):
 
308
        return [(None, {'label': 'public',
 
309
                       'ips': [{'ip': '192.168.0.3'}],
 
310
                                'ip6s': []})]
 
311
    if func is None:
 
312
        func = get_instance_nw_info
 
313
    stubs.Set(nova.network.API, 'get_instance_nw_info', func)