Skip to content

Commit

Permalink
[6.13.z] Add support for RHCloud Cloud Connector (#939)
Browse files Browse the repository at this point in the history
Co-authored-by: Ondřej Gajdušek <[email protected]>
Co-authored-by: Matyáš Strelec <[email protected]>
  • Loading branch information
3 people committed Jun 21, 2023
1 parent 4230434 commit 9c51426
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 @@ -6993,6 +6993,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 @@ -8566,7 +8594,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 @@ -382,6 +383,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 @@ -2201,6 +2203,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 @@ -2213,6 +2216,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 9c51426

Please sign in to comment.