zhhuabj

Untitled

Jul 9th, 2026
67
0
228 days
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. lxc launch ubuntu:26.04 resolute
  2. lxc exec resolute bash
  3. sudo tee /etc/apt/sources.list.d/resolute-proposed.sources >/dev/null <<'EOF'
  4. Types: deb
  5. URIs: http://archive.ubuntu.com/ubuntu
  6. Suites: resolute-proposed
  7. Components: main universe
  8. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  9. EOF
  10. sudo apt update
  11. apt-cache policy python3-heat heat-common heat-engine
  12. 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
  13.  
  14.  
  15. cat > /tmp/verify-lp2114984-heat-port.py <<'PY'
  16. #!/usr/bin/env python3
  17. """Package-level verifier for LP #2114984 / Heat Neutron port updates.
  18.  
  19. This script imports the installed python3-heat package, prints the source file
  20. and source body for Port.prepare_update_properties(), checks for the expected
  21. fix markers, then exercises the fixed behavior without requiring a real
  22. OpenStack deployment or SR-IOV hardware.
  23. """
  24.  
  25. import inspect
  26.  
  27. from heat.engine.resources.openstack.neutron import port
  28.  
  29.  
  30. EXPECTED_SOURCE_MARKERS = [
  31. "Prepare update properties with 3-way merge for binding:profile",
  32. "Preserve Neutron-managed fields",
  33. "current_attrs = self._show_resource()",
  34. "merged_profile = current_attrs['binding:profile'].copy()",
  35. "if new_val is None:",
  36. "merged_profile.pop(key, None)",
  37. ]
  38.  
  39.  
  40. class FakeProperties:
  41. def __init__(self, value_specs):
  42. self._value_specs = value_specs
  43.  
  44. def get(self, key):
  45. if key == port.Port.VALUE_SPECS:
  46. return self._value_specs
  47. return None
  48.  
  49.  
  50. class FakePort:
  51. VALUE_SPECS = port.Port.VALUE_SPECS
  52.  
  53. def __init__(self, before_value_specs, current_attrs):
  54. self.properties = FakeProperties(before_value_specs)
  55. self.resource_id = "fake-port-id"
  56. self._current_attrs = current_attrs
  57.  
  58. def _show_resource(self):
  59. return self._current_attrs
  60.  
  61. def physical_resource_name(self):
  62. return "fake-port"
  63.  
  64.  
  65. def verify_installed_source():
  66. source_file = inspect.getsourcefile(port.Port)
  67. source = inspect.getsource(port.Port.prepare_update_properties)
  68.  
  69. print("Installed Heat Port class source file:")
  70. print(source_file)
  71. print()
  72. print("Installed Port.prepare_update_properties source:")
  73. print(source)
  74.  
  75. missing = [marker for marker in EXPECTED_SOURCE_MARKERS if marker not in source]
  76. if missing:
  77. raise AssertionError(
  78. "installed python3-heat is missing expected LP #2114984 source "
  79. "markers: %r" % missing
  80. )
  81.  
  82.  
  83. def run_preserve_auto_populated_fields_case():
  84. fake = FakePort(
  85. before_value_specs={
  86. "binding:profile": {
  87. "trusted": True,
  88. },
  89. },
  90. current_attrs={
  91. "binding:profile": {
  92. "trusted": True,
  93. "pci_slot": "0000:86:00.1",
  94. "physical_network": "physnet1",
  95. "allocation": "auto",
  96. },
  97. },
  98. )
  99.  
  100. prop_diff = {
  101. "value_specs": {
  102. "binding:profile": {
  103. "trusted": False,
  104. },
  105. },
  106. }
  107.  
  108. port.Port.prepare_update_properties(fake, prop_diff)
  109.  
  110. expected = {
  111. "binding:profile": {
  112. "trusted": False,
  113. "pci_slot": "0000:86:00.1",
  114. "physical_network": "physnet1",
  115. "allocation": "auto",
  116. },
  117. }
  118.  
  119. assert prop_diff == expected, (
  120. "auto-populated binding:profile fields were not preserved\n"
  121. "expected: %r\n"
  122. "actual: %r" % (expected, prop_diff)
  123. )
  124.  
  125.  
  126. def run_null_deletes_user_managed_key_case():
  127. fake = FakePort(
  128. before_value_specs={
  129. "binding:profile": {
  130. "trusted": True,
  131. "delete_me": "old-value",
  132. },
  133. },
  134. current_attrs={
  135. "binding:profile": {
  136. "trusted": True,
  137. "delete_me": "old-value",
  138. "pci_slot": "0000:86:00.1",
  139. "physical_network": "physnet1",
  140. },
  141. },
  142. )
  143.  
  144. prop_diff = {
  145. "value_specs": {
  146. "binding:profile": {
  147. "delete_me": None,
  148. },
  149. },
  150. }
  151.  
  152. port.Port.prepare_update_properties(fake, prop_diff)
  153.  
  154. expected = {
  155. "binding:profile": {
  156. "trusted": True,
  157. "pci_slot": "0000:86:00.1",
  158. "physical_network": "physnet1",
  159. },
  160. }
  161.  
  162. assert prop_diff == expected, (
  163. "null did not delete only the user-managed key while preserving live fields\n"
  164. "expected: %r\n"
  165. "actual: %r" % (expected, prop_diff)
  166. )
  167.  
  168.  
  169. def main():
  170. verify_installed_source()
  171. run_preserve_auto_populated_fields_case()
  172. run_null_deletes_user_managed_key_case()
  173. print("PASS: LP #2114984 package-level source and behavior verified")
  174.  
  175.  
  176. if __name__ == "__main__":
  177. main()
  178. PY
  179.  
  180. chmod +x /tmp/verify-lp2114984-heat-port.py
  181.  
  182.  
  183. root@resolute:~# python3 /tmp/verify-lp2114984-heat-port.py
  184. Installed Heat Port class source file:
  185. /usr/lib/python3/dist-packages/heat/engine/resources/openstack/neutron/port.py
  186.  
  187. Installed Port.prepare_update_properties source:
  188. def prepare_update_properties(self, prop_diff):
  189. """Prepare update properties with 3-way merge for binding:profile.
  190.  
  191. Preserve Neutron-managed fields (e.g. SR-IOV pci_slot) on update.
  192. """
  193. if 'value_specs' in prop_diff:
  194. before_value_specs = self.properties.get(self.VALUE_SPECS)
  195.  
  196. if ('binding:profile' in prop_diff['value_specs'] and
  197. self.resource_id):
  198. current_attrs = self._show_resource()
  199. if current_attrs and 'binding:profile' in current_attrs:
  200. old_profile = (before_value_specs or {}).get(
  201. 'binding:profile', {})
  202. new_profile = prop_diff['value_specs']['binding:profile']
  203. merged_profile = current_attrs['binding:profile'].copy()
  204.  
  205. for key, new_val in new_profile.items():
  206. if new_val != old_profile.get(key):
  207. if new_val is None:
  208. merged_profile.pop(key, None)
  209. else:
  210. merged_profile[key] = new_val
  211.  
  212. prop_diff['value_specs']['binding:profile'] = (
  213. merged_profile)
  214. if (before_value_specs and
  215. 'binding:profile' in before_value_specs):
  216. # Exclude binding:profile to avoid
  217. # merge_value_specs overriding merged result.
  218. before_value_specs = {
  219. k: v for k, v in before_value_specs.items()
  220. if k != 'binding:profile'
  221. }
  222.  
  223. neutron.NeutronResource.merge_value_specs(
  224. prop_diff, before_value_specs)
  225. if 'name' in prop_diff and prop_diff['name'] is None:
  226. prop_diff['name'] = self.physical_resource_name()
  227.  
  228. PASS: LP #2114984 package-level source and behavior verified
  229.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment