def test_ensure_vlan_on_nb_new_trunk(self, mock_arb_vid, mock_avail_trunks, mock_orphan_validate, mock_orphan_vlans): """Validates new VLAN on new Load Group.""" # Build the responses self.adpt.read.side_effect = [ self.mgr_nbr_resp, self.mgr_vsw_resp, self.mgr_vnet_resp ] mock_arb_vid.return_value = False mock_avail_trunks.return_value = None mock_orphan_vlans.return_value = [] def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertIsNotNone(nb) self.assertEqual(0, len(nb.seas[0].primary_adpt.tagged_vlans)) self.assertEqual(2, len(nb.seas[0].addl_adpts)) self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb # Invoke net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 2000) # Validate the calls self.assertEqual(1, self.adpt.update_by_path.call_count)
def test_ensure_vlan_on_nb_new_vlan(self, mock_arb_vid, mock_find_vnet, mock_orphan_validate, mock_lock): """Validates new VLAN on existing Load Group.""" # Build the responses self.adpt.read.side_effect = [ self.mgr_nbr_resp, self.mgr_vsw_resp, self.mgr_vnet_resp ] mock_arb_vid.return_value = False mock_vnet = mock.MagicMock() mock_vnet.related_href = 'fake_href' mock_find_vnet.return_value = mock_vnet def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertIsNotNone(nb) self.assertEqual(1, len(nb.load_grps[0].vnet_uri_list)) self.assertEqual(2, len(nb.load_grps[1].vnet_uri_list)) self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb # Invoke net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 2000) # Validate the calls self.assertEqual(1, self.adpt.update_by_path.call_count) self.assertEqual(1, mock_lock.call_count)
def test_ensure_vlan_on_nb_new_trunk( self, mock_arb_vid, mock_avail_trunks, mock_orphan_validate, mock_orphan_vlans): """Validates new VLAN on new Load Group.""" # Build the responses self.adpt.read.side_effect = [self.mgr_nbr_resp, self.mgr_vsw_resp, self.mgr_vnet_resp] mock_arb_vid.return_value = False mock_avail_trunks.return_value = None mock_orphan_vlans.return_value = [] def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertIsNotNone(nb) self.assertEqual(0, len(nb.seas[0].primary_adpt.tagged_vlans)) self.assertEqual(2, len(nb.seas[0].addl_adpts)) self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb # Invoke net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 2000) # Validate the calls self.assertEqual(1, self.adpt.update_by_path.call_count)
def test_ensure_vlan_on_nb_new_lg( self, mock_arb_vid, mock_avail_lg, mock_find_vnet, mock_orphan_validate, mock_orphan_vlans): """Validates new VLAN on new Load Group.""" # Build the responses self.adpt.read.side_effect = [self.mgr_nbr_resp, self.mgr_vsw_resp, self.mgr_vnet_resp] mock_arb_vid.return_value = False mock_avail_lg.return_value = None mock_orphan_vlans.return_value = [] # Make the fake virtual networks (the new, then the arb vid) mock_vnet = mock.MagicMock() mock_vnet.related_href = 'fake_href' mock_vnet_avid = mock.MagicMock() mock_vnet_avid.related_href = 'fake_avid_href' mock_find_vnet.side_effect = [mock_vnet, mock_vnet_avid] def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertIsNotNone(nb) self.assertEqual(1, len(nb.load_grps[0].vnet_uri_list)) self.assertEqual(2, len(nb.load_grps[2].vnet_uri_list)) self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb # Invoke net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 2000) # Validate the calls self.assertEqual(1, self.adpt.update_by_path.call_count)
def test_ensure_vlan_on_nb(self): """This does a happy path test. Assumes VLAN on NB already. No subclass invocation. """ self.adpt.read.return_value = self.mgr_nbr_resp net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 2227) self.assertEqual(1, self.adpt.read.call_count)
def test_ensure_vlan_on_nb_wrong_peer(self, mock_remove, mock_orphan): """Test moving vlan from one peer to another. No subclass invocation. """ self.adpt.read.side_effect = [ self.mgr_nbr_peer_resp, self.mgr_vsw_resp, self.mgr_vnet_resp] def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 1001) mock_remove.assert_called_once_with( self.nb_uuid_peer, 1001, fail_if_pvid=True, existing_nbs=mock.ANY)
def test_ensure_vlan_on_nb_wrong_peer(self, mock_remove, mock_orphan): """Test moving vlan from one peer to another. No subclass invocation. """ self.adpt.read.side_effect = [ self.mgr_nbr_peer_resp, self.mgr_vsw_resp, self.mgr_vnet_resp ] def validate_of_update_nb(*kargs, **kwargs): # Validate args nb = kargs[0] self.assertEqual(self.nb_uuid, nb.uuid) return nb.entry self.adpt.update_by_path.side_effect = validate_of_update_nb net_br.ensure_vlan_on_nb(self.adpt, self.host_uuid, self.nb_uuid, 1001) mock_remove.assert_called_once_with(self.nb_uuid_peer, 1001, fail_if_pvid=True, existing_nbs=mock.ANY)