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

Remove content view version from environments if empty #1280

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
20 changes: 13 additions & 7 deletions plugins/modules/content_view_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,19 @@ def main():
content_view_version = {'id': -1, 'environments': []}

if 'lifecycle_environments' in module.foreman_params:
promote_content_view_version(
module,
content_view_version,
module.foreman_params['lifecycle_environments'],
force=module.foreman_params['force_promote'],
force_yum_metadata_regeneration=module.foreman_params['force_yum_metadata_regeneration'],
)
if module.foreman_params['lifecycle_environments'] == [] and content_view_version['environments']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this happen only if the user says [] or always when the list doesn't match?

The later has some complications as we never list Library and I think the current user expectation is "promote to these envs, don't touch the others"?

current_environment_ids = {environment['id'] for environment in content_view_version['environments']}

for environment_id in current_environment_ids:
response = module.resource_action('content_views', 'remove_from_environment', params={'id': content_view['id'], 'environment_id': environment_id})
Copy link
Member Author

@ehelms ehelms Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On newer releases of Katello, I think this can be done in one call via:

response = module.resource_action('content_views_versions', 'remove_from_environments', params={'id': content_view['id'], 'environment_ids': current_environment_ids})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer is 4.0+? If there is a possible perfomance gain, I'd be in favor of an if/else?

BTW, the linter says this line is too damn long (170>160 chars) ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find this in the Katello API?

else:
promote_content_view_version(
module,
content_view_version,
module.foreman_params['lifecycle_environments'],
force=module.foreman_params['force_promote'],
force_yum_metadata_regeneration=module.foreman_params['force_yum_metadata_regeneration'],
)


if __name__ == '__main__':
Expand Down