Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

add value check for the vapp.update_product_section. #753

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions pyvcloud/vcd/vapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,11 +2028,17 @@ def update_product_section(self,
if class_name == class_val and instance_name == instance_val:
properties = product_section.xpath(
'ovf:Property', namespaces=NSMAP)
for prop in properties:
id = prop.get('{' + NSMAP['ovf'] + '}key')
if key == id:
prop.getparent().remove(prop)
product_section.append(property)
prop = self.find_prop(properties, key)
if prop is not None:
if hasattr(prop, "Value"):
_value = prop.Value
_value.set("{" + NSMAP["ovf"] + "}value", str(value))
else:
_value = E_OVF.Value()
_value.set("{" + NSMAP["ovf"] + "}value", str(value))
prop.append(_value)
else:
product_section.append(property)
is_updated = True
break
if not is_updated:
Expand All @@ -2052,6 +2058,13 @@ def update_product_section(self,
media_type=EntityType.PRODUCT_SECTIONS.value,
contents=product_sections_res)

def find_prop(self, properties, key):
for prop in properties:
id = prop.get("{" + NSMAP["ovf"] + "}key")
if key == id:
return prop
return

def list_vm_interface(self, network_name):
"""List vm interfaces of network.

Expand Down
26 changes: 26 additions & 0 deletions tests/vcd_vapp_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,31 @@ def test_1005_reboot_vapp(self):
callback=None)
assert task.get('status') == TaskStatus.SUCCESS.value

def test_001_update_product_section(self):
_org=self.client.get_org_by_name(org_name=self.config['vcd']['org_to_use'])
org = Org(self.client, resource=_org)
v = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, href=v.get('href'))
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
assert vapp_resource.get('name') == self.config['vcd']['vapp']
vapp = VApp(self.client, resource=vapp_resource)
key_to_be_updated = "guestinfo.ignition.config.data.encoding"
value_to_be_updated_for_key = "base64"
result = vapp.update_product_section(key=key_to_be_updated, value=value_to_be_updated_for_key, instance_name=self.config['vcd']['vm'])
task = self.client.get_task_monitor().wait_for_status(
task=result,
timeout=60,
poll_frequency=2,
fail_on_statuses=None,
expected_target_statuses=[
TaskStatus.SUCCESS,
TaskStatus.ABORTED,
TaskStatus.ERROR,
TaskStatus.CANCELED],
callback=None)
assert task.get('status') == TaskStatus.SUCCESS.value


if __name__ == '__main__':
unittest.main()