Skip to content

Commit

Permalink
Add test and changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
tupyy committed Mar 13, 2024
1 parent 4ff553a commit 07f7cc4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- now - add caching(https://github.com/ansible-collections/servicenow.itsm/pull/315).
1 change: 1 addition & 0 deletions plugins/inventory/now.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- inventory_cache
notes:
- Query feature and constructed groups were added in version 1.2.0.
- Caching feature added in version 2.5.0.
options:
plugin:
description:
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/targets/inventory/files/cache.now.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
plugin: servicenow.itsm.now
table: cmdb_ci_ec2_instance
strict: false
cache: True
cache_plugin: ansible.builtin.jsonfile
cache_timeout: 3600
cache_connection: /tmp/cache
cache_prefix: now

columns:
- sys_id
- name
- fqdn

sysparm_query: nameSTARTSWITHmy-vm-
39 changes: 39 additions & 0 deletions tests/integration/targets/inventory/playbooks/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Test cache options
hosts: localhost
gather_facts: false

tasks:
- block:
- name: Create imaginary VMs
servicenow.itsm.configuration_item:
name: my-vm-{{ item }}
sys_class_name: cmdb_ci_ec2_instance
ip_address: 10.1.0.{{ item }}
environment: production
other:
fqdn: f{{ item }}.example.com
guest_os_fullname: OS0
vm_inst_id: i{{ item }}
loop: "{{ range(101, 109) | list }}"
register: vms

- name: Reload inventory
ansible.builtin.meta: refresh_inventory

- ansible.builtin.debug:
var: groups

- name: Make sure we have all expected groups
ansible.builtin.assert:
that:
- groups["all"] | length == 8

always:
- name: Delete VMs
servicenow.itsm.configuration_item:
state: absent
sys_id: "{{ item.record.sys_id }}"
loop: "{{ vms.results }}"
loop_control:
label: "{{ item.record.name }}"

0 comments on commit 07f7cc4

Please sign in to comment.