Add association_type for association CLI list and detail

Given that the non-primary association is automatically
generated, it is necessary to introduce a type indicator to
differentiate between primary and non-primary associations.
This commit aims to incorporate the association type when
listing and retrieving details of the association.

Test Plan:
- PASS: The command "dcmanager peer-group-association list"
        display the type information of the each association,
        indicating whether it is primary or non-primary.
- PASS: The command "dcmanager peer-group-association show"
        will include the "association_type" attribute.
- PASS: The association add/update/sync commands will include
        the association_type attribute.

Closes-Bug: 2046809
Depends-On: Ia917d0dc7c65fbea1e222fb52dbec79fdbe65b65

Change-Id: I4d55700f85956c785760b2cc0a5e2ea13a180c22
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
This commit is contained in:
Zhang Rong(Jon) 2023-12-20 10:23:04 +08:00
parent cee92f4f28
commit 56049f435a
3 changed files with 26 additions and 16 deletions

View File

@ -23,6 +23,7 @@ class PeerGroupAssociation(base.Resource):
peer_group_id, peer_group_id,
system_peer_id, system_peer_id,
peer_group_priority, peer_group_priority,
association_type,
sync_status, sync_status,
sync_message, sync_message,
created_at, created_at,
@ -32,6 +33,7 @@ class PeerGroupAssociation(base.Resource):
self.peer_group_id = peer_group_id self.peer_group_id = peer_group_id
self.system_peer_id = system_peer_id self.system_peer_id = system_peer_id
self.peer_group_priority = peer_group_priority self.peer_group_priority = peer_group_priority
self.association_type = association_type
self.sync_status = sync_status self.sync_status = sync_status
self.sync_message = sync_message self.sync_message = sync_message
self.created_at = created_at self.created_at = created_at
@ -50,6 +52,7 @@ class peer_group_association_manager(base.ResourceManager):
peer_group_id=json_object['peer-group-id'], peer_group_id=json_object['peer-group-id'],
system_peer_id=json_object['system-peer-id'], system_peer_id=json_object['system-peer-id'],
peer_group_priority=json_object['peer-group-priority'], peer_group_priority=json_object['peer-group-priority'],
association_type=json_object['association-type'],
sync_status=json_object['sync-status'], sync_status=json_object['sync-status'],
sync_message=sync_message, sync_message=sync_message,
created_at=json_object['created-at'], created_at=json_object['created-at'],

View File

@ -15,8 +15,9 @@ def association_format(peer_group_association=None):
'id', 'id',
'peer_group_id', 'peer_group_id',
'system_peer_id', 'system_peer_id',
'peer_group_priority', 'type',
'sync_status' 'sync_status',
'peer_group_priority'
) )
if peer_group_association: if peer_group_association:
@ -24,8 +25,9 @@ def association_format(peer_group_association=None):
peer_group_association.association_id, peer_group_association.association_id,
peer_group_association.peer_group_id, peer_group_association.peer_group_id,
peer_group_association.system_peer_id, peer_group_association.system_peer_id,
peer_group_association.peer_group_priority, peer_group_association.association_type,
peer_group_association.sync_status peer_group_association.sync_status,
peer_group_association.peer_group_priority
) )
else: else:
@ -41,8 +43,9 @@ def detail_association_format(peer_group_association=None):
'id', 'id',
'peer_group_id', 'peer_group_id',
'system_peer_id', 'system_peer_id',
'peer_group_priority', 'association_type',
'sync_status', 'sync_status',
'peer_group_priority',
'sync_message', 'sync_message',
'created_at', 'created_at',
'updated_at', 'updated_at',
@ -53,8 +56,9 @@ def detail_association_format(peer_group_association=None):
peer_group_association.association_id, peer_group_association.association_id,
peer_group_association.peer_group_id, peer_group_association.peer_group_id,
peer_group_association.system_peer_id, peer_group_association.system_peer_id,
peer_group_association.peer_group_priority, peer_group_association.association_type,
peer_group_association.sync_status, peer_group_association.sync_status,
peer_group_association.peer_group_priority,
peer_group_association.sync_message, peer_group_association.sync_message,
peer_group_association.created_at, peer_group_association.created_at,
peer_group_association.updated_at peer_group_association.updated_at
@ -88,9 +92,9 @@ class AddPeerGroupAssociation(base.DCManagerShowOne):
parser.add_argument( parser.add_argument(
'--peer-group-priority', '--peer-group-priority',
required=False, required=True,
type=int, type=int,
help='Priority of this peer group. Required when sync is enabled.' help='Priority of this peer group.'
) )
return parser return parser
@ -99,11 +103,9 @@ class AddPeerGroupAssociation(base.DCManagerShowOne):
peer_group_association_manager peer_group_association_manager
kwargs = { kwargs = {
'peer_group_id': parsed_args.peer_group_id, 'peer_group_id': parsed_args.peer_group_id,
'system_peer_id': parsed_args.system_peer_id 'system_peer_id': parsed_args.system_peer_id,
'peer_group_priority': parsed_args.peer_group_priority
} }
if parsed_args.peer_group_priority is not None:
kwargs['peer_group_priority'] = parsed_args.peer_group_priority
return dcmanager_client.peer_group_association_manager.\ return dcmanager_client.peer_group_association_manager.\
add_peer_group_association(**kwargs) add_peer_group_association(**kwargs)

View File

@ -18,6 +18,7 @@ PEER_GROUP_ASSOCIATION_ID = "1"
PEER_GROUP_ID = "2" PEER_GROUP_ID = "2"
SYSTEM_PEER_ID = "3" SYSTEM_PEER_ID = "3"
PG_GROUP_PRIORITY = "99" PG_GROUP_PRIORITY = "99"
ASSOCIATION_TYPE = "primary"
SYNC_STATUS = "synced" SYNC_STATUS = "synced"
SYNC_MESSAGE = "None" SYNC_MESSAGE = "None"
PG_GROUP_PRIORITY_UPDATED = "1" PG_GROUP_PRIORITY_UPDATED = "1"
@ -31,6 +32,7 @@ PEER_GROUP_ASSOCIATION = PeerAssociation(
PEER_GROUP_ID, PEER_GROUP_ID,
SYSTEM_PEER_ID, SYSTEM_PEER_ID,
PG_GROUP_PRIORITY, PG_GROUP_PRIORITY,
ASSOCIATION_TYPE,
SYNC_STATUS, SYNC_STATUS,
SYNC_MESSAGE, SYNC_MESSAGE,
CREATED_AT, CREATED_AT,
@ -40,8 +42,9 @@ PEER_GROUP_ASSOCIATION = PeerAssociation(
PEER_GROUP_ASSOCIATION_TUPLE = (PEER_GROUP_ASSOCIATION_ID, PEER_GROUP_ASSOCIATION_TUPLE = (PEER_GROUP_ASSOCIATION_ID,
PEER_GROUP_ID, PEER_GROUP_ID,
SYSTEM_PEER_ID, SYSTEM_PEER_ID,
PG_GROUP_PRIORITY, ASSOCIATION_TYPE,
SYNC_STATUS) SYNC_STATUS,
PG_GROUP_PRIORITY)
PEER_GROUP_ASSOCIATION_DETAIL_TUPLE = \ PEER_GROUP_ASSOCIATION_DETAIL_TUPLE = \
PEER_GROUP_ASSOCIATION_TUPLE + (SYNC_MESSAGE, CREATED_AT, UPDATED_AT) PEER_GROUP_ASSOCIATION_TUPLE + (SYNC_MESSAGE, CREATED_AT, UPDATED_AT)
@ -49,8 +52,9 @@ PEER_GROUP_ASSOCIATION_DETAIL_TUPLE = \
PEER_GROUP_ASSOCIATION_TUPLE_UPDATED = (PEER_GROUP_ASSOCIATION_ID, PEER_GROUP_ASSOCIATION_TUPLE_UPDATED = (PEER_GROUP_ASSOCIATION_ID,
PEER_GROUP_ID, PEER_GROUP_ID,
SYSTEM_PEER_ID, SYSTEM_PEER_ID,
PG_GROUP_PRIORITY_UPDATED, ASSOCIATION_TYPE,
SYNC_STATUS, SYNC_STATUS,
PG_GROUP_PRIORITY_UPDATED,
SYNC_MESSAGE, SYNC_MESSAGE,
CREATED_AT, CREATED_AT,
UPDATED_AT) UPDATED_AT)
@ -102,8 +106,9 @@ class TestCLIPeerGroupAssociationV1(base.BaseCommandTest):
self.assertEqual((PEER_GROUP_ASSOCIATION_ID, self.assertEqual((PEER_GROUP_ASSOCIATION_ID,
PEER_GROUP_ID, PEER_GROUP_ID,
SYSTEM_PEER_ID, SYSTEM_PEER_ID,
PG_GROUP_PRIORITY, ASSOCIATION_TYPE,
SYNC_STATUS, SYNC_STATUS,
PG_GROUP_PRIORITY,
SYNC_MESSAGE, SYNC_MESSAGE,
CREATED_AT, CREATED_AT,
UPDATED_AT), actual_call[1]) UPDATED_AT), actual_call[1])