From a3664dc1036455d4e4ef26e6bc65c42aedc12d19 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 1 Oct 2024 18:24:38 +0000 Subject: [PATCH 01/34] create controller_managed_device_groups --- plugins/module_utils/dcim.py | 2 + plugins/module_utils/utils.py | 4 + .../controller_managed_device_group.py | 120 ++++++++++++++++++ .../controller_managed_device_groups.yml | 36 ++++++ 4 files changed, 162 insertions(+) create mode 100644 plugins/modules/controller_managed_device_group.py create mode 100644 tests/integration/targets/latest/tasks/controller_managed_device_groups.yml diff --git a/plugins/module_utils/dcim.py b/plugins/module_utils/dcim.py index 9dce4313..4db37fec 100644 --- a/plugins/module_utils/dcim.py +++ b/plugins/module_utils/dcim.py @@ -18,6 +18,7 @@ NB_CONSOLE_SERVER_PORTS = "console_server_ports" NB_CONSOLE_SERVER_PORT_TEMPLATES = "console_server_port_templates" NB_CONTROLLERS = "controllers" +NB_CONTROLLER_MANAGED_DEVICE_GROUPS = "controller_managed_device_groups" NB_DEVICE_BAYS = "device_bays" NB_DEVICE_BAY_TEMPLATES = "device_bay_templates" NB_DEVICE_REDUNDANCY_GROUPS = "device_redundancy_groups" @@ -59,6 +60,7 @@ def run(self): - console_server_ports - console_server_port_templates - controllers + - controller_managed_device_groups - device_bays - device_bay_templates - devices diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index 08b9191b..ba61e05b 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -40,6 +40,7 @@ "console_server_ports", "console_server_port_templates", "controllers", + "controller_managed_device_groups", "device_bays", "device_bay_templates", "devices", @@ -105,6 +106,7 @@ cluster_group="name", cluster_type="name", controller="name", + controller_managed_device_group="name", device="name", role="name", device_type="model", @@ -238,6 +240,7 @@ "console_server_port_templates": "console_server_port_template", "contacts": "contact", "controllers": "controller", + "controller_managed_device_groups": "controller_managed_device_group", "custom_fields": "custom_field", "custom_field_choices": "custom_field_choice", "device_bays": "device_bay", @@ -306,6 +309,7 @@ "contact": set(["name", "phone", "email"]), "contacts": set(["name", "phone", "email"]), "controller": set(["name"]), + "controller_managed_device_group": set(["name"]), "custom_field": set(["label"]), "custom_field_choice": set(["value", "custom_field"]), "dcim.consoleport": set(["name", "device"]), diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py new file mode 100644 index 00000000..62ef079c --- /dev/null +++ b/plugins/modules/controller_managed_device_group.py @@ -0,0 +1,120 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2024, Network to Code (@networktocode) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = r""" +--- +module: controller_managed_device_group +short_description: Create, update or delete managed device groups within Nautobot +description: + - Creates, updates or removes managed device groups from Nautobot. +notes: + - Tags should be defined as a YAML list + - This should be ran with connection C(local) and hosts C(localhost) +author: + - Sven Winkelmann (@pugnacity) +version_added: "5.3.2" +extends_documentation_fragment: + - networktocode.nautobot.fragments.base + - networktocode.nautobot.fragments.tags + - networktocode.nautobot.fragments.custom_fields +options: + name: + description: + - The name of the controller managed device groups + required: true + type: str + controller: + description: + - The name of the controller for this group + required: true + type: str + weight: + description: + - weight of the managed device group + required: false + type: int + parent: + description: + - parent group of the managed device group + required: false + type: string +""" + +EXAMPLES = r""" +- name: "Test Nautobot modules" + connection: local + hosts: localhost + gather_facts: False + + tasks: + - name: Create controller within Nautobot with only required information + networktocode.nautobot.controller_managed_device_group: + url: http://nautobot.local + token: thisIsMyToken + name: "group_1" + controller: my_controller + state: present + + - name: Delete controller within nautobot + networktocode.nautobot.controller: + url: http://nautobot.local + token: thisIsMyToken + name: test_controller_group_3 + state: absent + +""" + +RETURN = r""" +controller_managed_device_group: + description: Serialized object as created or already existent within Nautobot + returned: success (when I(state=present)) + type: dict +msg: + description: Message indicating failure or info about what has been achieved + returned: always + type: str +""" + +from ansible_collections.networktocode.nautobot.plugins.module_utils.utils import ( + NAUTOBOT_ARG_SPEC, + TAGS_ARG_SPEC, + CUSTOM_FIELDS_ARG_SPEC, +) +from ansible_collections.networktocode.nautobot.plugins.module_utils.dcim import ( + NautobotDcimModule, + NB_CONTROLLER_MANAGED_DEVICE_GROUPS, +) +from ansible.module_utils.basic import AnsibleModule +from copy import deepcopy + + +def main(): + """ + Main entry point for module execution + """ + argument_spec = deepcopy(NAUTOBOT_ARG_SPEC) + argument_spec.update(deepcopy(TAGS_ARG_SPEC)) + argument_spec.update(deepcopy(CUSTOM_FIELDS_ARG_SPEC)) + argument_spec.update( + dict( + name=dict(required=True, type="str"), + controller=dict(required=True, type="str"), + weight=dict(required=False, type="int"), + parent=dict(required=False, type="str"), + ) + ) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + + controller = NautobotDcimModule(module, NB_CONTROLLER_MANAGED_DEVICE_GROUPS) + controller.run() + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml b/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml new file mode 100644 index 00000000..3d83de30 --- /dev/null +++ b/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml @@ -0,0 +1,36 @@ +--- +- debug: + 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: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller One + location: "Parent Test Location" + state: present + status: "Active" + register: test_one_controller + + - name: "CONTROLLER 2: Create Group" + networktocode.nautobot.controller_managed_device_groups: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + controller: Test Controller One + state: present + register: test_two + + - name: "CONTROLLER 2: ASSERT - Create Group" + assert: + that: + - test_two['changed'] + - test_two['controller_managed_device_group']['name'] == "Test Controller Group One" + + when: + # Controllers are only available on Nautobot 2.2+ + - "nautobot_version is version('2.2', '>=')" From b78becaa6171988963708d8342f1b3dbde4d9973 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 1 Oct 2024 18:30:48 +0000 Subject: [PATCH 02/34] fix use correct type --- plugins/modules/controller_managed_device_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index 62ef079c..22d0d106 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -43,7 +43,7 @@ description: - parent group of the managed device group required: false - type: string + type: str """ EXAMPLES = r""" From 4f8dd5e5024e1b30f138b2ad0362e4c9f3655c60 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 1 Oct 2024 18:35:38 +0000 Subject: [PATCH 03/34] fix version_added --- plugins/modules/controller_managed_device_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index 22d0d106..ce3f3931 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -18,7 +18,7 @@ - This should be ran with connection C(local) and hosts C(localhost) author: - Sven Winkelmann (@pugnacity) -version_added: "5.3.2" +version_added: "5.4.0" extends_documentation_fragment: - networktocode.nautobot.fragments.base - networktocode.nautobot.fragments.tags From ac4c6015b313a75fb2f916f3999341209d39c8e6 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 1 Oct 2024 18:49:06 +0000 Subject: [PATCH 04/34] added devices --- plugins/modules/controller_managed_device_group.py | 6 ++++++ tasks.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index ce3f3931..bcd26e7e 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -44,6 +44,11 @@ - parent group of the managed device group required: false type: str + devices: + description: + - devices which should be assigend to this group + type: list + elements: str """ EXAMPLES = r""" @@ -106,6 +111,7 @@ def main(): name=dict(required=True, type="str"), controller=dict(required=True, type="str"), weight=dict(required=False, type="int"), + devices=dict(required=False, type="list", elements="str"), parent=dict(required=False, type="str"), ) ) diff --git a/tasks.py b/tasks.py index c879a03d..8f1fea4a 100644 --- a/tasks.py +++ b/tasks.py @@ -32,9 +32,9 @@ def is_truthy(arg): namespace.configure( { "nautobot_ansible": { - "nautobot_ver": "2.0.0", + "nautobot_ver": "2.3.5", "project_name": "nautobot_ansible", - "python_ver": "3.10", + "python_ver": "3.11", "local": False, "compose_dir": os.path.join(os.path.dirname(__file__), "development"), "compose_files": ["docker-compose.yml"], From 8f16eb6ac5ea72ba6f95e10266a20f60d449fc1a Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 09:56:30 +0000 Subject: [PATCH 05/34] assign controller_managed_device_group --- plugins/modules/device.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/modules/device.py b/plugins/modules/device.py index 3e39e105..52658c49 100644 --- a/plugins/modules/device.py +++ b/plugins/modules/device.py @@ -158,6 +158,12 @@ required: false type: raw version_added: "5.1.0" + controller_managed_device_group: + description: + - Device controller_managed_device_group the device will be assigned to + required: false + type: raw + version_added: "5.4.0" device_redundancy_group_priority: description: - Priority in the assigned device redundancy group @@ -290,6 +296,7 @@ def main(): vc_priority=dict(required=False, type="int"), comments=dict(required=False, type="str"), local_config_context_data=dict(required=False, type="dict"), + controller_managed_device_group=dict(required=False, type="raw"), device_redundancy_group=dict(required=False, type="raw"), device_redundancy_group_priority=dict(required=False, type="int"), ) From 9dca56f70773a3443197639ed52be381e33b3b1d Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 19:34:36 +0200 Subject: [PATCH 06/34] Update plugins/modules/controller_managed_device_group.py Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- plugins/modules/controller_managed_device_group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index bcd26e7e..49ee65ea 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -66,8 +66,8 @@ controller: my_controller state: present - - name: Delete controller within nautobot - networktocode.nautobot.controller: + - name: Delete controller managed device group within nautobot + networktocode.nautobot.controller_managed_device_group: url: http://nautobot.local token: thisIsMyToken name: test_controller_group_3 From baf7812565f3e80916312d84826191f400c729f1 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 19:34:43 +0200 Subject: [PATCH 07/34] Update plugins/modules/controller_managed_device_group.py Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- plugins/modules/controller_managed_device_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index 49ee65ea..21719ac5 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -58,7 +58,7 @@ gather_facts: False tasks: - - name: Create controller within Nautobot with only required information + - name: Create controller managed device group within Nautobot with only required information networktocode.nautobot.controller_managed_device_group: url: http://nautobot.local token: thisIsMyToken From 9fe407a62d95ee01235863551e6812a8fd68adb3 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 19:34:50 +0200 Subject: [PATCH 08/34] Update plugins/modules/controller_managed_device_group.py Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- plugins/modules/controller_managed_device_group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index 21719ac5..e072b4b8 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -118,8 +118,8 @@ def main(): module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) - controller = NautobotDcimModule(module, NB_CONTROLLER_MANAGED_DEVICE_GROUPS) - controller.run() + controller_group = NautobotDcimModule(module, NB_CONTROLLER_MANAGED_DEVICE_GROUPS) + controller_group.run() if __name__ == "__main__": # pragma: no cover From eb1580f66435cc3236fb9523b6858303dac5efd9 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 19:35:01 +0200 Subject: [PATCH 09/34] Update plugins/modules/controller_managed_device_group.py Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- plugins/modules/controller_managed_device_group.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index e072b4b8..f561efb9 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -70,7 +70,8 @@ networktocode.nautobot.controller_managed_device_group: url: http://nautobot.local token: thisIsMyToken - name: test_controller_group_3 + name: "group_1" + controller: test_controller_group_3 state: absent """ From ce4111c1e54b629e6cb962dfa34cf2a04a29892f Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 19:35:29 +0200 Subject: [PATCH 10/34] Update plugins/modules/device.py Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- plugins/modules/device.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/device.py b/plugins/modules/device.py index 52658c49..b169e849 100644 --- a/plugins/modules/device.py +++ b/plugins/modules/device.py @@ -161,6 +161,7 @@ controller_managed_device_group: description: - Device controller_managed_device_group the device will be assigned to + - Requires Nautobot C(v2.2) or later required: false type: raw version_added: "5.4.0" From e8848934d9ba02fc2a9b6bc8bc1978a3aca1720e Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 18:07:39 +0000 Subject: [PATCH 11/34] added tests --- tasks.py | 4 +- tests/integration/nautobot-populate.py | 24 ++++++ .../controller_managed_device_groups.yml | 80 +++++++++++++++---- .../targets/latest/tasks/device.yml | 1 + .../integration/targets/latest/tasks/main.yml | 9 +++ 5 files changed, 102 insertions(+), 16 deletions(-) diff --git a/tasks.py b/tasks.py index 8f1fea4a..c879a03d 100644 --- a/tasks.py +++ b/tasks.py @@ -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"], diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 51efed61..094774fb 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -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 # ############### diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml b/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml index 3d83de30..5b62f30b 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml @@ -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', '>=')" diff --git a/tests/integration/targets/latest/tasks/device.yml b/tests/integration/targets/latest/tasks/device.yml index 400c0f53..b5581d2e 100644 --- a/tests/integration/targets/latest/tasks/device.yml +++ b/tests/integration/targets/latest/tasks/device.yml @@ -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: diff --git a/tests/integration/targets/latest/tasks/main.yml b/tests/integration/targets/latest/tasks/main.yml index 30291773..dd985926 100644 --- a/tests/integration/targets/latest/tasks/main.yml +++ b/tests/integration/targets/latest/tasks/main.yml @@ -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 \ No newline at end of file From 10ec4da86e5db16f98dbc979c64fb9c356a8587b Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 18:12:20 +0000 Subject: [PATCH 12/34] lint fix --- tests/integration/nautobot-populate.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 094774fb..cc80b75d 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -634,27 +634,14 @@ def make_nautobot_calls(endpoint, payload): # Create Controller controller = [ - { - "name": "controller_one", - "location": "Child Test Location", - "status": "Active" - }, - { - "name": "controller_two", - "location": "Child Test Location", - "status": "Active" - } + {"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) + 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 # From 7bebac4ea952a8ca684271e164b3ac744ad3a247 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 2 Oct 2024 18:53:16 +0000 Subject: [PATCH 13/34] try to fix populate --- tests/integration/nautobot-populate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index cc80b75d..437e03ed 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -634,8 +634,8 @@ def make_nautobot_calls(endpoint, payload): # Create Controller controller = [ - {"name": "controller_one", "location": "Child Test Location", "status": "Active"}, - {"name": "controller_two", "location": "Child Test Location", "status": "Active"}, + {"name": "controller_one", "location": "Child Test Location", "status": {"name": "Active"}}, + {"name": "controller_two", "location": "Child Test Location", "status": {"name": "Active"}}, ] created_controller = make_nautobot_calls(nb.extras.controller, controller) From 61d8e5741fe6711e1352be026b6371879176c0d0 Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 7 Oct 2024 07:14:01 +0000 Subject: [PATCH 14/34] fix test --- tests/integration/nautobot-populate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 437e03ed..713c916c 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -637,11 +637,11 @@ def make_nautobot_calls(endpoint, payload): {"name": "controller_one", "location": "Child Test Location", "status": {"name": "Active"}}, {"name": "controller_two", "location": "Child Test Location", "status": {"name": "Active"}}, ] - created_controller = make_nautobot_calls(nb.extras.controller, controller) + created_controller = make_nautobot_calls(nb.dcim.controllers, 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) + created_controller_device_group = make_nautobot_calls(nb.dcim.controller_device_groups, controller_device_group) ############### # v2.3+ items # From 3ddca0b97ac2d3e6f3c101f888fccffa2deea5ce Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 7 Oct 2024 07:41:45 +0000 Subject: [PATCH 15/34] fix use location id --- tests/integration/nautobot-populate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 713c916c..d1567196 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -634,8 +634,8 @@ def make_nautobot_calls(endpoint, payload): # Create Controller controller = [ - {"name": "controller_one", "location": "Child Test Location", "status": {"name": "Active"}}, - {"name": "controller_two", "location": "Child Test Location", "status": {"name": "Active"}}, + {"name": "controller_one", "location": location_child.id, "status": {"name": "Active"}}, + {"name": "controller_two", "location": location_child.id, "status": {"name": "Active"}}, ] created_controller = make_nautobot_calls(nb.dcim.controllers, controller) From a04775ffbb14649f5286c587dd7aa925ece3870b Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 7 Oct 2024 11:16:40 +0000 Subject: [PATCH 16/34] fix tests --- tests/integration/nautobot-populate.py | 5 +++-- ...ml => controller_managed_device_group.yml} | 19 ++++++++++--------- .../integration/targets/latest/tasks/main.yml | 6 +++--- 3 files changed, 16 insertions(+), 14 deletions(-) rename tests/integration/targets/latest/tasks/{controller_managed_device_groups.yml => controller_managed_device_group.yml} (78%) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index d1567196..6e3a1ebf 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -640,8 +640,9 @@ def make_nautobot_calls(endpoint, payload): created_controller = make_nautobot_calls(nb.dcim.controllers, controller) # Create Controller Managed Device Groups - controller_device_group = [{"name": "controller_group_one", "controller": "controller_one"}] - created_controller_device_group = make_nautobot_calls(nb.dcim.controller_device_groups, controller_device_group) + test_controller_one = nb.dcim.controllers.get(name="controller_one") + controller_device_group = [{"name": "controller_group_one", "weight": "1000", "controller": test_controller_one.id}] + created_controller_device_group = make_nautobot_calls(nb.dcim.controller_managed_device_groups, controller_device_group) ############### # v2.3+ items # diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml similarity index 78% rename from tests/integration/targets/latest/tasks/controller_managed_device_groups.yml rename to tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 5b62f30b..abe3f902 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_groups.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -4,7 +4,7 @@ - block: - name: "CONTROLLER GROUP 1: Create Group" - networktocode.nautobot.controller_managed_device_groups: + networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One @@ -19,7 +19,7 @@ - test_one['controller_managed_device_group']['name'] == "Test Controller Group One" - name: "CONTROLLER GROUP 2: Create duplicate" - networktocode.nautobot.controller_managed_device_groups: + networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One @@ -31,11 +31,11 @@ assert: that: - not test_two['changed'] - - test_two['controller_managed_device_groups']['name'] == "Test Controller Group One" + - test_two['controller_managed_device_group']['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: + networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One @@ -49,12 +49,12 @@ assert: that: - test_three['changed'] - - test_three['controller_managed_device_groups']['name'] == "Test Controller One" - - test_three['controller_managed_device_groups']['controller'] == "controller_two" + - test_three['controller_managed_device_group']['name'] == "Test Controller One" + - test_three['controller_managed_device_group']['controller'] == "controller_two" - test_three['msg'] == "Test Controller Group One updated" - name: "CONTROLLER GROUP 4: ASSERT - Delete" - networktocode.nautobot.controller_managed_device_groups: + networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One @@ -70,7 +70,7 @@ - test_four['msg'] == "Test Controller Group One deleted" - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" - networktocode.nautobot.controller_managed_device_groups: + networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Two @@ -81,8 +81,9 @@ assert: that: - not test_five['changed'] - - test_five['controller_managed_device_groups'] == None + - test_five['controller_managed_device_group'] == 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', '>=')" diff --git a/tests/integration/targets/latest/tasks/main.yml b/tests/integration/targets/latest/tasks/main.yml index dd985926..b0658a74 100644 --- a/tests/integration/targets/latest/tasks/main.yml +++ b/tests/integration/targets/latest/tasks/main.yml @@ -593,9 +593,9 @@ - name: "PYNAUTOBOT_CONTROLLER_MANAGED_DEVICE_GROUP TESTS" include_tasks: - file: "controller_managed_device_groups.yml" + file: "controller_managed_device_group.yml" apply: tags: - - controller_managed_device_groups + - controller_managed_device_group tags: - - controller_managed_device_groups \ No newline at end of file + - controller_managed_device_group \ No newline at end of file From ab3b86daf318d4694a2eb52bfbacd71dc3f2457a Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 7 Oct 2024 11:45:43 +0000 Subject: [PATCH 17/34] fix: added missing parameter --- .../targets/latest/tasks/controller_managed_device_group.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index abe3f902..035063a9 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -9,6 +9,7 @@ token: "{{ nautobot_token }}" name: Test Controller Group One controller: controller_one + weight: 1000 state: present register: test_one @@ -24,6 +25,7 @@ token: "{{ nautobot_token }}" name: Test Controller Group One controller: controller_one + weight: 1000 state: present register: test_two @@ -39,6 +41,7 @@ url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One + weight: 2000 controller: controller_two register: test_three From ce9adf484dc9dc465407a14f80948a2d88e07cf6 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 10:58:48 +0000 Subject: [PATCH 18/34] fix: tests --- plugins/lookup/lookup.py | 2 ++ .../tasks/controller_managed_device_group.yml | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/lookup/lookup.py b/plugins/lookup/lookup.py index 3989d462..85f8ba3f 100644 --- a/plugins/lookup/lookup.py +++ b/plugins/lookup/lookup.py @@ -173,6 +173,8 @@ def get_endpoint(nautobot, term): "circuits": {"endpoint": nautobot.circuits.circuits}, "circuit-providers": {"endpoint": nautobot.circuits.providers}, "cables": {"endpoint": nautobot.dcim.cables}, + "controllers": {"endpoint": nautobot.dcim.controllers}, + "controller-managed-device-groups": {"endpoint": nautobot.dcim.controller_managed_device_groups}, "cluster-groups": {"endpoint": nautobot.virtualization.cluster_groups}, "cluster-types": {"endpoint": nautobot.virtualization.cluster_types}, "clusters": {"endpoint": nautobot.virtualization.clusters}, diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 035063a9..914b2c85 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -24,10 +24,13 @@ url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One - controller: controller_one + controller: "{{ controller['key'] }}" weight: 1000 state: present register: test_two + vars: + # yamllint disable-line rule:line-length + controller: "{{ lookup('networktocode.nautobot.lookup', 'controllers', validate_certs=documentation_nautobot.validate_certs, num_retries=3, api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=controller_one') }}" - name: "CONTROLLER 2: ASSERT - Create duplicate" assert: @@ -52,15 +55,16 @@ assert: that: - test_three['changed'] - - test_three['controller_managed_device_group']['name'] == "Test Controller One" + - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" - test_three['controller_managed_device_group']['controller'] == "controller_two" - - test_three['msg'] == "Test Controller Group One updated" + - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" - name: "CONTROLLER GROUP 4: ASSERT - Delete" networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One + controller: controller_two state: absent register: test_four @@ -70,13 +74,14 @@ - test_four is changed - test_four['diff']['before']['state'] == "present" - test_four['diff']['after']['state'] == "absent" - - test_four['msg'] == "Test Controller Group One deleted" + - test_four['msg'] == "controller_managed_device_group Test Controller Group One deleted" - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" - name: Test Controller Two + name: Test Controller Group Two + controller: controller_two state: absent register: test_five @@ -85,7 +90,7 @@ that: - not test_five['changed'] - test_five['controller_managed_device_group'] == None - - test_five['msg'] == "controller Test Controller Two already absent" + - test_five['msg'] == "controller_managed_device_group Test Controller Two already absent" when: # Controllers are only available on Nautobot 2.2+ From ec8b41ac0538c152e1e337e208dd532d00acbc52 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 11:48:28 +0000 Subject: [PATCH 19/34] fix: an other try --- .../targets/latest/tasks/controller_managed_device_group.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 914b2c85..13c43601 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -37,7 +37,7 @@ that: - not test_two['changed'] - test_two['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_two['msg'] == "Test Controller Group One already exists" + - test_two['msg'] == "controller_managed_device_group Test Controller Group One already exists" - name: "CONTROLLER GROUP 3: Update" networktocode.nautobot.controller_managed_device_group: From 241a546943486e2be2b31101ae730ecf70841de9 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 12:13:34 +0000 Subject: [PATCH 20/34] fix: remove spaces --- .../targets/latest/tasks/controller_managed_device_group.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 13c43601..79b32db0 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -90,8 +90,8 @@ that: - not test_five['changed'] - test_five['controller_managed_device_group'] == None - - test_five['msg'] == "controller_managed_device_group Test Controller Two already absent" - + - test_five['msg'] == "controller_managed_device_group Test Controller Two already absent" + when: # Controllers are only available on Nautobot 2.2+ - "nautobot_version is version('2.2', '>=')" From b60b740453b4dfe77f92fc59456c0ce84140e56f Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 12:42:02 +0000 Subject: [PATCH 21/34] debug test --- .../latest/tasks/controller_managed_device_group.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 79b32db0..6035bda5 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -48,9 +48,6 @@ controller: controller_two register: test_three - - debug: - msg: "{{ test_three}}" - - name: "CONTROLLER GROUP 3: ASSERT - Update" assert: that: @@ -85,6 +82,9 @@ state: absent register: test_five + - debug: + msg: "{{ test_five}}" + - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" assert: that: From 7a9aaade5a9a60b71882c7d39e7c4a1773019c4c Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 13:05:51 +0000 Subject: [PATCH 22/34] typo fix --- .../targets/latest/tasks/controller_managed_device_group.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 6035bda5..cfed3edc 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -90,7 +90,7 @@ that: - not test_five['changed'] - test_five['controller_managed_device_group'] == None - - test_five['msg'] == "controller_managed_device_group Test Controller Two already absent" + - test_five['msg'] == "controller_managed_device_group Test Controller Group Two already absent" when: # Controllers are only available on Nautobot 2.2+ From 3acc5fa1245dfc7719e8db0aaee25b4f62ed5336 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 13:06:09 +0000 Subject: [PATCH 23/34] remove debug --- .../targets/latest/tasks/controller_managed_device_group.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index cfed3edc..b963bcda 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -82,9 +82,6 @@ state: absent register: test_five - - debug: - msg: "{{ test_five}}" - - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" assert: that: From a787e810d60f241226f33705c08c731eb1909600 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 15 Oct 2024 13:35:05 +0000 Subject: [PATCH 24/34] use CONVERT_TO_ID --- plugins/module_utils/utils.py | 1 + .../targets/latest/tasks/controller_managed_device_group.yml | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index ba61e05b..cca24bb3 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -161,6 +161,7 @@ "cluster_group": "cluster_groups", "cluster_type": "cluster_types", "contacts": "contacts", + "controller": "controllers", "dcim.consoleport": "console_ports", "dcim.consoleserverport": "console_server_ports", "dcim.frontport": "front_ports", diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index b963bcda..562ee6c3 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -24,13 +24,10 @@ url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One - controller: "{{ controller['key'] }}" + controller: controller_one weight: 1000 state: present register: test_two - vars: - # yamllint disable-line rule:line-length - controller: "{{ lookup('networktocode.nautobot.lookup', 'controllers', validate_certs=documentation_nautobot.validate_certs, num_retries=3, api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=controller_one') }}" - name: "CONTROLLER 2: ASSERT - Create duplicate" assert: From 473e028deba7eb7392f9fb2f6e224b7a934b0402 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 20 Nov 2024 08:49:57 +0000 Subject: [PATCH 25/34] debug test --- .../targets/latest/tasks/controller_managed_device_group.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 562ee6c3..aa39c3ad 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -50,7 +50,6 @@ that: - test_three['changed'] - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_three['controller_managed_device_group']['controller'] == "controller_two" - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" - name: "CONTROLLER GROUP 4: ASSERT - Delete" From 6e2f274a2a76c844372587e8ad3d4e2e1c944d75 Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 28 Nov 2024 10:28:46 +0000 Subject: [PATCH 26/34] update --- .../controller_managed_device_group.py | 16 +++---- .../tasks/controller_managed_device_group.yml | 43 +++++++++++++------ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index f561efb9..63d3415e 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -39,16 +39,13 @@ - weight of the managed device group required: false type: int - parent: + parent_cloud_network: + aliases: + - parent description: - - parent group of the managed device group + - The parent cloud network this network should be child to required: false - type: str - devices: - description: - - devices which should be assigend to this group - type: list - elements: str + type: raw """ EXAMPLES = r""" @@ -112,8 +109,7 @@ def main(): name=dict(required=True, type="str"), controller=dict(required=True, type="str"), weight=dict(required=False, type="int"), - devices=dict(required=False, type="list", elements="str"), - parent=dict(required=False, type="str"), + parent_cloud_network=dict(required=False, type="raw", aliases=["parent"]), ) ) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index aa39c3ad..bc5528dc 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -45,6 +45,9 @@ controller: controller_two register: test_three + - debug: + msg: "{{ test_three}}" + - name: "CONTROLLER GROUP 3: ASSERT - Update" assert: that: @@ -52,38 +55,54 @@ - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" - - name: "CONTROLLER GROUP 4: ASSERT - Delete" + - name: "CONTROLLER GROUP 4: idempotent" networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Controller Group One + weight: 2000 controller: controller_two - state: absent register: test_four - - name: "CONTROLLER 4: ASSERT - Delete" + - name: "CONTROLLER GROUP 4: ASSERT - idempotent" assert: that: - - test_four is changed - - test_four['diff']['before']['state'] == "present" - - test_four['diff']['after']['state'] == "absent" - - test_four['msg'] == "controller_managed_device_group Test Controller Group One deleted" + - not test_four['changed'] + - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_four['msg'] == "controller_managed_device_group Test Controller Group One updated" - - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" + - name: "CONTROLLER GROUP 5: ASSERT - Delete" networktocode.nautobot.controller_managed_device_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" - name: Test Controller Group Two + name: Test Controller Group One controller: controller_two state: absent register: test_five - - name: "CONTROLLER GROUP 5: ASSERT - Delete non existing" + - name: "CONTROLLER 5: ASSERT - Delete" + assert: + that: + - test_five is changed + - test_five['diff']['before']['state'] == "present" + - test_five['diff']['after']['state'] == "absent" + - test_five['msg'] == "controller_managed_device_group Test Controller Group One deleted" + + - name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group Two + controller: controller_two + state: absent + register: test_six + + - name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" assert: that: - not test_five['changed'] - - test_five['controller_managed_device_group'] == None - - test_five['msg'] == "controller_managed_device_group Test Controller Group Two already absent" + - test_six['controller_managed_device_group'] == None + - test_six['msg'] == "controller_managed_device_group Test Controller Group Two already absent" when: # Controllers are only available on Nautobot 2.2+ From 1e868e75775f94b7e6bfb5068827ec07f2acb13d Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 28 Nov 2024 10:56:28 +0000 Subject: [PATCH 27/34] debug tests --- .../latest/tasks/controller_managed_device_group.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index bc5528dc..7c9aa540 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -53,6 +53,7 @@ that: - test_three['changed'] - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_three['diff']['after']['weight'] == "2000" - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" - name: "CONTROLLER GROUP 4: idempotent" @@ -64,12 +65,15 @@ controller: controller_two register: test_four +- debug: + msg: "{{ test_four}}" + - name: "CONTROLLER GROUP 4: ASSERT - idempotent" assert: that: - not test_four['changed'] - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_four['msg'] == "controller_managed_device_group Test Controller Group One updated" + - test_four['msg'] == "controller_managed_device_group Test Controller Group One not changed" - name: "CONTROLLER GROUP 5: ASSERT - Delete" networktocode.nautobot.controller_managed_device_group: From d877546f503053926e9dbb3d5200cd00115ab69e Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 28 Nov 2024 11:24:03 +0000 Subject: [PATCH 28/34] typo fix --- .../latest/tasks/controller_managed_device_group.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 7c9aa540..bd654a2b 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -65,14 +65,14 @@ controller: controller_two register: test_four -- debug: - msg: "{{ test_four}}" + - debug: + msg: "{{ test_four}}" - name: "CONTROLLER GROUP 4: ASSERT - idempotent" assert: that: - not test_four['changed'] - - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_four['controller_managed_device_group']['name'] == "Test Controller Group One" - test_four['msg'] == "controller_managed_device_group Test Controller Group One not changed" - name: "CONTROLLER GROUP 5: ASSERT - Delete" From b7d6549f49d4e24dd47249a644793efbe8e3191e Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 28 Nov 2024 11:48:34 +0000 Subject: [PATCH 29/34] fix test --- .../latest/tasks/controller_managed_device_group.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index bd654a2b..38cdb1aa 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -45,9 +45,6 @@ controller: controller_two register: test_three - - debug: - msg: "{{ test_three}}" - - name: "CONTROLLER GROUP 3: ASSERT - Update" assert: that: @@ -66,14 +63,14 @@ register: test_four - debug: - msg: "{{ test_four}}" + msg: "{{ test_four}}" - name: "CONTROLLER GROUP 4: ASSERT - idempotent" assert: that: - not test_four['changed'] - test_four['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_four['msg'] == "controller_managed_device_group Test Controller Group One not changed" + - test_four['msg'] == "controller_managed_device_group Test Controller Group One already exists" - name: "CONTROLLER GROUP 5: ASSERT - Delete" networktocode.nautobot.controller_managed_device_group: From d6ff9306606abe376858297ebd70b9d588d6c5c6 Mon Sep 17 00:00:00 2001 From: Joe Wesch <10467633+joewesch@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:39:40 -0600 Subject: [PATCH 30/34] Apply suggestions from code review --- plugins/modules/controller_managed_device_group.py | 2 +- plugins/modules/device.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/controller_managed_device_group.py b/plugins/modules/controller_managed_device_group.py index 63d3415e..beeac1ff 100644 --- a/plugins/modules/controller_managed_device_group.py +++ b/plugins/modules/controller_managed_device_group.py @@ -18,7 +18,7 @@ - This should be ran with connection C(local) and hosts C(localhost) author: - Sven Winkelmann (@pugnacity) -version_added: "5.4.0" +version_added: "5.5.0" extends_documentation_fragment: - networktocode.nautobot.fragments.base - networktocode.nautobot.fragments.tags diff --git a/plugins/modules/device.py b/plugins/modules/device.py index b169e849..199ca0ac 100644 --- a/plugins/modules/device.py +++ b/plugins/modules/device.py @@ -164,7 +164,7 @@ - Requires Nautobot C(v2.2) or later required: false type: raw - version_added: "5.4.0" + version_added: "5.5.0" device_redundancy_group_priority: description: - Priority in the assigned device redundancy group From cb8d7322fca6112ca3e030c73ddb78b12bd7c2da Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 9 Jan 2025 19:04:01 +0100 Subject: [PATCH 31/34] Update tests/integration/targets/latest/tasks/main.yml Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- tests/integration/targets/latest/tasks/main.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/integration/targets/latest/tasks/main.yml b/tests/integration/targets/latest/tasks/main.yml index e52ada08..b7903116 100644 --- a/tests/integration/targets/latest/tasks/main.yml +++ b/tests/integration/targets/latest/tasks/main.yml @@ -610,19 +610,15 @@ tags: - controller -- name: "PYNAUTOBOT_CONTROLLER_MANAGED_DEVICE_GROUP TESTS" - include_tasks: - file: "controller_managed_device_group.yml" - apply: + - name: "PYNAUTOBOT_CONTROLLER_MANAGED_DEVICE_GROUP TESTS" + include_tasks: + file: "controller_managed_device_group.yml" + apply: + tags: + - controller_managed_device_group tags: - controller_managed_device_group - tags: - - controller_managed_device_group -- name: "PYNAUTOBOT_MODULE_TYPE TESTS" - include_tasks: - file: "module_type.yml" - apply: - name: "PYNAUTOBOT_VLAN_LOCATION TESTS" include_tasks: file: "vlan_location.yml" From c7d7dbb9e7e9a8712b5fb4de7fe2c75796ae78d7 Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 9 Jan 2025 19:04:12 +0100 Subject: [PATCH 32/34] Update tests/integration/targets/latest/tasks/controller_managed_device_group.yml Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- .../targets/latest/tasks/controller_managed_device_group.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 38cdb1aa..58f5ff88 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -1,7 +1,4 @@ --- -- debug: - msg: "{{ nautobot_version }}" - - block: - name: "CONTROLLER GROUP 1: Create Group" networktocode.nautobot.controller_managed_device_group: From d680da482ed0eb731e3f0cfefbae2285723eee5e Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 9 Jan 2025 18:34:50 +0000 Subject: [PATCH 33/34] fix --- .../tasks/controller_managed_device_group.yml | 213 +++++++++--------- 1 file changed, 109 insertions(+), 104 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 58f5ff88..06238672 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -1,107 +1,112 @@ --- -- block: - - name: "CONTROLLER GROUP 1: Create Group" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group One - controller: controller_one - weight: 1000 - state: present - 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 GROUP 2: Create duplicate" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group One - controller: controller_one - weight: 1000 - state: present - register: test_two - - - name: "CONTROLLER 2: ASSERT - Create duplicate" - assert: - that: - - not test_two['changed'] - - test_two['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_two['msg'] == "controller_managed_device_group Test Controller Group One already exists" - - - name: "CONTROLLER GROUP 3: Update" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group One - weight: 2000 - controller: controller_two - register: test_three - - - name: "CONTROLLER GROUP 3: ASSERT - Update" - assert: - that: - - test_three['changed'] - - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_three['diff']['after']['weight'] == "2000" - - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" - - - name: "CONTROLLER GROUP 4: idempotent" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group One - weight: 2000 - controller: controller_two - register: test_four +- name: "CONTROLLER GROUP 1: Create Group" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + controller: controller_one + weight: 1000 + state: present + 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 GROUP 2: Create duplicate" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + controller: controller_one + weight: 1000 + state: present + register: test_two + +- name: "CONTROLLER 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_two['msg'] == "controller_managed_device_group Test Controller Group One already exists" + +- name: "CONTROLLER GROUP 3: Update" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + weight: 2000 + controller: controller_two + register: test_three + +- debug: + msg: "{{ test_three }}" + +- name: "CONTROLLER GROUP 3: ASSERT - Update" + assert: + that: + - test_three['changed'] + - test_three['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_three['diff']['after']['weight'] == 2000 + - test_three['msg'] == "controller_managed_device_group Test Controller Group One updated" + +- name: "CONTROLLER GROUP 4: idempotent" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + weight: 2000 + controller: controller_two + register: test_four + +- debug: + msg: "{{ test_four }}" + +- name: "CONTROLLER GROUP 4: ASSERT - idempotent" + assert: + that: + - not test_four['changed'] + - test_four['controller_managed_device_group']['name'] == "Test Controller Group One" + - test_four['msg'] == "controller_managed_device_group Test Controller Group One already exists" + +- name: "CONTROLLER GROUP 5: ASSERT - Delete" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group One + controller: controller_two + state: absent + register: test_five - debug: - msg: "{{ test_four}}" - - - name: "CONTROLLER GROUP 4: ASSERT - idempotent" - assert: - that: - - not test_four['changed'] - - test_four['controller_managed_device_group']['name'] == "Test Controller Group One" - - test_four['msg'] == "controller_managed_device_group Test Controller Group One already exists" - - - name: "CONTROLLER GROUP 5: ASSERT - Delete" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group One - controller: controller_two - state: absent - register: test_five - - - name: "CONTROLLER 5: ASSERT - Delete" - assert: - that: - - test_five is changed - - test_five['diff']['before']['state'] == "present" - - test_five['diff']['after']['state'] == "absent" - - test_five['msg'] == "controller_managed_device_group Test Controller Group One deleted" - - - name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" - networktocode.nautobot.controller_managed_device_group: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - name: Test Controller Group Two - controller: controller_two - state: absent - register: test_six - - - name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" - assert: - that: - - not test_five['changed'] - - test_six['controller_managed_device_group'] == None - - test_six['msg'] == "controller_managed_device_group Test Controller Group Two already absent" - - when: - # Controllers are only available on Nautobot 2.2+ - - "nautobot_version is version('2.2', '>=')" + msg: "{{ test_five }}" + +- name: "CONTROLLER 5: ASSERT - Delete" + assert: + that: + - test_five is changed + - test_five['diff']['before']['state'] == "present" + - test_five['diff']['after']['state'] == "absent" + - test_five['msg'] == "controller_managed_device_group Test Controller Group One deleted" + +- name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" + networktocode.nautobot.controller_managed_device_group: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + name: Test Controller Group Two + controller: controller_two + state: absent + register: test_six + +- debug: + msg: "{{ test_six }}" + +- name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" + assert: + that: + - not test_five['changed'] + - test_six['controller_managed_device_group'] == None + - test_six['msg'] == "controller_managed_device_group Test Controller Group Two already absent" + From d77f516ae9652bbb7f1773e675555132bec87fed Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 9 Jan 2025 19:26:41 +0000 Subject: [PATCH 34/34] remove debug --- .../tasks/controller_managed_device_group.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml index 06238672..5904cc47 100644 --- a/tests/integration/targets/latest/tasks/controller_managed_device_group.yml +++ b/tests/integration/targets/latest/tasks/controller_managed_device_group.yml @@ -41,9 +41,6 @@ controller: controller_two register: test_three -- debug: - msg: "{{ test_three }}" - - name: "CONTROLLER GROUP 3: ASSERT - Update" assert: that: @@ -61,9 +58,6 @@ controller: controller_two register: test_four -- debug: - msg: "{{ test_four }}" - - name: "CONTROLLER GROUP 4: ASSERT - idempotent" assert: that: @@ -80,9 +74,6 @@ state: absent register: test_five - - debug: - msg: "{{ test_five }}" - - name: "CONTROLLER 5: ASSERT - Delete" assert: that: @@ -100,13 +91,10 @@ state: absent register: test_six -- debug: - msg: "{{ test_six }}" - - name: "CONTROLLER GROUP 6: ASSERT - Delete non existing" assert: that: - - not test_five['changed'] + - not test_six['changed'] - test_six['controller_managed_device_group'] == None - test_six['msg'] == "controller_managed_device_group Test Controller Group Two already absent"