def test_nexus_ncclient_disconnect(self):

        # Mock to keep track of number of close_session calls.
        ncclient_close = mock.patch.object(
            nexus_network_driver.CiscoNexusDriver,
            '_close_session').start()

        # Clear out call_count changes during initialization activity
        self.mock_ncclient.reset_mock()

        # Verify that ncclient is not closed by default.
        with self._create_resources():
            assert not ncclient_close.called

        # Patch to close ncclient session.
        mock.patch.object(nexus_network_driver.CiscoNexusDriver,
                          '_get_close_ssh_session',
                          return_value=True).start()

        # Verify that ncclient close is called twice. For create VLAN and
        # trunk interface calls.
        with self._create_resources():
            self.assertEqual(ncclient_close.call_count, 2)
Test handling of closing ncclient sessions.
dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py/TestCiscoPortsV2.test_nexus_ncclient_disconnect