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

gitlab_group: fix issue 4577 #4856

Closed
wants to merge 3 commits into from

Conversation

fzarifian
Copy link

@fzarifian fzarifian commented Jun 19, 2022

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

Fix #4577

ADDITIONAL INFORMATION

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug gitlab module module new_contributor Help guide this first time contributor plugins plugin (any type) source_control labels Jun 19, 2022
@felixfontein felixfontein changed the title fix issue-4855 gitlab_group: fix issue 4855 Jun 19, 2022
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. Unfortunately your fix does cause new bugs and cannot be merged in this form.

plugins/modules/source_control/gitlab/gitlab_group.py Outdated Show resolved Hide resolved
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 19, 2022
@Lunik
Copy link
Contributor

Lunik commented Jun 19, 2022

If we can't set à default value but the API expect those values, we should mark them as required

@Lunik
Copy link
Contributor

Lunik commented Jun 19, 2022

Can also fix #4577

@felixfontein
Copy link
Collaborator

You can also only require it on creation (and fail with a nicer error message), or dynamically pass a default on creation if no value is passed to the module.

@felixfontein felixfontein changed the title gitlab_group: fix issue 4855 gitlab_group: fix issue 4577 Jun 19, 2022
@fzarifian
Copy link
Author

@felixfontein the value is not mandatory, but passing the argument as null fails

@felixfontein
Copy link
Collaborator

Then forcing a default when one isn't needed is really a wrong fix. The correct fix would be to prevent null being passed when no value is specified.

@fzarifian
Copy link
Author

fzarifian commented Jun 19, 2022

    def create_or_update_group(self, name, parent, options):
        changed = False

        payload = {
            'name': name,
            'path': options['path'],
            'visibility': options['visibility'],
            'project_creation_level': options['project_creation_level'],
            'auto_devops_enabled': options['auto_devops_enabled'],
        }
        if options.get('project_creation_level'):
            payload['project_creation_level'] = options['project_creation_level']
        if options.get('subgroup_creation_level'):
            payload['subgroup_creation_level'] = options['subgroup_creation_level']
        if options.get('description'):
            payload['description'] = options['description']
        if options.get('require_two_factor_authentication'):
            payload['require_two_factor_authentication'] = options['require_two_factor_authentication']

        # Because we have already call userExists in main()
        if self.group_object is None:
            parent_id = self.get_group_id(parent)
            payload['parent_id'] = parent_id
            group = self.create_group(payload)

            # add avatar to group
            if options['avatar_path']:
                try:
                    group.avatar = open(options['avatar_path'], 'rb')
                except IOError as e:
                    self._module.fail_json(msg='Cannot open {0}: {1}'.format(options['avatar_path'], e))
            changed = True
        else:
            changed, group = self.update_group(self.group_object, payload)

        self.group_object = group
        if changed:
            if self._module.check_mode:
                self._module.exit_json(changed=True, msg="Successfully created or updated the group %s" % name)

            try:
                group.save()
            except Exception as e:
                self._module.fail_json(msg="Failed to update group: %s " % e)
            return True
        else:
            return False

@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 19, 2022
@fzarifian
Copy link
Author

Some typos in my payload, remaining 'subgroup_creation_level': options['subgroup_creation_level'], after putting it in optional : works great :)

This one resolve :

  • the broken creation
  • the idempotency for those optionnal values

After that, looots of questions about the avatar implemention, but that's not the PR subject...

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 19, 2022
@fzarifian
Copy link
Author

the implementation of the check_mode is also interresting, but not the PR subject too

Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Besides that, looks good. (Still needs a changelog fragment though.)

# Same payload for update or create, only parent_id is needed on creation
payload = {
'name': name,
'path': options['path'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

So far path was only passed on creation, I would handle it the same as parent_id.

@fzarifian
Copy link
Author

fzarifian commented Jun 20, 2022 via email

@ansibullbot ansibullbot added stale_ci CI is older than 7 days, rerun before merging stale_review labels Jun 28, 2022
@eifelmicha
Copy link

@fzarifian Just stumbled across this. Before switching over to curl requests. What's the status of this fix?

@felixfontein
Copy link
Collaborator

Please note that in #5461 the collection repository was restructured to remove the directory tree in plugins/modules/, and the corresponding tree in tests/unit/plugins/modules/. Your PR modifies files in this directory structure, and unfortunately now has some conflicts, potentially because of this. Please rebase with the current main branch to remove the conflicts.

@ansibullbot ansibullbot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed stale_review labels Nov 3, 2022
@felixfontein
Copy link
Collaborator

needs_info

@ansibullbot ansibullbot added the needs_info This issue requires further information. Please answer any outstanding questions label Nov 8, 2022
@ansibullbot
Copy link
Collaborator

@fzarifian This pullrequest is waiting for your response. Please respond or the pullrequest will be closed.

click here for bot help

@ansibullbot
Copy link
Collaborator

@fzarifian You have not responded to information requests in this pullrequest so we will assume it no longer affects you. If you are still interested in this, please create a new pullrequest with the requested information.

click here for bot help

@github-actions
Copy link

Docs Build 📝

This PR is closed and any previously published docsite has been unpublished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug gitlab module module needs_info This issue requires further information. Please answer any outstanding questions needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) source_control stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

community.general.gitlab_group module fails without optional arguments
5 participants