Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lxc launch ubuntu:26.04 resolute
- lxc exec resolute bash
- sudo tee /etc/apt/sources.list.d/resolute-proposed.sources >/dev/null <<'EOF'
- Types: deb
- URIs: http://archive.ubuntu.com/ubuntu
- Suites: resolute-proposed
- Components: main universe
- Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- EOF
- sudo apt update
- apt-cache policy python3-heat heat-common heat-engine
- sudo apt install heat-common=1:26.0.0-0ubuntu1.1 python3-heat=1:26.0.0-0ubuntu1.1 heat-engine=1:26.0.0-0ubuntu1.1 heat-api=1:26.0.0-0ubuntu1.1 heat-api-cfn=1:26.0.0-0ubuntu1.1
- cat > /tmp/verify-lp2114984-heat-port.py <<'PY'
- #!/usr/bin/env python3
- """Package-level verifier for LP #2114984 / Heat Neutron port updates.
- This script imports the installed python3-heat package, prints the source file
- and source body for Port.prepare_update_properties(), checks for the expected
- fix markers, then exercises the fixed behavior without requiring a real
- OpenStack deployment or SR-IOV hardware.
- """
- import inspect
- from heat.engine.resources.openstack.neutron import port
- EXPECTED_SOURCE_MARKERS = [
- "Prepare update properties with 3-way merge for binding:profile",
- "Preserve Neutron-managed fields",
- "current_attrs = self._show_resource()",
- "merged_profile = current_attrs['binding:profile'].copy()",
- "if new_val is None:",
- "merged_profile.pop(key, None)",
- ]
- class FakeProperties:
- def __init__(self, value_specs):
- self._value_specs = value_specs
- def get(self, key):
- if key == port.Port.VALUE_SPECS:
- return self._value_specs
- return None
- class FakePort:
- VALUE_SPECS = port.Port.VALUE_SPECS
- def __init__(self, before_value_specs, current_attrs):
- self.properties = FakeProperties(before_value_specs)
- self.resource_id = "fake-port-id"
- self._current_attrs = current_attrs
- def _show_resource(self):
- return self._current_attrs
- def physical_resource_name(self):
- return "fake-port"
- def verify_installed_source():
- source_file = inspect.getsourcefile(port.Port)
- source = inspect.getsource(port.Port.prepare_update_properties)
- print("Installed Heat Port class source file:")
- print(source_file)
- print()
- print("Installed Port.prepare_update_properties source:")
- print(source)
- missing = [marker for marker in EXPECTED_SOURCE_MARKERS if marker not in source]
- if missing:
- raise AssertionError(
- "installed python3-heat is missing expected LP #2114984 source "
- "markers: %r" % missing
- )
- def run_preserve_auto_populated_fields_case():
- fake = FakePort(
- before_value_specs={
- "binding:profile": {
- "trusted": True,
- },
- },
- current_attrs={
- "binding:profile": {
- "trusted": True,
- "pci_slot": "0000:86:00.1",
- "physical_network": "physnet1",
- "allocation": "auto",
- },
- },
- )
- prop_diff = {
- "value_specs": {
- "binding:profile": {
- "trusted": False,
- },
- },
- }
- port.Port.prepare_update_properties(fake, prop_diff)
- expected = {
- "binding:profile": {
- "trusted": False,
- "pci_slot": "0000:86:00.1",
- "physical_network": "physnet1",
- "allocation": "auto",
- },
- }
- assert prop_diff == expected, (
- "auto-populated binding:profile fields were not preserved\n"
- "expected: %r\n"
- "actual: %r" % (expected, prop_diff)
- )
- def run_null_deletes_user_managed_key_case():
- fake = FakePort(
- before_value_specs={
- "binding:profile": {
- "trusted": True,
- "delete_me": "old-value",
- },
- },
- current_attrs={
- "binding:profile": {
- "trusted": True,
- "delete_me": "old-value",
- "pci_slot": "0000:86:00.1",
- "physical_network": "physnet1",
- },
- },
- )
- prop_diff = {
- "value_specs": {
- "binding:profile": {
- "delete_me": None,
- },
- },
- }
- port.Port.prepare_update_properties(fake, prop_diff)
- expected = {
- "binding:profile": {
- "trusted": True,
- "pci_slot": "0000:86:00.1",
- "physical_network": "physnet1",
- },
- }
- assert prop_diff == expected, (
- "null did not delete only the user-managed key while preserving live fields\n"
- "expected: %r\n"
- "actual: %r" % (expected, prop_diff)
- )
- def main():
- verify_installed_source()
- run_preserve_auto_populated_fields_case()
- run_null_deletes_user_managed_key_case()
- print("PASS: LP #2114984 package-level source and behavior verified")
- if __name__ == "__main__":
- main()
- PY
- chmod +x /tmp/verify-lp2114984-heat-port.py
- root@resolute:~# python3 /tmp/verify-lp2114984-heat-port.py
- Installed Heat Port class source file:
- /usr/lib/python3/dist-packages/heat/engine/resources/openstack/neutron/port.py
- Installed Port.prepare_update_properties source:
- def prepare_update_properties(self, prop_diff):
- """Prepare update properties with 3-way merge for binding:profile.
- Preserve Neutron-managed fields (e.g. SR-IOV pci_slot) on update.
- """
- if 'value_specs' in prop_diff:
- before_value_specs = self.properties.get(self.VALUE_SPECS)
- if ('binding:profile' in prop_diff['value_specs'] and
- self.resource_id):
- current_attrs = self._show_resource()
- if current_attrs and 'binding:profile' in current_attrs:
- old_profile = (before_value_specs or {}).get(
- 'binding:profile', {})
- new_profile = prop_diff['value_specs']['binding:profile']
- merged_profile = current_attrs['binding:profile'].copy()
- for key, new_val in new_profile.items():
- if new_val != old_profile.get(key):
- if new_val is None:
- merged_profile.pop(key, None)
- else:
- merged_profile[key] = new_val
- prop_diff['value_specs']['binding:profile'] = (
- merged_profile)
- if (before_value_specs and
- 'binding:profile' in before_value_specs):
- # Exclude binding:profile to avoid
- # merge_value_specs overriding merged result.
- before_value_specs = {
- k: v for k, v in before_value_specs.items()
- if k != 'binding:profile'
- }
- neutron.NeutronResource.merge_value_specs(
- prop_diff, before_value_specs)
- if 'name' in prop_diff and prop_diff['name'] is None:
- prop_diff['name'] = self.physical_resource_name()
- PASS: LP #2114984 package-level source and behavior verified
Advertisement