Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.13.z] Add support for RHCloud Cloud Connector #939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading