_call_method should raise exception instead of returning None

Bug #1410160 reported by xhzhf
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.vmware
Opinion
Undecided
xhzhf

Bug Description

classic scenario:
def power_on_instance(session, instance, vm_ref=None):
    """Power on the specified instance."""

   if vm_ref is None:
        vm_ref = get_vm_ref(session, instance)

    LOG.debug("Powering on the VM", instance=instance)
    try:
        poweron_task = session._call_method(
                                    session._get_vim(),
                                    "PowerOnVM_Task", vm_ref)
        session._wait_for_task(poweron_task)
        LOG.debug("Powered on the VM", instance=instance)
    except vexc.InvalidPowerStateException:
        LOG.debug("VM already powered on", instance=instance)

if get_vm_ref return None, then PowerOnVM_Task execute with vm_ref None。 After that, _wait_for_task throw exception AttributeError: 'NoneType' object has no attribute 'state'。 It is hard to resolve problem according to the hint。

solution:
    we modify __getattr__() in the oslo.vmware.service.py.
    if not managed_object: return ====> raise ValueError(_('managed object is None'))

Tags: oslo vmware
xhzhf (guoyongxhzhf)
Changed in oslo.vmware:
assignee: nobody → xhzhf (guoyongxhzhf)
status: New → Confirmed
Revision history for this message
Gary Kotton (garyk) wrote :

Hi,
The get_vm_ref should throw an exception and not return None.
Can you please indicate how I can reproduce this.
Thanks
Gary

Revision history for this message
Sabari Murugesan (smurugesan) wrote :

I agree with Gary, get_vm_ref should throw an exception or check the vm_ref before powering on. Either looks fine. I think the bug should belong with Nova.

Changed in oslo.vmware:
status: Confirmed → Opinion
summary: - _call_method raise exception instead returning None
+ _call_method should raise exception instead returning None
summary: - _call_method should raise exception instead returning None
+ _call_method should raise exception instead of returning None
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.