Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # SRU verification for LP #2114984 (heat: preserve auto-populated
- # binding:profile fields during port update).
- #
- # Run as root inside a FRESH Ubuntu 26.04 (resolute) container or VM.
- # It installs keystone, neutron-api and heat only. Nova, a compute node
- # and a real SR-IOV NIC are not needed: binding:profile is a plain dict
- # on the neutron side as long as the port has no binding:host_id, and the
- # bug lives entirely in heat's merge logic.
- #
- # The script reproduces the bug on the release package first, then
- # upgrades to -proposed and checks that the fix holds. Every step asserts
- # the resulting binding_profile, so a silent regression cannot pass.
- #
- # bash verify-2114984.sh
- #
- set -euo pipefail
- ADMIN_PASS=ADMIN_PASS
- KEYSTONE_DBPASS=KEYSTONE_DBPASS
- NEUTRON_PASS=NEUTRON_PASS
- NEUTRON_DBPASS=NEUTRON_DBPASS
- HEAT_PASS=HEAT_PASS
- HEAT_DBPASS=HEAT_DBPASS
- HEAT_DOMAIN_PASS=HEAT_DOMAIN_PASS
- RABBIT_PASS=RABBIT_PASS
- SERIES=$(lsb_release -cs)
- STACK=sriov-port-stack
- PORT=heat-sriov-port1
- NET=sriov_net
- TPL=/root/tpl
- LOG=/root/verify-2114984-$(date +%Y%m%d-%H%M%S).log
- export DEBIAN_FRONTEND=noninteractive
- exec > >(tee -a "$LOG") 2>&1
- # Without this, "set -e" aborts with no output at all and the run looks
- # like a hang rather than a failure.
- trap 'echo "ERROR: line ${LINENO} exited with status $?"' ERR
- banner() { echo; echo "==================== $* ===================="; }
- # Compare two compact JSON strings and abort on mismatch.
- assert_eq() {
- local expected=$1 actual=$2 label=$3
- if [ "$expected" = "$actual" ]; then
- echo "PASS $label"
- else
- echo "FAIL $label"
- echo " expected: $expected"
- echo " actual: $actual"
- exit 1
- fi
- }
- profile() { openstack port show "$PORT" -f json | jq -Sc '.binding_profile'; }
- # The seven fields a real deployment would get auto-populated by nova.
- FULL='{"capabilities":["switchdev"],"card_serial_number":"MT2234420968","pci_slot":"0000:04:00.2","pci_vendor_info":"15b3:1016","pf_mac_address":"1e:38:96:af:a0:55","physical_network":"physnet1","vf_num":"1"}'
- FULL_SPOOF=$(jq -Sc '. + {spoof:"true"}' <<<"$FULL")
- BUGGY='{"spoof":"true"}'
- MULTI=$(jq -Sc '. + {spoof:"true", vf_num:"0"}' <<<"$FULL")
- banner "1. enable ${SERIES}-proposed, pinned so nothing upgrades by accident"
- cat > /etc/apt/sources.list.d/${SERIES}-proposed.sources <<EOF
- Types: deb
- URIs: http://archive.ubuntu.com/ubuntu
- Suites: ${SERIES}-proposed
- Components: main restricted universe multiverse
- Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- EOF
- # Priority 400 keeps -proposed visible but never auto-selected. Only an
- # explicit "apt install pkg=version" pulls from it.
- cat > /etc/apt/preferences.d/${SERIES}-proposed-pin <<EOF
- Package: *
- Pin: release a=${SERIES}-proposed
- Pin-Priority: 400
- EOF
- apt-get update -qq
- banner "2. base services"
- apt-get install -y -qq mysql-server rabbitmq-server memcached \
- python3-openstackclient python3-heatclient jq crudini >/dev/null
- # Tolerate an existing user so the script can be re-run against a container
- # that already got this far. Piping into "grep -q" instead would send
- # SIGPIPE upstream and trip pipefail.
- rabbitmqctl add_user openstack "$RABBIT_PASS" || true
- rabbitmqctl set_permissions openstack ".*" ".*" ".*"
- # MySQL 8 wants CREATE USER and GRANT as separate statements. The old
- # "GRANT ... IDENTIFIED BY" form from the OpenStack install guide is a
- # syntax error here.
- mysql <<EOF
- CREATE DATABASE IF NOT EXISTS keystone;
- CREATE DATABASE IF NOT EXISTS neutron;
- CREATE DATABASE IF NOT EXISTS heat;
- CREATE USER IF NOT EXISTS 'keystone'@'localhost' IDENTIFIED BY '${KEYSTONE_DBPASS}';
- CREATE USER IF NOT EXISTS 'neutron'@'localhost' IDENTIFIED BY '${NEUTRON_DBPASS}';
- CREATE USER IF NOT EXISTS 'heat'@'localhost' IDENTIFIED BY '${HEAT_DBPASS}';
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost';
- GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost';
- GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'localhost';
- FLUSH PRIVILEGES;
- EOF
- banner "3. keystone"
- apt-get install -y -qq keystone >/dev/null
- crudini --set /etc/keystone/keystone.conf database connection \
- "mysql+pymysql://keystone:${KEYSTONE_DBPASS}@localhost/keystone"
- crudini --set /etc/keystone/keystone.conf token provider fernet
- su -s /bin/sh -c "keystone-manage db_sync" keystone
- keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
- keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
- keystone-manage bootstrap \
- --bootstrap-password "$ADMIN_PASS" \
- --bootstrap-admin-url http://localhost:5000/v3/ \
- --bootstrap-internal-url http://localhost:5000/v3/ \
- --bootstrap-public-url http://localhost:5000/v3/ \
- --bootstrap-region-id RegionOne
- grep -q '^ServerName' /etc/apache2/apache2.conf || echo "ServerName $(hostname)" >> /etc/apache2/apache2.conf
- systemctl restart apache2
- cat > /root/admin-openrc <<EOF
- export OS_USERNAME=admin
- export OS_PASSWORD=${ADMIN_PASS}
- export OS_PROJECT_NAME=admin
- export OS_USER_DOMAIN_NAME=Default
- export OS_PROJECT_DOMAIN_NAME=Default
- export OS_AUTH_URL=http://localhost:5000/v3
- export OS_IDENTITY_API_VERSION=3
- EOF
- source /root/admin-openrc
- openstack project show service >/dev/null 2>&1 || openstack project create --domain default service
- openstack token issue -f value -c expires
- banner "4. neutron: API only, no L2 agent"
- apt-get install -y -qq neutron-server neutron-plugin-ml2 >/dev/null
- openstack user show neutron >/dev/null 2>&1 || \
- openstack user create --domain default --password "$NEUTRON_PASS" neutron
- openstack role add --project service --user neutron admin
- openstack service show neutron >/dev/null 2>&1 || \
- openstack service create --name neutron --description "OpenStack Networking" network
- for i in public internal admin; do
- openstack endpoint create --region RegionOne network $i http://localhost:9696 >/dev/null
- done
- nc=/etc/neutron/neutron.conf
- crudini --set $nc database connection "mysql+pymysql://neutron:${NEUTRON_DBPASS}@localhost/neutron"
- crudini --set $nc DEFAULT core_plugin ml2
- crudini --set $nc DEFAULT service_plugins ""
- crudini --set $nc DEFAULT transport_url "rabbit://openstack:${RABBIT_PASS}@localhost"
- crudini --set $nc DEFAULT auth_strategy keystone
- crudini --set $nc DEFAULT notify_nova_on_port_status_changes false
- crudini --set $nc DEFAULT notify_nova_on_port_data_changes false
- crudini --set $nc keystone_authtoken www_authenticate_uri http://localhost:5000
- crudini --set $nc keystone_authtoken auth_url http://localhost:5000
- crudini --set $nc keystone_authtoken memcached_servers localhost:11211
- crudini --set $nc keystone_authtoken auth_type password
- crudini --set $nc keystone_authtoken project_domain_name Default
- crudini --set $nc keystone_authtoken user_domain_name Default
- crudini --set $nc keystone_authtoken project_name service
- crudini --set $nc keystone_authtoken username neutron
- crudini --set $nc keystone_authtoken password "$NEUTRON_PASS"
- crudini --set $nc oslo_concurrency lock_path /var/lib/neutron/tmp
- # "local" networks need no physical NIC and no flat_networks mapping. The
- # openvswitch mechanism driver never runs because our ports carry no
- # binding:host_id, so they stay unbound with status DOWN. That is fine.
- cat > /etc/neutron/plugins/ml2/ml2_conf.ini <<'EOF'
- [ml2]
- type_drivers = local
- tenant_network_types = local
- mechanism_drivers = openvswitch
- extension_drivers = port_security
- EOF
- ln -sf /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
- mkdir -p /var/lib/neutron/tmp && chown neutron:neutron /var/lib/neutron/tmp
- su -s /bin/sh -c "neutron-db-manage --config-file $nc --config-file /etc/neutron/plugin.ini upgrade head" neutron >/dev/null
- # On resolute there is no neutron-server.service any more. The API runs
- # under apache mod_wsgi and the rest are separate units.
- systemctl restart apache2
- systemctl restart neutron-rpc-server neutron-periodic-workers
- sleep 5
- openstack network list >/dev/null
- echo "neutron API is up"
- banner "5. grant the 'service' role to admin"
- # neutron 28.0.0 ships enforce_new_defaults=True and moved
- # create/update_port:binding:profile to rule:service_api (role:service).
- # admin alone is refused. Heat creates the port through a keystone trust,
- # and a trust delegates the trustor's roles, so giving admin the service
- # role is enough. On jammy and noble this rule was still admin_only.
- openstack role show service >/dev/null 2>&1 || openstack role create service
- openstack role add --project admin --user admin service
- openstack role assignment list --user admin --project admin --names -f value -c Role
- banner "6. heat, release version (the buggy one)"
- apt-get install -y -qq heat-api heat-api-cfn heat-engine >/dev/null
- apt-cache policy heat-engine | sed -n '1,3p'
- openstack user show heat >/dev/null 2>&1 || \
- openstack user create --domain default --password "$HEAT_PASS" heat
- openstack role add --project service --user heat admin
- openstack service show heat >/dev/null 2>&1 || \
- openstack service create --name heat --description "Orchestration" orchestration
- openstack service show heat-cfn >/dev/null 2>&1 || \
- openstack service create --name heat-cfn --description "Orchestration" cloudformation
- for i in public internal admin; do
- openstack endpoint create --region RegionOne orchestration $i 'http://localhost:8004/v1/%(tenant_id)s' >/dev/null
- openstack endpoint create --region RegionOne cloudformation $i 'http://localhost:8000/v1' >/dev/null
- done
- openstack domain show heat >/dev/null 2>&1 || \
- openstack domain create --description "Stack projects and users" heat
- openstack user show --domain heat heat_domain_admin >/dev/null 2>&1 || \
- openstack user create --domain heat --password "$HEAT_DOMAIN_PASS" heat_domain_admin
- openstack role add --domain heat --user-domain heat --user heat_domain_admin admin
- openstack role show service >/dev/null 2>&1 || openstack role create service
- openstack role show heat_stack_owner >/dev/null 2>&1 || openstack role create heat_stack_owner
- openstack role show heat_stack_user >/dev/null 2>&1 || openstack role create heat_stack_user
- openstack role add --project admin --user admin heat_stack_owner
- hc=/etc/heat/heat.conf
- crudini --set $hc database connection "mysql+pymysql://heat:${HEAT_DBPASS}@localhost/heat"
- crudini --set $hc DEFAULT transport_url "rabbit://openstack:${RABBIT_PASS}@localhost"
- crudini --set $hc DEFAULT heat_metadata_server_url http://localhost:8000
- crudini --set $hc DEFAULT heat_waitcondition_server_url http://localhost:8000/v1/waitcondition
- crudini --set $hc DEFAULT stack_domain_admin heat_domain_admin
- crudini --set $hc DEFAULT stack_domain_admin_password "$HEAT_DOMAIN_PASS"
- crudini --set $hc DEFAULT stack_user_domain_name heat
- crudini --set $hc DEFAULT num_engine_workers 1
- crudini --set $hc keystone_authtoken www_authenticate_uri http://localhost:5000
- crudini --set $hc keystone_authtoken auth_url http://localhost:5000
- crudini --set $hc keystone_authtoken memcached_servers localhost:11211
- crudini --set $hc keystone_authtoken auth_type password
- crudini --set $hc keystone_authtoken project_domain_name Default
- crudini --set $hc keystone_authtoken user_domain_name Default
- crudini --set $hc keystone_authtoken project_name service
- crudini --set $hc keystone_authtoken username heat
- crudini --set $hc keystone_authtoken password "$HEAT_PASS"
- crudini --set $hc trustee auth_type password
- crudini --set $hc trustee auth_url http://localhost:5000
- crudini --set $hc trustee username heat
- crudini --set $hc trustee password "$HEAT_PASS"
- crudini --set $hc trustee user_domain_name Default
- crudini --set $hc clients_keystone auth_uri http://localhost:5000
- su -s /bin/sh -c "heat-manage db_sync" heat >/dev/null
- # heat-api and heat-api-cfn also run under apache now, but the shipped
- # vhost points at /usr/bin/heat-api, which no package installs. The real
- # entry points are heat-wsgi-api and heat-wsgi-api-cfn from python3-heat.
- # Without this every heat request returns 404. Separate resolute
- # packaging bug, unrelated to LP #2114984.
- fix_heat_wsgi_alias() {
- sed -i 's#WSGIScriptAlias / /usr/bin/heat-api$#WSGIScriptAlias / /usr/bin/heat-wsgi-api#' \
- /etc/apache2/sites-available/heat-api.conf
- sed -i 's#WSGIScriptAlias / /usr/bin/heat-api-cfn$#WSGIScriptAlias / /usr/bin/heat-wsgi-api-cfn#' \
- /etc/apache2/sites-available/heat-api-cfn.conf
- }
- fix_heat_wsgi_alias
- grep -h WSGIScriptAlias /etc/apache2/sites-available/heat-api*.conf
- systemctl restart apache2 heat-engine
- sleep 5
- openstack stack list >/dev/null
- echo "heat API is up"
- banner "7. templates"
- mkdir -p $TPL
- # network is a required property of OS::Neutron::Port.
- # binding:vnic_type is a schema property, so it must sit under properties.
- # NeutronResource.validate_properties() rejects any schema key placed in
- # value_specs. binding:profile is not a schema property, which is why it
- # can only travel through value_specs, and why the bug lives there.
- cat > $TPL/00-create.yaml <<EOF
- heat_template_version: 2015-10-15
- parameters:
- sriov_net: { type: string, default: ${NET} }
- resources:
- sriov_port:
- type: OS::Neutron::Port
- properties:
- name: ${PORT}
- network: { get_param: sriov_net }
- binding:vnic_type: direct
- value_specs:
- binding:profile:
- capabilities: ["switchdev"]
- card_serial_number: "MT2234420968"
- pci_slot: "0000:04:00.2"
- pci_vendor_info: "15b3:1016"
- pf_mac_address: "1e:38:96:af:a0:55"
- physical_network: "physnet1"
- vf_num: "1"
- EOF
- # Mentions only "spoof". A correct heat keeps the other seven fields.
- cat > $TPL/01-add-spoof.yaml <<EOF
- heat_template_version: 2015-10-15
- parameters:
- sriov_net: { type: string, default: ${NET} }
- resources:
- sriov_port:
- type: OS::Neutron::Port
- properties:
- name: ${PORT}
- network: { get_param: sriov_net }
- binding:vnic_type: direct
- value_specs:
- binding:profile:
- spoof: "true"
- EOF
- cat > $TPL/02-del-spoof.yaml <<EOF
- heat_template_version: 2015-10-15
- parameters:
- sriov_net: { type: string, default: ${NET} }
- resources:
- sriov_port:
- type: OS::Neutron::Port
- properties:
- name: ${PORT}
- network: { get_param: sriov_net }
- binding:vnic_type: direct
- value_specs:
- binding:profile:
- spoof: null
- EOF
- cat > $TPL/03-multi.yaml <<EOF
- heat_template_version: 2015-10-15
- parameters:
- sriov_net: { type: string, default: ${NET} }
- resources:
- sriov_port:
- type: OS::Neutron::Port
- properties:
- name: ${PORT}
- network: { get_param: sriov_net }
- binding:vnic_type: direct
- value_specs:
- binding:profile:
- vf_num: '0'
- spoof: 'true'
- card_serial_number: null
- EOF
- cat > $TPL/04-restore.yaml <<EOF
- heat_template_version: 2015-10-15
- parameters:
- sriov_net: { type: string, default: ${NET} }
- resources:
- sriov_port:
- type: OS::Neutron::Port
- properties:
- name: ${PORT}
- network: { get_param: sriov_net }
- binding:vnic_type: direct
- value_specs:
- binding:profile:
- capabilities: ["switchdev"]
- card_serial_number: "MT2234420968"
- pci_slot: "0000:04:00.2"
- pci_vendor_info: "15b3:1016"
- pf_mac_address: "1e:38:96:af:a0:55"
- physical_network: "physnet1"
- vf_num: "1"
- spoof: null
- EOF
- openstack network show $NET >/dev/null 2>&1 || openstack network create $NET -f value -c name
- banner "8. reproduce the bug on the release package"
- apt-cache policy heat-engine | sed -n '2p'
- openstack stack create -t $TPL/00-create.yaml $STACK --wait >/dev/null
- assert_eq "$FULL" "$(profile)" "release: profile after create has all seven fields"
- openstack stack update -t $TPL/01-add-spoof.yaml $STACK --wait >/dev/null
- assert_eq "$BUGGY" "$(profile)" "release: profile collapses to spoof only (bug reproduced)"
- banner "9. upgrade to -proposed"
- # awk must read madison to the end. An early "exit" would SIGPIPE apt-cache,
- # and pipefail plus set -e would then kill this script without a word.
- PROPOSED_VER=$(apt-cache madison heat-engine |
- awk -v s="${SERIES}-proposed" '$0 ~ s && !v {v=$3} END {print v}')
- [ -n "$PROPOSED_VER" ] || { echo "no heat-engine in ${SERIES}-proposed"; exit 1; }
- echo "installing heat ${PROPOSED_VER}"
- openstack stack delete -y --wait $STACK >/dev/null
- apt-get install -y -qq -o Dpkg::Options::="--force-confold" \
- heat-common="$PROPOSED_VER" python3-heat="$PROPOSED_VER" heat-engine="$PROPOSED_VER" \
- heat-api="$PROPOSED_VER" heat-api-cfn="$PROPOSED_VER" >/dev/null
- apt-cache policy heat-engine | sed -n '1,3p'
- grep -n "def prepare_update_properties" \
- /usr/lib/python3/dist-packages/heat/engine/resources/openstack/neutron/port.py
- fix_heat_wsgi_alias
- systemctl restart apache2 heat-engine
- sleep 5
- banner "10. confirm the fix"
- openstack stack create -t $TPL/00-create.yaml $STACK --wait >/dev/null
- assert_eq "$FULL" "$(profile)" "proposed: profile after create has all seven fields"
- openstack stack update -t $TPL/01-add-spoof.yaml $STACK --wait >/dev/null
- assert_eq "$FULL_SPOOF" "$(profile)" "proposed: seven fields preserved, spoof added"
- banner "11. remaining cases from the test plan"
- openstack stack update -t $TPL/01-add-spoof.yaml $STACK --wait >/dev/null
- assert_eq "$FULL_SPOOF" "$(profile)" "idempotent: re-running the same template changes nothing"
- openstack stack update -t $TPL/02-del-spoof.yaml $STACK --wait >/dev/null
- assert_eq "$FULL" "$(profile)" "spoof: null removes only spoof"
- # card_serial_number survives here. The previous template had no such key,
- # so its old value is None and the new value is null. The three way merge
- # treats an unchanged key as untouched and keeps whatever the API holds.
- # noble recorded the same behaviour.
- openstack stack update -t $TPL/03-multi.yaml $STACK --wait >/dev/null
- assert_eq "$MULTI" "$(profile)" "multi change: vf_num=0, spoof added, card_serial_number kept"
- openstack stack update -t $TPL/04-restore.yaml $STACK --wait >/dev/null
- assert_eq "$FULL" "$(profile)" "restore: back to the original seven fields"
- echo
- echo "-- neutron API down: the update must fail"
- a2dissite neutron-api >/dev/null
- systemctl reload apache2
- sleep 3
- if openstack stack update -t $TPL/01-add-spoof.yaml $STACK --wait >/dev/null 2>&1; then
- echo "FAIL update succeeded while neutron was down"
- exit 1
- fi
- echo "PASS update failed while neutron was down"
- echo
- echo "-- neutron API back: the same update must succeed"
- a2ensite neutron-api >/dev/null
- systemctl reload apache2
- sleep 5
- openstack stack update -t $TPL/01-add-spoof.yaml $STACK --wait >/dev/null
- assert_eq "$FULL_SPOOF" "$(profile)" "recovery: same update completes after neutron returns"
- banner "summary"
- lsb_release -ds
- dpkg -l | awk '/^ii +(heat-|python3-heat |neutron-|keystone )/ {printf "%-28s %s\n", $2, $3}'
- echo
- echo "stack status: $(openstack stack show $STACK -f value -c stack_status)"
- echo "final binding_profile: $(profile)"
- echo
- echo "ALL CHECKS PASSED"
- echo "log: $LOG"
Advertisement