Move DB functions to class

To better apply obligatory decorators like db_session_cleanup, this
commit moves dcmanager and dcorch DB functions to a class. A follow up
commit will move db_session_cleanup to a class decorator and add this
commit hash in .git-blame-ignore-revs as this is a reformat commit.

Because of this change, unit tests were also reformated to use the
DB interface instead of sqlalchemy backend directly.

Test plan:
  - PASS: Build a custom ISO with the changes and deploy a DX system
          controller and a SX subcloud. Verify the system works as
          expected.
  - PASS: Manage a subcloud and verify the sync_status is "in-sync".
  - PASS: Unmanage a subcloud and verify the management status was
          updated to "unmanaged".
  - PASS: Run "dcmanager subcloud show <subcloud_name> --detail" and
          verify the output is correct.
  - PASS: Run "sudo dcorch-manage db_clean 0" and verify old jobs were
          successfully purged.
  - PASS: Verify no errors were observed on dcmanager or dcorch logs.

Story: 2011311
Task: 51894

Change-Id: Ie193906be3a475f3b09e924b2c23a3bc767b3204
Signed-off-by: Victor Romano <victor.gluzromano@windriver.com>
This commit is contained in:
Victor Romano
2025-03-31 15:01:35 -03:00
parent 17fd32ebeb
commit 319331e8fe
43 changed files with 3205 additions and 3397 deletions

View File

@@ -50,32 +50,34 @@ def get_session():
def subcloud_audits_get(context, subcloud_id):
"""Get subcloud_audits info for a subcloud."""
return IMPL.subcloud_audits_get(context, subcloud_id)
return IMPL.Connection(context).subcloud_audits_get(subcloud_id)
def subcloud_audits_get_all(context, subcloud_ids=None):
"""Get subcloud_audits info for subclouds."""
return IMPL.subcloud_audits_get_all(context, subcloud_ids)
return IMPL.Connection(context).subcloud_audits_get_all(subcloud_ids)
def subcloud_audits_update_all(context, values):
"""Mark sub-audits as needed for all subclouds."""
return IMPL.subcloud_audits_update_all(context, values)
return IMPL.Connection(context).subcloud_audits_update_all(values)
def subcloud_audits_create(context, subcloud_id):
"""Create subcloud_audits info for a subcloud."""
return IMPL.subcloud_audits_create(context, subcloud_id)
return IMPL.Connection(context).subcloud_audits_create(subcloud_id)
def subcloud_audits_update(context, subcloud_id, values):
"""Get all subcloud_audits that need auditing."""
return IMPL.subcloud_audits_update(context, subcloud_id, values)
return IMPL.Connection(context).subcloud_audits_update(subcloud_id, values)
def subcloud_audits_get_all_need_audit(context, last_audit_threshold):
"""Get all subcloud_audits that need auditing."""
return IMPL.subcloud_audits_get_all_need_audit(context, last_audit_threshold)
return IMPL.Connection(context).subcloud_audits_get_all_need_audit(
last_audit_threshold
)
# In the functions below it would be cleaner if the timestamp were calculated
@@ -84,24 +86,26 @@ def subcloud_audits_get_all_need_audit(context, last_audit_threshold):
def subcloud_audits_get_and_start_audit(context, subcloud_id):
"""Set the 'audit started' timestamp for the main audit."""
return IMPL.subcloud_audits_get_and_start_audit(context, subcloud_id)
return IMPL.Connection(context).subcloud_audits_get_and_start_audit(subcloud_id)
def subcloud_audits_bulk_end_audit(context, audits_finished):
"""Update the subcloud's audit end status in a bulk request"""
return IMPL.subcloud_audits_bulk_end_audit(context, audits_finished)
return IMPL.Connection(context).subcloud_audits_bulk_end_audit(audits_finished)
def subcloud_audits_bulk_update_audit_finished_at(context, subcloud_ids):
"""Set the 'audit finished' timestamp for the main audit in bulk."""
return IMPL.subcloud_audits_bulk_update_audit_finished_at(context, subcloud_ids)
return IMPL.Connection(context).subcloud_audits_bulk_update_audit_finished_at(
subcloud_ids
)
def subcloud_audits_fix_expired_audits(
context, last_audit_threshold, trigger_audits=False
):
return IMPL.subcloud_audits_fix_expired_audits(
context, last_audit_threshold, trigger_audits
return IMPL.Connection(context).subcloud_audits_fix_expired_audits(
last_audit_threshold, trigger_audits
)
@@ -164,8 +168,7 @@ def subcloud_create(
data_install=None,
):
"""Create a subcloud."""
return IMPL.subcloud_create(
context,
return IMPL.Connection(context).subcloud_create(
name,
description,
location,
@@ -187,47 +190,47 @@ def subcloud_create(
def subcloud_get(context, subcloud_id):
"""Retrieve a subcloud or raise if it does not exist."""
return IMPL.subcloud_get(context, subcloud_id)
return IMPL.Connection(context).subcloud_get(subcloud_id)
def subcloud_get_with_status(context, subcloud_id):
"""Retrieve a subcloud and all endpoint sync statuses."""
return IMPL.subcloud_get_with_status(context, subcloud_id)
return IMPL.Connection(context).subcloud_get_with_status(subcloud_id)
def subcloud_get_by_name(context, name) -> models.Subcloud:
"""Retrieve a subcloud by name or raise if it does not exist."""
return IMPL.subcloud_get_by_name(context, name)
return IMPL.Connection(context).subcloud_get_by_name(name)
def subcloud_get_by_region_name(context, region_name):
"""Retrieve a subcloud by region name or raise if it does not exist."""
return IMPL.subcloud_get_by_region_name(context, region_name)
return IMPL.Connection(context).subcloud_get_by_region_name(region_name)
def subcloud_get_by_name_or_region_name(context, name):
"""Retrieve a subcloud by name or region name or raise if it does not exist."""
return IMPL.subcloud_get_by_name_or_region_name(context, name)
return IMPL.Connection(context).subcloud_get_by_name_or_region_name(name)
def subcloud_get_all(context):
"""Retrieve all subclouds."""
return IMPL.subcloud_get_all(context)
return IMPL.Connection(context).subcloud_get_all()
def subcloud_get_all_by_group_id(context, group_id):
"""Retrieve all subclouds that belong to the specified group id"""
return IMPL.subcloud_get_all_by_group_id(context, group_id)
return IMPL.Connection(context).subcloud_get_all_by_group_id(group_id)
def subcloud_get_all_ordered_by_id(context):
"""Retrieve all subclouds ordered by id."""
return IMPL.subcloud_get_all_ordered_by_id(context)
return IMPL.Connection(context).subcloud_get_all_ordered_by_id()
def subcloud_get_all_with_status(context):
"""Retrieve all subclouds and sync statuses."""
return IMPL.subcloud_get_all_with_status(context)
return IMPL.Connection(context).subcloud_get_all_with_status()
def subcloud_get_all_valid_for_strategy_step_creation(
@@ -239,8 +242,7 @@ def subcloud_get_all_valid_for_strategy_step_creation(
sync_status=None,
):
"""Queries all the subclouds that are valid for the strategy step to create"""
return IMPL.subcloud_get_all_valid_for_strategy_step_creation(
context,
return IMPL.Connection(context).subcloud_get_all_valid_for_strategy_step_creation(
endpoint_type,
group_id,
subcloud_name,
@@ -253,8 +255,8 @@ def subcloud_count_invalid_for_strategy_type(
context, endpoint_type, group_id=None, subcloud_name=None
):
"""Queries the count of invalid subclouds for a strategy's creation"""
return IMPL.subcloud_count_invalid_for_strategy_type(
context, endpoint_type, group_id, subcloud_name
return IMPL.Connection(context).subcloud_count_invalid_for_strategy_type(
endpoint_type, group_id, subcloud_name
)
@@ -291,8 +293,7 @@ def subcloud_update(
region_name=None,
):
"""Update a subcloud or raise if it does not exist."""
return IMPL.subcloud_update(
context,
return IMPL.Connection(context).subcloud_update(
subcloud_id,
management_state,
availability_status,
@@ -327,27 +328,29 @@ def subcloud_update(
def subcloud_bulk_update_by_ids(context, subcloud_ids, update_form):
"""Update subclouds in bulk using a set of subcloud IDs."""
return IMPL.subcloud_bulk_update_by_ids(context, subcloud_ids, update_form)
return IMPL.Connection(context).subcloud_bulk_update_by_ids(
subcloud_ids, update_form
)
def subcloud_destroy(context, subcloud_id):
"""Destroy the subcloud or raise if it does not exist."""
return IMPL.subcloud_destroy(context, subcloud_id)
return IMPL.Connection(context).subcloud_destroy(subcloud_id)
def subcloud_status_create(context, subcloud_id, endpoint_type):
"""Create a subcloud status for an endpoint_type."""
return IMPL.subcloud_status_create(context, subcloud_id, endpoint_type)
return IMPL.Connection(context).subcloud_status_create(subcloud_id, endpoint_type)
def subcloud_status_create_all(context, subcloud_id):
"""Create a subcloud status for all endpoint_types."""
return IMPL.subcloud_status_create_all(context, subcloud_id)
return IMPL.Connection(context).subcloud_status_create_all(subcloud_id)
def subcloud_status_delete(context, subcloud_id, endpoint_type):
"""Delete a subcloud status for an endpoint_type."""
return IMPL.subcloud_status_delete(context, subcloud_id, endpoint_type)
return IMPL.Connection(context).subcloud_status_delete(subcloud_id, endpoint_type)
def subcloud_status_db_model_to_dict(subcloud_status):
@@ -382,22 +385,24 @@ def subcloud_status_get(context, subcloud_id, endpoint_type):
Will raise if subcloud does not exist.
"""
return IMPL.subcloud_status_get(context, subcloud_id, endpoint_type)
return IMPL.Connection(context).subcloud_status_get(subcloud_id, endpoint_type)
def subcloud_status_get_all(context, subcloud_id):
"""Retrieve all statuses for a subcloud."""
return IMPL.subcloud_status_get_all(context, subcloud_id)
return IMPL.Connection(context).subcloud_status_get_all(subcloud_id)
def subcloud_status_get_all_by_name(context, name):
"""Retrieve all statuses for a subcloud by name."""
return IMPL.subcloud_status_get_all_by_name(context, name)
return IMPL.Connection(context).subcloud_status_get_all_by_name(name)
def subcloud_status_update(context, subcloud_id, endpoint_type, sync_status):
"""Update the status of a subcloud or raise if it does not exist."""
return IMPL.subcloud_status_update(context, subcloud_id, endpoint_type, sync_status)
return IMPL.Connection(context).subcloud_status_update(
subcloud_id, endpoint_type, sync_status
)
def subcloud_status_update_endpoints(
@@ -405,16 +410,16 @@ def subcloud_status_update_endpoints(
):
"""Update all statuses of the endpoints in endpoint_type_list of a subcloud."""
return IMPL.subcloud_status_update_endpoints(
context, subcloud_id, endpoint_type_list, sync_status
return IMPL.Connection(context).subcloud_status_update_endpoints(
subcloud_id, endpoint_type_list, sync_status
)
def subcloud_status_bulk_update_endpoints(context, subcloud_id, endpoint_list):
"""Update the status of the specified endpoints for a subcloud"""
return IMPL.subcloud_status_bulk_update_endpoints(
context, subcloud_id, endpoint_list
return IMPL.Connection(context).subcloud_status_bulk_update_endpoints(
subcloud_id, endpoint_list
)
@@ -424,7 +429,7 @@ def subcloud_status_destroy_all(context, subcloud_id):
Will raise if subcloud does not exist.
"""
return IMPL.subcloud_status_destroy_all(context, subcloud_id)
return IMPL.Connection(context).subcloud_status_destroy_all(subcloud_id)
###################
@@ -449,43 +454,43 @@ def subcloud_group_create(
context, name, description, update_apply_type, max_parallel_subclouds
):
"""Create a subcloud_group."""
return IMPL.subcloud_group_create(
context, name, description, update_apply_type, max_parallel_subclouds
return IMPL.Connection(context).subcloud_group_create(
name, description, update_apply_type, max_parallel_subclouds
)
def subcloud_group_get(context, group_id):
"""Retrieve a subcloud_group or raise if it does not exist."""
return IMPL.subcloud_group_get(context, group_id)
return IMPL.Connection(context).subcloud_group_get(group_id)
def subcloud_group_get_by_name(context, name):
"""Retrieve a subcloud_group b name or raise if it does not exist."""
return IMPL.subcloud_group_get_by_name(context, name)
return IMPL.Connection(context).subcloud_group_get_by_name(name)
def subcloud_group_get_all(context):
"""Retrieve all subcloud groups."""
return IMPL.subcloud_group_get_all(context)
return IMPL.Connection(context).subcloud_group_get_all()
def subcloud_get_for_group(context, group_id):
"""Retrieve a subcloud_group or raise if it does not exist."""
return IMPL.subcloud_get_for_group(context, group_id)
return IMPL.Connection(context).subcloud_get_for_group(group_id)
def subcloud_group_update(
context, group_id, name, description, update_apply_type, max_parallel_subclouds
):
"""Update the subcloud group or raise if it does not exist."""
return IMPL.subcloud_group_update(
context, group_id, name, description, update_apply_type, max_parallel_subclouds
return IMPL.Connection(context).subcloud_group_update(
group_id, name, description, update_apply_type, max_parallel_subclouds
)
def subcloud_group_destroy(context, group_id):
"""Destroy the subcloud group or raise if it does not exist."""
return IMPL.subcloud_group_destroy(context, group_id)
return IMPL.Connection(context).subcloud_group_destroy(group_id)
###################
@@ -526,8 +531,7 @@ def system_peer_create(
heartbeat_maintenance_timeout,
):
"""Create a system_peer."""
return IMPL.system_peer_create(
context,
return IMPL.Connection(context).system_peer_create(
peer_uuid,
peer_name,
endpoint,
@@ -544,27 +548,27 @@ def system_peer_create(
def system_peer_get(context, peer_id) -> models.SystemPeer:
"""Retrieve a system_peer or raise if it does not exist."""
return IMPL.system_peer_get(context, peer_id)
return IMPL.Connection(context).system_peer_get(peer_id)
def system_peer_get_by_uuid(context, uuid) -> models.SystemPeer:
"""Retrieve a system_peer by uuid or raise if it does not exist."""
return IMPL.system_peer_get_by_uuid(context, uuid)
return IMPL.Connection(context).system_peer_get_by_uuid(uuid)
def system_peer_get_by_name(context, uuid) -> models.SystemPeer:
"""Retrieve a system_peer by name or raise if it does not exist."""
return IMPL.system_peer_get_by_name(context, uuid)
return IMPL.Connection(context).system_peer_get_by_name(uuid)
def system_peer_get_all(context) -> list[models.SystemPeer]:
"""Retrieve all system peers."""
return IMPL.system_peer_get_all(context)
return IMPL.Connection(context).system_peer_get_all()
def peer_group_get_for_system_peer(context, peer_id) -> list[models.SubcloudPeerGroup]:
"""Get subcloud peer groups associated with a system peer."""
return IMPL.peer_group_get_for_system_peer(context, peer_id)
return IMPL.Connection(context).peer_group_get_for_system_peer(peer_id)
def system_peer_update(
@@ -584,8 +588,7 @@ def system_peer_update(
availability_state=None,
):
"""Update the system peer or raise if it does not exist."""
return IMPL.system_peer_update(
context,
return IMPL.Connection(context).system_peer_update(
peer_id,
peer_uuid,
peer_name,
@@ -604,7 +607,7 @@ def system_peer_update(
def system_peer_destroy(context, peer_id):
"""Destroy the system peer or raise if it does not exist."""
return IMPL.system_peer_destroy(context, peer_id)
return IMPL.Connection(context).system_peer_destroy(peer_id)
###################
@@ -640,8 +643,7 @@ def subcloud_peer_group_create(
migration_status=None,
):
"""Create a subcloud_peer_group."""
return IMPL.subcloud_peer_group_create(
context,
return IMPL.Connection(context).subcloud_peer_group_create(
peer_group_name,
group_priority,
group_state,
@@ -654,24 +656,26 @@ def subcloud_peer_group_create(
def subcloud_peer_group_destroy(context, group_id):
"""Destroy the subcloud peer group or raise if it does not exist."""
return IMPL.subcloud_peer_group_destroy(context, group_id)
return IMPL.Connection(context).subcloud_peer_group_destroy(group_id)
def subcloud_peer_group_get(context, group_id) -> models.SubcloudPeerGroup:
"""Retrieve a subcloud_peer_group or raise if it does not exist."""
return IMPL.subcloud_peer_group_get(context, group_id)
return IMPL.Connection(context).subcloud_peer_group_get(group_id)
def subcloud_peer_group_get_by_name(context, name) -> models.SubcloudPeerGroup:
"""Retrieve a subcloud_peer_group by name or raise if it does not exist."""
return IMPL.subcloud_peer_group_get_by_name(context, name)
return IMPL.Connection(context).subcloud_peer_group_get_by_name(name)
def subcloud_peer_group_get_by_leader_id(
context, system_leader_id
) -> list[models.SubcloudPeerGroup]:
"""Retrieve subcloud peer groups by system_leader_id."""
return IMPL.subcloud_peer_group_get_by_leader_id(context, system_leader_id)
return IMPL.Connection(context).subcloud_peer_group_get_by_leader_id(
system_leader_id
)
def subcloud_get_for_peer_group(context, group_id) -> list[models.Subcloud]:
@@ -679,12 +683,12 @@ def subcloud_get_for_peer_group(context, group_id) -> list[models.Subcloud]:
or raise if it does not exist.
"""
return IMPL.subcloud_get_for_peer_group(context, group_id)
return IMPL.Connection(context).subcloud_get_for_peer_group(group_id)
def subcloud_peer_group_get_all(context) -> list[models.SubcloudPeerGroup]:
"""Retrieve all subcloud peer groups."""
return IMPL.subcloud_peer_group_get_all(context)
return IMPL.Connection(context).subcloud_peer_group_get_all()
def subcloud_peer_group_update(
@@ -699,8 +703,7 @@ def subcloud_peer_group_update(
migration_status=None,
):
"""Update the subcloud peer group or raise if it does not exist."""
return IMPL.subcloud_peer_group_update(
context,
return IMPL.Connection(context).subcloud_peer_group_update(
group_id,
peer_group_name,
group_priority,
@@ -743,8 +746,7 @@ def peer_group_association_create(
sync_message=None,
):
"""Create a peer_group_association."""
return IMPL.peer_group_association_create(
context,
return IMPL.Connection(context).peer_group_association_create(
peer_group_id,
system_peer_id,
peer_group_priority,
@@ -758,32 +760,34 @@ def peer_group_association_update(
context, id, peer_group_priority=None, sync_status=None, sync_message=None
):
"""Update the system peer or raise if it does not exist."""
return IMPL.peer_group_association_update(
context, id, peer_group_priority, sync_status, sync_message
return IMPL.Connection(context).peer_group_association_update(
id, peer_group_priority, sync_status, sync_message
)
def peer_group_association_destroy(context, id):
"""Destroy the peer_group_association or raise if it does not exist."""
return IMPL.peer_group_association_destroy(context, id)
return IMPL.Connection(context).peer_group_association_destroy(id)
def peer_group_association_get(context, id) -> models.PeerGroupAssociation:
"""Retrieve a peer_group_association or raise if it does not exist."""
return IMPL.peer_group_association_get(context, id)
return IMPL.Connection(context).peer_group_association_get(id)
def peer_group_association_get_all(context) -> list[models.PeerGroupAssociation]:
"""Retrieve all peer_group_associations."""
return IMPL.peer_group_association_get_all(context)
return IMPL.Connection(context).peer_group_association_get_all()
def peer_group_association_get_by_peer_group_and_system_peer_id(
context, peer_group_id, system_peer_id
) -> list[models.PeerGroupAssociation]:
"""Get peer group associations by peer_group_id and system_peer_id."""
return IMPL.peer_group_association_get_by_peer_group_and_system_peer_id(
context, peer_group_id, system_peer_id
return IMPL.Connection(
context
).peer_group_association_get_by_peer_group_and_system_peer_id(
peer_group_id, system_peer_id
)
@@ -791,14 +795,18 @@ def peer_group_association_get_by_peer_group_id(
context, peer_group_id
) -> list[models.PeerGroupAssociation]:
"""Get the peer_group_association list by peer_group_id"""
return IMPL.peer_group_association_get_by_peer_group_id(context, peer_group_id)
return IMPL.Connection(context).peer_group_association_get_by_peer_group_id(
peer_group_id
)
def peer_group_association_get_by_system_peer_id(
context, system_peer_id
) -> list[models.PeerGroupAssociation]:
"""Get the peer_group_association list by system_peer_id"""
return IMPL.peer_group_association_get_by_system_peer_id(context, system_peer_id)
return IMPL.Connection(context).peer_group_association_get_by_system_peer_id(
system_peer_id
)
###################
@@ -830,8 +838,7 @@ def sw_update_strategy_create(
extra_args=None,
):
"""Create a sw update."""
return IMPL.sw_update_strategy_create(
context,
return IMPL.Connection(context).sw_update_strategy_create(
type,
subcloud_apply_type,
max_parallel_subclouds,
@@ -843,21 +850,21 @@ def sw_update_strategy_create(
def sw_update_strategy_get(context, update_type=None):
"""Retrieve a sw update or raise if it does not exist."""
return IMPL.sw_update_strategy_get(context, update_type=update_type)
return IMPL.Connection(context).sw_update_strategy_get(update_type=update_type)
def sw_update_strategy_update(
context, state=None, update_type=None, additional_args=None
):
"""Update a sw update or raise if it does not exist."""
return IMPL.sw_update_strategy_update(
context, state, update_type=update_type, additional_args=additional_args
return IMPL.Connection(context).sw_update_strategy_update(
state, update_type=update_type, additional_args=additional_args
)
def sw_update_strategy_destroy(context, update_type=None):
"""Destroy the sw update or raise if it does not exist."""
return IMPL.sw_update_strategy_destroy(context, update_type=update_type)
return IMPL.Connection(context).sw_update_strategy_destroy(update_type=update_type)
###################
@@ -889,24 +896,24 @@ def strategy_step_get(context, subcloud_id):
Will raise if subcloud does not exist.
"""
return IMPL.strategy_step_get(context, subcloud_id)
return IMPL.Connection(context).strategy_step_get(subcloud_id)
def strategy_step_get_by_name(context, name):
"""Retrieve the patch strategy step for a subcloud name."""
return IMPL.strategy_step_get_by_name(context, name)
return IMPL.Connection(context).strategy_step_get_by_name(name)
def strategy_step_get_all(context, steps_id=None, last_update_threshold=None):
"""Retrieve all patch strategy steps."""
return IMPL.strategy_step_get_all(
context, steps_id=steps_id, last_update_threshold=last_update_threshold
return IMPL.Connection(context).strategy_step_get_all(
steps_id=steps_id, last_update_threshold=last_update_threshold
)
def strategy_step_count_all_states(context):
"""Retrieve the count of steps in each possible state"""
return IMPL.strategy_step_count_all_states(context)
return IMPL.Connection(context).strategy_step_count_all_states()
def strategy_step_states_to_dict(states):
@@ -931,12 +938,16 @@ def strategy_step_states_to_dict(states):
def strategy_step_bulk_create(context, subcloud_ids, stage, state, details):
"""Creates the strategy step for a list of subclouds"""
return IMPL.strategy_step_bulk_create(context, subcloud_ids, stage, state, details)
return IMPL.Connection(context).strategy_step_bulk_create(
subcloud_ids, stage, state, details
)
def strategy_step_create(context, subcloud_id, stage, state, details):
"""Create a patch strategy step."""
return IMPL.strategy_step_create(context, subcloud_id, stage, state, details)
return IMPL.Connection(context).strategy_step_create(
subcloud_id, stage, state, details
)
def strategy_step_update(
@@ -949,8 +960,8 @@ def strategy_step_update(
finished_at=None,
):
"""Update a patch strategy step or raise if it does not exist."""
return IMPL.strategy_step_update(
context, subcloud_id, stage, state, details, started_at, finished_at
return IMPL.Connection(context).strategy_step_update(
subcloud_id, stage, state, details, started_at, finished_at
)
@@ -962,12 +973,12 @@ def strategy_step_update_all(context, filters, values, steps_id=None):
:param values: values to be set for the specified strategies
:param steps_id: list of strategy steps to update
"""
return IMPL.strategy_step_update_all(context, filters, values, steps_id)
return IMPL.Connection(context).strategy_step_update_all(filters, values, steps_id)
def strategy_step_destroy_all(context, steps_id=None):
"""Destroy all the patch strategy steps."""
return IMPL.strategy_step_destroy_all(context, steps_id)
return IMPL.Connection(context).strategy_step_destroy_all(steps_id)
###################
@@ -1000,8 +1011,7 @@ def sw_update_opts_create(
default_instance_action,
):
"""Create sw update options."""
return IMPL.sw_update_opts_create(
context,
return IMPL.Connection(context).sw_update_opts_create(
subcloud_id,
storage_apply_type,
worker_apply_type,
@@ -1013,12 +1023,12 @@ def sw_update_opts_create(
def sw_update_opts_get(context, subcloud_id):
"""Retrieve sw update options."""
return IMPL.sw_update_opts_get(context, subcloud_id)
return IMPL.Connection(context).sw_update_opts_get(subcloud_id)
def sw_update_opts_get_all_plus_subcloud_info(context):
"""Retrieve sw update options plus subcloud info."""
return IMPL.sw_update_opts_get_all_plus_subcloud_info(context)
return IMPL.Connection(context).sw_update_opts_get_all_plus_subcloud_info()
def sw_update_opts_update(
@@ -1031,8 +1041,7 @@ def sw_update_opts_update(
default_instance_action=None,
):
"""Update sw update options or raise if it does not exist."""
return IMPL.sw_update_opts_update(
context,
return IMPL.Connection(context).sw_update_opts_update(
subcloud_id,
storage_apply_type,
worker_apply_type,
@@ -1044,7 +1053,7 @@ def sw_update_opts_update(
def sw_update_opts_destroy(context, subcloud_id):
"""Destroy sw update options or raise if it does not exist."""
return IMPL.sw_update_opts_destroy(context, subcloud_id)
return IMPL.Connection(context).sw_update_opts_destroy(subcloud_id)
###################
@@ -1057,8 +1066,7 @@ def sw_update_opts_default_create(
default_instance_action,
):
"""Create default sw update options."""
return IMPL.sw_update_opts_default_create(
context,
return IMPL.Connection(context).sw_update_opts_default_create(
storage_apply_type,
worker_apply_type,
max_parallel_workers,
@@ -1069,7 +1077,7 @@ def sw_update_opts_default_create(
def sw_update_opts_default_get(context):
"""Retrieve default sw update options."""
return IMPL.sw_update_opts_default_get(context)
return IMPL.Connection(context).sw_update_opts_default_get()
def sw_update_opts_default_update(
@@ -1081,8 +1089,7 @@ def sw_update_opts_default_update(
default_instance_action=None,
):
"""Update default sw update options."""
return IMPL.sw_update_opts_default_update(
context,
return IMPL.Connection(context).sw_update_opts_default_update(
storage_apply_type,
worker_apply_type,
max_parallel_workers,
@@ -1093,7 +1100,7 @@ def sw_update_opts_default_update(
def sw_update_opts_default_destroy(context):
"""Destroy the default sw update options or raise if it does not exist."""
return IMPL.sw_update_opts_default_destroy(context)
return IMPL.Connection(context).sw_update_opts_default_destroy()
###################
@@ -1101,35 +1108,35 @@ def sw_update_opts_default_destroy(context):
def db_sync(engine, version=None):
"""Migrate the database to `version` or the most recent version."""
return IMPL.db_sync(engine, version=version)
return IMPL.Connection.db_sync(engine, version=version)
def db_version(engine):
"""Display the current database version."""
return IMPL.db_version(engine)
return IMPL.Connection.db_version(engine)
# Alarm Resources
###################
def subcloud_alarms_get(context, name):
return IMPL.subcloud_alarms_get(context, name)
return IMPL.Connection(context).subcloud_alarms_get(name)
def subcloud_alarms_get_all(context, name=None):
return IMPL.subcloud_alarms_get_all(context, name=name)
return IMPL.Connection(context).subcloud_alarms_get_all(name=name)
def subcloud_alarms_create(context, name, values):
return IMPL.subcloud_alarms_create(context, name, values)
return IMPL.Connection(context).subcloud_alarms_create(name, values)
def subcloud_alarms_update(context, name, values):
return IMPL.subcloud_alarms_update(context, name, values)
return IMPL.Connection(context).subcloud_alarms_update(name, values)
def subcloud_alarms_delete(context, name):
return IMPL.subcloud_alarms_delete(context, name)
return IMPL.Connection(context).subcloud_alarms_delete(name)
def subcloud_rename_alarms(context, subcloud_name, new_name):
return IMPL.subcloud_rename_alarms(context, subcloud_name, new_name)
return IMPL.Connection(context).subcloud_rename_alarms(subcloud_name, new_name)

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2015 Ericsson AB
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -29,11 +29,10 @@ from sqlalchemy import event
from dcmanager.audit import subcloud_audit_worker_manager
from dcmanager.common import consts
from dcmanager.db import api
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import utils
get_engine = api.get_engine
get_engine = db_api.get_engine
# Enable foreign key support in sqlite - see:
# http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2020-2024 Wind River Systems, Inc.
# Copyright (c) 2020-2025 Wind River Systems, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -12,7 +12,7 @@
# under the License.
#
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests.unit.api.test_root_controller import DCManagerApiTest
from dcmanager.tests import utils

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2023-2024 Wind River Systems, Inc.
# Copyright (c) 2023-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -14,24 +14,13 @@ from oslo_messaging import RemoteError
from dcmanager.api.controllers.v1 import peer_group_association
from dcmanager.common import consts
from dcmanager.common import phased_subcloud_deploy as psd_common
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests.unit.api.controllers.v1.mixins import APIMixin
from dcmanager.tests.unit.api.controllers.v1.mixins import GetMixin
from dcmanager.tests.unit.api.test_root_controller import DCManagerApiTest
from dcmanager.tests.unit.common import fake_subcloud
# SAMPLE SYSTEM PEER DATA
SAMPLE_SYSTEM_PEER_UUID = str(uuid.uuid4())
SAMPLE_SYSTEM_PEER_NAME = "SystemPeer1"
SAMPLE_MANAGER_ENDPOINT = "http://127.0.0.1:5000"
SAMPLE_MANAGER_USERNAME = "admin"
SAMPLE_MANAGER_PASSWORD = "password"
SAMPLE_PEER_CONTROLLER_GATEWAY_IP = "128.128.128.1"
SAMPLE_ADMINISTRATIVE_STATE = "enabled"
SAMPLE_HEARTBEAT_INTERVAL = 10
SAMPLE_HEARTBEAT_FAILURE_THRESHOLD = 3
SAMPLE_HEARTBEAT_FAILURES_POLICY = "alarm"
SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT = 600
SAMPLE_AVAILABILITY_STATE_AVAILABLE = "available"
# SAMPLE SUBCLOUD PEER GROUP DATA
@@ -67,35 +56,6 @@ class PeerGroupAssociationAPIMixin(APIMixin):
def setUp(self):
super().setUp()
def _get_test_system_peer_dict(self, **kw):
# id should not be part of the structure
system_peer = {
"peer_uuid": kw.get("peer_uuid", SAMPLE_SYSTEM_PEER_UUID),
"peer_name": kw.get("peer_name", SAMPLE_SYSTEM_PEER_NAME),
"endpoint": kw.get("manager_endpoint", SAMPLE_MANAGER_ENDPOINT),
"username": kw.get("manager_username", SAMPLE_MANAGER_USERNAME),
"password": kw.get("manager_password", SAMPLE_MANAGER_PASSWORD),
"gateway_ip": kw.get(
"peer_controller_gateway_ip", SAMPLE_PEER_CONTROLLER_GATEWAY_IP
),
"administrative_state": kw.get(
"administrative_state", SAMPLE_ADMINISTRATIVE_STATE
),
"heartbeat_interval": kw.get(
"heartbeat_interval", SAMPLE_HEARTBEAT_INTERVAL
),
"heartbeat_failure_threshold": kw.get(
"heartbeat_failure_threshold", SAMPLE_HEARTBEAT_FAILURE_THRESHOLD
),
"heartbeat_failure_policy": kw.get(
"heartbeat_failure_policy", SAMPLE_HEARTBEAT_FAILURES_POLICY
),
"heartbeat_maintenance_timeout": kw.get(
"heartbeat_maintenance_timeout", SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT
),
}
return system_peer
def _get_test_subcloud_peer_group_dict(self, **kw):
# id should not be part of the structure
group = {
@@ -148,7 +108,7 @@ class PeerGroupAssociationAPIMixin(APIMixin):
return []
def _create_db_related_objects(self, context):
system_peer_fields = self._get_test_system_peer_dict()
system_peer_fields = fake_subcloud.get_test_system_peer_dict("db")
peer = db_api.system_peer_create(context, **system_peer_fields)
peer_group_fields = self._get_test_subcloud_peer_group_dict()

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2024 Wind River Systems, Inc.
# Copyright (c) 2022-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -14,7 +14,7 @@ from oslo_messaging import RemoteError
from dccommon import consts as dccommon_consts
from dcmanager.common import consts
import dcmanager.common.utils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests import base
from dcmanager.tests.unit.api.test_root_controller import DCManagerApiTest

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB
# Copyright (c) 2020-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2020-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,7 +22,7 @@ from oslo_messaging import RemoteError
from dcmanager.api.controllers.v1 import subcloud_group
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests.unit.api.controllers.v1.mixins import APIMixin
from dcmanager.tests.unit.api.controllers.v1.mixins import DeleteMixin

View File

@@ -1,10 +1,9 @@
# Copyright (c) 2023-2024 Wind River Systems, Inc.
# Copyright (c) 2023-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import http.client
import uuid
import mock
from oslo_db import exception as db_exc
@@ -13,7 +12,7 @@ from oslo_messaging import RemoteError
from dccommon import consts as dccommon_consts
from dcmanager.api.controllers.v1 import subcloud_peer_group
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests.base import FakeException
from dcmanager.tests.unit.api.controllers.v1.mixins import APIMixin
@@ -1210,15 +1209,8 @@ class TestSubcloudPeerGroupControllerDelete(BaseTestSubcloudPeerGroupController)
"""Test delete fails when association exists"""
self._create_subcloud()
system_peer = db_api.system_peer_create(
self.ctx,
str(uuid.uuid4()),
"SystemPeer1",
"http://127.0.0.1:5000",
"admin",
"password",
"128.128.128.1",
)
system_peer_fields = fake_subcloud.get_test_system_peer_dict("db")
system_peer = db_api.system_peer_create(self.ctx, **system_peer_fields)
db_api.peer_group_association_create(
self.ctx,
self.subcloud.peer_group_id,

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -40,7 +40,6 @@ from dcmanager.common import phased_subcloud_deploy as psd_common
from dcmanager.common import prestage
from dcmanager.common import utils as cutils
from dcmanager.db import api as db_api
from dcmanager.db.sqlalchemy import api as sql_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests.unit.api.controllers.v1.mixins import APIMixin
from dcmanager.tests.unit.api.controllers.v1.mixins import PostMixin
@@ -211,7 +210,7 @@ class SubcloudAPIMixin(APIMixin):
def _create_db_object(self, context, **kw):
creation_fields = self._get_test_subcloud_dict(**kw)
return sql_api.subcloud_create(context, **creation_fields)
return db_api.subcloud_create(context, **creation_fields)
def get_post_params(self):
return copy.copy(fake_subcloud.FAKE_BOOTSTRAP_VALUE)
@@ -269,7 +268,7 @@ class BaseTestSubcloudsController(DCManagerApiTest, SubcloudAPIMixin):
self.mock_is_valid_software_deploy_state.return_value = True
def _update_subcloud(self, **kwargs):
self.subcloud = sql_api.subcloud_update(self.ctx, self.subcloud.id, **kwargs)
self.subcloud = db_api.subcloud_update(self.ctx, self.subcloud.id, **kwargs)
class TestSubcloudsController(BaseTestSubcloudsController):
@@ -1598,7 +1597,7 @@ class TestSubcloudsPatch(BaseTestSubcloudsPatch):
def _assert_response_payload(self, response, key, value):
"""Asserts the response's payload"""
updated_subcloud = sql_api.subcloud_get(self.ctx, self.subcloud.id)
updated_subcloud = db_api.subcloud_get(self.ctx, self.subcloud.id)
self.assertEqual(updated_subcloud[key], value)
def test_patch_fails_without_subcloud_ref(self):
@@ -1898,11 +1897,11 @@ class TestSubcloudsPatch(BaseTestSubcloudsPatch):
update_subcloud_with_network_reconfig.assert_called_once()
self.mock_vim_client().get_strategy.assert_called_once()
@mock.patch.object(sql_api, "strategy_step_get")
def test_patch_fails_with_db_api_get_vim_strategy_exception(self, mock_sql_api):
@mock.patch.object(db_api, "strategy_step_get")
def test_patch_fails_with_db_api_get_vim_strategy_exception(self, mock_db_api):
"""Test patch fails with db api's get vim strategy exception"""
mock_sql_api.side_effect = Exception()
mock_db_api.side_effect = Exception()
self._test_patch_fails_with_vim_strategy()
@@ -2266,10 +2265,15 @@ class TestSubcloudsPatchWithPeerGroup(BaseTestSubcloudsPatch):
def _setup_system_peer_for_subcloud(self, availability_state):
system_peer = (
test_system_peer_manager.TestSystemPeerManager.create_system_peer_static(
self.ctx, availability_state=availability_state
self.ctx
)
)
self.peer_group = sql_api.subcloud_peer_group_update(
db_api.system_peer_update(
self.ctx,
system_peer.id,
availability_state=availability_state,
)
self.peer_group = db_api.subcloud_peer_group_update(
self.ctx, self.peer_group.id, group_priority=1
)
system_peer_manager = test_system_peer_manager.TestSystemPeerManager
@@ -2368,7 +2372,7 @@ class TestSubcloudsPatchWithPeerGroup(BaseTestSubcloudsPatch):
def test_patch_with_peer_group_fails_on_non_primary_site(self):
"""Test patch with peer group fails on non primary site"""
self.peer_group = sql_api.subcloud_peer_group_update(
self.peer_group = db_api.subcloud_peer_group_update(
self.ctx, self.peer_group.id, group_priority=1
)
self._update_subcloud(rehome_data="", peer_group_id=self.peer_group.id)
@@ -2443,7 +2447,7 @@ class TestSubcloudsPatchWithPeerGroup(BaseTestSubcloudsPatch):
self.mock_rpc_client().update_association_sync_status.assert_not_called()
self.assertEqual(
consts.ASSOCIATION_SYNC_STATUS_IN_SYNC,
sql_api.peer_group_association_get(
db_api.peer_group_association_get(
self.ctx, self.peer_group_association.id
).sync_status,
)
@@ -2489,7 +2493,7 @@ class TestSubcloudsPatchWithPeerGroup(BaseTestSubcloudsPatch):
)
self.assertEqual(
consts.ASSOCIATION_SYNC_STATUS_OUT_OF_SYNC,
sql_api.peer_group_association_get(
db_api.peer_group_association_get(
self.ctx, self.peer_group_association.id
).sync_status,
)

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB
# Copyright (c) 2017-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2017-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,7 +22,7 @@ from oslo_messaging import RemoteError
from dccommon import consts as dccommon_consts
from dcmanager.common import consts
from dcmanager.common import utils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator import rpcapi as rpc_client
from dcmanager.tests.unit.api.test_root_controller import DCManagerApiTest
from dcmanager.tests.unit.common import fake_strategy

View File

@@ -1,18 +1,17 @@
# Copyright (c) 2023-2024 Wind River Systems, Inc.
# Copyright (c) 2023-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import http.client
import json
import uuid
import mock
from oslo_messaging import RemoteError
from dcmanager.api.controllers.v1 import system_peers
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests.unit.api.controllers.v1.mixins import APIMixin
from dcmanager.tests.unit.api.controllers.v1.mixins import DeleteMixin
@@ -22,18 +21,6 @@ from dcmanager.tests.unit.api.controllers.v1.mixins import UpdateMixin
from dcmanager.tests.unit.api.test_root_controller import DCManagerApiTest
from dcmanager.tests.unit.common import fake_subcloud
SAMPLE_SYSTEM_PEER_UUID = str(uuid.uuid4())
SAMPLE_SYSTEM_PEER_NAME = "SystemPeer1"
SAMPLE_MANAGER_ENDPOINT = "http://127.0.0.1:5000"
SAMPLE_MANAGER_USERNAME = "admin"
SAMPLE_MANAGER_PASSWORD = "password"
SAMPLE_ADMINISTRATIVE_STATE = "enabled"
SAMPLE_HEARTBEAT_INTERVAL = 10
SAMPLE_HEARTBEAT_FAILURE_THRESHOLD = 3
SAMPLE_HEARTBEAT_FAILURES_POLICY = "alarm"
SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT = 600
SAMPLE_PEER_CONTROLLER_GATEWAY_IP = "128.128.128.1"
class SystemPeersAPIMixin(APIMixin):
API_PREFIX = "/v1.0/system-peers"
@@ -54,59 +41,8 @@ class SystemPeersAPIMixin(APIMixin):
"updated-at",
]
def _get_test_system_peer_dict(self, data_type, **kw):
# id should not be part of the structure
system_peer = {
"peer_uuid": kw.get("peer_uuid", SAMPLE_SYSTEM_PEER_UUID),
"peer_name": kw.get("peer_name", SAMPLE_SYSTEM_PEER_NAME),
"administrative_state": kw.get(
"administrative_state", SAMPLE_ADMINISTRATIVE_STATE
),
"heartbeat_interval": kw.get(
"heartbeat_interval", SAMPLE_HEARTBEAT_INTERVAL
),
"heartbeat_failure_threshold": kw.get(
"heartbeat_failure_threshold", SAMPLE_HEARTBEAT_FAILURE_THRESHOLD
),
"heartbeat_failure_policy": kw.get(
"heartbeat_failure_policy", SAMPLE_HEARTBEAT_FAILURES_POLICY
),
"heartbeat_maintenance_timeout": kw.get(
"heartbeat_maintenance_timeout", SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT
),
}
if data_type == "db":
system_peer["endpoint"] = kw.get(
"manager_endpoint", SAMPLE_MANAGER_ENDPOINT
)
system_peer["username"] = kw.get(
"manager_username", SAMPLE_MANAGER_USERNAME
)
system_peer["password"] = kw.get(
"manager_password", SAMPLE_MANAGER_PASSWORD
)
system_peer["gateway_ip"] = kw.get(
"peer_controller_gateway_ip", SAMPLE_PEER_CONTROLLER_GATEWAY_IP
)
else:
system_peer["manager_endpoint"] = kw.get(
"manager_endpoint", SAMPLE_MANAGER_ENDPOINT
)
system_peer["manager_username"] = kw.get(
"manager_username", SAMPLE_MANAGER_USERNAME
)
system_peer["manager_password"] = kw.get(
"manager_password", SAMPLE_MANAGER_PASSWORD
)
system_peer["peer_controller_gateway_address"] = kw.get(
"peer_controller_gateway_ip", SAMPLE_PEER_CONTROLLER_GATEWAY_IP
)
return system_peer
def _post_get_test_system_peer(self, **kw):
return self._get_test_system_peer_dict("dict", **kw)
return fake_subcloud.get_test_system_peer_dict("dict", **kw)
# The following methods are required for subclasses of APIMixin
def get_api_prefix(self):
@@ -122,7 +58,7 @@ class SystemPeersAPIMixin(APIMixin):
return []
def _create_db_object(self, context, **kw):
creation_fields = self._get_test_system_peer_dict("db", **kw)
creation_fields = fake_subcloud.get_test_system_peer_dict("db", **kw)
return db_api.system_peer_create(context, **creation_fields)
def get_post_object(self):

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2021, 2024 Wind River Systems, Inc.
# Copyright (c) 2021, 2024-2025 Wind River Systems, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -17,7 +17,7 @@ import mock
from dccommon.drivers.openstack import sdk_platform as sdk
from dcmanager.audit import alarm_aggregation
from dcmanager.common import exceptions
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
from dcmanager.tests import utils

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,7 +22,7 @@ from dccommon import consts as dccommon_consts
from dcmanager.audit import rpcapi
from dcmanager.audit import subcloud_audit_manager
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
sys.modules["fm_core"] = mock.Mock()

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -27,7 +27,7 @@ from dcmanager.audit import subcloud_audit_manager
from dcmanager.audit import subcloud_audit_worker_manager
from dcmanager.common import consts
from dcmanager.common import scheduler
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.rpc import client as rpc_client
from dcmanager.tests import base
from dcorch.rpc import client as dcorch_rpc_client

View File

@@ -1,11 +1,11 @@
#
# Copyright (c) 2020, 2024 Wind River Systems, Inc.
# Copyright (c) 2020, 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
def create_fake_strategy(

View File

@@ -1,13 +1,14 @@
#
# Copyright (c) 2020-2024 Wind River Systems, Inc.
# Copyright (c) 2020-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import base64
import uuid
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
from dcmanager.tests import utils
@@ -133,6 +134,24 @@ FAKE_UPGRADES_METADATA = (
% FAKE_SOFTWARE_VERSION
)
# FAKE SYSINV DATA
FAKE_SITE0_SYSTEM_UUID = str(uuid.uuid4())
FAKE_SITE1_SYSTEM_UUID = str(uuid.uuid4())
# SAMPLE SYSTEM PEER DATA
SAMPLE_SYSTEM_PEER_UUID = FAKE_SITE1_SYSTEM_UUID
SAMPLE_SYSTEM_PEER_NAME = "SystemPeer1"
SAMPLE_MANAGER_ENDPOINT = "http://127.0.0.1:5000"
SAMPLE_MANAGER_USERNAME = "admin"
SAMPLE_MANAGER_PASSWORD = (base64.b64encode("password".encode("utf-8"))).decode("ascii")
SAMPLE_PEER_CONTROLLER_GATEWAY_IP = "128.128.128.1"
SAMPLE_ADMINISTRATIVE_STATE = "enabled"
SAMPLE_HEARTBEAT_INTERVAL = 10
SAMPLE_HEARTBEAT_FAILURE_THRESHOLD = 3
SAMPLE_HEARTBEAT_FAILURES_POLICY = "alarm"
SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT = 600
SAMPLE_AVAILABILITY_STATE_AVAILABLE = "available"
def create_fake_subcloud(ctxt, **kwargs):
values = {
@@ -155,3 +174,47 @@ def create_fake_subcloud(ctxt, **kwargs):
}
values.update(kwargs)
return db_api.subcloud_create(ctxt, **values)
def get_test_system_peer_dict(data_type, **kw):
# id should not be part of the structure
system_peer = {
"peer_uuid": kw.get("peer_uuid", SAMPLE_SYSTEM_PEER_UUID),
"peer_name": kw.get("peer_name", SAMPLE_SYSTEM_PEER_NAME),
"administrative_state": kw.get(
"administrative_state", SAMPLE_ADMINISTRATIVE_STATE
),
"heartbeat_interval": kw.get("heartbeat_interval", SAMPLE_HEARTBEAT_INTERVAL),
"heartbeat_failure_threshold": kw.get(
"heartbeat_failure_threshold", SAMPLE_HEARTBEAT_FAILURE_THRESHOLD
),
"heartbeat_failure_policy": kw.get(
"heartbeat_failure_policy", SAMPLE_HEARTBEAT_FAILURES_POLICY
),
"heartbeat_maintenance_timeout": kw.get(
"heartbeat_maintenance_timeout", SAMPLE_HEARTBEAT_MAINTENANCE_TIMEOUT
),
}
if data_type == "db":
system_peer["endpoint"] = kw.get("manager_endpoint", SAMPLE_MANAGER_ENDPOINT)
system_peer["username"] = kw.get("manager_username", SAMPLE_MANAGER_USERNAME)
system_peer["password"] = kw.get("manager_password", SAMPLE_MANAGER_PASSWORD)
system_peer["gateway_ip"] = kw.get(
"peer_controller_gateway_ip", SAMPLE_PEER_CONTROLLER_GATEWAY_IP
)
else:
system_peer["manager_endpoint"] = kw.get(
"manager_endpoint", SAMPLE_MANAGER_ENDPOINT
)
system_peer["manager_username"] = kw.get(
"manager_username", SAMPLE_MANAGER_USERNAME
)
system_peer["manager_password"] = kw.get(
"manager_password", SAMPLE_MANAGER_PASSWORD
)
system_peer["peer_controller_gateway_address"] = kw.get(
"peer_controller_gateway_ip", SAMPLE_PEER_CONTROLLER_GATEWAY_IP
)
return system_peer

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021, 2024 Wind River Systems, Inc.
# Copyright (c) 2020-2021, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,11 +18,10 @@ from oslo_db import exception as db_exception
from dcmanager.common import consts
from dcmanager.common import exceptions as exception
from dcmanager.db import api
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
get_engine = api.get_engine
get_engine = db_api.get_engine
class DBAPISubcloudAlarm(base.DCManagerTestCase):

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2021-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -21,11 +21,10 @@ from oslo_utils import timeutils
from oslo_utils import uuidutils
from dcmanager.common import exceptions as exception
from dcmanager.db import api
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
get_engine = api.get_engine
get_engine = db_api.get_engine
class DBAPISubcloudAuditsTest(base.DCManagerTestCase):

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2015 Ericsson AB
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -23,13 +23,12 @@ from dccommon import consts as dccommon_consts
from dcmanager.common import config
from dcmanager.common import consts
from dcmanager.common import exceptions
from dcmanager.db import api
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.tests import base
from dcmanager.tests import utils
config.register_options()
get_engine = api.get_engine
get_engine = db_api.get_engine
@event.listens_for(Engine, "connect")

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -12,11 +12,12 @@ import mock
from dccommon import consts as dccommon_consts
from dcmanager.common import consts
from dcmanager.common import utils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.manager import peer_group_audit_manager
from dcmanager.manager import subcloud_manager
from dcmanager.manager.system_peer_manager import SystemPeerManager
from dcmanager.tests.base import DCManagerTestCase
from dcmanager.tests.unit.common import fake_subcloud
from dcmanager.tests.unit.manager import test_peer_monitor_manager as tpm
from dcmanager.tests.unit.manager import test_system_peer_manager as tsm
@@ -222,7 +223,7 @@ class TestPeerGroupAudit(DCManagerTestCase):
)
# Verify that the system leader id is updated to the peer site uuid
self.assertEqual(
tpm.FAKE_SITE1_SYSTEM_UUID,
fake_subcloud.FAKE_SITE1_SYSTEM_UUID,
db_api.subcloud_peer_group_get(
self.ctx, self.peer_group.id
).system_leader_id,
@@ -259,7 +260,7 @@ class TestPeerGroupAudit(DCManagerTestCase):
)
# Verify that the system leader id is updated to the peer site uuid
self.assertEqual(
tpm.FAKE_SITE1_SYSTEM_UUID,
fake_subcloud.FAKE_SITE1_SYSTEM_UUID,
db_api.subcloud_peer_group_get(
self.ctx, self.peer_group.id
).system_leader_id,
@@ -296,7 +297,7 @@ class TestPeerGroupAudit(DCManagerTestCase):
)
# Verify that the system leader id is updated to the peer site uuid
self.assertEqual(
tpm.FAKE_SITE1_SYSTEM_UUID,
fake_subcloud.FAKE_SITE1_SYSTEM_UUID,
db_api.subcloud_peer_group_get(
self.ctx, self.peer_group.id
).system_leader_id,

View File

@@ -1,36 +1,32 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import threading
import uuid
from fm_api import constants as fm_const
import mock
from dcmanager.common import consts
from dcmanager.common import utils as dutils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.manager import peer_group_audit_manager
from dcmanager.manager import peer_monitor_manager
from dcmanager.manager import subcloud_manager
from dcmanager.tests import base
from dcmanager.tests.unit.common import fake_subcloud
from dcmanager.tests.unit.manager import test_system_peer_manager
# FAKE SYSINV DATA
FAKE_SITE0_SYSTEM_UUID = str(uuid.uuid4())
FAKE_SITE1_SYSTEM_UUID = str(uuid.uuid4())
# FAKE SYSTEM PEER DATA
FAKE_SYSTEM_PEER_ID = 1
FAKE_SYSTEM_PEER_UUID = FAKE_SITE1_SYSTEM_UUID
FAKE_SYSTEM_PEER_NAME = "PeerSite1"
FAKE_MANAGER_ENDPOINT = "http://128.128.128.128:5000/v3"
FAKE_MANAGER_USERNAME = "admin"
FAKE_MANAGER_PASSWORD = "cGFzc3dvcmQ="
FAKE_PEER_CONTROLLER_GATEWAY_IP = "128.128.1.1"
FAKE_SYSTEM_PEER_UUID = fake_subcloud.FAKE_SITE1_SYSTEM_UUID
FAKE_SYSTEM_PEER_NAME = fake_subcloud.SAMPLE_SYSTEM_PEER_NAME
FAKE_MANAGER_ENDPOINT = fake_subcloud.SAMPLE_MANAGER_ENDPOINT
FAKE_MANAGER_USERNAME = fake_subcloud.SAMPLE_MANAGER_USERNAME
FAKE_MANAGER_PASSWORD = fake_subcloud.SAMPLE_MANAGER_PASSWORD
FAKE_PEER_CONTROLLER_GATEWAY_IP = fake_subcloud.SAMPLE_PEER_CONTROLLER_GATEWAY_IP
# FAKE SYSTEM PEER DATA (SITE1)
FAKE_SITE1_SYSTEM_PEER_ID = 10
@@ -78,16 +74,9 @@ class TestPeerMonitor(base.DCManagerTestCase):
@staticmethod
def create_system_peer_static(ctxt, **kwargs):
values = {
"peer_uuid": FAKE_SYSTEM_PEER_UUID,
"peer_name": FAKE_SYSTEM_PEER_NAME,
"endpoint": FAKE_MANAGER_ENDPOINT,
"username": FAKE_MANAGER_USERNAME,
"password": FAKE_MANAGER_PASSWORD,
"gateway_ip": FAKE_PEER_CONTROLLER_GATEWAY_IP,
}
values.update(kwargs)
return db_api.system_peer_create(ctxt, **values)
system_peer_fields = fake_subcloud.get_test_system_peer_dict("db")
system_peer_fields.update(kwargs)
return db_api.system_peer_create(ctxt, **system_peer_fields)
def test_initialize_peer_monitor_manager(self):
self.assertIsNotNone(self.peer_monitor)
@@ -152,7 +141,7 @@ class TestPeerMonitor(base.DCManagerTestCase):
def test_update_sync_status_secondary_site_becomes_reachable(self):
self.mock_get_local_system.return_value = test_system_peer_manager.FakeSystem(
FAKE_SITE0_SYSTEM_UUID
fake_subcloud.FAKE_SITE0_SYSTEM_UUID
)
db_api.peer_group_association_update(
self.ctx,
@@ -175,7 +164,7 @@ class TestPeerMonitor(base.DCManagerTestCase):
self.peer_monitor._update_sync_status_secondary_site_becomes_reachable()
self.mock_get_peer_dc_client().get_subcloud_peer_group.assert_called_once()
self.mock_get_peer_dc_client().get_system_peer.assert_called_once_with(
FAKE_SITE0_SYSTEM_UUID
fake_subcloud.FAKE_SITE0_SYSTEM_UUID
)
peer_group_assoc.assert_called_once_with(
FAKE_SITE1_SYSTEM_PEER_ID, FAKE_SITE1_PEER_GROUP_ID
@@ -342,7 +331,7 @@ class TestPeerMonitor(base.DCManagerTestCase):
mock_event.side_effect = [False, False, True]
self.peer_monitor._do_monitor_peer()
self.mock_log.exception.assert_called_with(
"Unexpected error monitoring peer 'PeerSite1': boom"
f"Unexpected error monitoring peer '{FAKE_SYSTEM_PEER_NAME}': boom"
)
def test_heartbeat_check_via_get_peer_group_list_pg_not_found(self):
@@ -350,8 +339,8 @@ class TestPeerMonitor(base.DCManagerTestCase):
ret = self.peer_monitor._heartbeat_check_via_get_peer_group_list()
self.mock_get_peer_dc_client.assert_called()
self.mock_log.warning.assert_called_once_with(
"No subcloud peer groups found for DC peer: PeerSite1 "
"(endpoint: http://128.128.128.128:5000/v3)"
f"No subcloud peer groups found for DC peer: {FAKE_SYSTEM_PEER_NAME} "
f"(endpoint: {FAKE_MANAGER_ENDPOINT})"
)
self.assertEqual((False, []), ret)

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -52,7 +52,7 @@ from dcmanager.common import consts
from dcmanager.common import exceptions
from dcmanager.common import prestage
from dcmanager.common import utils as cutils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.manager import subcloud_manager
from dcmanager.manager import system_peer_manager
from dcmanager.rpc import client as rpc_client

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2023-2024 Wind River Systems, Inc.
# Copyright (c) 2023-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -14,28 +14,18 @@ from dcmanager.audit import rpcapi
from dcmanager.common import consts
from dcmanager.common import exceptions
from dcmanager.common import utils as dutils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.manager import system_peer_manager
from dcmanager.tests import base
from dcmanager.tests.unit.common import fake_subcloud
# FAKE SYSINV DATA
FAKE_SITE0_SYSTEM_UUID = str(uuid.uuid4())
FAKE_SITE1_SYSTEM_UUID = str(uuid.uuid4())
# FAKE SYSTEM PEER DATA
FAKE_SYSTEM_PEER_ID = 1
FAKE_SYSTEM_PEER_UUID = FAKE_SITE1_SYSTEM_UUID
FAKE_SYSTEM_PEER_NAME = "PeerSite1"
FAKE_MANAGER_ENDPOINT = "http://128.128.128.128:5000/v3"
FAKE_MANAGER_USERNAME = "admin"
FAKE_MANAGER_PASSWORD = "cGFzc3dvcmQ="
FAKE_PEER_CONTROLLER_GATEWAY_IP = "128.128.1.1"
# FAKE SUBCLOUD PEER GROUP DATA (SITE0)
FAKE_SITE0_PEER_GROUP_ID = 1
FAKE_SITE0_PEER_GROUP_NAME = "PeerGroup1"
FAKE_SITE0_PEER_GROUP_SYSTEM_LEADER_ID = FAKE_SITE0_SYSTEM_UUID
FAKE_SITE0_PEER_GROUP_SYSTEM_LEADER_ID = fake_subcloud.FAKE_SITE0_SYSTEM_UUID
FAKE_SITE0_PEER_GROUP_SYSTEM_LEADER_NAME = "site0"
FAKE_SITE0_PEER_GROUP_MAX_SUBCLOUDS_REHOMING = 50
FAKE_SITE0_PEER_GROUP_PRIORITY = 0
@@ -72,7 +62,7 @@ class FakeSystem(object):
class FakeSysinvClient(object):
def __init__(self):
self.system = FakeSystem(FAKE_SITE1_SYSTEM_UUID)
self.system = FakeSystem(fake_subcloud.FAKE_SITE1_SYSTEM_UUID)
def get_system(self):
return self.system
@@ -164,17 +154,14 @@ class TestSystemPeerManager(base.DCManagerTestCase):
@staticmethod
def create_system_peer_static(ctxt, **kwargs):
values = {
"peer_uuid": FAKE_SYSTEM_PEER_UUID,
"peer_name": FAKE_SYSTEM_PEER_NAME,
"endpoint": FAKE_MANAGER_ENDPOINT,
"username": FAKE_MANAGER_USERNAME,
"password": FAKE_MANAGER_PASSWORD,
"gateway_ip": FAKE_PEER_CONTROLLER_GATEWAY_IP,
"availability_state": consts.SYSTEM_PEER_AVAILABILITY_STATE_AVAILABLE,
}
values.update(kwargs)
return db_api.system_peer_create(ctxt, **values)
system_peer_fields = fake_subcloud.get_test_system_peer_dict("db")
system_peer_fields.update(kwargs)
peer = db_api.system_peer_create(ctxt, **system_peer_fields)
return db_api.system_peer_update(
ctxt,
peer.id,
availability_state=consts.SYSTEM_PEER_AVAILABILITY_STATE_AVAILABLE,
)
@staticmethod
def create_subcloud_peer_group_static(ctxt, **kwargs):
@@ -360,11 +347,13 @@ class TestSystemPeerManager(base.DCManagerTestCase):
)
def test_update_sync_status(self, mock_client):
mock_client.return_value = self.mock_dc_client()
self.mock_get_local_system.return_value = FakeSystem(FAKE_SITE0_SYSTEM_UUID)
self.mock_get_local_system.return_value = FakeSystem(
fake_subcloud.FAKE_SITE0_SYSTEM_UUID
)
db_api.peer_group_association_update(
self.ctx,
associate_id=self.association.id,
id=self.association.id,
sync_status=consts.ASSOCIATION_SYNC_STATUS_UNKNOWN,
)
@@ -384,7 +373,7 @@ class TestSystemPeerManager(base.DCManagerTestCase):
self.peer_group.peer_group_name
)
self.mock_dc_client().get_system_peer.assert_called_once_with(
FAKE_SITE0_SYSTEM_UUID
fake_subcloud.FAKE_SITE0_SYSTEM_UUID
)
self.peer_group_association.assert_called_once_with(
FAKE_SITE1_SYSTEM_PEER_ID, FAKE_SITE1_PEER_GROUP_ID
@@ -408,7 +397,7 @@ class TestSystemPeerManager(base.DCManagerTestCase):
db_api.peer_group_association_update(
self.ctx,
associate_id=self.association.id,
id=self.association.id,
sync_status=consts.ASSOCIATION_SYNC_STATUS_IN_SYNC,
)
@@ -433,7 +422,7 @@ class TestSystemPeerManager(base.DCManagerTestCase):
db_api.peer_group_association_update(
self.ctx,
associate_id=self.association.id,
id=self.association.id,
sync_status=consts.ASSOCIATION_SYNC_STATUS_UNKNOWN,
)
@@ -780,7 +769,7 @@ class TestSystemPeerManager(base.DCManagerTestCase):
associations = db_api.peer_group_association_get_all(self.ctx)
self.assertEqual(1, len(associations))
self.mock_log.warning.assert_called_once_with(
f"Peer site system uuid {FAKE_SITE1_SYSTEM_UUID} "
f"Peer site system uuid {fake_subcloud.FAKE_SITE1_SYSTEM_UUID} "
f"does not match with the peer_uuid {peer.peer_uuid}"
)

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2020, 2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2020, 2022, 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -13,7 +13,7 @@ from dcmanager.common.consts import (
STRATEGY_STATE_KUBE_CREATING_VIM_KUBE_UPGRADE_STRATEGY,
)
from dcmanager.common.consts import STRATEGY_STATE_KUBE_UPGRADE_PRE_CHECK
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.states.base import BaseState
from dcmanager.tests.unit.common import fake_strategy
from dcmanager.tests.unit.orchestrator.states.fakes import FakeAlarm

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2024 Wind River Systems, Inc.
# Copyright (c) 2022-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -21,7 +21,7 @@ from dcmanager.common.consts import STRATEGY_STATE_PRESTAGE_PACKAGES
from dcmanager.common.consts import STRATEGY_STATE_PRESTAGE_PRE_CHECK
from dcmanager.common import exceptions
from dcmanager.common import prestage
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.cache import clients
from dcmanager.tests.unit.common import fake_strategy
from dcmanager.tests.unit.orchestrator.test_base import TestSwUpdate

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -19,7 +19,7 @@ from oslo_config import cfg
from dccommon import consts as dccommon_consts
from dcmanager.common import consts
from dcmanager.common import context
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.states.base import BaseState
from dcmanager.orchestrator import sw_update_manager
from dcmanager.tests import base

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2020-2022, 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -11,7 +11,7 @@ from dccommon.drivers.openstack import vim
from dcmanager.common import consts
from dcmanager.common import exceptions as exception
from dcmanager.common import scheduler
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.orch_thread import OrchThread
from dcmanager.tests.unit.common import fake_strategy

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024 Wind River Systems, Inc.
# Copyright (c) 2017-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -29,7 +29,7 @@ from dcmanager.common import context
from dcmanager.common import exceptions
from dcmanager.common import prestage
from dcmanager.common import utils as cutils
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator import sw_update_manager
from dcmanager.tests import base

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -7,7 +7,7 @@
Firmware strategy validation tests
"""
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.firmware_validator import (
FirmwareStrategyValidator,
)

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -8,7 +8,7 @@ Kube root-ca strategy validation tests
"""
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.kube_root_ca_validator import (
KubeRootCaStrategyValidator,
)

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -8,7 +8,7 @@ Kubernetes strategy validation tests
"""
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.kubernetes_validator import (
KubernetesStrategyValidator,
)

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -8,7 +8,7 @@ Patch strategy validation tests
"""
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.patch_validator import PatchStrategyValidator
from dcmanager.tests.base import DCManagerTestCase
from dcmanager.tests.unit.orchestrator.validators.validators_mixin import (

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -7,7 +7,7 @@
Prestage strategy validation tests
"""
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.prestage_validator import (
PrestageStrategyValidator,
)

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -8,7 +8,7 @@ Software deploy strategy validation tests
"""
from dcmanager.common import consts
from dcmanager.db.sqlalchemy import api as db_api
from dcmanager.db import api as db_api
from dcmanager.orchestrator.validators.sw_deploy_validator import (
SoftwareDeployStrategyValidator,
)

View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2018-2020, 2024 Wind River Systems, Inc.
# Copyright (c) 2018-2020, 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -48,98 +48,98 @@ def get_session():
def quota_create(context, project_id, resource, limit):
"""Create a quota for the given project and resource."""
return IMPL.quota_create(context, project_id, resource, limit)
return IMPL.Connection(context).quota_create(project_id, resource, limit)
def quota_get(context, project_id, resource):
"""Retrieve a quota or raise if it does not exist."""
return IMPL.quota_get(context, project_id, resource)
return IMPL.Connection(context).quota_get(project_id, resource)
def quota_get_all_by_project(context, project_id):
"""Retrieve all quotas associated with a given project."""
return IMPL.quota_get_all_by_project(context, project_id)
return IMPL.Connection(context).quota_get_all_by_project(project_id)
def quota_update(context, project_id, resource, limit):
"""Update a quota or raise if it does not exist."""
return IMPL.quota_update(context, project_id, resource, limit)
return IMPL.Connection(context).quota_update(project_id, resource, limit)
def quota_destroy(context, project_id, resource):
"""Destroy the quota or raise if it does not exist."""
return IMPL.quota_destroy(context, project_id, resource)
return IMPL.Connection(context).quota_destroy(project_id, resource)
def quota_destroy_all(context, project_id):
"""Destroy the quota or raise if it does not exist."""
return IMPL.quota_destroy(context, project_id)
return IMPL.Connection(context).quota_destroy(project_id)
def quota_class_get(context, class_name, resource):
"""Retrieve quota from the given quota class."""
return IMPL.quota_class_get(context, class_name, resource)
return IMPL.Connection(context).quota_class_get(class_name, resource)
def quota_class_get_default(context):
"""Get default class quotas."""
return IMPL.quota_class_get_default(context)
return IMPL.Connection(context).quota_class_get_default()
def quota_class_get_all_by_name(context, class_name):
"""Get all quota limits for a specified class."""
return IMPL.quota_class_get_all_by_name(context, class_name)
return IMPL.Connection(context).quota_class_get_all_by_name(class_name)
def quota_class_create(context, class_name, resource, limit):
"""Create a new quota limit in a specified class."""
return IMPL.quota_class_create(context, class_name, resource, limit)
return IMPL.Connection(context).quota_class_create(class_name, resource, limit)
def quota_class_destroy_all(context, class_name):
"""Destroy all quotas for class."""
return IMPL.quota_class_destroy_all(context, class_name)
return IMPL.Connection(context).quota_class_destroy_all(class_name)
def quota_class_update(context, class_name, resource, limit):
"""Update a quota or raise if it doesn't exist."""
return IMPL.quota_class_update(context, class_name, resource, limit)
return IMPL.Connection(context).quota_class_update(class_name, resource, limit)
def db_sync(engine, version=None):
"""Migrate the database to `version` or the most recent version."""
return IMPL.db_sync(engine, version=version)
return IMPL.Connection.db_sync(engine, version=version)
def db_version(engine):
"""Display the current database version."""
return IMPL.db_version(engine)
return IMPL.Connection.db_version(engine)
def service_create(context, service_id, host=None, binary=None, topic=None):
return IMPL.service_create(
context, service_id=service_id, host=host, binary=binary, topic=topic
return IMPL.Connection(context).service_create(
service_id=service_id, host=host, binary=binary, topic=topic
)
def service_update(context, service_id, values=None):
return IMPL.service_update(context, service_id, values=values)
return IMPL.Connection(context).service_update(service_id, values=values)
def service_delete(context, service_id):
return IMPL.service_delete(context, service_id)
return IMPL.Connection(context).service_delete(service_id)
def service_get(context, service_id):
return IMPL.service_get(context, service_id)
return IMPL.Connection(context).service_get(service_id)
def service_get_all(context):
return IMPL.service_get_all(context)
return IMPL.Connection(context).service_get_all()
def subcloud_get(context, region_id):
return IMPL.subcloud_get(context, region_id)
return IMPL.Connection(context).subcloud_get(region_id)
def subcloud_get_all(
@@ -149,8 +149,7 @@ def subcloud_get_all(
availability_status=None,
initial_sync_state=None,
):
return IMPL.subcloud_get_all(
context,
return IMPL.Connection(context).subcloud_get_all(
region_name=region_name,
management_state=management_state,
availability_status=availability_status,
@@ -165,8 +164,7 @@ def subcloud_capabilities_get_all(
availability_status=None,
initial_sync_state=None,
):
return IMPL.subcloud_capabilities_get_all(
context,
return IMPL.Connection(context).subcloud_capabilities_get_all(
region_name=region_name,
management_state=management_state,
availability_status=availability_status,
@@ -177,8 +175,7 @@ def subcloud_capabilities_get_all(
def subcloud_sync_update_all_to_in_progress(
context, management_state, availability_status, initial_sync_state, sync_requests
):
return IMPL.subcloud_sync_update_all_to_in_progress(
context,
return IMPL.Connection(context).subcloud_sync_update_all_to_in_progress(
management_state=management_state,
availability_status=availability_status,
initial_sync_state=initial_sync_state,
@@ -188,14 +185,13 @@ def subcloud_sync_update_all_to_in_progress(
def subcloud_audit_update_last_audit_time(context, subcloud_name):
"""Updates the last audit time for all rows of a subcloud"""
return IMPL.subcloud_audit_update_last_audit_time(context, subcloud_name)
return IMPL.Connection(context).subcloud_audit_update_last_audit_time(subcloud_name)
def subcloud_audit_update_all_to_in_progress(
context, management_state, availability_status, initial_sync_state, audit_interval
):
return IMPL.subcloud_audit_update_all_to_in_progress(
context,
return IMPL.Connection(context).subcloud_audit_update_all_to_in_progress(
management_state=management_state,
availability_status=availability_status,
initial_sync_state=initial_sync_state,
@@ -204,127 +200,129 @@ def subcloud_audit_update_all_to_in_progress(
def subcloud_create(context, region_name, values):
return IMPL.subcloud_create(context, region_name, values)
return IMPL.Connection(context).subcloud_create(region_name, values)
def subcloud_update(context, region_name, values):
return IMPL.subcloud_update(context, region_name, values)
return IMPL.Connection(context).subcloud_update(region_name, values)
def subcloud_delete(context, region_name):
return IMPL.subcloud_delete(context, region_name)
return IMPL.Connection(context).subcloud_delete(region_name)
def subcloud_update_initial_state(
context, subcloud_name, pre_initial_sync_state, initial_sync_state
):
return IMPL.subcloud_update_initial_state(
context, subcloud_name, pre_initial_sync_state, initial_sync_state
return IMPL.Connection(context).subcloud_update_initial_state(
subcloud_name, pre_initial_sync_state, initial_sync_state
)
def subcloud_update_all_initial_state(
context, pre_initial_sync_state, initial_sync_state
):
return IMPL.subcloud_update_all_initial_state(
context, pre_initial_sync_state, initial_sync_state
return IMPL.Connection(context).subcloud_update_all_initial_state(
pre_initial_sync_state, initial_sync_state
)
def resource_get_by_type_and_master_id(context, resource_type, master_id):
return IMPL.resource_get_by_type_and_master_id(context, resource_type, master_id)
return IMPL.Connection(context).resource_get_by_type_and_master_id(
resource_type, master_id
)
def resource_get_by_id(context, id):
return IMPL.resource_get_by_id(context, id)
return IMPL.Connection(context).resource_get_by_id(id)
def resource_get_all(context, resource_type=None):
return IMPL.resource_get_all(context, resource_type=resource_type)
return IMPL.Connection(context).resource_get_all(resource_type=resource_type)
def resource_create(context, resource_type, values):
return IMPL.resource_create(context, resource_type, values)
return IMPL.Connection(context).resource_create(resource_type, values)
def resource_update(context, resource_type, values):
return IMPL.resource_update(context, resource_type, values)
return IMPL.Connection(context).resource_update(resource_type, values)
def resource_delete(context, resource_type, master_id):
return IMPL.resource_delete(context, resource_type, master_id)
def add_subcloud_resource_filter_by_subcloud(query, value):
return IMPL.add_subcloud_resource_filter_by_subcloud(query, value)
return IMPL.Connection(context).resource_delete(resource_type, master_id)
def subcloud_resource_get(context, subcloud_resource_id):
return IMPL.subcloud_resource_get(context, subcloud_resource_id)
return IMPL.Connection(context).subcloud_resource_get(subcloud_resource_id)
def subcloud_resources_get_by_subcloud(context, subcloud_id):
return IMPL.subcloud_resources_get_by_subcloud(context, subcloud_id)
return IMPL.Connection(context).subcloud_resources_get_by_subcloud(subcloud_id)
def subcloud_resources_get_by_resource(context, resource_id):
return IMPL.subcloud_resources_get_by_resource(context, resource_id)
return IMPL.Connection(context).subcloud_resources_get_by_resource(resource_id)
def subcloud_resource_get_by_resource_and_subcloud(context, resource_id, subcloud_id):
return IMPL.subcloud_resource_get_by_resource_and_subcloud(
context, resource_id, subcloud_id
return IMPL.Connection(context).subcloud_resource_get_by_resource_and_subcloud(
resource_id, subcloud_id
)
def subcloud_resources_get_all(context):
return IMPL.subcloud_resources_get_all(context)
return IMPL.Connection(context).subcloud_resources_get_all()
def subcloud_resource_create(context, subcloud_id, resource_id, values):
return IMPL.subcloud_resource_create(context, subcloud_id, resource_id, values)
return IMPL.Connection(context).subcloud_resource_create(
subcloud_id, resource_id, values
)
def subcloud_resource_update(context, subcloud_resource_id, values):
return IMPL.subcloud_resource_update(context, subcloud_resource_id, values)
return IMPL.Connection(context).subcloud_resource_update(
subcloud_resource_id, values
)
def subcloud_resource_delete(context, subcloud_resource_id):
return IMPL.subcloud_resource_delete(context, subcloud_resource_id)
return IMPL.Connection(context).subcloud_resource_delete(subcloud_resource_id)
def orch_job_get(context, orch_job_id):
return IMPL.orch_job_get(context, orch_job_id)
return IMPL.Connection(context).orch_job_get(orch_job_id)
def orch_job_get_all(context, resource_id=None):
return IMPL.orch_job_get_all(context, resource_id=resource_id)
return IMPL.Connection(context).orch_job_get_all(resource_id=resource_id)
def orch_job_create(context, resource_id, endpoint_type, operation_type, values):
return IMPL.orch_job_create(
context, resource_id, endpoint_type, operation_type, values
return IMPL.Connection(context).orch_job_create(
resource_id, endpoint_type, operation_type, values
)
def orch_job_update(context, orch_job_id, values):
return IMPL.orch_job_update(context, orch_job_id, values)
return IMPL.Connection(context).orch_job_update(orch_job_id, values)
def orch_job_delete(context, orch_job_id):
return IMPL.orch_job_delete(context, orch_job_id)
return IMPL.Connection(context).orch_job_delete(orch_job_id)
def orch_request_get(context, orch_request_id):
return IMPL.orch_request_get(context, orch_request_id)
return IMPL.Connection(context).orch_request_get(orch_request_id)
def orch_request_get_most_recent_failed_request(context):
return IMPL.orch_request_get_most_recent_failed_request(context)
return IMPL.Connection(context).orch_request_get_most_recent_failed_request()
def orch_request_get_all(context, orch_job_id=None):
return IMPL.orch_request_get_all(context, orch_job_id=orch_job_id)
return IMPL.Connection(context).orch_request_get_all(orch_job_id=orch_job_id)
def orch_request_get_by_attrs(
@@ -339,8 +337,7 @@ def orch_request_get_by_attrs(
:param states: [OrchRequest.state] must be a list
:return: [OrchRequests] sorted by OrchRequest.id
"""
return IMPL.orch_request_get_by_attrs(
context,
return IMPL.Connection(context).orch_request_get_by_attrs(
endpoint_type,
resource_type=resource_type,
target_region_name=target_region_name,
@@ -349,53 +346,61 @@ def orch_request_get_by_attrs(
def orch_request_create(context, orch_job_id, target_region_name, values):
return IMPL.orch_request_create(context, orch_job_id, target_region_name, values)
return IMPL.Connection(context).orch_request_create(
orch_job_id, target_region_name, values
)
def orch_request_create_bulk(context, orch_requests):
return IMPL.orch_request_create_bulk(context, orch_requests)
return IMPL.Connection(context).orch_request_create_bulk(orch_requests)
def orch_request_update(context, orch_request_id, values):
return IMPL.orch_request_update(context, orch_request_id, values)
return IMPL.Connection(context).orch_request_update(orch_request_id, values)
def orch_request_destroy(context, orch_request_id):
return IMPL.orch_request_destroy(context, orch_request_id)
return IMPL.Connection(context).orch_request_destroy(orch_request_id)
def orch_request_delete_by_subcloud(context, region_name):
return IMPL.orch_request_delete_by_subcloud(context, region_name)
return IMPL.Connection(context).orch_request_delete_by_subcloud(region_name)
def orch_request_delete_previous_failed_requests(context, delete_timestamp):
return IMPL.orch_request_delete_previous_failed_requests(context, delete_timestamp)
return IMPL.Connection(context).orch_request_delete_previous_failed_requests(
delete_timestamp
)
# Periodic cleanup
def purge_deleted_records(context, age_in_days=1):
return IMPL.purge_deleted_records(context, age_in_days)
return IMPL.Connection(context).purge_deleted_records(age_in_days)
def subcloud_sync_get(context, subcloud_name, endpoint_type):
return IMPL.subcloud_sync_get(context, subcloud_name, endpoint_type)
return IMPL.Connection(context).subcloud_sync_get(subcloud_name, endpoint_type)
def subcloud_sync_update(context, subcloud_name, endpoint_type, values):
return IMPL.subcloud_sync_update(context, subcloud_name, endpoint_type, values)
return IMPL.Connection(context).subcloud_sync_update(
subcloud_name, endpoint_type, values
)
def subcloud_sync_update_all_except_in_progress(
context, management_state, endpoint_type, values
):
return IMPL.subcloud_sync_update_all_except_in_progress(
context, management_state, endpoint_type, values
return IMPL.Connection(context).subcloud_sync_update_all_except_in_progress(
management_state, endpoint_type, values
)
def subcloud_sync_create(context, subcloud_name, endpoint_type, values):
return IMPL.subcloud_sync_create(context, subcloud_name, endpoint_type, values)
return IMPL.Connection(context).subcloud_sync_create(
subcloud_name, endpoint_type, values
)
def subcloud_sync_delete(context, subcloud_name, endpoint_type):
return IMPL.subcloud_sync_delete(context, subcloud_name, endpoint_type)
return IMPL.Connection(context).subcloud_sync_delete(subcloud_name, endpoint_type)

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2015 Ericsson AB
# Copyright (c) 2020-2024 Wind River Systems, Inc.
# Copyright (c) 2020-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -24,12 +24,11 @@ from oslotest import base
import sqlalchemy
from dccommon import consts as dccommon_consts
from dcorch.db import api
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.tests import utils
get_engine = api.get_engine
get_engine = db_api.get_engine
CAPABILITIES = {

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB
# Copyright (c) 2018-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2018-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -27,13 +27,12 @@ from dccommon import consts as dccommon_consts
from dcorch.common import config
from dcorch.common import consts
from dcorch.common import exceptions
from dcorch.db import api
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.tests import base
from dcorch.tests import utils
config.register_options()
get_engine = api.get_engine
get_engine = db_api.get_engine
SUBCLOUD_NAME_REGION_ONE = "RegionOne"

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2015 Ericsson AB
# Copyright (c) 2017-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2017-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -23,13 +23,12 @@ from oslo_db import options
from dccommon import consts as dccommon_consts
from dcorch.common import config
from dcorch.common import exceptions
from dcorch.db import api
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.tests import base
from dcorch.tests import utils
config.register_options()
get_engine = api.get_engine
get_engine = db_api.get_engine
class DBAPISubcloudTest(base.OrchestratorTestCase):

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB
# Copyright (c) 2017-2021, 2024 Wind River Systems, Inc.
# Copyright (c) 2017-2021, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -23,13 +23,12 @@ import sqlalchemy
from dcorch.common import config
from dcorch.common import consts
from dcorch.common import exceptions
from dcorch.db import api
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.tests import base
from dcorch.tests import utils
config.register_options()
get_engine = api.get_engine
get_engine = db_api.get_engine
UUID1 = utils.UUID1
UUID2 = utils.UUID2
SUBCLOUD_NAME_REGION_ONE = "RegionOne"

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2020-2022, 2024-2025 Wind River Systems, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -20,7 +20,7 @@ from oslo_utils import timeutils
from dccommon import consts as dccommon_consts
from dcorch.common import consts
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.engine import generic_sync_manager
from dcorch.rpc import client as rpc_client
from dcorch.tests import base

View File

@@ -1,5 +1,5 @@
#
# Copyright (c) 2024 Wind River Systems, Inc.
# Copyright (c) 2024-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -9,7 +9,7 @@ from oslo_utils import uuidutils
from dccommon import consts as dccommon_consts
from dcorch.common import consts
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.engine import generic_sync_worker_manager
from dcorch.engine.scheduler import ThreadGroupManager
from dcorch.tests import base

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, 2024 Wind River Systems, Inc.
# Copyright (c) 2020-2022, 2024-2025 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,7 +18,7 @@ import mock
from oslo_config import cfg
from dcorch.common import consts
from dcorch.db.sqlalchemy import api as db_api
from dcorch.db import api as db_api
from dcorch.engine import initial_sync_manager
from dcorch.rpc import client
from dcorch.tests import base