Heal and optimize fails to retrieve vifs.

heal_and_optimize flow retrieves a list of vifs
using a method in util module. For SR-IOV agent,
_find_vifs methid is invoked, it is common to CNA
and VNIC objects. The vswitch_id is retrieved and
validated, since vswitch_id is not present in VNIC
object, getattr call fails. Since this method is
common to both CNA and VNIC, a default return value
of None should be included in the list of parameters.

networking_powervm/plugins/ibm/agent/powervm/util.py
_find_vifs method :
 Instead of getattr(vif, 'vswitch_id')
 getattr(vif, 'vswitch_id', None) should be used.

Change-Id: I38f1662801ad773408ab581c77161677b1cb6b36
Closes-Bug: #1691584
changes/61/465761/3
Sridhar Venkat 5 years ago
parent e2e7d28752
commit ace8c0ef0d
  1. 2
      networking_powervm/plugins/ibm/agent/powervm/utils.py
  2. 15
      networking_powervm/tests/unit/plugins/ibm/powervm/test_utils.py

@ -271,7 +271,7 @@ def _find_vifs(adapter, vif_class, vm_wrap, vs_exclu):
return [vif for vif in vif_list if
((isinstance(vm_wrap, pvm_lpar.LPAR) or
not getattr(vif, 'is_tagged_vlan_supported', False)) and
not getattr(vif, 'vswitch_id') in vs_exclu)]
getattr(vif, 'vswitch_id', None) not in vs_exclu)]
except pvm_exc.HttpError as e:
# If it is a 404 (not found) then just skip.
if e.response is not None and e.response.status == 404:

@ -99,6 +99,21 @@ class UtilsTest(base.BasePVMTestCase):
resp = utils.find_nb_for_cna(nb_wraps, mock_client_adpt, vswitch_map)
self.assertIsNone(resp)
@mock.patch('networking_powervm.plugins.ibm.agent.powervm.utils.'
'_remove_log_helper')
def test_find_vifs(self, mock_rmlog):
mock_vif_class = mock.Mock()
vea1 = mock.Mock(uuid='1', is_tagged_vlan_supported=True, vswitch_id=2)
vea2 = mock.Mock(uuid='2', is_tagged_vlan_supported=False,
spec=['uuid', 'is_tagged_vlan_supported'])
mock_vif_class.get.return_value = [vea1, vea2]
lpar = mock.Mock(spec=pvm_lpar.LPAR)
# Should return both veas, though second has no vswitch id
# This test is applicable for listing VNIC vifs.
self.assertEqual([vea1, vea2],
utils._find_vifs('adap', mock_vif_class, lpar, [0]))
@mock.patch('pypowervm.tasks.partition.get_partitions')
@mock.patch('networking_powervm.plugins.ibm.agent.powervm.utils.'
'_find_vifs')

Loading…
Cancel
Save