Public bug reported: HypervisorsController._view_hypervisor only sets hypervisor['servers'] when servers passed in is non empty list (if servers:). Instead it should check to see if servers is not passed in (if not None:).
The reason why this is useful is that currently novaclient would return a Resource object with no servers attribute set, because it only deserializes what the API returns. Therefore, when using the novaclient to get hypervisor servers, it requires an additional hasattr(hypervisor, 'servers') check. This is a pretty standard convention for any API that is expected to return a list to return an empty list to indicate that there is no item. Git version: 02b7e64b29dd707c637ea7026d337e5cb196f337v Reproduce steps: 1. Have a hypervisor with no instances on it. 2. Call any API that is expected to return hypervisor object that also return the instances in it. 2.1. This API should indirectly call HypervisorsController._view_hypervisor and pass the servers argument. i.e. HypervisorsController.servers 3. Notice that for hypervisor with instances, the hypervisor object has a list of servers set. While the hypervisor that does not have any instances, it would not have the servers attribute set at all. ** Affects: nova Importance: Undecided Status: New ** Summary changed: - os-hypervisors servers API does not properly handle hypervisor with no instance. + os-hypervisors servers API does not properly serialize hypervisor with no instance. ** Description changed: HypervisorsController._view_hypervisor only sets hypervisor['servers'] when servers passed in is non empty list (if servers:). Instead it should check to see if servers is not passed in (if not None:). The reason why this is useful is that currently novaclient would return a Resource object with no servers attribute set, because it only deserializes what the API returns. Therefore, when using the novaclient to get hypervisor servers, it requires an additional hasattr(hypervisor, 'servers') check. This is a pretty standard convention for any API that is expected to return a list to return an empty list to indicate that there is no item. Git version: 02b7e64b29dd707c637ea7026d337e5cb196f337v Reproduce steps: 1. Have a hypervisor with no instances on it. - 2. Call any API is expected to return hypervisor object that also return the instances in it. + 2. Call any API that is expected to return hypervisor object that also return the instances in it. 2.1. This API should indirectly call HypervisorsController._view_hypervisor and pass the servers argument. i.e. HypervisorsController.servers - 3. Notice that for hypervisor with instances, the hypervisor object has a list of servers set. While the hypervisor that does not have any instances, it would have no the servers attribute set at all. + 3. Notice that for hypervisor with instances, the hypervisor object has a list of servers set. While the hypervisor that does not have any instances, it would not have the servers attribute set at all. -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to OpenStack Compute (nova). https://bugs.launchpad.net/bugs/1505434 Title: os-hypervisors servers API does not properly serialize hypervisor with no instance. Status in OpenStack Compute (nova): New Bug description: HypervisorsController._view_hypervisor only sets hypervisor['servers'] when servers passed in is non empty list (if servers:). Instead it should check to see if servers is not passed in (if not None:). The reason why this is useful is that currently novaclient would return a Resource object with no servers attribute set, because it only deserializes what the API returns. Therefore, when using the novaclient to get hypervisor servers, it requires an additional hasattr(hypervisor, 'servers') check. This is a pretty standard convention for any API that is expected to return a list to return an empty list to indicate that there is no item. Git version: 02b7e64b29dd707c637ea7026d337e5cb196f337v Reproduce steps: 1. Have a hypervisor with no instances on it. 2. Call any API that is expected to return hypervisor object that also return the instances in it. 2.1. This API should indirectly call HypervisorsController._view_hypervisor and pass the servers argument. i.e. HypervisorsController.servers 3. Notice that for hypervisor with instances, the hypervisor object has a list of servers set. While the hypervisor that does not have any instances, it would not have the servers attribute set at all. To manage notifications about this bug go to: https://bugs.launchpad.net/nova/+bug/1505434/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : yahoo-eng-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp