Merge pull request #8109 from AlanCoding/hack_null_org

Hack to delete orphaned organizations, consolidate get_one methods

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-09-10 18:15:45 +00:00
committed by GitHub
16 changed files with 166 additions and 120 deletions

View File

@@ -104,7 +104,6 @@ options:
description:
- Name of organization for project.
type: str
required: True
state:
description:
- Desired state of the resource.
@@ -200,7 +199,7 @@ def main():
allow_override=dict(type='bool', aliases=['scm_allow_override']),
timeout=dict(type='int', default=0, aliases=['job_timeout']),
custom_virtualenv=dict(),
organization=dict(required=True),
organization=dict(),
notification_templates_started=dict(type="list", elements='str'),
notification_templates_success=dict(type="list", elements='str'),
notification_templates_error=dict(type="list", elements='str'),
@@ -234,21 +233,22 @@ def main():
wait = module.params.get('wait')
# Attempt to look up the related items the user specified (these will fail the module if not found)
org_id = module.resolve_name_to_id('organizations', organization)
if credential is not None:
credential = module.resolve_name_to_id('credentials', credential)
lookup_data = {}
org_id = None
if organization:
org_id = module.resolve_name_to_id('organizations', organization)
lookup_data['organization'] = org_id
# Attempt to look up project based on the provided name and org ID
project = module.get_one('projects', name_or_id=name, **{
'data': {
'organization': org_id
}
})
project = module.get_one('projects', name_or_id=name, data=lookup_data)
if state == 'absent':
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
module.delete_if_needed(project)
if credential is not None:
credential = module.resolve_name_to_id('credentials', credential)
# Attempt to look up associated field items the user specified.
association_fields = {}

View File

@@ -129,12 +129,7 @@ def main():
resource_name = params.get(param)
if resource_name:
resource = module.get_one_by_name_or_id(module.param_to_endpoint(param), resource_name)
if not resource:
module.fail_json(
msg='Failed to update role, {0} not found in {1}'.format(param, endpoint),
changed=False
)
resource = module.get_exactly_one(module.param_to_endpoint(param), resource_name)
resource_data[param] = resource
# separate actors from resources