mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-06 10:50:28 -07:00
fixing compute_url_map, add cleanup script
Compute_url_map was broken by #509: It also merged in #393, which has an erroneous understanding that compute_url_map always returns a diff (integration tests show it does not). Adding a cleanup script to help with environment hygiene. Added cleanup to CI to help make tests less flakey.
This commit is contained in:
parent
0cece672cf
commit
4816e97719
3 changed files with 53 additions and 5 deletions
24
.github/workflows/ansible-integration-tests.yml
vendored
24
.github/workflows/ansible-integration-tests.yml
vendored
|
@ -6,6 +6,9 @@ on:
|
||||||
pull_request: {}
|
pull_request: {}
|
||||||
push:
|
push:
|
||||||
branches: master
|
branches: master
|
||||||
|
env:
|
||||||
|
GCP_SERVICE_ACCOUNT: "github-ci@ansible-gcp-ci.iam.gserviceaccount.com"
|
||||||
|
GCP_PROJECT: "ansible-gcp-ci"
|
||||||
jobs:
|
jobs:
|
||||||
integration:
|
integration:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -30,20 +33,31 @@ jobs:
|
||||||
run: pip install -r requirements.txt
|
run: pip install -r requirements.txt
|
||||||
- name: Install ansible-base (${{ matrix.ansible_version }})
|
- name: Install ansible-base (${{ matrix.ansible_version }})
|
||||||
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible_version }}.tar.gz --disable-pip-version-check
|
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible_version }}.tar.gz --disable-pip-version-check
|
||||||
|
# bootstrap integration env
|
||||||
- name: Write integration-test configuration files
|
- name: Write integration-test configuration files
|
||||||
env:
|
env:
|
||||||
CI_SERVICE_ACCOUNT_FILE_CONTENTS: ${{ secrets.CI_SERVICE_ACCOUNT_FILE_CONTENTS }}
|
CI_SERVICE_ACCOUNT_FILE_CONTENTS: ${{ secrets.CI_SERVICE_ACCOUNT_FILE_CONTENTS }}
|
||||||
run: |
|
run: |
|
||||||
echo "$CI_SERVICE_ACCOUNT_FILE_CONTENTS" > /tmp/service-account-key.json
|
echo "$CI_SERVICE_ACCOUNT_FILE_CONTENTS" > /tmp/service-account-key.json
|
||||||
echo "[default]
|
echo "[default]
|
||||||
gcp_project: ansible-gcp-ci
|
gcp_project: $GCP_PROJECT
|
||||||
gcp_cred_file: /tmp/service-account-key.json
|
gcp_cred_file: /tmp/service-account-key.json
|
||||||
gcp_cred_kind: serviceaccount
|
gcp_cred_kind: serviceaccount
|
||||||
gcp_cred_email: github-ci@ansible-gcp-ci.iam.gserviceaccount.com
|
gcp_cred_email: $GCP_SERVICE_ACCOUNT
|
||||||
" > ./tests/integration/cloud-config-gcp.ini
|
" > ./tests/integration/cloud-config-gcp.ini
|
||||||
- name: test secrets
|
# cleanup test environment
|
||||||
env: ${{ secrets }}
|
- name: Auth to Gcloud
|
||||||
run: echo "$CI_SERVICE_ACCOUNT_FILE_CONTENTS"
|
uses: google-github-actions/auth@v1
|
||||||
|
env:
|
||||||
|
CI_SERVICE_ACCOUNT_FILE_CONTENTS: ${{ secrets.CI_SERVICE_ACCOUNT_FILE_CONTENTS }}
|
||||||
|
with:
|
||||||
|
service_account: "$GCP_SERVICE_ACCOUNT"
|
||||||
|
credentials_json: "${{ secrets.CI_SERVICE_ACCOUNT_FILE_CONTENTS }}"
|
||||||
|
- name: Set up Cloud SDK
|
||||||
|
uses: google-github-actions/setup-gcloud@v1
|
||||||
|
- name: Run cleanup
|
||||||
|
run: ./scripts/cleanup-project.sh $GCP_PROJECT $GCP_SERVICE_ACCOUNT
|
||||||
|
# run tests
|
||||||
- name: Run integration tests
|
- name: Run integration tests
|
||||||
# Add the -vvv flag to print out more output
|
# Add the -vvv flag to print out more output
|
||||||
run: ansible-test integration -v --color --python 3.8 --venv-system-site-packages
|
run: ansible-test integration -v --color --python 3.8 --venv-system-site-packages
|
|
@ -5489,6 +5489,7 @@ def main():
|
||||||
if fetch:
|
if fetch:
|
||||||
module.params['fingerprint'] = fetch['fingerprint']
|
module.params['fingerprint'] = fetch['fingerprint']
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
if is_different(module, fetch):
|
||||||
update(module, self_link(module), kind)
|
update(module, self_link(module), kind)
|
||||||
fetch = fetch_resource(module, self_link(module), kind)
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
33
scripts/cleanup-project.sh
Executable file
33
scripts/cleanup-project.sh
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# cleanup-project cleans up an ansible testing project
|
||||||
|
#
|
||||||
|
# WARNING: do not run tests against a project while
|
||||||
|
# this is running, or else your tests will fail.
|
||||||
|
#
|
||||||
|
# dependencies:
|
||||||
|
# - google-cloud-sdk (gcloudgcloud )
|
||||||
|
set -e
|
||||||
|
PROJECT_ID="${1}"
|
||||||
|
SERVICE_ACCOUNT_NAME="${2}"
|
||||||
|
ZONE="us-central1-a"
|
||||||
|
|
||||||
|
main() {
|
||||||
|
# note: the ordering here is deliberate, to start with
|
||||||
|
# leaf resources and work upwards to parent resources.
|
||||||
|
cleanup_resource "compute instances" "--zone=$ZONE"
|
||||||
|
cleanup_resource "compute target-http-proxies" "--global"
|
||||||
|
cleanup_resource "compute forwarding-rules" "--global"
|
||||||
|
cleanup_resource "compute url-maps" "--global"
|
||||||
|
cleanup_resource "compute backend-services" "--global"
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_resource() {
|
||||||
|
resource_group="$1"
|
||||||
|
extra_delete_args="$2"
|
||||||
|
|
||||||
|
for resource in $(gcloud $resource_group list --project="${PROJECT_ID}" --format="csv[no-heading](name)"); do
|
||||||
|
gcloud $resource_group delete "${resource}" --project="${PROJECT_ID}" -q $extra_delete_args
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
Loading…
Add table
Reference in a new issue