Skip to content

Commit

Permalink
adding tests for ip_info
Browse files Browse the repository at this point in the history
  • Loading branch information
jriddle-linode committed Nov 6, 2023
1 parent c100797 commit 4dc7e72
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion plugins/modules/ip_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def __init__(self) -> None:

def _get_ip(self, address: str) -> IPAddress:
try:
return self.client.load(IPAddress, address)
ip_addr = IPAddress(self.client, address)
ip_addr._api_get()
return ip_addr
except Exception as exception:
self.fail(
msg="failed to get IP address {0}: {1}".format(
Expand Down
23 changes: 18 additions & 5 deletions tests/integration/targets/instance_config_vpc/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: Create a VPC
linode.cloud.vpc:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
description: test description
state: present
register: create_vpc
Expand All @@ -22,7 +22,7 @@
- name: Create a Linode instance with interface
linode.cloud.instance:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
type: g6-standard-1
disks:
- label: test-disk
Expand Down Expand Up @@ -58,10 +58,23 @@
- create_instance.configs[0].interfaces[0].ipv4.nat_1_1 == create_instance.instance.ipv4[0]
- create_instance.configs[0].interfaces[0].ipv4.vpc == '10.0.0.3'

- name: Get ip_info about the instance's vpc ip
linode.cloud.ip_info:
address: '{{ create_instance.instance.ipv4[0] }}'
register: ip_info

- name: Assert ip_info matches vpc settings
assert:
that:
- ip_info.ip.address == create_instance.instance.ipv4[0]
- ip_info.ip.vpc_nat_1_1.address == '10.0.0.3'
- ip_info.ip.vpc_nat_1_1.vpc_id == create_vpc.vpc.id
- ip_info.ip.vpc_nat_1_1.subnet_id == create_subnet.subnet.id

- name: Update the config interfaces
linode.cloud.instance:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
type: g6-standard-1
disks:
- label: test-disk
Expand Down Expand Up @@ -103,7 +116,7 @@
- name: Don't change the config interfaces
linode.cloud.instance:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
type: g6-standard-1
disks:
- label: test-disk
Expand Down Expand Up @@ -158,4 +171,4 @@
LINODE_API_TOKEN: '{{ api_token }}'
LINODE_API_URL: '{{ api_url }}'
LINODE_API_VERSION: '{{ api_version }}'
REQUESTS_CA_BUNDLE: '{{ ca_file }}'
REQUESTS_CA_BUNDLE: '{{ ca_file or "" }}'
14 changes: 7 additions & 7 deletions tests/integration/targets/vpc_basic/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: Create a VPC
linode.cloud.vpc:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
description: test description
state: present
register: create_vpc
Expand All @@ -16,13 +16,13 @@
that:
- create_vpc.changed
- create_vpc.vpc.label == 'ansible-test-{{ r }}'
- create_vpc.vpc.region == 'us-east'
- create_vpc.vpc.region == 'us-mia'
- create_vpc.vpc.description == 'test description'

- name: Create a VPC with invalid label
linode.cloud.vpc:
label: 'test-vpc!!'
region: us-east
region: us-mia
description: test description
state: present
register: invalid_label
Expand All @@ -31,7 +31,7 @@
- name: Update the VPC
linode.cloud.vpc:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
description: test description updated
state: present
register: update_vpc
Expand All @@ -46,7 +46,7 @@
- name: Update the VPC with invalid label
linode.cloud.vpc:
label: 'ansible-test-{{ r }}!'
region: us-east
region: us-mia
description: test description updated
state: present
register: modify_vpc
Expand All @@ -55,7 +55,7 @@
- name: Don't update the VPC
linode.cloud.vpc:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
description: test description updated
state: present
register: no_update_vpc
Expand Down Expand Up @@ -115,4 +115,4 @@
LINODE_API_VERSION: '{{ api_version }}'

# Temporary testing override; remove before merge to dev
REQUESTS_CA_BUNDLE: '{{ ca_file }}'
REQUESTS_CA_BUNDLE: '{{ ca_file or "" }}'
6 changes: 3 additions & 3 deletions tests/integration/targets/vpc_subnet/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: Create a VPC
linode.cloud.vpc:
label: 'ansible-test-{{ r }}'
region: us-east
region: us-mia
description: test description
state: present
register: create_vpc
Expand All @@ -16,7 +16,7 @@
that:
- create_vpc.changed
- create_vpc.vpc.label == 'ansible-test-{{ r }}'
- create_vpc.vpc.region == 'us-east'
- create_vpc.vpc.region == 'us-mia'
- create_vpc.vpc.description == 'test description'

- name: Create a subnet
Expand Down Expand Up @@ -100,4 +100,4 @@
LINODE_API_VERSION: '{{ api_version }}'

# Temporary testing override; remove before merge to dev
REQUESTS_CA_BUNDLE: '{{ ca_file }}'
REQUESTS_CA_BUNDLE: '{{ ca_file or "" }}'

0 comments on commit 4dc7e72

Please sign in to comment.