Add management_ip field to dcorch subcloud table

This commit adds a new management_ip field to the dcorch subcloud
table. This field will be used to build the subclouds service endpoints
after the OptimizedOpenStackDriver [1] is integrated into dcorch.

The DB upgrade script and related upgrade tests will be done in a
separate commit.

Test Plan:
1. PASS - Run the dcorch database migration script to update it to
          version 009, verify that the management_ip column is added
          to the subcloud table.
2. PASS - Add a new subcloud and verify in dcorch DB that the a new
          subcloud item was added with the correct management_ip field.
3. PASS - Run a subcloud update with network reconfiguration, changing
          the management_ip, verify that in dcorch DB that the subcloud
          item was updated correctly.

[1]: https://review.opendev.org/c/starlingx/distcloud/+/918311

Story: 2011106
Task: 50105

Change-Id: If1c299700fd769dc8f89172c5088fe7de66d0774
Signed-off-by: Gustavo Herzmann <gustavo.herzmann@windriver.com>
This commit is contained in:
Gustavo Herzmann 2024-05-15 10:11:36 -03:00
parent 287246bf4f
commit fbd78b235c
13 changed files with 72 additions and 11 deletions

View File

@ -1416,7 +1416,11 @@ class SubcloudManager(manager.Manager):
# Inform orchestrator that subcloud has been added
self.dcorch_rpc_client.add_subcloud(
context, subcloud.region_name, subcloud.software_version)
context,
subcloud.region_name,
subcloud.software_version,
subcloud.management_start_ip
)
# create entry into alarm summary table, will get real values later
alarm_updates = {'critical_alarms': -1,
@ -3201,8 +3205,13 @@ class SubcloudManager(manager.Manager):
# Update service URLs in subcloud endpoint cache
self.audit_rpc_client.trigger_subcloud_endpoints_update(
context, subcloud_region, services_endpoints)
# TODO(gherzm): Remove the update_subcloud_endpoints call once
# the OpenStackDriver is moved to be used only in the master process
self.dcorch_rpc_client.update_subcloud_endpoints(
context, subcloud_region, services_endpoints)
# Update the management ip inside dcorch database
self.dcorch_rpc_client.update_subcloud_management_ip(
context, subcloud_region, endpoint_ip)
# Update sysinv URL in cert-mon cache
dc_notification = dcmanager_rpc_client.DCManagerNotifications()
dc_notification.subcloud_sysinv_endpoint_update(

View File

@ -89,6 +89,7 @@ class SubcloudController(object):
:param result: Result object to return an output.
"""
name = payload['subcloud']
management_ip = payload['management_ip']
version = '17.06'
self.rpc_client.add_subcloud(context, name, version)
self.rpc_client.add_subcloud(context, name, version, management_ip)
return {'added': {'subcloud': name}}

View File

@ -0,0 +1,23 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import sqlalchemy
def upgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
subcloud = sqlalchemy.Table("subcloud", meta, autoload=True)
# Add the management_ip attribute
subcloud.create_column(sqlalchemy.Column("management_ip", sqlalchemy.String(64)))
return True
def downgrade(migrate_engine):
raise NotImplementedError("Database downgrade is unsupported.")

View File

@ -179,6 +179,7 @@ class Subcloud(BASE, OrchestratorBase):
capabilities = Column(JSONEncodedDict)
initial_sync_state = Column('initial_sync_state', String(64),
default=consts.INITIAL_SYNC_STATE_NONE)
management_ip = Column('management_ip', String(64))
class Resource(BASE, OrchestratorBase):

View File

@ -109,7 +109,7 @@ class GenericSyncWorkerManager(object):
values={'sync_request': new_state})
LOG.info(f"End of sync_subcloud {subcloud_name}.")
def add_subcloud(self, context, name, version):
def add_subcloud(self, context, name, version, management_ip):
# create subcloud in DB and create the sync objects
LOG.info(f"adding subcloud {name}")
endpoint_type_list = dco_consts.SYNC_ENDPOINT_TYPES_LIST[:]
@ -117,7 +117,7 @@ class GenericSyncWorkerManager(object):
sc = subcloud.Subcloud(
context, region_name=name, software_version=version,
capabilities=capabilities)
capabilities=capabilities, management_ip=management_ip)
sc = sc.create()
for endpoint_type in endpoint_type_list:
db_api.subcloud_sync_create(context, name, endpoint_type,
@ -300,6 +300,14 @@ class GenericSyncWorkerManager(object):
LOG.error(f"Failed to update services endpoints for "
f"subcloud: {subcloud_name} in dcorch.")
def update_subcloud_management_ip(self, context, subcloud_name, management_ip):
try:
sc = subcloud.Subcloud.get_by_name(context, subcloud_name)
sc.management_ip = management_ip
sc.save()
except KeyError:
raise exceptions.SubcloudNotFound(region_name=subcloud_name)
def _audit_subcloud(self, context, subcloud_name, endpoint_type, sync_obj):
new_state = dco_consts.AUDIT_STATUS_COMPLETED
timeout = eventlet.timeout.Timeout(SYNC_TIMEOUT)

View File

@ -228,8 +228,8 @@ class EngineWorkerService(service.Service):
'%s' % (self.engine_id, ex))
@request_context
def add_subcloud(self, ctxt, subcloud_name, sw_version):
self.gswm.add_subcloud(ctxt, subcloud_name, sw_version)
def add_subcloud(self, ctxt, subcloud_name, sw_version, management_ip):
self.gswm.add_subcloud(ctxt, subcloud_name, sw_version, management_ip)
@request_context
# todo: add authentication since ctxt not actually needed later
@ -333,6 +333,10 @@ class EngineWorkerService(service.Service):
def update_subcloud_endpoints(self, ctxt, subcloud_name, endpoints):
self.gswm.update_subcloud_endpoints(ctxt, subcloud_name, endpoints)
@request_context
def update_subcloud_management_ip(self, ctxt, subcloud_name, management_ip):
self.gswm.update_subcloud_management_ip(ctxt, subcloud_name, management_ip)
def _stop_rpc_server(self):
# Stop RPC connection to prevent new requests
LOG.debug(_("Attempting to stop engine-worker service..."))

View File

@ -42,6 +42,7 @@ class Subcloud(base.OrchestratorObject, base.VersionedObjectDictCompat):
'availability_status': ovo_fields.StringField(),
'capabilities': ovo_fields.DictOfListOfStringsField(),
'initial_sync_state': ovo_fields.StringField(),
'management_ip': ovo_fields.StringField()
}
def create(self):

View File

@ -117,11 +117,11 @@ class EngineWorkerClient(object):
ctxt,
self.make_msg('image_sync', job_id=job_id, payload=payload))
def add_subcloud(self, ctxt, subcloud_name, sw_version):
def add_subcloud(self, ctxt, subcloud_name, sw_version, management_ip):
return self.call(
ctxt,
self.make_msg('add_subcloud', subcloud_name=subcloud_name,
sw_version=sw_version))
sw_version=sw_version, management_ip=management_ip))
def del_subcloud(self, ctxt, subcloud_name):
return self.call(
@ -181,3 +181,13 @@ class EngineWorkerClient(object):
return self.cast(ctxt, self.make_msg(
'update_subcloud_endpoints', subcloud_name=subcloud_name,
endpoints=endpoints), fanout=True, version=self.BASE_RPC_API_VERSION)
def update_subcloud_management_ip(self, ctxt, subcloud_name, management_ip):
return self.call(
ctxt,
self.make_msg(
"update_subcloud_management_ip",
subcloud_name=subcloud_name,
management_ip=management_ip,
),
)

View File

@ -61,6 +61,7 @@ class DBAPIOrchRequestTest(base.OrchestratorTestCase):
def create_subcloud(ctxt, region_name, **kwargs):
values = {
'management_state': None,
'management_ip': '192.168.0.1'
}
values.update(kwargs)
return db_api.subcloud_create(ctxt, region_name, values)

View File

@ -54,7 +54,7 @@ class DBAPISubcloudTest(base.OrchestratorTestCase):
@staticmethod
def create_subcloud(ctxt, region_name, **kwargs):
values = {}
values = {'management_ip': '192.168.0.1'}
values.update(kwargs)
return db_api.subcloud_create(ctxt, region_name, values)

View File

@ -59,6 +59,7 @@ class DBAPISubcloudResourceTest(base.OrchestratorTestCase):
def create_subcloud(ctxt, region_name, **kwargs):
values = {
'management_state': None,
'management_ip': '192.168.0.1'
}
values.update(kwargs)
return db_api.subcloud_create(ctxt, region_name, values)

View File

@ -65,7 +65,8 @@ class BaseTestIdentitySyncThread(OrchestratorTestCase, mixins.BaseMixin):
'management_state': dccommon_consts.MANAGEMENT_MANAGED,
'availability_status': dccommon_consts.AVAILABILITY_ONLINE,
'initial_sync_state': '',
'capabilities': {}
'capabilities': {},
'management_ip': '192.168.0.1'
}
self.subcloud = db_api.subcloud_create(self.ctx, 'subcloud', values)
self.subcloud_resource = subcloud_resource.SubcloudResource(

View File

@ -105,7 +105,8 @@ def create_subcloud_static(ctxt, name, **kwargs):
'management_state': dccommon_consts.MANAGEMENT_MANAGED,
'availability_status': dccommon_consts.AVAILABILITY_ONLINE,
'initial_sync_state': '',
'capabilities': base.CAPABILITES
'capabilities': base.CAPABILITES,
'management_ip': '192.168.0.1'
}
values.update(kwargs)
return db_api.subcloud_create(ctxt, name, values=values)