22
22
from nova import context
23
23
from nova import db
24
from nova import flags
25
24
from nova.network import linux_net
25
from nova.openstack.common import cfg
26
from nova.openstack.common import fileutils
26
27
from nova.openstack.common import importutils
27
28
from nova.openstack.common import log as logging
28
29
from nova import test
29
30
from nova import utils
33
CONF.import_opt('network_driver', 'nova.config')
34
34
LOG = logging.getLogger(__name__)
39
38
instances = {'00000000-0000-0000-0000-0000000000000000':
217
216
super(LinuxNetworkTestCase, self).setUp()
218
network_driver = FLAGS.network_driver
217
network_driver = CONF.network_driver
219
218
self.driver = importutils.import_module(network_driver)
220
219
self.driver.db = db
221
220
self.context = context.RequestContext('testuser', 'testproject',
224
223
def get_vifs(_context, instance_uuid):
225
return [vif for vif in vifs if vif['instance_uuid'] == \
224
return [vif for vif in vifs if vif['instance_uuid'] ==
228
227
def get_instance(_context, instance_id):
236
235
self.flags(use_single_default_gateway=True)
238
237
self.mox.StubOutWithMock(self.driver, 'write_to_file')
239
self.mox.StubOutWithMock(utils, 'ensure_tree')
238
self.mox.StubOutWithMock(fileutils, 'ensure_tree')
240
239
self.mox.StubOutWithMock(os, 'chmod')
242
241
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
243
242
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
244
utils.ensure_tree(mox.IgnoreArg())
245
utils.ensure_tree(mox.IgnoreArg())
246
utils.ensure_tree(mox.IgnoreArg())
247
utils.ensure_tree(mox.IgnoreArg())
248
utils.ensure_tree(mox.IgnoreArg())
249
utils.ensure_tree(mox.IgnoreArg())
250
utils.ensure_tree(mox.IgnoreArg())
243
fileutils.ensure_tree(mox.IgnoreArg())
244
fileutils.ensure_tree(mox.IgnoreArg())
245
fileutils.ensure_tree(mox.IgnoreArg())
246
fileutils.ensure_tree(mox.IgnoreArg())
247
fileutils.ensure_tree(mox.IgnoreArg())
248
fileutils.ensure_tree(mox.IgnoreArg())
249
fileutils.ensure_tree(mox.IgnoreArg())
251
250
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
252
251
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
259
258
self.flags(use_single_default_gateway=True)
261
260
self.mox.StubOutWithMock(self.driver, 'write_to_file')
262
self.mox.StubOutWithMock(utils, 'ensure_tree')
261
self.mox.StubOutWithMock(fileutils, 'ensure_tree')
263
262
self.mox.StubOutWithMock(os, 'chmod')
265
264
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
266
265
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
267
utils.ensure_tree(mox.IgnoreArg())
268
utils.ensure_tree(mox.IgnoreArg())
269
utils.ensure_tree(mox.IgnoreArg())
270
utils.ensure_tree(mox.IgnoreArg())
271
utils.ensure_tree(mox.IgnoreArg())
272
utils.ensure_tree(mox.IgnoreArg())
273
utils.ensure_tree(mox.IgnoreArg())
266
fileutils.ensure_tree(mox.IgnoreArg())
267
fileutils.ensure_tree(mox.IgnoreArg())
268
fileutils.ensure_tree(mox.IgnoreArg())
269
fileutils.ensure_tree(mox.IgnoreArg())
270
fileutils.ensure_tree(mox.IgnoreArg())
271
fileutils.ensure_tree(mox.IgnoreArg())
272
fileutils.ensure_tree(mox.IgnoreArg())
274
273
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
275
274
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
308
307
self.assertEquals(actual_hosts, expected)
310
309
def test_get_dhcp_opts_for_nw00(self):
311
expected_opts = 'NW-0,3\nNW-3,3\nNW-4,3'
310
expected_opts = 'NW-3,3\nNW-4,3'
312
311
actual_opts = self.driver.get_dhcp_opts(self.context, networks[0])
314
313
self.assertEquals(actual_opts, expected_opts)