Merge "Add peer group association API support"
This commit is contained in:
commit
5b00ad57ed
|
@ -26,6 +26,7 @@ from dcmanagerclient.api.v1 import alarm_manager as am
|
||||||
from dcmanagerclient.api.v1 import fw_update_manager as fum
|
from dcmanagerclient.api.v1 import fw_update_manager as fum
|
||||||
from dcmanagerclient.api.v1 import kube_rootca_update_manager as krum
|
from dcmanagerclient.api.v1 import kube_rootca_update_manager as krum
|
||||||
from dcmanagerclient.api.v1 import kube_upgrade_manager as kupm
|
from dcmanagerclient.api.v1 import kube_upgrade_manager as kupm
|
||||||
|
from dcmanagerclient.api.v1 import peer_group_association_manager as pgam
|
||||||
from dcmanagerclient.api.v1 import phased_subcloud_deploy_manager as psdm
|
from dcmanagerclient.api.v1 import phased_subcloud_deploy_manager as psdm
|
||||||
from dcmanagerclient.api.v1 import strategy_step_manager as ssm
|
from dcmanagerclient.api.v1 import strategy_step_manager as ssm
|
||||||
from dcmanagerclient.api.v1 import subcloud_backup_manager as sbm
|
from dcmanagerclient.api.v1 import subcloud_backup_manager as sbm
|
||||||
|
@ -104,11 +105,14 @@ class Client(object):
|
||||||
self.subcloud_peer_group_manager = \
|
self.subcloud_peer_group_manager = \
|
||||||
pm.subcloud_peer_group_manager(self.http_client,
|
pm.subcloud_peer_group_manager(self.http_client,
|
||||||
self.subcloud_manager)
|
self.subcloud_manager)
|
||||||
|
self.peer_group_association_manager = \
|
||||||
|
pgam.peer_group_association_manager(self.http_client)
|
||||||
self.subcloud_backup_manager = sbm.subcloud_backup_manager(
|
self.subcloud_backup_manager = sbm.subcloud_backup_manager(
|
||||||
self.http_client)
|
self.http_client)
|
||||||
self.subcloud_deploy_manager = sdm.subcloud_deploy_manager(
|
self.subcloud_deploy_manager = sdm.subcloud_deploy_manager(
|
||||||
self.http_client)
|
self.http_client)
|
||||||
self.system_peer_manager = sp.system_peer_manager(self.http_client)
|
self.system_peer_manager = sp.system_peer_manager(
|
||||||
|
self.http_client, self.subcloud_peer_group_manager)
|
||||||
self.alarm_manager = am.alarm_manager(self.http_client)
|
self.alarm_manager = am.alarm_manager(self.http_client)
|
||||||
self.fw_update_manager = fum.fw_update_manager(self.http_client)
|
self.fw_update_manager = fum.fw_update_manager(self.http_client)
|
||||||
self.kube_rootca_update_manager = \
|
self.kube_rootca_update_manager = \
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from dcmanagerclient.api import base
|
||||||
|
from dcmanagerclient.api.base import get_json
|
||||||
|
|
||||||
|
OPTION_NOT_APPLICABLE = 'Not applicable'
|
||||||
|
SYNC_STATUS_INVALID = 'invalid'
|
||||||
|
BASE_URL = '/peer-group-associations/'
|
||||||
|
|
||||||
|
|
||||||
|
class PeerGroupAssociation(base.Resource):
|
||||||
|
resource_name = 'peer_group_association'
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
manager,
|
||||||
|
association_id,
|
||||||
|
peer_group_id,
|
||||||
|
system_peer_id,
|
||||||
|
peer_group_priority,
|
||||||
|
sync_status,
|
||||||
|
sync_message,
|
||||||
|
created_at,
|
||||||
|
updated_at):
|
||||||
|
self.manager = manager
|
||||||
|
self.association_id = association_id
|
||||||
|
self.peer_group_id = peer_group_id
|
||||||
|
self.system_peer_id = system_peer_id
|
||||||
|
self.peer_group_priority = peer_group_priority
|
||||||
|
self.sync_status = sync_status
|
||||||
|
self.sync_message = sync_message
|
||||||
|
self.created_at = created_at
|
||||||
|
self.updated_at = updated_at
|
||||||
|
|
||||||
|
|
||||||
|
class peer_group_association_manager(base.ResourceManager):
|
||||||
|
resource_class = PeerGroupAssociation
|
||||||
|
|
||||||
|
def _json_to_resource(self, json_object):
|
||||||
|
sync_message = None if 'sync-message' not in json_object else \
|
||||||
|
json_object['sync-message']
|
||||||
|
return self.resource_class(
|
||||||
|
self,
|
||||||
|
association_id=json_object['id'],
|
||||||
|
peer_group_id=json_object['peer-group-id'],
|
||||||
|
system_peer_id=json_object['system-peer-id'],
|
||||||
|
peer_group_priority=json_object['peer-group-priority'],
|
||||||
|
sync_status=json_object['sync-status'],
|
||||||
|
sync_message=sync_message,
|
||||||
|
created_at=json_object['created-at'],
|
||||||
|
updated_at=json_object['updated-at'])
|
||||||
|
|
||||||
|
def _peer_group_association_detail(self, url):
|
||||||
|
resp = self.http_client.get(url)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_object = get_json(resp)
|
||||||
|
resource = [self._json_to_resource(json_object)]
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def peer_group_association_list(self, url):
|
||||||
|
resp = self.http_client.get(url)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_response_key = get_json(resp)
|
||||||
|
json_objects = json_response_key['peer_group_associations']
|
||||||
|
resource = list()
|
||||||
|
for json_object in json_objects:
|
||||||
|
resource.append(self._json_to_resource(json_object))
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def peer_group_association_sync(self, url):
|
||||||
|
resp = self.http_client.patch(url, {})
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_object = get_json(resp)
|
||||||
|
resource = [self._json_to_resource(json_object)]
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def peer_group_association_create(self, url, data):
|
||||||
|
data = json.dumps(data)
|
||||||
|
resp = self.http_client.post(url, data)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_object = get_json(resp)
|
||||||
|
resource = [self._json_to_resource(json_object)]
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def peer_group_association_update(self, url, data):
|
||||||
|
data = json.dumps(data)
|
||||||
|
resp = self.http_client.patch(url, data)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_object = get_json(resp)
|
||||||
|
resource = [self._json_to_resource(json_object)]
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def add_peer_group_association(self, **kwargs):
|
||||||
|
data = kwargs
|
||||||
|
url = BASE_URL
|
||||||
|
return self.peer_group_association_create(url, data)
|
||||||
|
|
||||||
|
def list_peer_group_associations(self):
|
||||||
|
url = BASE_URL
|
||||||
|
return self.peer_group_association_list(url)
|
||||||
|
|
||||||
|
def peer_group_association_detail(self, associate_ref):
|
||||||
|
url = BASE_URL + associate_ref
|
||||||
|
return self._peer_group_association_detail(url)
|
||||||
|
|
||||||
|
def sync_peer_group_association(self, associate_ref):
|
||||||
|
url = BASE_URL + '%s/sync' % associate_ref
|
||||||
|
return self.peer_group_association_sync(url)
|
||||||
|
|
||||||
|
def delete_peer_group_association(self, id):
|
||||||
|
url = BASE_URL + id
|
||||||
|
return self._delete(url)
|
||||||
|
|
||||||
|
def update_peer_group_association(self, id, **kwargs):
|
||||||
|
data = kwargs
|
||||||
|
url = BASE_URL + id
|
||||||
|
return self.peer_group_association_update(url, data)
|
|
@ -1,3 +1,4 @@
|
||||||
|
#
|
||||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -50,6 +51,10 @@ class SystemPeer(base.Resource):
|
||||||
class system_peer_manager(base.ResourceManager):
|
class system_peer_manager(base.ResourceManager):
|
||||||
resource_class = SystemPeer
|
resource_class = SystemPeer
|
||||||
|
|
||||||
|
def __init__(self, http_client, subcloud_peer_group_manager):
|
||||||
|
super(system_peer_manager, self).__init__(http_client)
|
||||||
|
self.subcloud_peer_group_manager = subcloud_peer_group_manager
|
||||||
|
|
||||||
def _json_to_resource(self, json_object):
|
def _json_to_resource(self, json_object):
|
||||||
return self.resource_class(
|
return self.resource_class(
|
||||||
self,
|
self,
|
||||||
|
@ -111,6 +116,18 @@ class system_peer_manager(base.ResourceManager):
|
||||||
resource.append(self._json_to_resource(json_object))
|
resource.append(self._json_to_resource(json_object))
|
||||||
return resource
|
return resource
|
||||||
|
|
||||||
|
def _list_peer_groups_for_system_peer(self, url):
|
||||||
|
resp = self.http_client.get(url)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
self._raise_api_exception(resp)
|
||||||
|
json_response_key = get_json(resp)
|
||||||
|
json_objects = json_response_key['subcloud_peer_groups']
|
||||||
|
resource = list()
|
||||||
|
for json_object in json_objects:
|
||||||
|
resource.append(
|
||||||
|
self.subcloud_peer_group_manager.json_to_resource(json_object))
|
||||||
|
return resource
|
||||||
|
|
||||||
def add_system_peer(self, **kwargs):
|
def add_system_peer(self, **kwargs):
|
||||||
data = kwargs
|
data = kwargs
|
||||||
url = BASE_URL
|
url = BASE_URL
|
||||||
|
@ -132,3 +149,7 @@ class system_peer_manager(base.ResourceManager):
|
||||||
data = kwargs
|
data = kwargs
|
||||||
url = BASE_URL + system_peer_ref
|
url = BASE_URL + system_peer_ref
|
||||||
return self.system_peer_update(url, data)
|
return self.system_peer_update(url, data)
|
||||||
|
|
||||||
|
def system_peer_list_peer_groups(self, system_peer_ref):
|
||||||
|
url = BASE_URL + '%s/subcloud-peer-groups' % system_peer_ref
|
||||||
|
return self._list_peer_groups_for_system_peer(url)
|
||||||
|
|
|
@ -0,0 +1,235 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
from osc_lib.command import command
|
||||||
|
|
||||||
|
from dcmanagerclient.commands.v1 import base
|
||||||
|
from dcmanagerclient import exceptions
|
||||||
|
|
||||||
|
|
||||||
|
def association_format(peer_group_association=None):
|
||||||
|
columns = (
|
||||||
|
'id',
|
||||||
|
'peer_group_id',
|
||||||
|
'system_peer_id',
|
||||||
|
'peer_group_priority',
|
||||||
|
'sync_status'
|
||||||
|
)
|
||||||
|
|
||||||
|
if peer_group_association:
|
||||||
|
data = (
|
||||||
|
peer_group_association.association_id,
|
||||||
|
peer_group_association.peer_group_id,
|
||||||
|
peer_group_association.system_peer_id,
|
||||||
|
peer_group_association.peer_group_priority,
|
||||||
|
peer_group_association.sync_status
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
data = (tuple('<none>' for _ in range(len(columns))),)
|
||||||
|
|
||||||
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
|
def detail_association_format(peer_group_association=None):
|
||||||
|
# Include all the fields in detail_association_format
|
||||||
|
# plus some additional fields
|
||||||
|
columns = (
|
||||||
|
'id',
|
||||||
|
'peer_group_id',
|
||||||
|
'system_peer_id',
|
||||||
|
'peer_group_priority',
|
||||||
|
'sync_status',
|
||||||
|
'sync_message',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
)
|
||||||
|
|
||||||
|
if peer_group_association:
|
||||||
|
data = (
|
||||||
|
peer_group_association.association_id,
|
||||||
|
peer_group_association.peer_group_id,
|
||||||
|
peer_group_association.system_peer_id,
|
||||||
|
peer_group_association.peer_group_priority,
|
||||||
|
peer_group_association.sync_status,
|
||||||
|
peer_group_association.sync_message,
|
||||||
|
peer_group_association.created_at,
|
||||||
|
peer_group_association.updated_at
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
data = (tuple('<none>' for _ in range(len(columns))),)
|
||||||
|
|
||||||
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
|
class AddPeerGroupAssociation(base.DCManagerShowOne):
|
||||||
|
"""Add a new peer group association."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return detail_association_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(AddPeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--peer-group-id',
|
||||||
|
required=True,
|
||||||
|
help='Subcloud peer group ID.'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--system-peer-id',
|
||||||
|
required=True,
|
||||||
|
help='System Peer ID.'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--peer-group-priority',
|
||||||
|
required=False,
|
||||||
|
type=int,
|
||||||
|
help='Priority of this peer group. Required when sync is enabled.'
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
kwargs = {
|
||||||
|
'peer_group_id': parsed_args.peer_group_id,
|
||||||
|
'system_peer_id': parsed_args.system_peer_id
|
||||||
|
}
|
||||||
|
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.\
|
||||||
|
add_peer_group_association(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ListPeerGroupAssociation(base.DCManagerLister):
|
||||||
|
"""List peer group associations."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return association_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListPeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
return dcmanager_client.peer_group_association_manager.\
|
||||||
|
list_peer_group_associations()
|
||||||
|
|
||||||
|
|
||||||
|
class ShowPeerGroupAssociation(base.DCManagerShowOne):
|
||||||
|
"""Show the details of a peer group association."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return detail_association_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowPeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'id',
|
||||||
|
help='ID of the peer group association to view the details.'
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
association_ref = parsed_args.id
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
return dcmanager_client.peer_group_association_manager.\
|
||||||
|
peer_group_association_detail(association_ref)
|
||||||
|
|
||||||
|
|
||||||
|
class SyncPeerGroupAssociation(base.DCManagerShowOne):
|
||||||
|
"""Sync the subcloud peer group to peer site."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return detail_association_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(SyncPeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'id',
|
||||||
|
help='ID of the peer group association to sync.'
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
association_ref = parsed_args.id
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
return dcmanager_client.peer_group_association_manager.\
|
||||||
|
sync_peer_group_association(association_ref)
|
||||||
|
|
||||||
|
|
||||||
|
class DeletePeerGroupAssociation(command.Command):
|
||||||
|
"""Delete peer group association from the database."""
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(DeletePeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'id',
|
||||||
|
help='ID of the peer group association to delete.'
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
try:
|
||||||
|
dcmanager_client.peer_group_association_manager.\
|
||||||
|
delete_peer_group_association(parsed_args.id)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
msg = "Unable to delete peer group association %s" % (
|
||||||
|
parsed_args.id)
|
||||||
|
raise exceptions.DCManagerClientException(msg)
|
||||||
|
|
||||||
|
|
||||||
|
class UpdatePeerGroupAssociation(base.DCManagerShowOne):
|
||||||
|
"""Update attributes of a peer group association."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return detail_association_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(UpdatePeerGroupAssociation, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'id',
|
||||||
|
help='ID of the peer group association to update.'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--peer-group-priority',
|
||||||
|
required=True,
|
||||||
|
type=int,
|
||||||
|
help='Priority of the subcloud peer group in this association.'
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
dcmanager_client = self.app.client_manager.\
|
||||||
|
peer_group_association_manager
|
||||||
|
|
||||||
|
kwargs = {'peer_group_priority': parsed_args.peer_group_priority}
|
||||||
|
try:
|
||||||
|
return dcmanager_client.peer_group_association_manager.\
|
||||||
|
update_peer_group_association(parsed_args.id, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
msg = "Unable to update peer group association %s" % (
|
||||||
|
parsed_args.id)
|
||||||
|
raise exceptions.DCManagerClientException(msg)
|
|
@ -1,3 +1,4 @@
|
||||||
|
#
|
||||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -11,6 +12,34 @@ from dcmanagerclient import exceptions
|
||||||
from dcmanagerclient import utils
|
from dcmanagerclient import utils
|
||||||
|
|
||||||
|
|
||||||
|
def group_format(subcloud_peer_group=None):
|
||||||
|
columns = (
|
||||||
|
'id',
|
||||||
|
'peer_group_name',
|
||||||
|
'group_priority',
|
||||||
|
'group_state',
|
||||||
|
'system_leader_id',
|
||||||
|
'system_leader_name',
|
||||||
|
'max_subcloud_rehoming',
|
||||||
|
)
|
||||||
|
|
||||||
|
if subcloud_peer_group:
|
||||||
|
data = (
|
||||||
|
subcloud_peer_group.id,
|
||||||
|
subcloud_peer_group.peer_group_name,
|
||||||
|
subcloud_peer_group.group_priority,
|
||||||
|
subcloud_peer_group.group_state,
|
||||||
|
subcloud_peer_group.system_leader_id,
|
||||||
|
subcloud_peer_group.system_leader_name,
|
||||||
|
subcloud_peer_group.max_subcloud_rehoming,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
data = (tuple('<none>' for _ in range(len(columns))),)
|
||||||
|
|
||||||
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
def peer_format(system_peer=None):
|
def peer_format(system_peer=None):
|
||||||
columns = (
|
columns = (
|
||||||
'id',
|
'id',
|
||||||
|
@ -232,6 +261,29 @@ class ListSystemPeer(base.DCManagerLister):
|
||||||
return dcmanager_client.system_peer_manager.list_system_peers()
|
return dcmanager_client.system_peer_manager.list_system_peers()
|
||||||
|
|
||||||
|
|
||||||
|
class ListSystemPeerSubcloudPeerGroups(base.DCManagerLister):
|
||||||
|
"""List Subcloud Peer Groups referencing a System Peer."""
|
||||||
|
|
||||||
|
def _get_format_function(self):
|
||||||
|
return group_format
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListSystemPeerSubcloudPeerGroups,
|
||||||
|
self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'peer',
|
||||||
|
help='Name or ID or UUID of system peer to list \
|
||||||
|
associated subcloud peer groups.'
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _get_resources(self, parsed_args):
|
||||||
|
system_peer_ref = parsed_args.peer
|
||||||
|
dcmanager_client = self.app.client_manager.system_peer_manager
|
||||||
|
return dcmanager_client.system_peer_manager. \
|
||||||
|
system_peer_list_peer_groups(system_peer_ref)
|
||||||
|
|
||||||
|
|
||||||
class ShowSystemPeer(base.DCManagerShowOne):
|
class ShowSystemPeer(base.DCManagerShowOne):
|
||||||
"""Show the details of a system peer."""
|
"""Show the details of a system peer."""
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ from dcmanagerclient.commands.v1 import alarm_manager as am
|
||||||
from dcmanagerclient.commands.v1 import fw_update_manager as fum
|
from dcmanagerclient.commands.v1 import fw_update_manager as fum
|
||||||
from dcmanagerclient.commands.v1 import kube_rootca_update_manager as krum
|
from dcmanagerclient.commands.v1 import kube_rootca_update_manager as krum
|
||||||
from dcmanagerclient.commands.v1 import kube_upgrade_manager as kupm
|
from dcmanagerclient.commands.v1 import kube_upgrade_manager as kupm
|
||||||
|
from dcmanagerclient.commands.v1 import peer_group_association_manager as pgam
|
||||||
from dcmanagerclient.commands.v1 import phased_subcloud_deploy_manager as psdm
|
from dcmanagerclient.commands.v1 import phased_subcloud_deploy_manager as psdm
|
||||||
from dcmanagerclient.commands.v1 import subcloud_backup_manager as sbm
|
from dcmanagerclient.commands.v1 import subcloud_backup_manager as sbm
|
||||||
from dcmanagerclient.commands.v1 import subcloud_deploy_manager as sdm
|
from dcmanagerclient.commands.v1 import subcloud_deploy_manager as sdm
|
||||||
|
@ -501,7 +502,8 @@ class DCManagerShell(app.App):
|
||||||
kube_rootca_update_manager=self.client,
|
kube_rootca_update_manager=self.client,
|
||||||
sw_prestage_manager=self.client,
|
sw_prestage_manager=self.client,
|
||||||
phased_subcloud_deploy_manager=self.client,
|
phased_subcloud_deploy_manager=self.client,
|
||||||
subcloud_peer_group_manager=self.client)
|
subcloud_peer_group_manager=self.client,
|
||||||
|
peer_group_association_manager=self.client)
|
||||||
)
|
)
|
||||||
self.client_manager = ClientManager()
|
self.client_manager = ClientManager()
|
||||||
|
|
||||||
|
@ -575,6 +577,14 @@ class DCManagerShell(app.App):
|
||||||
'system-peer show': sp.ShowSystemPeer,
|
'system-peer show': sp.ShowSystemPeer,
|
||||||
'system-peer update': sp.UpdateSystemPeer,
|
'system-peer update': sp.UpdateSystemPeer,
|
||||||
'system-peer delete': sp.DeleteSystemPeer,
|
'system-peer delete': sp.DeleteSystemPeer,
|
||||||
|
'system-peer list-subcloud-peer-groups':
|
||||||
|
sp.ListSystemPeerSubcloudPeerGroups,
|
||||||
|
'peer-group-association add': pgam.AddPeerGroupAssociation,
|
||||||
|
'peer-group-association list': pgam.ListPeerGroupAssociation,
|
||||||
|
'peer-group-association show': pgam.ShowPeerGroupAssociation,
|
||||||
|
'peer-group-association sync': pgam.SyncPeerGroupAssociation,
|
||||||
|
'peer-group-association update': pgam.UpdatePeerGroupAssociation,
|
||||||
|
'peer-group-association delete': pgam.DeletePeerGroupAssociation,
|
||||||
'alarm summary': am.ListAlarmSummary,
|
'alarm summary': am.ListAlarmSummary,
|
||||||
'fw-update-strategy create': fum.CreateFwUpdateStrategy,
|
'fw-update-strategy create': fum.CreateFwUpdateStrategy,
|
||||||
'fw-update-strategy delete': fum.DeleteFwUpdateStrategy,
|
'fw-update-strategy delete': fum.DeleteFwUpdateStrategy,
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import mock
|
||||||
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
from dcmanagerclient.api.v1.peer_group_association_manager \
|
||||||
|
import PeerGroupAssociation as PeerAssociation
|
||||||
|
from dcmanagerclient.commands.v1 import peer_group_association_manager \
|
||||||
|
as peer_group_association_cmd
|
||||||
|
from dcmanagerclient.tests import base
|
||||||
|
|
||||||
|
PEER_GROUP_ASSOCIATION_ID = "1"
|
||||||
|
PEER_GROUP_ID = "2"
|
||||||
|
SYSTEM_PEER_ID = "3"
|
||||||
|
PG_GROUP_PRIORITY = "99"
|
||||||
|
SYNC_STATUS = "synced"
|
||||||
|
SYNC_MESSAGE = "None"
|
||||||
|
PG_GROUP_PRIORITY_UPDATED = "1"
|
||||||
|
TIME_NOW = timeutils.utcnow().isoformat()
|
||||||
|
CREATED_AT = TIME_NOW
|
||||||
|
UPDATED_AT = TIME_NOW
|
||||||
|
|
||||||
|
PEER_GROUP_ASSOCIATION = PeerAssociation(
|
||||||
|
mock,
|
||||||
|
PEER_GROUP_ASSOCIATION_ID,
|
||||||
|
PEER_GROUP_ID,
|
||||||
|
SYSTEM_PEER_ID,
|
||||||
|
PG_GROUP_PRIORITY,
|
||||||
|
SYNC_STATUS,
|
||||||
|
SYNC_MESSAGE,
|
||||||
|
CREATED_AT,
|
||||||
|
UPDATED_AT
|
||||||
|
)
|
||||||
|
|
||||||
|
PEER_GROUP_ASSOCIATION_TUPLE = (PEER_GROUP_ASSOCIATION_ID,
|
||||||
|
PEER_GROUP_ID,
|
||||||
|
SYSTEM_PEER_ID,
|
||||||
|
PG_GROUP_PRIORITY,
|
||||||
|
SYNC_STATUS)
|
||||||
|
|
||||||
|
PEER_GROUP_ASSOCIATION_DETAIL_TUPLE = \
|
||||||
|
PEER_GROUP_ASSOCIATION_TUPLE + (SYNC_MESSAGE, CREATED_AT, UPDATED_AT)
|
||||||
|
|
||||||
|
PEER_GROUP_ASSOCIATION_TUPLE_UPDATED = (PEER_GROUP_ASSOCIATION_ID,
|
||||||
|
PEER_GROUP_ID,
|
||||||
|
SYSTEM_PEER_ID,
|
||||||
|
PG_GROUP_PRIORITY_UPDATED,
|
||||||
|
SYNC_STATUS,
|
||||||
|
SYNC_MESSAGE,
|
||||||
|
CREATED_AT,
|
||||||
|
UPDATED_AT)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCLIPeerGroupAssociationV1(base.BaseCommandTest):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestCLIPeerGroupAssociationV1, self).setUp()
|
||||||
|
# The client is the peer_group_association_manager
|
||||||
|
self.client = self.app.client_manager.peer_group_association_manager
|
||||||
|
|
||||||
|
def test_list_peer_group_association(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
list_peer_group_associations.return_value =\
|
||||||
|
[PEER_GROUP_ASSOCIATION]
|
||||||
|
actual_call = self.call(peer_group_association_cmd.
|
||||||
|
ListPeerGroupAssociation)
|
||||||
|
self.assertEqual([PEER_GROUP_ASSOCIATION_TUPLE],
|
||||||
|
actual_call[1])
|
||||||
|
|
||||||
|
def test_list_peer_group_association_empty(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
list_peer_group_associations.return_value = []
|
||||||
|
actual_call = self.call(peer_group_association_cmd.
|
||||||
|
ListPeerGroupAssociation)
|
||||||
|
self.assertEqual((tuple('<none>' for _ in range(
|
||||||
|
len(PEER_GROUP_ASSOCIATION_TUPLE))),), actual_call[1])
|
||||||
|
|
||||||
|
def test_add_peer_group_association(self):
|
||||||
|
self.client.peer_group_association_manager.add_peer_group_association.\
|
||||||
|
return_value = [PEER_GROUP_ASSOCIATION]
|
||||||
|
actual_call = self.call(
|
||||||
|
peer_group_association_cmd.AddPeerGroupAssociation, app_args=[
|
||||||
|
'--peer-group-id', PEER_GROUP_ID,
|
||||||
|
'--system-peer-id', SYSTEM_PEER_ID,
|
||||||
|
'--peer-group-priority', PG_GROUP_PRIORITY
|
||||||
|
])
|
||||||
|
self.assertEqual(
|
||||||
|
PEER_GROUP_ASSOCIATION_DETAIL_TUPLE,
|
||||||
|
actual_call[1])
|
||||||
|
|
||||||
|
def test_show_peer_group_association(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
peer_group_association_detail.return_value =\
|
||||||
|
[PEER_GROUP_ASSOCIATION]
|
||||||
|
actual_call = self.call(peer_group_association_cmd.
|
||||||
|
ShowPeerGroupAssociation,
|
||||||
|
app_args=[PEER_GROUP_ASSOCIATION_ID])
|
||||||
|
self.assertEqual((PEER_GROUP_ASSOCIATION_ID,
|
||||||
|
PEER_GROUP_ID,
|
||||||
|
SYSTEM_PEER_ID,
|
||||||
|
PG_GROUP_PRIORITY,
|
||||||
|
SYNC_STATUS,
|
||||||
|
SYNC_MESSAGE,
|
||||||
|
CREATED_AT,
|
||||||
|
UPDATED_AT), actual_call[1])
|
||||||
|
|
||||||
|
def test_show_peer_group_association_without_id(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
peer_group_association_detail.return_value = []
|
||||||
|
self.assertRaises(SystemExit, self.call,
|
||||||
|
peer_group_association_cmd.ShowPeerGroupAssociation,
|
||||||
|
app_args=[])
|
||||||
|
|
||||||
|
def test_delete_peer_group_association(self):
|
||||||
|
self.call(peer_group_association_cmd.DeletePeerGroupAssociation,
|
||||||
|
app_args=[PEER_GROUP_ASSOCIATION_ID])
|
||||||
|
self.client.peer_group_association_manager. \
|
||||||
|
delete_peer_group_association.\
|
||||||
|
assert_called_once_with(PEER_GROUP_ASSOCIATION_ID)
|
||||||
|
|
||||||
|
def test_delete_peer_group_association_without_id(self):
|
||||||
|
self.assertRaises(SystemExit, self.call,
|
||||||
|
peer_group_association_cmd.
|
||||||
|
DeletePeerGroupAssociation, app_args=[])
|
||||||
|
|
||||||
|
def test_update_peer_group_association(self):
|
||||||
|
UPDATED_PEER_GROUP_ASSOCIATION = copy.copy(PEER_GROUP_ASSOCIATION)
|
||||||
|
UPDATED_PEER_GROUP_ASSOCIATION.peer_group_priority =\
|
||||||
|
PG_GROUP_PRIORITY_UPDATED
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
update_peer_group_association.\
|
||||||
|
return_value = [UPDATED_PEER_GROUP_ASSOCIATION]
|
||||||
|
actual_call = self.call(
|
||||||
|
peer_group_association_cmd.UpdatePeerGroupAssociation,
|
||||||
|
app_args=[PEER_GROUP_ASSOCIATION_ID,
|
||||||
|
'--peer-group-priority', PG_GROUP_PRIORITY_UPDATED])
|
||||||
|
self.assertEqual(
|
||||||
|
(PEER_GROUP_ASSOCIATION_TUPLE_UPDATED),
|
||||||
|
actual_call[1])
|
||||||
|
|
||||||
|
def test_update_peer_group_association_without_priority(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
update_peer_group_association.\
|
||||||
|
return_value = [PEER_GROUP_ASSOCIATION]
|
||||||
|
self.assertRaises(SystemExit,
|
||||||
|
self.call,
|
||||||
|
peer_group_association_cmd.
|
||||||
|
UpdatePeerGroupAssociation,
|
||||||
|
app_args=[PEER_GROUP_ID])
|
||||||
|
|
||||||
|
def test_sync_peer_group_association(self):
|
||||||
|
self.client.peer_group_association_manager.\
|
||||||
|
sync_peer_group_association.\
|
||||||
|
return_value = [PEER_GROUP_ASSOCIATION]
|
||||||
|
actual_call = self.call(
|
||||||
|
peer_group_association_cmd.SyncPeerGroupAssociation,
|
||||||
|
app_args=[PEER_GROUP_ASSOCIATION_ID])
|
||||||
|
self.assertEqual(
|
||||||
|
(PEER_GROUP_ASSOCIATION_DETAIL_TUPLE),
|
||||||
|
actual_call[1])
|
|
@ -1,3 +1,4 @@
|
||||||
|
#
|
||||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -8,12 +9,14 @@ import mock
|
||||||
|
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
from dcmanagerclient.api.v1.subcloud_peer_group_manager \
|
||||||
|
import SubcloudPeerGroup as Peergroup
|
||||||
from dcmanagerclient.api.v1 import system_peer_manager as spm
|
from dcmanagerclient.api.v1 import system_peer_manager as spm
|
||||||
from dcmanagerclient.commands.v1 \
|
from dcmanagerclient.commands.v1 \
|
||||||
import system_peer_manager as system_peer_cmd
|
import system_peer_manager as system_peer_cmd
|
||||||
from dcmanagerclient.tests import base
|
from dcmanagerclient.tests import base
|
||||||
|
|
||||||
|
# Sample System Peer data
|
||||||
ID = '2'
|
ID = '2'
|
||||||
SYSTEM_PEER_UUID = 'test1234-0dfd-46cd-9a93-e3c2b74ef20f'
|
SYSTEM_PEER_UUID = 'test1234-0dfd-46cd-9a93-e3c2b74ef20f'
|
||||||
SYSTEM_PEER_NAME = 'SystemPeer1'
|
SYSTEM_PEER_NAME = 'SystemPeer1'
|
||||||
|
@ -30,6 +33,17 @@ PEER_CONTROLLER_GATEWAY_IP = '128.128.128.1'
|
||||||
TIME_NOW = timeutils.utcnow().isoformat()
|
TIME_NOW = timeutils.utcnow().isoformat()
|
||||||
NEW_PEER_CONTROLLER_GATEWAY_IP = '128.1.1.1'
|
NEW_PEER_CONTROLLER_GATEWAY_IP = '128.1.1.1'
|
||||||
|
|
||||||
|
# Sample Subcloud Peer Group data
|
||||||
|
PG_ID = "1"
|
||||||
|
PG_NAME = "SubcloudPeerGroup1"
|
||||||
|
PG_GROUP_PRIORITY = "99"
|
||||||
|
PG_GROUP_STATE = "disabled"
|
||||||
|
PG_MAX_SUBCLOUD_REHOMING = "10"
|
||||||
|
PG_SYSTEM_LEADER_ID = "d9dea83f-f271-470d-9cce-44b0162a800b"
|
||||||
|
PG_SYSTEM_LEADER_NAME = "DC-1"
|
||||||
|
PG_CREATED_AT = TIME_NOW
|
||||||
|
PG_UPDATED_AT = TIME_NOW
|
||||||
|
|
||||||
SYSTEM_PEER_DICT = {
|
SYSTEM_PEER_DICT = {
|
||||||
'PEER_ID': ID,
|
'PEER_ID': ID,
|
||||||
'PEER_UUID': SYSTEM_PEER_UUID,
|
'PEER_UUID': SYSTEM_PEER_UUID,
|
||||||
|
@ -47,7 +61,7 @@ SYSTEM_PEER_DICT = {
|
||||||
'UPDATED_AT': TIME_NOW
|
'UPDATED_AT': TIME_NOW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# System Peer CLI resource object
|
||||||
SYSTEM_PEER = spm.SystemPeer(
|
SYSTEM_PEER = spm.SystemPeer(
|
||||||
mock,
|
mock,
|
||||||
peer_id=SYSTEM_PEER_DICT['PEER_ID'],
|
peer_id=SYSTEM_PEER_DICT['PEER_ID'],
|
||||||
|
@ -69,6 +83,27 @@ SYSTEM_PEER = spm.SystemPeer(
|
||||||
updated_at=SYSTEM_PEER_DICT['UPDATED_AT']
|
updated_at=SYSTEM_PEER_DICT['UPDATED_AT']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Subcloud Peer Group CLI resource object
|
||||||
|
PEER_GROUP = Peergroup(
|
||||||
|
mock,
|
||||||
|
PG_ID,
|
||||||
|
PG_NAME,
|
||||||
|
PG_GROUP_PRIORITY,
|
||||||
|
PG_GROUP_STATE,
|
||||||
|
PG_SYSTEM_LEADER_ID,
|
||||||
|
PG_SYSTEM_LEADER_NAME,
|
||||||
|
PG_MAX_SUBCLOUD_REHOMING,
|
||||||
|
PG_CREATED_AT,
|
||||||
|
PG_UPDATED_AT
|
||||||
|
)
|
||||||
|
PG_TUPLE = (PG_ID,
|
||||||
|
PG_NAME,
|
||||||
|
PG_GROUP_PRIORITY,
|
||||||
|
PG_GROUP_STATE,
|
||||||
|
PG_SYSTEM_LEADER_ID,
|
||||||
|
PG_SYSTEM_LEADER_NAME,
|
||||||
|
PG_MAX_SUBCLOUD_REHOMING)
|
||||||
|
|
||||||
|
|
||||||
class TestCLISystemPeerManagerV1(base.BaseCommandTest):
|
class TestCLISystemPeerManagerV1(base.BaseCommandTest):
|
||||||
|
|
||||||
|
@ -130,6 +165,14 @@ class TestCLISystemPeerManagerV1(base.BaseCommandTest):
|
||||||
self.assertEqual((tuple('<none>' for _ in range(14)),),
|
self.assertEqual((tuple('<none>' for _ in range(14)),),
|
||||||
actual_call[1])
|
actual_call[1])
|
||||||
|
|
||||||
|
def test_list_system_peer_subcloud_peer_groups(self):
|
||||||
|
self.client.system_peer_manager.\
|
||||||
|
system_peer_list_peer_groups.return_value = [PEER_GROUP]
|
||||||
|
actual_call = self.call(
|
||||||
|
system_peer_cmd.ListSystemPeerSubcloudPeerGroups,
|
||||||
|
app_args=[ID])
|
||||||
|
self.assertEqual([PG_TUPLE], actual_call[1])
|
||||||
|
|
||||||
def test_add_system_peer(self):
|
def test_add_system_peer(self):
|
||||||
self.client.system_peer_manager.add_system_peer.\
|
self.client.system_peer_manager.add_system_peer.\
|
||||||
return_value = [SYSTEM_PEER]
|
return_value = [SYSTEM_PEER]
|
||||||
|
|
Loading…
Reference in New Issue