diff --git a/modules/scripts/startup-script/files/install_ansible.sh b/modules/scripts/startup-script/files/install_ansible.sh index 41c483307f..7146ecea36 100644 --- a/modules/scripts/startup-script/files/install_ansible.sh +++ b/modules/scripts/startup-script/files/install_ansible.sh @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -e REQ_ANSIBLE_VERSION=2.11 REQ_ANSIBLE_PIP_VERSION=4.10.0 REQ_PIP_WHEEL_VERSION=0.37.1 @@ -197,13 +198,13 @@ main() { fi # upgrade wheel if necessary - wheel_pkg=$(${venv_python_path} -m pip list --format=freeze | grep "^wheel") + wheel_pkg=$(${venv_python_path} -m pip list --format=freeze | grep "^wheel" || true) if [ "$wheel_pkg" != "wheel==${REQ_PIP_WHEEL_VERSION}" ]; then ${venv_python_path} -m pip install -U wheel==${REQ_PIP_WHEEL_VERSION} fi # upgrade setuptools if necessary - setuptools_pkg=$(${venv_python_path} -m pip list --format=freeze | grep "^setuptools") + setuptools_pkg=$(${venv_python_path} -m pip list --format=freeze | grep "^setuptools" || true) if [ "$setuptools_pkg" != "setuptools==${REQ_PIP_SETUPTOOLS_VERSION}" ]; then ${venv_python_path} -m pip install -U setuptools==${REQ_PIP_SETUPTOOLS_VERSION} fi diff --git a/tools/cloud-build/daily-tests/ansible_playbooks/test-validation/test-ansible-vm.yml b/tools/cloud-build/daily-tests/ansible_playbooks/test-validation/test-ansible-vm.yml new file mode 100644 index 0000000000..da73958dd5 --- /dev/null +++ b/tools/cloud-build/daily-tests/ansible_playbooks/test-validation/test-ansible-vm.yml @@ -0,0 +1,24 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +- name: Check if Ansible is installed + ansible.builtin.shell: | + command -v ansible >/dev/null 2>&1 && echo "Ansible is installed" || echo "Ansible is not installed" + register: ansible_check_result + +- name: Assert Ansible is installed + ansible.builtin.assert: + that: + - ansible_check_result.stdout == "Ansible is installed" diff --git a/tools/cloud-build/daily-tests/blueprints/ansible-vm.yaml b/tools/cloud-build/daily-tests/blueprints/ansible-vm.yaml new file mode 100644 index 0000000000..2b5ac93131 --- /dev/null +++ b/tools/cloud-build/daily-tests/blueprints/ansible-vm.yaml @@ -0,0 +1,115 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- + +blueprint_name: test-workstation-ansible + +vars: + project_id: ## Set GCP Project ID Here ## + deployment_name: test-workstation-ansible + region: us-central1 + zone: us-central1-a + machine_type: n2-standard-2 + disk_type: pd-ssd + instance_count: 1 + +deployment_groups: +- group: primary + modules: + + - id: network1 + source: modules/network/pre-existing-vpc + + - id: startup-script + source: modules/scripts/startup-script + settings: + install_ansible: true + runners: + - type: shell + destination: startup.sh + content: | + #!/bin/bash + set -ex + echo \$(ansible --version) + + - id: workstation-centos + source: modules/compute/vm-instance + use: + - network1 + - startup-script + settings: + name_prefix: centos + add_deployment_name_before_prefix: true + instance_image: + name: centos-7-v20240611 + project: centos-cloud + + - id: workstation-ubuntu-2004 + source: modules/compute/vm-instance + use: + - network1 + - startup-script + settings: + name_prefix: ubuntu2004 + add_deployment_name_before_prefix: true + instance_image: + family: ubuntu-2004-lts + project: ubuntu-os-cloud + + - id: workstation-ubuntu-2204 + source: modules/compute/vm-instance + use: + - network1 + - startup-script + settings: + name_prefix: ubuntu2204 + add_deployment_name_before_prefix: true + instance_image: + family: ubuntu-2204-lts + project: ubuntu-os-cloud + + - id: workstation-debian + source: modules/compute/vm-instance + use: + - network1 + - startup-script + settings: + name_prefix: debian + instance_image: + family: debian-11 + project: debian-cloud + + - id: workstation-rocky-8 + source: modules/compute/vm-instance + use: + - network1 + - startup-script + settings: + name_prefix: rocky8 + add_deployment_name_before_prefix: true + instance_image: + family: rocky-linux-8-optimized-gcp + project: rocky-linux-cloud + + - id: wait-for-startup + source: community/modules/scripts/wait-for-startup + settings: + instance_names: + - $(workstation-centos.name[0]) + - $(workstation-ubuntu-2004.name[0]) + - $(workstation-ubuntu-2204.name[0]) + - $(workstation-debian.name[0]) + - $(workstation-rocky-8.name[0]) + timeout: 7200 diff --git a/tools/cloud-build/daily-tests/builds/ansible-vm.yaml b/tools/cloud-build/daily-tests/builds/ansible-vm.yaml new file mode 100644 index 0000000000..a3aba07522 --- /dev/null +++ b/tools/cloud-build/daily-tests/builds/ansible-vm.yaml @@ -0,0 +1,41 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +tags: +- m.pre-existing-vpc +- m.startup-script +- m.vm-instance +- m.wait-for-startup +- vm + +timeout: 14400s # 4hr +steps: +- id: anisble-vm + name: us-central1-docker.pkg.dev/$PROJECT_ID/hpc-toolkit-repo/test-runner + entrypoint: /bin/bash + env: + - "ANSIBLE_HOST_KEY_CHECKING=false" + - "ANSIBLE_CONFIG=/workspace/tools/cloud-build/ansible.cfg" + args: + - -c + - | + set -x -e + cd /workspace && make + BUILD_ID_FULL=$BUILD_ID + BUILD_ID_SHORT=$${BUILD_ID_FULL:0:6} + + ansible-playbook tools/cloud-build/daily-tests/ansible_playbooks/base-integration-test.yml \ + --user=sa_106486320838376751393 --extra-vars="project=${PROJECT_ID} build=$${BUILD_ID_SHORT}" \ + --extra-vars="@tools/cloud-build/daily-tests/tests/ansible-vm.yml" diff --git a/tools/cloud-build/daily-tests/tests/ansible-vm.yml b/tools/cloud-build/daily-tests/tests/ansible-vm.yml new file mode 100644 index 0000000000..39f773d544 --- /dev/null +++ b/tools/cloud-build/daily-tests/tests/ansible-vm.yml @@ -0,0 +1,25 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- + +test_name: test-workstation-ansible +deployment_name: "ansible-vm-{{ build }}" +zone: us-central1-a +workspace: /workspace +blueprint_yaml: "{{ workspace }}/tools/cloud-build/daily-tests/blueprints/ansible-vm.yaml" +network: "default" +remote_node: "{{ deployment_name }}-centos-0" +post_deploy_tests: +- test-validation/test-ansible-vm.yml