Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # TODO |
| 4 | #personality option |
| 5 | #security_compliance option |
| 6 | #port_security option |
| 7 | |
| 8 | variables=( |
| 9 | OS_USERNAME |
| 10 | OS_PASSWORD |
| 11 | OS_TENANT_NAME |
| 12 | OS_AUTH_URL |
| 13 | ) |
| 14 | |
| 15 | check_variables () { |
| 16 | for i in $(seq 0 $(( ${#variables[@]} - 1 )) ); do |
| 17 | if [ -z "${!variables[$i]}" ]; then |
| 18 | echo "Variable \"${variables[$i]}\" is not defined" |
| 19 | exit 1 |
| 20 | fi |
| 21 | done |
| 22 | } |
| 23 | |
| 24 | rally_configuration () { |
| 25 | sub_name=`date "+%H_%M_%S"` |
| 26 | rally deployment create --fromenv --name=tempest_$sub_name |
| 27 | rally deployment config |
| 28 | } |
| 29 | |
| 30 | tempest_configuration () { |
| 31 | sub_name=`date "+%H_%M_%S"` |
| 32 | if [ -n "${PROXY}" ]; then |
| 33 | export https_proxy=$PROXY |
| 34 | fi |
| 35 | rally verify create-verifier --name tempest_verifier_$sub_name --type tempest --source $TEMPEST_ENDPOINT --version $tempest_version |
| 36 | unset https_proxy |
| 37 | rally verify configure-verifier --show |
| 38 | } |
| 39 | |
| 40 | collecting_openstack_data () { |
| 41 | current_path=$(pwd) |
| 42 | |
| 43 | PUBLIC_NETWORK_ID=$(neutron net-list --router:external=True -f csv -c id --quote none | tail -1) |
| 44 | PUBLIC_NETWORK_NAME="`neutron --insecure net-list --router:external=True -f csv -c name --quote none | tail -1`" |
| 45 | NEUTRON_EXT_LIST=$(neutron ext-list | grep -v "+" | grep -v "alias" | awk '{print $2}' | tr '\n ' ', ' | head -c -1) |
| 46 | neutron net-list | grep fixed 2>&1 >/dev/null || { |
| 47 | neutron net-create --shared fixed |
| 48 | neutron subnet-create --name fixed-subnet --gateway 192.168.0.1 --allocation-pool start=192.168.0.2,end=192.168.0.254 --ip-version 4 fixed 192.168.0.0/24 |
| 49 | } |
| 50 | SHARED_NETWORK_NAME=fixed |
| 51 | SHARED_NETWORK_ID=$(neutron net-list | grep "\b${SHARED_NETWORK_NAME}\b" | cut -c3-38) |
| 52 | neutron net-update ${SHARED_NETWORK_ID} --shared true |
| 53 | |
| 54 | #flavor |
| 55 | nova flavor-list | grep tiny 2>&1 >/dev/null || { |
| 56 | nova flavor-create --is-public true m1.tiny auto 128 1 1 |
| 57 | } |
| 58 | FLAVOR_REF=$(nova flavor-list | grep '\bm1.tiny\b' | awk '{print $2}') |
| 59 | nova flavor-list | grep m1.micro 2>&1 >/dev/null || { |
| 60 | nova flavor-create --is-public true m1.micro auto 1024 2 2 |
| 61 | } |
| 62 | FLAVOR_REF2=$(nova flavor-list | grep '\bm1.micro\b' | awk '{print $2}') |
| 63 | |
| 64 | #image |
| 65 | glance image-list | grep "\bTestVM\b" 2>&1 >/dev/null || { |
| 66 | if [ -n "${PROXY}" ]; then |
| 67 | export http_proxy=$PROXY |
| 68 | fi |
| 69 | ls $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img || wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img |
| 70 | unset http_proxy |
| 71 | echo "TODO: add md5check here" |
| 72 | echo "should be ee1eca47dc88f4879d8a229cc70a07c6" |
| 73 | md5sum $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img |
| 74 | glance image-create --name=TestVM --visibility=public --container-format=bare --disk-format=qcow2 < $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img |
| 75 | glance image-create --name=Test2VM --visibility=public --container-format=bare --disk-format=qcow2 < $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img |
| 76 | } |
| 77 | IMAGE_REF=$(glance image-list | grep 'TestVM' | awk '{print $2}') |
| 78 | IMAGE_REF2=$(glance image-list | grep 'Test2VM' | awk '{print $2}') |
| 79 | |
| 80 | url_base=$(echo ${OS_AUTH_URL} | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/') |
| 81 | |
| 82 | #neutron net-create --shared fixed |
| 83 | #neutron subnet-create --name fixed-subnet --gateway 192.168.0.1 --allocation-pool start=192.168.0.2,end=192.168.0.254 --ip-version 4 fixed 192.168.0.0/24 |
| 84 | |
| 85 | check_service_availability() { |
| 86 | SVC=$(openstack service list | grep $1 | wc -l) |
| 87 | if [ "${SVC}" -eq "0" ]; then |
| 88 | echo "false" |
| 89 | else |
| 90 | echo "true" |
| 91 | fi |
| 92 | } |
| 93 | |
| 94 | NEUTRON_AVAILABLE=$(check_service_availability "neutron") |
| 95 | NOVA_AVAILABLE=$(check_service_availability "nova") |
| 96 | CINDER_AVAILABLE=$(check_service_availability "cinder") |
| 97 | GLANCE_AVAILABLE=$(check_service_availability "glance") |
| 98 | SWIFT_AVAILABLE=$(check_service_availability "swift") |
| 99 | HEAT_AVAILABLE=$(check_service_availability "heat") |
| 100 | CEILOMETER_AVAILABLE=$(check_service_availability "ceilometer") |
| 101 | SAHARA_AVAILABLE=$(check_service_availability "sahara") |
| 102 | IRONIC_AVAILABLE=$(check_service_availability "ironic") |
| 103 | TROVE_AVAILABLE=$(check_service_availability "trove") |
| 104 | ZAQAR_AVAILABLE=$(check_service_availability "zaqar") |
| 105 | } |
| 106 | |
| 107 | create_tempest_config () { |
| 108 | sed -i 's/${OS_USERNAME}/'$OS_USERNAME'/g' $current_path/cvp-configuration/tempest_full.conf |
| 109 | sed -i 's/${OS_PASSWORD}/'$OS_PASSWORD'/g' $current_path/cvp-configuration/tempest_full.conf |
| 110 | sed -i 's/${OS_TENANT_NAME}/'$OS_TENANT_NAME'/g' $current_path/cvp-configuration/tempest_full.conf |
| 111 | sed -i 's/${OS_DEFAULT_DOMAIN}/'$OS_DEFAULT_DOMAIN'/g' $current_path/cvp-configuration/tempest_full.conf |
| 112 | sed -i 's/${IMAGE_REF}/'$IMAGE_REF'/g' $current_path/cvp-configuration/tempest_full.conf |
| 113 | sed -i 's/${IMAGE_REF2}/'$IMAGE_REF2'/g' $current_path/cvp-configuration/tempest_full.conf |
| 114 | sed -i 's/${FLAVOR_REF}/'$FLAVOR_REF'/g' $current_path/cvp-configuration/tempest_full.conf |
| 115 | sed -i 's/${FLAVOR_REF2}/'$FLAVOR_REF2'/g' $current_path/cvp-configuration/tempest_full.conf |
| 116 | sed -i 's/${SHARED_NETWORK_NAME}/'$SHARED_NETWORK_NAME'/g' $current_path/cvp-configuration/tempest_full.conf |
| 117 | sed -i 's/${OS_REGION_NAME}/'$OS_REGION_NAME'/g' $current_path/cvp-configuration/tempest_full.conf |
| 118 | sed -i 's/${url_base}/'$url_base'/g' $current_path/cvp-configuration/tempest_full.conf |
| 119 | sed -i 's/${PUBLIC_NETWORK_ID}/'$PUBLIC_NETWORK_ID'/g' $current_path/cvp-configuration/tempest_full.conf |
| 120 | sed -i 's/${PUBLIC_NETWORK_NAME}/'$PUBLIC_NETWORK_NAME'/g' $current_path/cvp-configuration/tempest_full.conf |
| 121 | sed -i 's/${NEUTRON_EXT_LIST}/'$NEUTRON_EXT_LIST'/g' $current_path/cvp-configuration/tempest_full.conf |
| 122 | sed -i 's/publicURL/'$TEMPEST_ENDPOINT_TYPE'/g' $current_path/cvp-configuration/tempest_full.conf |
| 123 | cat $current_path/cvp-configuration/tempest_full.conf |
| 124 | } |
| 125 | |
| 126 | check_variables |
| 127 | rally_configuration |
| 128 | if [ -n "${TEMPEST_ENDPOINT}" ]; then |
| 129 | tempest_configuration |
| 130 | collecting_openstack_data |
| 131 | create_tempest_config |
| 132 | rally verify configure-verifier --override /home/rally/cvp-configuration/tempest_full.conf |
| 133 | fi |
| 134 | set -e |
| 135 | |
| 136 | echo "Job is done!" |