Skip to content

Commit

Permalink
Add support for RHCloud Cloud Connector (#920)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
  • Loading branch information
mstrlc and ogajduse authored Jun 21, 2023
1 parent 162e767 commit 13c0375
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
30 changes: 29 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7122,6 +7122,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."""

Expand Down Expand Up @@ -8702,7 +8730,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)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def test_init_succeeds(self):
entities.Report,
entities.Repository,
entities.RepositorySet,
entities.RHCloud,
entities.Role,
entities.RoleLDAPGroups,
entities.ScapContents,
Expand Down Expand Up @@ -383,6 +384,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'),
Expand Down Expand Up @@ -2206,6 +2208,7 @@ def setUpClass(cls):
(entities.Template(**generic).exports, 'post'),
(entities.VirtWhoConfig(**generic).deploy_script, 'get'),
)
plain_taxonomy = {'server_config': cfg, 'organization': 1, 'location': 2}
capsule = {'server_config': cfg, 'id': 1}
repo_set = {'server_config': cfg, 'id': 1, 'product': 2}
snapshot = {'server_config': cfg, 'id': 'snapshot-1', 'host': 1}
Expand All @@ -2218,6 +2221,11 @@ def setUpClass(cls):
(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', {}),
)

Expand Down

0 comments on commit 13c0375

Please sign in to comment.