Merge "Process v6 pool's uuid option in create_network"

This commit is contained in:
Jenkins 2017-03-21 08:51:11 +00:00 committed by Gerrit Code Review
commit aaa60cace0
2 changed files with 26 additions and 23 deletions
kuryr_libnetwork

@ -674,7 +674,6 @@ def network_driver_create_network():
neutron_uuid = None
neutron_name = None
existing_pool_id = ''
v4_pool_name = ''
v4_pool_id = ''
v6_pool_name = ''
@ -688,8 +687,10 @@ def network_driver_create_network():
v4_pool_name = generic_options.get(const.NEUTRON_POOL_NAME_OPTION)
v6_pool_name = generic_options.get(
const.NEUTRON_V6_POOL_NAME_OPTION)
existing_pool_id = generic_options.get(
v4_pool_id = generic_options.get(
const.NEUTRON_POOL_UUID_OPTION)
v6_pool_id = generic_options.get(
const.NEUTRON_V6_POOL_UUID_OPTION)
def _get_pool_id(pool_name, pool_cidr):
pool_id = ''
@ -705,20 +706,21 @@ def network_driver_create_network():
"exist.").format(pool_name))
return pool_id
if existing_pool_id:
pools = _get_subnetpools_by_attrs(id=existing_pool_id)
if pools:
existing_pool_id = pools[0]['id']
else:
def _verify_pool_id(pool_id):
pools = _get_subnetpools_by_attrs(id=pool_id)
if not pools:
raise exceptions.KuryrException(
("Specified pool id({0}) does not "
"exist.").format(existing_pool_id))
"exist.").format(pool_id))
if existing_pool_id:
v4_pool_id = existing_pool_id
if v4_pool_id:
_verify_pool_id(v4_pool_id)
else:
v4_pool_id = _get_pool_id(v4_pool_name, v4_pool_cidr)
v6_pool_id = _get_pool_id(v6_pool_name, v6_pool_cidr)
if v6_pool_id:
_verify_pool_id(v6_pool_id)
else:
v6_pool_id = _get_pool_id(v6_pool_name, v6_pool_cidr)
# let the user override the driver default
if not neutron_uuid and not neutron_name:

@ -751,7 +751,7 @@ class TestKuryr(base.TestKuryrBase):
@mock.patch(
'kuryr_libnetwork.controllers.app.driver.get_default_network_id')
@ddt.data((True), (False))
def test_network_driver_create_network_with_v4_pool_name_option(self,
def test_network_driver_create_network_with_pool_name_option(self,
driver_default_net, mock_get_default_network_id,
mock_list_networks, mock_create_network, mock_add_tag,
mock_create_subnet, mock_list_subnetpools,
@ -762,6 +762,11 @@ class TestKuryr(base.TestKuryrBase):
kuryr_v4_subnetpools = self._get_fake_v4_subnetpools(
fake_kuryr_v4_subnetpool_id, name=fake_v4_pool_name)
fake_kuryr_v6_subnetpool_id = uuidutils.generate_uuid()
fake_v6_pool_name = "fake_v6pool_name"
kuryr_v6_subnetpools = self._get_fake_v6_subnetpools(
fake_kuryr_v6_subnetpool_id, name=fake_v6_pool_name)
docker_network_id = lib_utils.get_hash()
network_request = {
'NetworkID': docker_network_id,
@ -778,15 +783,11 @@ class TestKuryr(base.TestKuryrBase):
'Options': {
'com.docker.network.enable_ipv6': True,
'com.docker.network.generic': {
'neutron.pool.name': fake_v4_pool_name
'neutron.pool.name': fake_v4_pool_name,
'neutron.pool.v6.name': fake_v6_pool_name,
}
}
}
fake_kuryr_v6_subnetpool_id = uuidutils.generate_uuid()
fake_v6_pool_name = lib_utils.get_neutron_subnetpool_name(
network_request['IPv6Data'][0]['Pool'])
kuryr_v6_subnetpools = self._get_fake_v6_subnetpools(
fake_kuryr_v6_subnetpool_id, name=fake_v6_pool_name)
# The following fake response is retrieved from the Neutron doc:
# http://developer.openstack.org/api-ref-networking-v2.html#createNetwork # noqa
@ -926,6 +927,10 @@ class TestKuryr(base.TestKuryrBase):
kuryr_v4_subnetpools = self._get_fake_v4_subnetpools(
fake_kuryr_v4_subnetpool_id)
fake_kuryr_v6_subnetpool_id = uuidutils.generate_uuid()
kuryr_v6_subnetpools = self._get_fake_v6_subnetpools(
fake_kuryr_v6_subnetpool_id)
docker_network_id = lib_utils.get_hash()
network_request = {
'NetworkID': docker_network_id,
@ -943,14 +948,10 @@ class TestKuryr(base.TestKuryrBase):
'com.docker.network.enable_ipv6': False,
'com.docker.network.generic': {
'neutron.pool.uuid': fake_kuryr_v4_subnetpool_id,
'neutron.pool.v6.uuid': fake_kuryr_v6_subnetpool_id,
}
}
}
fake_kuryr_v6_subnetpool_id = uuidutils.generate_uuid()
fake_v6_pool_name = lib_utils.get_neutron_subnetpool_name(
network_request['IPv6Data'][0]['Pool'])
kuryr_v6_subnetpools = self._get_fake_v6_subnetpools(
fake_kuryr_v6_subnetpool_id, name=fake_v6_pool_name)
# The following fake response is retrieved from the Neutron doc:
# http://developer.openstack.org/api-ref-networking-v2.html#createNetwork # noqa