Skip to content

Commit

Permalink
Refactor image replication test cases (linode#589)
Browse files Browse the repository at this point in the history
* refactor test case

* disable too-many-positional

* fix option name

* fix lint
  • Loading branch information
yec-akamai authored Sep 27, 2024
1 parent 7769e33 commit 82657bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/linode_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
RETRY_STATUSES = {408, 429, 502}


class LinodeModuleBase:
class LinodeModuleBase: # pylint: disable=too-many-positional-arguments
"""A base for all Linode resource modules."""

def __init__(
Expand Down
1 change: 1 addition & 0 deletions plugins/module_utils/linode_common_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class InfoModule(LinodeModuleBase):
"""A common module for listing API resources given a set of filters."""

def __init__(
# pylint: disable=too-many-positional-arguments
self,
primary_result: InfoModuleResult,
secondary_results: List[InfoModuleResult] = None,
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/linode_common_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ListModuleParam:

class ListModule(
LinodeModuleBase
): # pylint: disable=too-many-instance-attributes
): # pylint: disable=too-many-instance-attributes,too-many-positional-arguments
"""A common module for listing API resources given a set of filters."""

def __init__(
Expand Down
20 changes: 14 additions & 6 deletions tests/integration/targets/image_basic/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
- set_fact:
r: "{{ 1000000000 | random }}"

- name: List regions
linode.cloud.region_list: {}
register: all_regions

- set_fact:
capable_regions: '{{ (all_regions.regions | selectattr("capabilities", "search", "Object Storage") | selectattr("site_type", "equalto", "core") | map(attribute="id") | list) }}'

- name: Create an instance to image
linode.cloud.instance:
label: 'ansible-test-{{ r }}'
region: us-east
region: '{{ capable_regions[1] }}'
type: g6-standard-1
image: linode/alpine3.19
state: present
Expand Down Expand Up @@ -83,8 +90,8 @@
tags:
- 'test'
replica_regions:
- 'us-east'
- 'eu-west'
- '{{ capable_regions[0] }}'
- '{{ capable_regions[1] }}'
wait_for_replications: yes
wait_timeout: 1200
state: present
Expand All @@ -96,7 +103,8 @@
- image_replicate.changed
- image_replicate.image.id == image_create.image.id
- image_replicate.image.regions | length == 2
- image_replicate.image.regions[0].region == 'us-east'
- image_replicate.image.regions[0].region == capable_regions[1]
- image_replicate.image.regions[1].region == capable_regions[0]
- image_replicate.image.regions[0].status == 'available'
- image_replicate.image.regions[1].status == 'available'

Expand All @@ -108,7 +116,7 @@
tags:
- 'test'
replica_regions:
- 'eu-west'
- '{{ capable_regions[0] }}'
wait_for_replications: yes
wait_timeout: 1200
state: present
Expand All @@ -119,7 +127,7 @@
that:
- image_replicate.changed
- image_replicate.image.regions | length == 1
- image_replicate.image.regions[0].region == 'eu-west'
- image_replicate.image.regions[0].region == capable_regions[0]
- image_replicate.image.regions[0].status == 'available'

- name: Overwrite the image
Expand Down

0 comments on commit 82657bd

Please sign in to comment.