From 8f96f8a2d221d959db85a6c592504f985a3a1326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Strelec?= Date: Wed, 21 Jun 2023 13:34:41 +0200 Subject: [PATCH] Add support for RHCloud Cloud Connector (#920) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add support for RHCloud Cloud Connector * remove location_id and organization_id from args * add Nailgun tests * add Nailgun tests * update entity fields Co-authored-by: Ondřej Gajdušek * change the way data are passed to the function * change the way data are passed to the function * update test to match change --------- Co-authored-by: Ondřej Gajdušek (cherry picked from commit 13c0375dcd2c1135652400091beff610efbc2e6f) --- nailgun/entities.py | 30 +++++++++++++++++++++++++++++- tests/test_entities.py | 8 ++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/nailgun/entities.py b/nailgun/entities.py index 1f0d90bf..04443a98 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -6780,6 +6780,34 @@ def deploy(self, synchronous=True, timeout=None, **kwargs): return _handle_response(response, self._server_config, synchronous, timeout) +class RHCloud(Entity): + """A representation of a RHCloud entity.""" + + def __init__(self, server_config=None, **kwargs): + self._fields = { + 'organization': entity_fields.OneToOneField(Organization), + 'location': entity_fields.OneToOneField(Location), + } + super().__init__(server_config, **kwargs) + self._meta = {'api_path': 'api/v2/rh_cloud'} + + def path(self, which=None): + """Extend ``nailgun.entity_mixins.Entity.path``.""" + if which in ("enable_connector",): + return f'{super().path(which="base")}/{which}' + return super().path(which) + + def enable_connector(self, synchronous=True, timeout=None, **kwargs): + """Function to enable RH Cloud connector""" + kwargs = kwargs.copy() + kwargs.update(self._server_config.get_client_kwargs()) + kwargs['data'] = {} + if data := _payload(self.get_fields(), self.get_values()): + kwargs['data'] = data + response = client.post(self.path('enable_connector'), **kwargs) + return _handle_response(response, self._server_config, synchronous, timeout) + + class RoleLDAPGroups(Entity): """A representation of a Role LDAP Groups entity.""" @@ -8352,7 +8380,7 @@ def path(self, which=None): ``super`` is called otherwise. """ - if which in ("sync"): + if which in ("sync",): return f'{super().path(which="base")}/{which}' return super().path(which) diff --git a/tests/test_entities.py b/tests/test_entities.py index 12c8bf93..7bf262dc 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -163,6 +163,7 @@ def test_init_succeeds(self): entities.Report, entities.Repository, entities.RepositorySet, + entities.RHCloud, entities.Role, entities.RoleLDAPGroups, entities.ScapContents, @@ -377,6 +378,7 @@ def test_noid_and_which(self): (entities.ForemanTask, 'bulk_resume'), (entities.ForemanTask, 'bulk_search'), (entities.ForemanTask, 'summary'), + (entities.RHCloud, 'enable_connector'), (entities.Host, 'bulk/install_content'), (entities.Template, 'imports'), (entities.Template, 'exports'), @@ -2196,12 +2198,18 @@ def setUpClass(cls): (entities.Template(**generic).exports, 'post'), (entities.VirtWhoConfig(**generic).deploy_script, 'get'), ) + plain_taxonomy = {'server_config': cfg, 'organization': 1, 'location': 2} repo_set = {'server_config': cfg, 'id': 1, 'product': 2} snapshot = {'server_config': cfg, 'id': 'snapshot-1', 'host': 1} cls.intelligent_methods_requests = ( (entities.RepositorySet(**repo_set).available_repositories, 'get', {'product_id': 2}), (entities.RepositorySet(**repo_set).disable, 'put', {'product_id': 2}), (entities.RepositorySet(**repo_set).enable, 'put', {'product_id': 2}), + ( + entities.RHCloud(**plain_taxonomy).enable_connector, + 'post', + {'organization_id': 1, 'location_id': 2}, + ), (entities.Snapshot(**snapshot).revert, 'put', {}), )