Skip to content

Commit

Permalink
Fix sanity and added vLAN integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nitish-ks committed Jan 10, 2025
1 parent 38a5e9d commit aa92879
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 28 deletions.
3 changes: 3 additions & 0 deletions tests/integration/targets/nios_vlan/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/cloud/group1
cloud/nios
destructive
3 changes: 3 additions & 0 deletions tests/integration/targets/nios_vlan/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
testcase: "*"
test_items: []
3 changes: 3 additions & 0 deletions tests/integration/targets/nios_vlan/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_nios_tests
3 changes: 3 additions & 0 deletions tests/integration/targets/nios_vlan/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Include idempotence tasks for vlan
ansible.builtin.include_tasks: nios_vlan_idempotence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
- name: Cleanup VLAN
nios_vlan:
name: ansible-vlan
id: 10
parent: default
state: absent
provider: "{{ nios_provider }}"

- name: Configure a VLAN on the system
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
contact: '[email protected]'
department: 'IT'
description: 'This is an example VLAN'
reserved: true
state: present
provider: "{{ nios_provider }}"
register: vlan_create1

- name: Configure another VLAN on the system
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
contact: '[email protected]'
department: 'IT'
description: 'This is an example VLAN'
reserved: true
state: present
provider: "{{ nios_provider }}"
register: vlan_create2

- name: Update the comment and ext attributes for an existing VLAN
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
contact: '[email protected]'
department: 'IT'
description: 'This is an example VLAN'
reserved: true
comment: this is an example comment
extattrs:
Site: west-dc
state: present
provider: "{{ nios_provider }}"
register: vlan_update1

- name: Update again the comment and ext attributes for an existing VLAN
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
contact: '[email protected]'
department: 'IT'
description: 'This is an example VLAN'
reserved: true
comment: this is an example comment
extattrs:
Site: west-dc
state: present
provider: "{{ nios_provider }}"
register: vlan_update2

- name: Remove the VLAN
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
state: absent
provider: "{{ nios_provider }}"
register: vlan_delete1

- name: Remove again the VLAN
infoblox.nios_modules.nios_vlan:
name: ansible-vlan
id: 10
parent: default
state: absent
provider: "{{ nios_provider }}"
register: vlan_delete2

- name: Assert changes in VLAN
ansible.builtin.assert:
that:
- vlan_create1.changed
- not vlan_create2.changed
- vlan_update1.changed
- not vlan_update2.changed
- vlan_delete1.changed
- not vlan_delete2.changed
72 changes: 47 additions & 25 deletions tests/unit/plugins/modules/test_nios_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def test_nios_network_ipv4_update_with_use_logic_filter_rules(self):

def test_nios_network_ipv4_create_with_vlan(self):
self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24',
'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan',
'parent': 'default' ,'id': '10'}]}
'comment': None, 'extattrs': None, 'vlans': [{'name': 'ansible_vlan',
'parent': 'default', 'id': '10'}]}

test_object = None
test_spec = {
Expand All @@ -331,26 +331,34 @@ def test_nios_network_ipv4_create_with_vlan(self):
res = wapi.run('NIOS_IPV4_NETWORK', test_spec)

self.assertTrue(res['changed'])
wapi.create_object.assert_called_once_with('NIOS_IPV4_NETWORK', {'network': '192.168.10.0/24',
'vlans': [{'name':'ansible_vlan',
'parent': 'default' ,'id': '10'}]
}
)
wapi.create_object.assert_called_once_with(
'NIOS_IPV4_NETWORK',
{
'network': '192.168.10.0/24',
'vlans': [
{
'name': 'ansible_vlan',
'parent': 'default',
'id': '10'
}
]
}
)

def test_nios_network_ipv4_update_vlan(self):
self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24',
'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan1',
'parent': 'default' ,'id': '10'},
{'name':'ansible_vlan2',
'parent': 'default' ,'id': '20'}]}
'comment': None, 'extattrs': None, 'vlans': [{'name': 'ansible_vlan1',
'parent': 'default', 'id': '10'},
{'name': 'ansible_vlan2',
'parent': 'default', 'id': '20'}]}
ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"

test_object = [
{
"comment": "test comment",
"_ref": ref,
"network": "192.168.10.0/24",
"vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}]
"vlans": [{'name': 'ansible_vlan1', 'parent': 'default', 'id': '10'}]
}
]
test_spec = {
Expand All @@ -365,13 +373,24 @@ def test_nios_network_ipv4_update_vlan(self):

self.assertTrue(res['changed'])

wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24',
'vlans': [{'name':'ansible_vlan1',
'parent': 'default' ,'id': '10'},
{'name':'ansible_vlan2',
'parent': 'default' ,'id': '20'}]
}
)
wapi.update_object.assert_called_once_with(
ref,
{
'network': '192.168.10.0/24',
'vlans': [
{
'name': 'ansible_vlan1',
'parent': 'default',
'id': '10'
},
{
'name': 'ansible_vlan2',
'parent': 'default',
'id': '20'
}
]
}
)

def test_nios_network_ipv4_remove_vlan(self):
self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24',
Expand All @@ -383,8 +402,8 @@ def test_nios_network_ipv4_remove_vlan(self):
"comment": "test comment",
"_ref": ref,
"network": "192.168.10.0/24",
"vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'},
{'name':'ansible_vlan2', 'parent': 'default' ,'id': '20'}
"vlans": [{'name': 'ansible_vlan1', 'parent': 'default', 'id': '10'},
{'name': 'ansible_vlan2', 'parent': 'default', 'id': '20'}
]
}
]
Expand All @@ -399,7 +418,10 @@ def test_nios_network_ipv4_remove_vlan(self):
res = wapi.run('NIOS_IPV4_NETWORK', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24',
'vlans': []
}
)
wapi.update_object.assert_called_once_with(
ref,
{
'network': '192.168.10.0/24',
'vlans': []
}
)
12 changes: 9 additions & 3 deletions tests/unit/plugins/modules/test_nios_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ def test_nios_vlan_create(self):
res = wapi.run('NIOS_VLAN', test_spec)

self.assertTrue(res['changed'])
wapi.create_object.assert_called_once_with('NIOS_VLAN', {'name': 'ansible_vlan',
'parent': 'default', 'id': '10'})
wapi.create_object.assert_called_once_with(
'NIOS_VLAN',
{
'name': 'ansible_vlan',
'parent': 'default',
'id': '10'
}
)

def test_nios_vlan_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible_vlan',
'parent': 'default', 'id': '10', 'comment': 'updated comment',
'contact': '[email protected]', 'department': 'IT', 'description': 'test',
'reserved': True,'extattrs': None}
'reserved': True, 'extattrs': None}

ref = "vlan/ZG5zLm5ldHdvcmtfdmlldyQw:ansible_vlan"
test_object = [
Expand Down

0 comments on commit aa92879

Please sign in to comment.