def test_plug_existing_vif(self, mock_find_trunks, mock_get_cnas, mock_pvm_uuid, mock_mgmt_lpar): # Mock the data t1, t2 = mock.MagicMock(), mock.MagicMock() mock_find_trunks.return_value = [t1, t2] mock_cna = mock.Mock(mac='aa:bb:cc:dd:ee:ff') mock_get_cnas.return_value = [mock_cna] mock_pvm_uuid.return_value = 'lpar_uuid' mock_mgmt_lpar.return_value = mock.Mock(uuid='mgmt_uuid') self.inst = mock.MagicMock(uuid='c2e7ff9f-b9b6-46fa-8716-93bbb795b8b4') self.drv = vif.PvmOvsVifDriver(self.adpt, self.inst) # Run the plug network_model = model.Model({'bridge': 'br0', 'meta': {'mtu': 1500}}) mock_vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', network=network_model, devname='devname') resp = self.drv.plug(mock_vif, new_vif=False) self.assertIsNone(resp) # Validate if trunk.update got invoked for all trunks of CNA of vif self.assertTrue(t1.update.called) self.assertTrue(t2.update.called)
def test_plug( self, mock_pvm_uuid, mock_mgmt_lpar, mock_p2p_cna, ): # Mock the data mock_pvm_uuid.return_value = 'lpar_uuid' mock_mgmt_lpar.return_value = mock.Mock(uuid='mgmt_uuid') # mock_trunk_dev_name.return_value = 'device' cna_w, trunk_wraps = mock.MagicMock(), [mock.MagicMock()] mock_p2p_cna.return_value = cna_w, trunk_wraps # Run the plug network_model = model.Model({'bridge': 'br0', 'meta': {'mtu': 1450}}) mock_vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', network=network_model, devname='device') self.drv.plug(mock_vif) # Validate the calls ovs_ext_ids = ('iface-id=vif_id,iface-status=active,' 'attached-mac=aa:bb:cc:dd:ee:ff,vm-uuid=inst_uuid') mock_p2p_cna.assert_called_once_with(self.adpt, None, 'lpar_uuid', ['mgmt_uuid'], 'NovaLinkVEABridge', configured_mtu=1450, crt_vswitch=True, mac_addr='aa:bb:cc:dd:ee:ff', dev_name='device', ovs_bridge='br0', ovs_ext_ids=ovs_ext_ids)
def test_plug(self, mock_pvm_uuid, mock_mgmt_lpar, mock_p2p_cna, mock_trunk_dev_name, mock_crt_ovs_vif_port, mock_exec): # Mock the data mock_pvm_uuid.return_value = 'lpar_uuid' mock_mgmt_lpar.return_value = mock.Mock(uuid='mgmt_uuid') mock_trunk_dev_name.return_value = 'device' cna_w, trunk_wraps = mock.MagicMock(), [mock.MagicMock()] mock_p2p_cna.return_value = cna_w, trunk_wraps # Run the plug network_model = model.Model({'bridge': 'br0', 'meta': {'mtu': 1450}}) mock_vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', network=network_model) slot_num = 5 self.drv.plug(mock_vif, slot_num) # Validate the calls mock_crt_ovs_vif_port.assert_called_once_with( 'br0', 'device', 'vif_id', 'aa:bb:cc:dd:ee:ff', 'inst_uuid', mtu=1450) mock_p2p_cna.assert_called_once_with( self.adpt, 'host_uuid', 'lpar_uuid', ['mgmt_uuid'], 'NovaLinkVEABridge', crt_vswitch=True, mac_addr='aa:bb:cc:dd:ee:ff', slot_num=slot_num, dev_name='device') mock_exec.assert_called_with('ip', 'link', 'set', 'device', 'up', run_as_root=True)
def test_plug_existing_vif(self, mock_trunk_dev_name): # Mock the data mock_trunk_dev_name.return_value = 'device' # Run the plug network_model = model.Model({'bridge': 'br0', 'meta': {'mtu': 1500}}) mock_vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', network=network_model) slot_num = 5 resp = self.drv.plug(mock_vif, slot_num, new_vif=False) self.assertIsNone(resp)
def test_plug_existing_vif(self, mock_trunk_dev_name, mock_crt_ovs_vif_port, mock_exec): # Mock the data mock_trunk_dev_name.return_value = 'device' # Run the plug network_model = model.Model({'bridge': 'br0', 'meta': {'mtu': 1500}}) mock_vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', network=network_model) slot_num = 5 resp = self.drv.plug(mock_vif, slot_num, new_vif=False) # Validate the calls mock_crt_ovs_vif_port.assert_called_once_with( 'br0', 'device', 'vif_id', 'aa:bb:cc:dd:ee:ff', 'inst_uuid', mtu=1500) mock_exec.assert_called_with('ip', 'link', 'set', 'device', 'up', run_as_root=True) self.assertIsNone(resp)
def test_pre_live_migrate_at_destination(self, mock_part_get, mock_find_trunks, mock_trunk_crt): # Mock the vif net_model = model.Model({'bridge': 'br-int', 'meta': {'mtu': 1450}}) vif = model.VIF(address='aa:bb:cc:dd:ee:ff', id='vif_id', devname='tap-dev', network=net_model) # Mock out the management partition mock_mgmt_wrap = mock.MagicMock() mock_mgmt_wrap.uuid = 'mgmt_uuid' mock_part_get.return_value = mock_mgmt_wrap mock_trunk_crt.return_value = [mock.Mock(pvid=2)] mock_orphan_wrap = mock.MagicMock(mac='aabbccddeeff') mock_find_trunks.return_value = [mock_orphan_wrap] # Invoke and test the basic response vea_vlan_mappings = {} self.drv.pre_live_migrate_at_destination(vif, vea_vlan_mappings) self.assertEqual(vea_vlan_mappings['aa:bb:cc:dd:ee:ff'], 2) # Now validate it called the things it needed to ovs_ext_ids = ('iface-id=vif_id,iface-status=active,' 'attached-mac=aa:bb:cc:dd:ee:ff,vm-uuid=inst_uuid') mock_trunk_crt.assert_called_once_with( self.adpt, 'host_uuid', ['mgmt_uuid'], CONF.powervm.pvm_vswitch_for_novalink_io, dev_name='tap-dev', ovs_bridge='br-int', ovs_ext_ids=ovs_ext_ids, configured_mtu=1450) mock_find_trunks.assert_called_once_with( self.adpt, CONF.powervm.pvm_vswitch_for_novalink_io) mock_orphan_wrap.delete.assert_called_once_with()