From c8ae2457c7fd86975d77d6bc67b50b155f602944 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 16 Feb 2018 15:59:23 +0000 Subject: [PATCH] Register traits on nodes in devstack This change adds support for assiging traits to nodes in the ironic devstack plugin. The set of traits added is configured by IRONIC_DEFAULT_TRAITS, which defaults to a single trait - CUSTOM_GOLD Using nodes with traits during testing ensures that we are exercising node traits code paths in the Ironic CI. Node traits are not used for upgrade testing, as the queens devstack plugin does not currently register traits. Once this change is backported to queens, we can enable traits during upgrade testing. Change-Id: I18b9dbf8a5b16e36e0cc14f290b12ffdd634364a Related-Bug: #1722194 Related-Bug: #1750027 --- devstack/lib/ironic | 22 +++++++++++++++++++ .../run.yaml | 3 +++ playbooks/legacy/grenade-dsvm-ironic/run.yaml | 3 +++ 3 files changed, 28 insertions(+) diff --git a/devstack/lib/ironic b/devstack/lib/ironic index 328a12a837f..dba8e482589 100644 --- a/devstack/lib/ironic +++ b/devstack/lib/ironic @@ -203,6 +203,9 @@ IRONIC_VM_LOG_ROTATE=$(trueorfalse True IRONIC_VM_LOG_ROTATE) # Set resource_classes for nodes to use Nova's placement engine IRONIC_DEFAULT_RESOURCE_CLASS=${IRONIC_DEFAULT_RESOURCE_CLASS:-baremetal} +# Set traits for nodes. Traits should be separated by whitespace. +IRONIC_DEFAULT_TRAITS=${IRONIC_DEFAULT_TRAITS-CUSTOM_GOLD} + # Whether to build the ramdisk or download a prebuilt one. IRONIC_BUILD_DEPLOY_RAMDISK=$(trueorfalse True IRONIC_BUILD_DEPLOY_RAMDISK) @@ -1646,6 +1649,17 @@ function wait_for_nova_resources { | jq ".inventories.CUSTOM_$resource_class as \$cls | (\$cls.total // 0) - (\$cls.reserved // 0)") + # Check whether the resource provider has all expected traits + # registered against it. + rp_traits=$(curl -sH "X-Auth-Token: $token" \ + -H "OpenStack-API-Version: placement 1.6" \ + $endpoint/resource_providers/$p/traits) + for trait in $IRONIC_DEFAULT_TRAITS; do + if [[ $(echo "$rp_traits" | jq ".traits | contains([\"$trait\"])") == false ]]; then + amount=0 + fi + done + if [ $amount -gt 0 ]; then count=$(( count + $amount )) fi @@ -1931,6 +1945,10 @@ function enroll_nodes { die_if_not_set $LINENO node_id "Failed to create node" node_uuids+=" $node_id" + if [[ -n $IRONIC_DEFAULT_TRAITS ]]; then + $IRONIC_CMD node add trait $node_id $IRONIC_DEFAULT_TRAITS + fi + $IRONIC_CMD node manage $node_id --wait $IRONIC_MANAGE_TIMEOUT || \ die $LINENO "Node did not reach manageable state in $IRONIC_MANAGE_TIMEOUT seconds" @@ -2011,6 +2029,10 @@ function enroll_nodes { openstack flavor set baremetal --property "capabilities:boot_mode"="uefi" fi + for trait in $IRONIC_DEFAULT_TRAITS; do + openstack flavor set baremetal --property "trait:$trait"="required" + done + # NOTE(dtantsur): sometimes nova compute fails to start with ironic due # to keystone restarting and not being able to authenticate us. # Restart it just to be sure (and avoid gate problems like bug 1537076) diff --git a/playbooks/legacy/grenade-dsvm-ironic-multinode-multitenant/run.yaml b/playbooks/legacy/grenade-dsvm-ironic-multinode-multitenant/run.yaml index a8b251db58d..771b9a5d540 100644 --- a/playbooks/legacy/grenade-dsvm-ironic-multinode-multitenant/run.yaml +++ b/playbooks/legacy/grenade-dsvm-ironic-multinode-multitenant/run.yaml @@ -135,6 +135,9 @@ cat << 'EOF' >> ironic-extra-vars export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_SPECS_RAM=384" export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_RAMDISK_TYPE=tinyipa" + # TODO(mgoddard): Remove this when the queens ironic devstack + # plugin has support for registering traits. + export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_DEFAULT_TRAITS=\"\"" EOF chdir: '{{ ansible_user_dir }}/workspace' diff --git a/playbooks/legacy/grenade-dsvm-ironic/run.yaml b/playbooks/legacy/grenade-dsvm-ironic/run.yaml index a36fcfd504d..eac5f3526c0 100644 --- a/playbooks/legacy/grenade-dsvm-ironic/run.yaml +++ b/playbooks/legacy/grenade-dsvm-ironic/run.yaml @@ -78,6 +78,9 @@ cat << 'EOF' >> ironic-extra-vars export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_SPECS_RAM=384" export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_RAMDISK_TYPE=tinyipa" + # TODO(mgoddard): Remove this when the queens ironic devstack + # plugin has support for registering traits. + export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_DEFAULT_TRAITS=\"\"" EOF chdir: '{{ ansible_user_dir }}/workspace'