Setting access ip values on server create.

Change-Id: Id67c5e9d7bb00227e88ecbc2ffb0e772fcd69066
This commit is contained in:
Naveed Massjouni
2012-02-14 19:46:19 +00:00
parent bf173290c5
commit de7b7463dc
2 changed files with 37 additions and 3 deletions

View File

@@ -454,7 +454,10 @@ global_opts = [
help='The volume API class to use'), help='The volume API class to use'),
cfg.StrOpt('security_group_handler', cfg.StrOpt('security_group_handler',
default='nova.network.quantum.sg.NullSecurityGroupHandler', default='nova.network.quantum.sg.NullSecurityGroupHandler',
help='security group handler class') help='security group handler class'),
cfg.StrOpt('default_access_ip_network_name',
default=None,
help='Name of network to use to set access ips for instances'),
] ]
FLAGS.register_opts(global_opts) FLAGS.register_opts(global_opts)

View File

@@ -192,7 +192,7 @@ class BaseTestCase(test.TestCase):
class ComputeTestCase(BaseTestCase): class ComputeTestCase(BaseTestCase):
def setUp(self): def setUp(self):
def fake_get_nw_info(cls, ctxt, instance): def fake_get_nw_info(cls, ctxt, instance, *args, **kwargs):
self.assertTrue(ctxt.is_admin) self.assertTrue(ctxt.is_admin)
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1, return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True) spectacular=True)
@@ -200,6 +200,8 @@ class ComputeTestCase(BaseTestCase):
super(ComputeTestCase, self).setUp() super(ComputeTestCase, self).setUp()
self.stubs.Set(nova.network.API, 'get_instance_nw_info', self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info) fake_get_nw_info)
self.stubs.Set(nova.network.API, 'allocate_for_instance',
fake_get_nw_info)
def test_wrap_instance_fault(self): def test_wrap_instance_fault(self):
inst_uuid = "fake_uuid" inst_uuid = "fake_uuid"
@@ -271,6 +273,35 @@ class ComputeTestCase(BaseTestCase):
finally: finally:
db.instance_destroy(self.context, instance['id']) db.instance_destroy(self.context, instance['id'])
def test_default_access_ip(self):
self.flags(default_access_ip_network_name='test1', stub_network=False)
instance = self._create_fake_instance()
try:
self.compute.run_instance(self.context, instance['uuid'],
is_first_time=True)
instances = db.instance_get_all(context.get_admin_context())
instance = instances[0]
self.assertEqual(instance.access_ip_v4, '192.168.1.100')
self.assertEqual(instance.access_ip_v6, '2001:db8:0:1::1')
finally:
db.instance_destroy(self.context, instance['id'])
def test_no_default_access_ip(self):
instance = self._create_fake_instance()
try:
self.compute.run_instance(self.context, instance['uuid'],
is_first_time=True)
instances = db.instance_get_all(context.get_admin_context())
instance = instances[0]
self.assertFalse(instance.access_ip_v4)
self.assertFalse(instance.access_ip_v6)
finally:
db.instance_destroy(self.context, instance['id'])
def _assert_state(self, state_dict): def _assert_state(self, state_dict):
"""assert the instance is in the state defined by state_dict""" """assert the instance is in the state defined by state_dict"""
instances = db.instance_get_all(context.get_admin_context()) instances = db.instance_get_all(context.get_admin_context())