diff --git a/tests/run.yml b/tests/run.yml index 83477800fb..53a0af924f 100644 --- a/tests/run.yml +++ b/tests/run.yml @@ -2,7 +2,10 @@ - hosts: all tasks: # NOTE(yoctozepto): setting vars as facts for all to have them around in all the plays - - set_fact: + - name: set facts for commonly used variables + vars: + api_interface_address: "{{ nodepool.private_ipv4 }}" + set_fact: kolla_inventory_path: "/etc/kolla/inventory" logs_dir: "/tmp/logs" kolla_ansible_src_dir: "{{ ansible_env.PWD }}/src/{{ zuul.project.canonical_hostname }}/openstack/kolla-ansible" @@ -11,6 +14,17 @@ build_image_tag: "change_{{ zuul.change | default('none') }}" is_upgrade: "{{ 'upgrade' in scenario }}" is_ceph: "{{ 'ceph' in scenario }}" + api_interface_address: "{{ api_interface_address }}" + # FIXME: in multi node env, api_interface may be different on each node. + api_interface_name: >- + {{ (ansible_interfaces | + map('replace', '-', '_') | + map('extract', ansible_facts) | + selectattr('ipv4.address', 'defined') | + selectattr('ipv4.address', 'equalto', api_interface_address) | + first).device }} + # We use HAProxy and a VIP for single node, not for multinode jobs. + kolla_internal_vip_address: "{{ api_interface_address if hostvars | length > 2 else '169.254.169.10' }}" - name: Prepare disks for Ceph or LVM script: "setup_disks.sh {{ disk_type }}" @@ -22,19 +36,6 @@ - hosts: primary tasks: - # FIXME: in multi node env, api_interface may be different on each node. - - name: detect api_interface_name variable - vars: - ansible_interface_name: "ansible_{{ item.replace('-', '_') }}" - api_interface_address: "{{ hostvars[inventory_hostname]['nodepool']['private_ipv4'] }}" - set_fact: - api_interface_name: "{{ item }}" - api_interface_address: "{{ api_interface_address }}" - when: - - hostvars[inventory_hostname][ansible_interface_name]['ipv4'] is defined - - hostvars[inventory_hostname][ansible_interface_name]['ipv4']['address'] == api_interface_address - with_items: "{{ ansible_interfaces }}" - - name: detect whether need build images set_fact: need_build_image: true @@ -206,6 +207,7 @@ chdir: "{{ kolla_ansible_src_dir }}" environment: ACTION: "{{ scenario }}" + DASHBOARD_URL: "http://{{ kolla_internal_vip_address }}" when: scenario not in ['ironic', 'scenario_nfv'] - name: Run test-zun.sh script @@ -353,6 +355,7 @@ chdir: "{{ kolla_ansible_src_dir }}" environment: ACTION: "{{ scenario }}" + DASHBOARD_URL: "http://{{ kolla_internal_vip_address }}" - name: Run test-zun.sh script shell: diff --git a/tests/templates/globals-default.j2 b/tests/templates/globals-default.j2 index 37d86ac5eb..70a1e31c71 100644 --- a/tests/templates/globals-default.j2 +++ b/tests/templates/globals-default.j2 @@ -9,7 +9,7 @@ docker_restart_policy: "no" keepalived_virtual_router_id: "{{ 250 | random(1) }}" {% if enable_core_openstack | bool %} -kolla_internal_vip_address: "{{ api_interface_address if hostvars | length > 2 else '169.254.169.10' }}" +kolla_internal_vip_address: "{{ kolla_internal_vip_address }}" enable_haproxy: "{{ 'no' if hostvars | length > 2 else 'yes' }}" neutron_external_interface: "fake_interface" openstack_logging_debug: "True" diff --git a/tests/test-openstack.sh b/tests/test-openstack.sh index ae2dea5903..fe627f7321 100755 --- a/tests/test-openstack.sh +++ b/tests/test-openstack.sh @@ -2,17 +2,17 @@ set -o xtrace set -o errexit +set -o pipefail # Enable unbuffered output for Ansible in Jenkins. export PYTHONUNBUFFERED=1 -function test_openstack_logged { - . /etc/kolla/admin-openrc.sh - . ~/openstackclient-venv/bin/activate - +function test_smoke { openstack --debug compute service list openstack --debug network agent list +} +function test_instance_boot { echo "TESTING: Server creation" openstack server create --wait --image cirros --flavor m1.tiny --key-name mykey --network demo-net kolla_boot_test openstack --debug server list @@ -71,6 +71,45 @@ function test_openstack_logged { echo "SUCCESS: Server deletion" } +function check_dashboard { + # Query the dashboard, and check that the returned page looks like a login + # page. + output_path=$1 + if ! curl --include --location --fail $DASHBOARD_URL > $output_path; then + return 1 + fi + if ! grep Login $output_path >/dev/null; then + return 1 + fi +} + +function test_dashboard { + echo "TESTING: Dashboard" + # The dashboard has been known to take some time to become accessible, so + # use retries. + output_path=$(mktemp) + attempt=1 + while ! check_dashboard $output_path; do + echo "Dashboard not accessible yet" + attempt=$((attempt+1)) + if [[ $attempt -eq 10 ]]; then + echo "FAILED: Dashboard did not become accessible. Response:" + cat $output_path + return 1 + fi + sleep 10 + done + echo "SUCCESS: Dashboard" +} + +function test_openstack_logged { + . /etc/kolla/admin-openrc.sh + . ~/openstackclient-venv/bin/activate + test_smoke + test_instance_boot + test_dashboard +} + function test_openstack { echo "Testing OpenStack" log_file=/tmp/logs/ansible/test-openstack