From cac5ab136efc2ac4c0e5b0c4b353d98dbfad6b7e Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 6 Oct 2016 13:21:29 +0200 Subject: [PATCH] devstack: remove old exercise scripts Now that our gate is using tempest, these are no longer needed and maintained. Also stop recommending them in CONTRIBUTING. Change-Id: I6bd10cf1052b5cd66fc0580439801171739bf7e0 --- CONTRIBUTING.rst | 8 - devstack/discovery_exercise.sh | 84 --------- devstack/exercise.sh | 238 ------------------------- devstack/exercise_common.sh | 312 --------------------------------- 4 files changed, 642 deletions(-) delete mode 100755 devstack/discovery_exercise.sh delete mode 100755 devstack/exercise.sh delete mode 100644 devstack/exercise_common.sh diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a446b784d..b269857a3 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -105,14 +105,6 @@ Notes * This configuration disables Heat and Cinder, adjust it if you need these services. -Test ----- - -There is a test script included:: - - source devstack/openrc admin admin - /opt/stack/ironic-inspector/devstack/exercise.sh - Usage ----- diff --git a/devstack/discovery_exercise.sh b/devstack/discovery_exercise.sh deleted file mode 100755 index b368c55ba..000000000 --- a/devstack/discovery_exercise.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -set -eux - -# Import help functions -IRONIC_INSPECTOR_DEVSTACK_PLUGIN_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd) -source ${IRONIC_INSPECTOR_DEVSTACK_PLUGIN_DIR}/exercise_common.sh - -# this exercise destroys BM nodes -# precaution measures -assert_sudo -hook=$(get_ini $IRONIC_INSPECTOR_CONF_FILE processing node_not_found_hook) || { - echo "Please, enable node_not_found_hook in processing section of inspector.conf" - exit 1 -} - -if [ -z "$hook" ] ; then - echo "Please, provide a value for node_not_found_hook in processing section of inspector.conf" - exit 1 -fi - -nodes=$(node_list) -if [ -z "$nodes" ]; then - echo "No nodes found in Ironic" - exit 1 -fi - -# Choose one ironic node for discover -discover_uuid= -for uuid in $nodes; do - provision_state=$(node_attribute $uuid provision_state) - if [[ $provision_state = "available" ]] || [[ $provision_state = "enroll" ]] ; then - discover_uuid=$uuid - break - fi -done - -if [ -z "$discover_uuid" ] ; then - echo "No nodes in available provisioning state" - exit 1 -fi - -# Get node details before delete it -node_name=$(node_attribute $discover_uuid name) -node_driver=$(node_attribute $discover_uuid driver) -node_mac=$(node_mac $discover_uuid) -declare -A driver_info -node_driver_info $discover_uuid driver_info - -# create temporary discovery rule -discovery_rule=$(mktemp) -node_discovery_rule $node_name $node_driver driver_info > "$discovery_rule" - -echo "Purging introspection rules; importing custom rules" -openstack baremetal introspection rule purge -openstack baremetal introspection rule import "$discovery_rule" - -# get virsh node uuid -virsh_uuid=$(node_to_virsh_uuid $discover_uuid) - -# delete&rediscover node -echo "Delete Ironic node $discover_uuid (and ports) for discovery" -ironic node-delete $discover_uuid -wait_for 120 ! assert_mac_blacklisted $node_mac - -# Start vm's for discover -echo "booting virsh $virsh_uuid domain to be discovered" -sudo virsh start $virsh_uuid - -echo "waiting for discovered node to appear" -discovered_node= -wait_for 900 node_exists $node_name discovered_node - -echo "waiting for introspection to finish" -wait_for 900 assert_node_introspection_status $discovered_node - -# validate discovery result -validate_node_flavor $discovered_node baremetal -assert_equal $node_driver $(node_attribute $discovered_node driver) -validate_node_driver_info $discovered_node driver_info - -rm -f $discovery_rule - -echo "Validation passed" diff --git a/devstack/exercise.sh b/devstack/exercise.sh deleted file mode 100755 index 999103dfe..000000000 --- a/devstack/exercise.sh +++ /dev/null @@ -1,238 +0,0 @@ -#!/bin/bash - -set -ex - -# NOTE(vsaienko) this script is launched with sudo. -# Only exported variables are passed here. -# Source to make sure all vars are available. -STACK_ROOT="$(dirname "$0")/../../" -source "$STACK_ROOT/devstack/stackrc" -source "$STACK_ROOT/ironic/devstack/lib/ironic" - -set -u - -INTROSPECTION_SLEEP=${INTROSPECTION_SLEEP:-30} -export IRONIC_API_VERSION=${IRONIC_API_VERSION:-latest} -# Copied from devstack -PRIVATE_NETWORK_NAME=${PRIVATE_NETWORK_NAME:-"private"} - -rules_file=$(mktemp) -cat > "$rules_file" << EOM -[ - { - "description": "Successful Rule", - "conditions": [ - {"op": "ge", "field": "memory_mb", "value": 256}, - {"op": "ge", "field": "local_gb", "value": 1} - ], - "actions": [ - {"action": "set-attribute", "path": "/extra/rule_success", - "value": "yes"} - ] - }, - { - "description": "Failing Rule", - "conditions": [ - {"op": "lt", "field": "memory_mb", "value": 42}, - {"op": "eq", "field": "local_gb", "value": 0} - ], - "actions": [ - {"action": "set-attribute", "path": "/extra/rule_success", - "value": "no"}, - {"action": "fail", "message": "This rule should not have run"} - ] - } -] -EOM - -expected_cpus=$(openstack flavor show baremetal -f value -c vcpus) -expected_memory_mb=$(openstack flavor show baremetal -f value -c ram) -expected_cpu_arch=$(openstack flavor show baremetal -f value -c properties | sed "s/.*cpu_arch='\([^']*\)'.*/\1/") - -disk_size=$(openstack flavor show baremetal -f value -c disk) -ephemeral_size=$(openstack flavor show baremetal -f value -c "OS-FLV-EXT-DATA:ephemeral") -expected_local_gb=$(($disk_size + $ephemeral_size)) - -ironic_url=$(openstack endpoint show baremetal -f value -c publicurl) -if [ -z "$ironic_url" ]; then - echo "Cannot find Ironic URL" - exit 1 -fi - -# NOTE(dtantsur): it's hard to get JSON field from Ironic client output, using -# HTTP API and JQ instead. - -function curl_ir { - local token=$(openstack token issue -f value -c id) - curl -H "X-Auth-Token: $token" -X $1 "$ironic_url/$2" -} - -function curl_ins { - local token=$(openstack token issue -f value -c id) - local args=${3:-} - curl -f -H "X-Auth-Token: $token" -X $1 $args "http://127.0.0.1:5050/$2" -} - -nodes=$(openstack baremetal node list -f value -c UUID) -if [ -z "$nodes" ]; then - echo "No nodes found in Ironic" - exit 1 -fi - -for uuid in $nodes; do - for p in cpus cpu_arch memory_mb local_gb; do - openstack baremetal node unset --property $p $uuid > /dev/null || true - done - if [[ "$(openstack baremetal node show $uuid -f value -c provision_state)" != "manageable" ]]; then - openstack baremetal node manage $uuid - fi -done - -openstack baremetal introspection rule purge -openstack baremetal introspection rule import "$rules_file" - -for uuid in $nodes; do - openstack baremetal node inspect $uuid -done - -current_nodes=$nodes -temp_nodes= -while true; do - sleep $INTROSPECTION_SLEEP - for uuid in $current_nodes; do - finished=$(openstack baremetal introspection status $uuid -f value -c finished) - if [ "$finished" = "True" ]; then - error=$(openstack baremetal introspection status $uuid -f value -c error) - if [ "$error" != "None" ]; then - echo "Introspection for $uuid failed: $error" - exit 1 - fi - else - temp_nodes="$temp_nodes $uuid" - fi - done - if [ "$temp_nodes" = "" ]; then - echo "Introspection done" - break - else - current_nodes=$temp_nodes - temp_nodes= - fi -done - -openstack baremetal introspection rule purge - -function test_swift { - # Basic sanity check of the data stored in Swift - stored_data_json=$(openstack baremetal introspection data save $uuid) - stored_cpu_arch=$(echo $stored_data_json | jq -r '.cpu_arch') - echo CPU arch for $uuid from stored data: $stored_cpu_arch - if [ "$stored_cpu_arch" != "$expected_cpu_arch" ]; then - echo "The data stored in Swift does not match the expected data." - exit 1 - fi -} - -function wait_for_provision_state { - local uuid=$1 - local expected=$2 - local max_attempts=${3:-6} - - for attempt in $(seq 1 $max_attempts); do - local current=$(openstack baremetal node show $uuid -f value -c provision_state) - - if [ "$current" != "$expected" ]; then - if [ "$attempt" -eq "$max_attempts" ]; then - echo "Expected provision_state $expected, got $current:" - openstack baremetal node show $uuid - exit 1 - fi - else - break - fi - sleep 10 - done -} - -for uuid in $nodes; do - node_json=$(curl_ir GET v1/nodes/$uuid) - properties=$(echo $node_json | jq '.properties') - - echo Properties for $uuid: $properties - if [ "$(echo $properties | jq -r '.cpu_arch')" != "$expected_cpu_arch" ]; then - echo "Expected CPU architecture: $expected_cpu_arch" - exit 1 - fi - if [ "$(echo $properties | jq -r '.cpus')" != "$expected_cpus" ]; then - echo "Expected number of CPUS: $expected_cpus" - exit 1 - fi - if [ "$(echo $properties | jq -r '.local_gb')" != "$expected_local_gb" ]; then - echo "Expected disk: $expected_local_gb" - exit 1 - fi - if [ "$(echo $properties | jq -r '.memory_mb')" != "$expected_memory_mb" ]; then - echo "Expected memory: $expected_memory_mb" - exit 1 - fi - - extra=$(echo $node_json | jq '.extra') - echo Extra properties for $uuid: $extra - if [ "$(echo $extra | jq -r '.rule_success')" != "yes" ]; then - echo "Rule matching failed" - exit 1 - fi - - openstack service list | grep swift && test_swift - - wait_for_provision_state $uuid manageable - openstack baremetal node provide $uuid -done - -# Cleaning kicks in here, we have to wait until it finishes (~ 2 minutes) -for uuid in $nodes; do - wait_for_provision_state $uuid available 60 # 10 minutes for cleaning -done - -echo "Wait until nova becomes aware of bare metal instances" - -for attempt in {1..24}; do - if [ $(openstack hypervisor stats show -f value -c vcpus) -ge $expected_cpus ]; then - break - elif [ "$attempt" -eq 24 ]; then - echo "Timeout while waiting for nova hypervisor-stats, current:" - openstack hypervisor stats show - exit 1 - fi - sleep 5 -done - -echo "Try nova boot for one instance" - -image=$(openstack image list --property disk_format=ami -f value -c ID | head -n1) -net_id=$(openstack network show "$PRIVATE_NETWORK_NAME" -f value -c id) -# TODO(vsaienko) replace by openstack create with --wait flag -uuid=$(nova boot --flavor baremetal --nic net-id=$net_id --image $image testing | grep " id " | awk '{ print $4 }') - -for attempt in {1..30}; do - status=$(nova show $uuid | grep " status " | awk '{ print $4 }') - if [ "$status" = "ERROR" ]; then - echo "Instance failed to boot" - # Some debug output - openstack server show $uuid - openstack hypervisor stats show - exit 1 - elif [ "$status" != "ACTIVE" ]; then - if [ "$attempt" -eq 30 ]; then - echo "Instance didn't become ACTIVE, status is $status" - exit 1 - fi - else - break - fi - sleep 30 -done - -openstack server delete $uuid - -echo "Validation passed" diff --git a/devstack/exercise_common.sh b/devstack/exercise_common.sh deleted file mode 100644 index a1bd262cc..000000000 --- a/devstack/exercise_common.sh +++ /dev/null @@ -1,312 +0,0 @@ -#!/bin/bash - -IRONIC_INSPECTOR_CONF_FILE="/etc/ironic-inspector/inspector.conf" - -function assert_sudo { - # make sure sudo works in non-interactive mode - if ! sudo -n true ; then - echo "ERROR: sudo doesn't work" - return 1 - fi -} - -function token_issue { - openstack token issue -f value -c id -} - -function endpoint_url { - local endpoint=${1:?endpoint not specified} - openstack endpoint show ${endpoint} -f value -c adminurl -} - -function auth_curl { - local url=${1:?url not specified} ; shift - local method=${1:-GET} ; shift - local token=$(token_issue) - - curl -H "X-Auth-Token: $token" -X ${method} ${url} ${@} -} - -function curl_ironic { - local url=${1:?url not specified} ; shift - local method=${1:-GET} ; shift - - auth_curl "$(endpoint_url baremetal)/${url#/}" ${method} ${@} -} - -function node_list { - openstack baremetal list -f value -c UUID -} - -function node_attribute { - local uuid=${1:?uuid not specified} - local attribute=${2:?attribute not specified} - - openstack baremetal show ${uuid} -f value -c ${attribute} -} - -function json_query { - local data_name=${1:?data variable name not specified}; shift - local var_name=${1:?variable name not specified}; shift - local key=${1:?key not specified}; shift - local query=$@ - - local tmp=$(jq ${query} <<<${!data_name}) - eval ${var_name}[${key}]=${tmp} -} - -function virsh_domains { - - # Id Name State - #---------------------------------------------------- - # - baremetalbrbm_0 shut off - # - sudo -n virsh list --all | tail -n+3 | awk '{print $2;}' | head -n-1 -} - -function virsh_domain_mac { - local domain=${1:?domain not specified} - - # .... - # - # .... - sudo -n virsh dumpxml $domain | grep 'mac address' | cut -d \' -f2 -} - -function node_mac { - local uuid=${1:?uuid not specified} - - # +--------------------------------------+-------------------+ - # | UUID | Address | - # +--------------------------------------+-------------------+ - # | 4d734b98-bae9-43a7-ba27-8dbdce2b0bf1 | 52:54:00:df:96:0c | - # +--------------------------------------+-------------------+ - ironic node-port-list $uuid | tail -n+4 | head -n+1 | head -1 | tr -d \| | awk '{print $2;}' -} - -function node_to_virsh_uuid { - local uuid=${1:?uuid not specified} - local node_mac=$(node_attribute $uuid mac_address) - local map - local node - local domain - - declare -A map - - for node in $(node_list) ; do - map[$(node_mac $node)]=$node - done - - for domain in $(virsh_domains) ; do - if [[ ${map[$(virsh_domain_mac $domain)]} = $uuid ]] ; then - echo $domain - return - fi - done - return 1 -} - -function node_exists { - local query=${1:?query not specified} - local result_name=${2} - - for node in $(node_list) ; do - if [ "${node}" == "${query}" ] || [ $(node_attribute $node name) == "${query}" ] ; then - if [ -n "$result_name" ] ; then - eval $result_name=$node - fi - return - fi - done - return 1 -} - -function flavor_expand { - local flavor=${1:?flavor not specified} - local var_name=${2:?variable name not specified} - - eval $var_name[vcpus]=$(openstack flavor show ${flavor} -f value -c vcpus) - eval $var_name[ram]=$(openstack flavor show ${flavor} -f value -c ram) - eval $var_name[cpu_arch]=$(openstack flavor show ${flavor} -f value -c properties | sed "s/.*cpu_arch='\([^']*\)'.*/\1/") - eval $var_name[disk]=$(openstack flavor show ${flavor} -f value -c disk) - eval $var_name[ephemeral]=$(openstack flavor show ${flavor} -f value -c "OS-FLV-EXT-DATA:ephemeral") - eval $var_name[local_gb]=$(($var_name[disk] + $var_name[ephemeral])) - -} - -function assert_last { - local code=${1:?code not specified} - local expected=${2:-0} - local message=${3:-} - - if [ ${code} -ne ${expected} ] ; then - if [ -n "${message}" ] ; then - echo "${message}" - fi - return 1 - fi -} - -function assert_equal { - local lvalue=${1:?lvalue not specified} - local rvalue=${2:?rvalue not specified} - local message=${3:-} - - [ "${lvalue}" == "${rvalue}" ] || assert_last ${?} 0 "${message}" || return ${?} -} - -function assert_equal_arrays { - local lvalue_name=${1:?lvalue name not specified} - local rvalue_name=${2:?rvalue name not specified} - local lvalue - local rvalue - local keys - local key - - eval keys=\${!${lvalue_name}[@]} - for key in ${keys} ; do - eval lvalue=\${$lvalue_name[$key]} - eval rvalue=\${$rvalue_name[$key]} - assert_equal $lvalue $rvalue "$key: $lvalue != $rvalue" || return ${?} - done - eval keys=\${!${rvalue_name}[@]} - for key in ${keys} ; do - eval lvalue=\${$lvalue_name[$key]} - eval rvalue=\${$rvalue_name[$key]} - assert_equal $lvalue $rvalue "$key: $lvalue != $rvalue" || return ${?} - done -} - -function assert_mac_blacklisted { - local mac=${1:?mac not specified} - - sudo -n iptables -L ironic-inspector | grep -iq "${mac}" && return - return 1 -} - -function assert_node_introspection_status { - local node=${1:?uuid not specified} - local finished_query=${2:-True} - local error_query=${3:-None} - local finished=$(openstack baremetal introspection status $node -f value -c finished) - local error=$(openstack baremetal introspection status $node -f value -c error) - - assert_equal ${finished_query} ${finished} || return ${?} - assert_equal ${error_query} ${error} || return ${?} -} - -function node_discovery_rule { - local node_name=${1:?node name not specified} - local node_driver=${2:?driver not specified} - local driver_info_name=${3:?driver info name not specified} - local keys - local key - local value - - cat <