Add host-stor for new ceph-rook

The host-stor-add command accepts adding new host-stor only if the
storage-backend is ceph, so now we need to change it to accept rook-ceph
as well.

This adds/modifies checks in host-stor-add to accept adding host-stor
OSD for new ceph-rook storage backend.

Test Plan:
 - PASS: Check host-stor can be added with OSD function
 - PASS: Check host-stor state is aligned with host lock/unlock
 - PASS: Check if when host is unlocked the host-stor state is updated
         to 'configuring' and the storage_backend task is cleared.

Depends-On: https://review.opendev.org/c/starlingx/config/+/918749

Story: 2011117
Task: 50071

Change-Id: I660abab2313fd37cc20b2d255d355bba0d198613
Signed-off-by: Gustavo Ornaghi Antunes <gustavo.ornaghiantunes@windriver.com>
This commit is contained in:
Gustavo Ornaghi Antunes 2024-05-10 09:24:10 -03:00 committed by gustavo ornaghi antunes
parent b997cae4b7
commit 600d2b4bcf
4 changed files with 113 additions and 16 deletions

View File

@ -5191,6 +5191,14 @@ class HostController(rest.RestController):
if ihost.config_status == constants.CONFIG_STATUS_OUT_OF_DATE:
return
if backend.task == constants.SB_TASK_OSD_CONFIGURING:
stors = api.istor_get_list()
for stor in stors:
if stor.function == constants.STOR_FUNCTION_OSD:
api.istor_update(stor.uuid, {
'state': constants.SB_STATE_CONFIGURING
})
api.storage_backend_update(backend.uuid, {
'state': constants.SB_STATE_CONFIGURING,
'task': None

View File

@ -532,14 +532,26 @@ def _satisfy_other_conditions_to_delete_osd():
pecan.request.dbapi,
constants.SB_TYPE_CEPH
)
if is_simplex and is_ceph_backend_configured:
is_ceph_rook_backend_configuring = StorageBackendConfig.has_backend_configuring(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
)
is_ceph_rook_backend_configuring_on_unlock = StorageBackendConfig.has_backend_configuring_on_unlock(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
)
if (is_simplex and
(is_ceph_backend_configured or
is_ceph_rook_backend_configuring or
is_ceph_rook_backend_configuring_on_unlock)):
LOG.info('Verifying simplex is allowed to delete OSD')
all_stors_gt_one, amount_osd_err_msg = \
_amount_stors_function_osd_greater_than(1)
all_pools_size_gt_one, pools_size_err_msg = \
_all_pools_size_greater_than(1)
if is_ceph_backend_configured:
all_pools_size_gt_one, pools_size_err_msg = \
_all_pools_size_greater_than(1)
# I'm raising these ClientSideError exceptions here because this method
# should be called only by StorageController.delete method.
@ -547,13 +559,16 @@ def _satisfy_other_conditions_to_delete_osd():
# place.
if not all_stors_gt_one:
raise wsme.exc.ClientSideError(_(amount_osd_err_msg))
if not all_pools_size_gt_one:
if is_ceph_backend_configured and not all_pools_size_gt_one:
raise wsme.exc.ClientSideError(_(pools_size_err_msg))
return True
else:
LOG.info('System is not allowed to delete stor. is simplex ? {}.'
'is ceph configured ? {}.'
.format(is_simplex, is_ceph_backend_configured))
'is ceph-rook configuring ? {}.'
'is ceph-rook configuring-on-unlock ? {}.'
.format(is_simplex, is_ceph_backend_configured, is_ceph_rook_backend_configuring,
is_ceph_rook_backend_configuring_on_unlock))
return False
@ -618,13 +633,20 @@ def _check_host(stor):
raise wsme.exc.ClientSideError(_("Host %s must be locked." %
ihost['hostname']))
# semantic check: whether system has a ceph backend
if not StorageBackendConfig.has_backend_configured(
# semantic check: whether system has a ceph or ceph-rook backend
if (not StorageBackendConfig.has_backend_configured(
pecan.request.dbapi,
constants.SB_TYPE_CEPH
):
) and not StorageBackendConfig.has_backend_configuring(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
) and not StorageBackendConfig.has_backend_configuring_on_unlock(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
)):
raise wsme.exc.ClientSideError(_(
"System must have a %s backend" % constants.SB_TYPE_CEPH))
"System must have a %s backend in configured state or %s backend in configuring "
"or configuring-on-unlock state" % (constants.SB_TYPE_CEPH, constants.SB_TYPE_CEPH_ROOK)))
# semantic check: whether host can be locked or unsafely force locked based on
# ceph monitors availability
@ -970,6 +992,17 @@ def _create(stor):
new_stor = pecan.request.dbapi.istor_create(forihostid,
create_attrs)
if create_attrs['state'] == constants.SB_STATE_CONFIGURING_ON_UNLOCK:
if StorageBackendConfig.has_backend_configuring_on_unlock(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
):
ceph_rook_backend = StorageBackendConfig.get_configuring_on_unlock_backend(pecan.request.dbapi)
if ceph_rook_backend:
pecan.request.dbapi.storage_backend_update(ceph_rook_backend.uuid, {
'task': constants.SB_TASK_OSD_CONFIGURING
})
# Associate the disk to db record
values = {'foristorid': new_stor.id}
pecan.request.dbapi.idisk_update(idisk_uuid,
@ -1003,14 +1036,24 @@ def _create(stor):
# is not updated.
LOG.exception(e)
# Apply runtime manifests for OSDs on "available" nodes.
runtime_manifests = False
if ihost['operational'] == constants.OPERATIONAL_ENABLED:
runtime_manifests = True
is_ceph_rook_backend_configuring = StorageBackendConfig.has_backend_configuring(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
)
is_ceph_rook_backend_configuring_on_unlock = StorageBackendConfig.has_backend_configuring_on_unlock(
pecan.request.dbapi,
constants.SB_TYPE_CEPH_ROOK
)
if (not is_ceph_rook_backend_configuring and
not is_ceph_rook_backend_configuring_on_unlock):
# Apply runtime manifests for OSDs on "available" nodes.
runtime_manifests = False
if ihost['operational'] == constants.OPERATIONAL_ENABLED:
runtime_manifests = True
pecan.request.rpcapi.update_ceph_osd_config(pecan.request.context,
ihost, new_stor['uuid'],
runtime_manifests)
pecan.request.rpcapi.update_ceph_osd_config(pecan.request.context,
ihost, new_stor['uuid'],
runtime_manifests)
return new_stor

View File

@ -551,6 +551,7 @@ SB_TASK_RECONFIG_WORKER = 'reconfig-worker'
SB_TASK_RESIZE_CEPH_MON_LV = 'resize-ceph-mon-lv'
SB_TASK_ADD_OBJECT_GATEWAY = 'add-object-gateway'
SB_TASK_RESTORE = 'restore'
SB_TASK_OSD_CONFIGURING = 'osd-configuring'
# Storage backend ceph-mon-lv size
SB_CEPH_MON_GIB = 20

View File

@ -192,6 +192,51 @@ class StorageBackendConfig(object):
return False
@staticmethod
def has_backend_configuring(dbapi, target, service=None,
check_only_defaults=True):
""" Check if a backend is configuring. """
backend_list = dbapi.storage_backend_get_list()
for backend in backend_list:
LOG.info(backend.state)
if backend.state == constants.SB_STATE_CONFIGURING and \
backend.backend == target:
# Check if the backend name matches the default name
if check_only_defaults and \
backend.name != constants.SB_DEFAULT_NAMES[target]:
continue
# Check if a specific service is configured on the
# backend.
if service and service not in backend.services:
continue
return True
return False
@staticmethod
def has_backend_configuring_on_unlock(dbapi, target, service=None,
check_only_defaults=True):
""" Check if a backend is configuring-on-unlock. """
backend_list = dbapi.storage_backend_get_list()
for backend in backend_list:
if backend.state == constants.SB_STATE_CONFIGURING_ON_UNLOCK and \
backend.backend == target:
# Check if the backend name matches the default name
if check_only_defaults and \
backend.name != constants.SB_DEFAULT_NAMES[target]:
continue
# Check if a specific service is configured on the
# backend.
if service and service not in backend.services:
continue
return True
return False
@staticmethod
def has_backend(api, target):
backend_list = api.storage_backend_get_list()