def test_get_vnics(self, mock_get, mock_search, mock_uuid): # No kwargs: get self.assertEqual(mock_get.return_value, vm.get_vnics(self.apt, 'inst')) mock_uuid.assert_called_once_with('inst') mock_get.assert_called_once_with(self.apt, parent_type=pvm_lpar.LPAR, parent_uuid=mock_uuid.return_value) mock_search.assert_not_called() # With kwargs: search mock_get.reset_mock() mock_uuid.reset_mock() self.assertEqual(mock_search.return_value, vm.get_vnics( self.apt, 'inst', one=2, three=4)) mock_uuid.assert_called_once_with('inst') mock_search.assert_called_once_with( self.apt, parent_type=pvm_lpar.LPAR, parent_uuid=mock_uuid.return_value, one=2, three=4) mock_get.assert_not_called()
def unplug(self, vif, cna_w_list=None): mac = pvm_util.sanitize_mac_for_api(vif['address']) vnic = vm.get_vnics(self.adapter, self.instance, mac=mac, one_result=True) if not vnic: LOG.warning( 'Unable to unplug VIF with mac %(mac)s. No matching ' 'vNIC was found on the instance. VIF: %(vif)s', { 'mac': mac, 'vif': vif }, instance=self.instance) return None vnic.delete() return vnic
def _vif_exists(self, network_info): """Does the instance have a CNA/VNIC (as appropriate) for a given net? :param network_info: A network information dict. This method expects it to contain keys 'vnic_type' (value is 'direct' for VNIC; otherwise assume CNA); and 'address' (MAC address). :return: True if a CNA/VNIC (as appropriate) with the network_info's MAC address exists on the instance. False otherwise. """ # Are we looking for a VNIC or a CNA? if network_info['vnic_type'] == 'direct': if self.vnics is None: self.vnics = vm.get_vnics(self.adapter, self.instance) vifs = self.vnics else: if self.cnas is None: self.cnas = vm.get_cnas(self.adapter, self.instance) vifs = self.cnas return network_info['address'] in [vm.norm_mac(v.mac) for v in vifs]