DC: Set system controller gateway for admin network

When a subcloud is provisioned with the admin network,
it is required to set the system controller gateway
address so that a route to the system controller is
created when the distributed cloud config is run.

This commit also fixes a bug in the handling of
'address already exists' exception messaging during
route creation.

Test Plan:

Provision a subcloud to use the admin network
  - Ensure a route to the system controller is created
  - Ensure the subcloud can become managed, in-sync

Provision a subcloud to use the mgmt network (regression)
  - Ensure a route to the system controller is created
  - Ensure the subcloud can become managed, in-sync

Story: 2010319
Task: 46910

Signed-off-by: Steven Webster <steven.webster@windriver.com>
Change-Id: I0c62fbecd90258213075f2c22af60529d9ed2b88
This commit is contained in:
Steven Webster 2023-01-31 15:05:31 +00:00
parent 08f7ca4444
commit e9705f5bc6
3 changed files with 29 additions and 5 deletions

View File

@ -183,7 +183,7 @@ class NetworkController(rest.RestController):
if network['type'] == constants.NETWORK_TYPE_MGMT:
addresses = self._create_mgmt_network_address(pool)
elif network['type'] == constants.NETWORK_TYPE_ADMIN:
addresses = self._create_admin_network_address()
addresses = self._create_admin_network_address(pool)
elif network['type'] == constants.NETWORK_TYPE_PXEBOOT:
addresses = self._create_pxeboot_network_address()
elif network['type'] == constants.NETWORK_TYPE_CLUSTER_HOST:
@ -220,11 +220,22 @@ class NetworkController(rest.RestController):
pool.gateway_address
return addresses
def _create_admin_network_address(self):
def _create_admin_network_address(self, pool):
addresses = collections.OrderedDict()
addresses[constants.CONTROLLER_HOSTNAME] = None
addresses[constants.CONTROLLER_0_HOSTNAME] = None
addresses[constants.CONTROLLER_1_HOSTNAME] = None
if pool.gateway_address is not None:
if utils.get_distributed_cloud_role() == \
constants.DISTRIBUTED_CLOUD_ROLE_SUBCLOUD:
# In subcloud configurations, the admin gateway is used
# to communicate with the central cloud.
addresses[constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME] =\
pool.gateway_address
else:
addresses[constants.CONTROLLER_GATEWAY] =\
pool.gateway_address
return addresses
def _create_pxeboot_network_address(self):

View File

@ -1821,12 +1821,14 @@ def perform_distributed_cloud_config(dbapi, mgmt_iface_id):
# the system controller gateway into the database.
try:
# Prefer admin network
dbapi.network_get_by_type(
sc_network = dbapi.network_get_by_type(
constants.NETWORK_TYPE_ADMIN)
cc_gtwy_addr_name = '%s-%s' % (
constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME,
constants.NETWORK_TYPE_ADMIN)
except exception.NetworkTypeNotFound:
sc_network = dbapi.network_get_by_type(
constants.NETWORK_TYPE_MGMT)
cc_gtwy_addr_name = '%s-%s' % (
constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME,
constants.NETWORK_TYPE_MGMT)
@ -1859,6 +1861,14 @@ def perform_distributed_cloud_config(dbapi, mgmt_iface_id):
'metric': 1
}
for ifnet in dbapi.interface_network_get_by_interface(mgmt_iface_id):
if ifnet.network_id == sc_network.id:
break
else:
LOG.warning("DC Config: Failed to retrieve network for interface "
"id %s", mgmt_iface_id)
return
try:
dbapi.route_create(mgmt_iface_id, route)
except exception.RouteAlreadyExists:

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2013-2022 Wind River Systems, Inc.
# Copyright (c) 2013-2023 Wind River Systems, Inc.
#
"""SQLAlchemy storage backend."""
@ -5515,7 +5515,10 @@ class Connection(api.Connection):
session.add(route)
session.flush()
except db_exc.DBDuplicateEntry:
raise exception.RouteAlreadyExists(uuid=values['uuid'])
raise exception.RouteAlreadyExists(
network=route['network'],
prefix=route['prefix'],
gateway=route['gateway'])
return self._route_get(values['uuid'])
@db_objects.objectify(objects.route)