Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pugnacity committed Oct 2, 2024
1 parent ce4111c commit e884893
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def is_truthy(arg):
namespace.configure(
{
"nautobot_ansible": {
"nautobot_ver": "2.3.5",
"nautobot_ver": "2.0.0",
"project_name": "nautobot_ansible",
"python_ver": "3.11",
"python_ver": "3.10",
"local": False,
"compose_dir": os.path.join(os.path.dirname(__file__), "development"),
"compose_files": ["docker-compose.yml"],
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/nautobot-populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,30 @@ def make_nautobot_calls(endpoint, payload):
contacts = [{"name": "My Contact"}, {"name": "My Contact 2"}]
created_contacts = make_nautobot_calls(nb.extras.contacts, contacts)

# Create Controller
controller = [
{
"name": "controller_one",
"location": "Child Test Location",
"status": "Active"
},
{
"name": "controller_two",
"location": "Child Test Location",
"status": "Active"
}
]
created_controller = make_nautobot_calls(nb.extras.controller, controller)

# Create Controller Managed Device Groups
controller_device_group = [
{
"name": "controller_group_one",
"controller": "controller_one"
}
]
created_controller_device_group= make_nautobot_calls(nb.extras.controller_device_group, controller_device_group)

###############
# v2.3+ items #
###############
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,86 @@
msg: "{{ nautobot_version }}"

- block:
- set_fact:
parent_location: "{{ lookup('networktocode.nautobot.lookup', 'locations', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Parent Test Location\"') }}"

- name: "CONTROLLER 1: Necessary info creation"
networktocode.nautobot.controller:
- name: "CONTROLLER GROUP 1: Create Group"
networktocode.nautobot.controller_managed_device_groups:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Controller One
location: "Parent Test Location"
name: Test Controller Group One
controller: controller_one
state: present
status: "Active"
register: test_one_controller
register: test_one

- name: "CONTROLLER 1: ASSERT - Create Group"
assert:
that:
- test_one['changed']
- test_one['controller_managed_device_group']['name'] == "Test Controller Group One"

- name: "CONTROLLER 2: Create Group"
- name: "CONTROLLER GROUP 2: Create duplicate"
networktocode.nautobot.controller_managed_device_groups:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Controller Group One
controller: Test Controller One
controller: controller_one
state: present
register: test_two

- name: "CONTROLLER 2: ASSERT - Create Group"
- name: "CONTROLLER 2: ASSERT - Create duplicate"
assert:
that:
- not test_two['changed']
- test_two['controller_managed_device_groups']['name'] == "Test Controller Group One"
- test_two['msg'] == "Test Controller Group One already exists"

- name: "CONTROLLER GROUP 3: Update"
networktocode.nautobot.controller_managed_device_groups:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Controller Group One
controller: controller_two
register: test_three

- debug:
msg: "{{ test_three}}"

- name: "CONTROLLER GROUP 3: ASSERT - Update"
assert:
that:
- test_two['changed']
- test_two['controller_managed_device_group']['name'] == "Test Controller Group One"
- test_three['changed']
- test_three['controller_managed_device_groups']['name'] == "Test Controller One"
- test_three['controller_managed_device_groups']['controller'] == "controller_two"
- test_three['msg'] == "Test Controller Group One updated"

- name: "CONTROLLER GROUP 4: ASSERT - Delete"
networktocode.nautobot.controller_managed_device_groups:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Controller Group One
state: absent
register: test_four

- name: "CONTROLLER 4: ASSERT - Delete"
assert:
that:
- test_four is changed
- test_four['diff']['before']['state'] == "present"
- test_four['diff']['after']['state'] == "absent"
- test_four['msg'] == "Test Controller Group One deleted"

- name: "CONTROLLER GROUP 5: ASSERT - Delete non existing"
networktocode.nautobot.controller_managed_device_groups:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Controller Two
state: absent
register: test_five

- name: "CONTROLLER GROUP 5: ASSERT - Delete non existing"
assert:
that:
- not test_five['changed']
- test_five['controller_managed_device_groups'] == None
- test_five['msg'] == "controller Test Controller Two already absent"
when:
# Controllers are only available on Nautobot 2.2+
- "nautobot_version is version('2.2', '>=')"
1 change: 1 addition & 0 deletions tests/integration/targets/latest/tasks/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
parent: "Parent Test Location"
rack: "Main Test Rack"
status: "Active"
controller_managed_device_group: "{{ 'controller_group_one' if nautobot_version is version('2.2', '>=') else omit }}"
position: 35
face: "Front"
tags:
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/targets/latest/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,12 @@
- controller
tags:
- controller

- name: "PYNAUTOBOT_CONTROLLER_MANAGED_DEVICE_GROUP TESTS"
include_tasks:
file: "controller_managed_device_groups.yml"
apply:
tags:
- controller_managed_device_groups
tags:
- controller_managed_device_groups

0 comments on commit e884893

Please sign in to comment.