Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove jinja vars from conditional statements in test asserts #639

Merged
merged 15 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
profile: production
parseable: true
skip_list:
- ANSIBLE0010
use_default_rules: true
verbosity: 1
exclude_paths:
- ./roles/gcp_http_lb/
- ./tests/
- ./plugins
# Ignore submodule https://github.com/GoogleCloudPlatform/google-cloud-ops-agents-ansible
- roles/google_cloud_ops_agents/
2 changes: 1 addition & 1 deletion .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install ansible-lint
run: pip install ansible-lint==24.7.0
- name: Run ansible-lint
run: ansible-lint
run: ansible-lint --exclude roles/google_cloud_ops_agents/
unit:
runs-on: ubuntu-latest
defaults:
Expand Down
2 changes: 1 addition & 1 deletion roles/gcloud/tasks/archive/command_completion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
when: ansible_os_family == "Debian"

- name: Gcloud | Archive | RedHat | Ensure bash completion is installed
ansible.builtin.yum:
ansible.builtin.dnf:
name:
- bash-completion
register: task_result
Expand Down
12 changes: 6 additions & 6 deletions roles/gcloud/tasks/package/redhat.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
- name: Gcloud | RHEL | Add an Apt signing key, uses whichever key is at the URL
# https://cloud.google.com/sdk/docs/install#rpm
- name: Gcloud | RHEL | Add a dnf signing key, uses whichever key is at the URL
ansible.builtin.yum_repository:
name: google-cloud-sdk
description: Google Cloud SDK
baseurl: https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
baseurl: https://packages.cloud.google.com/yum/repos/cloud-sdk-el9-x86_64
enabled: true
gpgcheck: true
repo_gpgcheck: true
repo_gpgcheck: false
gpgkey:
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: Gcloud | RHEL | Install the google-cloud-sdk package
ansible.builtin.yum:
ansible.builtin.dnf:
name: google-cloud-sdk
update_cache: "yes"
register: task_result
Expand All @@ -21,7 +21,7 @@
delay: 2

- name: Gcloud | Debian | Install the google-cloud-sdk additional components
ansible.builtin.yum:
ansible.builtin.dnf:
name: google-cloud-sdk-{{ item }}
update_cache: "yes"
register: task_result
Expand Down
1 change: 1 addition & 0 deletions scripts/cleanup-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ZONE="us-central1-a"
main() {
# note: the ordering here is deliberate, to start with
# leaf resources and work upwards to parent resources.
cleanup_resource "container" "clusters" "" "--zone=$ZONE"
cleanup_resource_per_region "compute" "vpn-tunnels"
cleanup_resource "compute" "instances" "" "--zone=$ZONE"
cleanup_resource_per_region "compute" "addresses"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'my-cluster' in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*my-cluster.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a cluster that already exists
google.cloud.gcp_container_cluster:
Expand Down Expand Up @@ -104,7 +104,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'my-cluster' not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*my-cluster.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a cluster that does not exist
google.cloud.gcp_container_cluster:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'my-pool' in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*my-pool.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a node pool that already exists
google.cloud.gcp_container_node_pool:
Expand Down Expand Up @@ -108,7 +108,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'my-pool' not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*my-pool.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a node pool that does not exist
google.cloud.gcp_container_node_pool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'www.testzone-4.com.'in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*www\\.testzone-4\\.com.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a resource record set that already exists
google.cloud.gcp_dns_resource_record_set:
Expand Down Expand Up @@ -118,7 +118,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'www.testzone-4.com.'not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*www\\.testzone-4\\.com.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a resource record set that does not exist
google.cloud.gcp_dns_resource_record_set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "\"{{ resource_name }}\" in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a subscription that already exists
google.cloud.gcp_pubsub_subscription:
Expand Down Expand Up @@ -98,7 +98,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "\"{{ resource_name }}\" not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a subscription that does not exist
google.cloud.gcp_pubsub_subscription:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/gcp_pubsub_topic/tasks/autogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'test-topic1' in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*test-topic1.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a topic that already exists
google.cloud.gcp_pubsub_topic:
Expand Down Expand Up @@ -82,7 +82,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'test-topic1' not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*test-topic1.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a topic that does not exist
google.cloud.gcp_pubsub_topic:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/gcp_sql_database/tasks/autogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "\"{{ resource_name }}\" in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a database that already exists
google.cloud.gcp_sql_database:
Expand Down Expand Up @@ -107,7 +107,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "\"{{ resource_name }}\" not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a database that does not exist
google.cloud.gcp_sql_database:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/gcp_sql_user/tasks/autogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'test-user' in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*test-user.*") | list | length == 1
# ----------------------------------------------------------------------------
- name: Create a user that already exists
google.cloud.gcp_sql_user:
Expand Down Expand Up @@ -111,7 +111,7 @@
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- "'test-user' not in \"{{ results['resources'] | map(attribute='name') | list }}\""
- results['resources'] | map(attribute='name') | select("match", ".*test-user.*") | list | length == 0
# ----------------------------------------------------------------------------
- name: Delete a user that does not exist
google.cloud.gcp_sql_user:
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/plugins/test_gcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_simple_different(self):
difference = {"test": "original"}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertNotEqual(request1, request2)
self.assertEqual(request1.difference(request2), difference)

def test_nested_dictionaries_no_difference(self):
Expand All @@ -99,7 +99,7 @@ def test_nested_dictionaries_with_difference(self):
difference = {"foo": {"quiet": {"tree": "test"}, "bar": "baz"}}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertNotEqual(request1, request2)
self.assertEqual(request1.difference(request2), difference)

def test_arrays_strings_no_difference(self):
Expand All @@ -123,7 +123,7 @@ def test_arrays_strings_with_difference(self):
}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertNotEqual(request1, request2)
self.assertEqual(request1.difference(request2), difference)

def test_arrays_dicts_with_no_difference(self):
Expand All @@ -141,7 +141,7 @@ def test_arrays_dicts_with_difference(self):
difference = {"foo": [{"test": "value", "foo": "bar"}]}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertNotEqual(request1, request2)
self.assertEqual(request1.difference(request2), difference)

def test_dicts_boolean_with_difference(self):
Expand All @@ -165,5 +165,5 @@ def test_dicts_boolean_with_difference(self):
}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertNotEqual(request1, request2)
self.assertEqual(request1.difference(request2), difference)
Loading