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 hard coding of choices of category in change_request #322

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions changelogs/fragments/change_request_category.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- change_request - allow change_request_mapping for category parameter.
tupyy marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions plugins/module_utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
impact=dict(type="dict"),
urgency=dict(type="dict"),
state=dict(type="dict"),
category=dict(type="dict"),
),
)

Expand Down
12 changes: 12 additions & 0 deletions plugins/module_utils/change_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@
("3", "closed"),
("4", "canceled"),
],
category=[
("1", "hardware"),
("2", "software"),
("3", "service"),
("4", "system_software"),
("5", "aplication_software"),
("6", "network"),
("7", "telecom"),
("8", "documentation"),
("9", "other"),
],

on_hold=[("true", True), ("false", False)],
)
17 changes: 4 additions & 13 deletions plugins/modules/change_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@
category:
description:
- The category of the change request.
choices: [ hardware, software, service, system_software, aplication_software,
network, telecom, documentation, other ]
- Default choices are: C(hardware), C(software), C(service), C(system_software), C(aplication_software),
C(network), C(telecom), C(documentation), C(other).
- One can override them by setting C(change_request_mapping.category).
- Choices for C(category) removed in 2.5.0.
tupyy marked this conversation as resolved.
Show resolved Hide resolved
type: str
priority:
description:
Expand Down Expand Up @@ -405,17 +407,6 @@ def main():
),
category=dict(
type="str",
choices=[
"hardware",
"software",
"service",
"system_software",
"aplication_software",
"network",
"telecom",
"documentation",
"other",
],
),
priority=dict(
type="str",
Expand Down
63 changes: 63 additions & 0 deletions tests/integration/targets/change_request/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,66 @@
requested_by: admin
number: "{{ result.records[0].number }}"
state: absent


- name: Update category choices
servicenow.itsm.api:
resource: sys_choice
action: post
data:
name: change_request
element: category
value: 1
label: hardware
register: change_request_category

- set_fact:
solved_remotely_choice: "{{ change_request_category.record.sys_id }}"

- name: Create change_request
servicenow.itsm.change_request:
requested_by: admin
state: new
type: standard
template: Clear BGP sessions on a Cisco router - 1
priority: low
risk: low
impact: low
short_description: some short description
category: Software
register: chg_request

- ansible.builtin.assert:
that:
- chg_request is changed
- chg_request.record.state == "new"
- chg_request.record.type == "standard"
- chg_request.record.priority == "low"
- chg_request.record.risk == "low"
- chg_request.record.impact == "low"
- chg_request.record.category == "Software"

- name: Update change_request with new option
servicenow.itsm.change_request:
number: "{{ chg_request.record.number }}"
category: hardware

- name: Get change_request
servicenow.itsm.change_request_info:
number: "{{ chg_request.record.number }}"
register: result

- ansible.builtin.assert:
that:
- result.records[0].category == "hardware"

- name: Delete change_request
servicenow.itsm.change_request:
sys_id: "{{ chg_request.record.sys_id }}"
state: absent

- name: Delete change_request choices
servicenow.itsm.api:
resource: sys_choice
action: delete
sys_id: "{{ solved_remotely_choice }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
- environment:
SN_HOST: "{{ sn_host }}"
SN_USERNAME: "{{ sn_username }}"
SN_PASSWORD: "{{ sn_password }}"

vars:
mapping:
change_request:
category:
1: "category 1"
2: "category 2"

block:
- name: Create first category
servicenow.itsm.api:
resource: sys_choice
action: post
data:
name: change_request
element: category
value: 1
label: category 1
register: first_category

- set_fact:
first_category: "{{ first_category.record.sys_id }}"

- name: Create second category
servicenow.itsm.api:
resource: sys_choice
action: post
data:
name: change_request
element: category
value: 2
label: category 2
register: second_category

- set_fact:
second_category: "{{ second_category.record.sys_id }}"

- name: Create change_request
servicenow.itsm.change_request:
change_request_mapping: "{{ mapping.change_request }}"
requested_by: admin
state: new
type: standard
template: Clear BGP sessions on a Cisco router - 1
priority: low
risk: low
impact: low
short_description: some short description
category: category 1
register: chg_request

- ansible.builtin.assert:
that:
- chg_request is changed
- chg_request.record.state == "new"
- chg_request.record.type == "standard"
- chg_request.record.priority == "low"
- chg_request.record.risk == "low"
- chg_request.record.impact == "low"
- chg_request.record.category == "category 1"

- name: Update change_request with new category
servicenow.itsm.change_request:
change_request_mapping: "{{ mapping.change_request }}"
number: "{{ chg_request.record.number }}"
category: category 2

- name: Get change_request
servicenow.itsm.change_request_info:
change_request_mapping: "{{ mapping.change_request }}"
number: "{{ chg_request.record.number }}"
register: result

- ansible.builtin.assert:
that:
- result.records[0].category == "category 2"

- name: Delete change_request
servicenow.itsm.change_request:
sys_id: "{{ chg_request.record.sys_id }}"
state: absent

- name: Delete change_request choices
servicenow.itsm.api:
resource: sys_choice
action: delete
sys_id: "{{ item }}"
loop:
- first_category
- second_category
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ compose:
location_name: lookup('ansible.builtin.vars', 'location.name')
street: lookup('ansible.builtin.vars', 'location.street')

strict: true
strict: false
display_value: false
tupyy marked this conversation as resolved.
Show resolved Hide resolved
Loading