Exemple #1
0
def test_get_os_version_empty(mocker):
    system_mock = mocker.patch("util.system.platform.system")
    system_mock.return_value = "abc"
    os_name, os_version = get_os_version()

    assert os_name == ""
    assert os_version == LooseVersion("0")
Exemple #2
0
def test_get_os_version_macos(mocker):
    system_mock = mocker.patch("util.system.platform.system")
    system_mock.return_value = "Darwin"
    mac_ver_mock = mocker.patch("util.system.platform.mac_ver")
    mac_ver_mock.return_value = ("10.0.13", )
    os_name, os_version = get_os_version()

    assert os_name == "macos"
    assert os_version == LooseVersion("10.0.13")
Exemple #3
0
def test_get_os_version_debian(mocker):
    system_mock = mocker.patch("util.system.platform.system")
    system_mock.return_value = "Linux"
    read_os_release_mock = mocker.patch("util.system.distro.info")
    read_os_release_mock.return_value = {"id": "debian", "version": "9.3"}
    os_name, os_version = get_os_version()

    assert os_name == "debian"
    assert os_version == LooseVersion("9.3")
Exemple #4
0
def test_get_os_version_windows_not_10(mocker):
    system_mock = mocker.patch("util.system.platform.system")
    system_mock.return_value = "Windows"
    release_mock = mocker.patch("util.system.platform.release")
    release_mock.return_value = "8"
    get_windows_edition_mock = mocker.patch("util.system.get_windows_edition")
    os_name, os_version = get_os_version()

    assert os_name == "windows"
    assert os_version == LooseVersion("8")
    assert get_windows_edition_mock.call_count == 0
Exemple #5
0
def check_os():
    """ Check if user's OS is supported by nctl. """
    try:
        os_name, os_version = get_os_version()
        if os_name == "":
            raise InvalidOsError(Texts.UNKNOWN_OS_ERROR_MSG)
    except InvalidOsError:
        raise
    except Exception as exe:
        raise InvalidOsError(Texts.GET_OS_VERSION_ERROR_MSG) from exe
    log.info(f"Detected OS: {os_name} {os_version}")
    if os_name not in SUPPORTED_OS_MAP:
        raise InvalidOsError(
            Texts.UNSUPPORTED_OS_ERROR_MSG.format(os_name=os_name,
                                                  os_version=os_version))
    if not _is_version_valid(os_version, SUPPORTED_OS_MAP[os_name]):
        raise InvalidOsError(
            Texts.INVALID_OS_VERSION_ERROR_MSG.format(os_name=os_name,
                                                      os_version=os_version))