Refactor check_connectivity and python_check_connectivity