예제 #1
0
def _test_main(mocker, tls=False, root=True):
    if tls:
        options = {'tls': None}
    else:
        options = {}

    if root:
        mocker.patch('os.geteuid', return_value=0)
    else:
        mocker.patch('os.geteuid', return_value=100)

    bootstrap_logging_mock = mocker.patch('mount_efs.bootstrap_logging')
    get_dns_mock = mocker.patch('mount_efs.get_dns_name')
    parse_arguments_mock = mocker.patch('mount_efs.parse_arguments',
                                        return_value=('fs-deadbeef', '/',
                                                      '/mnt', options))
    bootstrap_tls_mock = mocker.patch('mount_efs.bootstrap_tls',
                                      side_effect=dummy_contextmanager)
    mount_mock = mocker.patch('mount_efs.mount_nfs')

    mount_efs.main()

    bootstrap_logging_mock.assert_called_once()
    get_dns_mock.assert_called_once()
    parse_arguments_mock.assert_called_once()
    mount_mock.assert_called_once()

    if tls:
        bootstrap_tls_mock.assert_called_once()
    else:
        bootstrap_tls_mock.assert_not_called()
예제 #2
0
def _test_main(mocker,
               tls=False,
               root=True,
               ap_id=None,
               iam=False,
               awsprofile=None,
               ocsp=False,
               noocsp=False,
               port=None,
               tlsport=None,
               awscredsuri=None):
    options = {}
    if tls:
        options['tls'] = None
    if ap_id is not None:
        options['accesspoint'] = ap_id
    if iam:
        options['iam'] = None
    if awsprofile is not None:
        options['awsprofile'] = awsprofile
    if ocsp:
        options['ocsp'] = None
    if noocsp:
        options['noocsp'] = None
    if port is not None:
        options['port'] = port
    if tlsport is not None:
        options['tlsport'] = tlsport
    if awscredsuri is not None:
        options['awscredsuri'] = AWSCREDSURI

    if root:
        mocker.patch('os.geteuid', return_value=0)
    else:
        mocker.patch('os.geteuid', return_value=100)

    bootstrap_logging_mock = mocker.patch('mount_efs.bootstrap_logging')
    get_dns_mock = mocker.patch('mount_efs.get_dns_name')
    parse_arguments_mock = mocker.patch('mount_efs.parse_arguments',
                                        return_value=('fs-deadbeef', '/',
                                                      '/mnt', options))
    bootstrap_tls_mock = mocker.patch('mount_efs.bootstrap_tls',
                                      side_effect=dummy_contextmanager)
    mount_mock = mocker.patch('mount_efs.mount_nfs')

    mount_efs.main()

    utils.assert_called_once(bootstrap_logging_mock)
    utils.assert_called_once(get_dns_mock)
    utils.assert_called_once(parse_arguments_mock)
    utils.assert_called_once(mount_mock)

    if tls:
        utils.assert_called_once(bootstrap_tls_mock)
    else:
        utils.assert_not_called(bootstrap_tls_mock)
예제 #3
0
def _test_main(
    mocker,
    tls=False,
    root=True,
    ap_id=None,
    iam=False,
    awsprofile=None,
    ocsp=False,
    noocsp=False,
    port=None,
    tlsport=None,
    awscredsuri=None,
    notls=False,
):
    options = {}

    if tls:
        options["tls"] = None
    if notls:
        options["notls"] = None
    if ap_id is not None:
        options["accesspoint"] = ap_id
    if iam:
        options["iam"] = None
    if awsprofile is not None:
        options["awsprofile"] = awsprofile
    if ocsp:
        options["ocsp"] = None
    if noocsp:
        options["noocsp"] = None
    if port is not None:
        options["port"] = port
    if tlsport is not None:
        options["tlsport"] = tlsport
    if awscredsuri is not None:
        options["awscredsuri"] = AWSCREDSURI

    if root:
        mocker.patch("os.geteuid", return_value=0)
    else:
        mocker.patch("os.geteuid", return_value=100)

    bootstrap_logging_mock = mocker.patch("mount_efs.bootstrap_logging")
    get_dns_mock = mocker.patch(
        "mount_efs.get_dns_name_and_fallback_mount_target_ip_address",
        return_value=("fs-deadbeef.efs.us-west-1.amazonaws.com", None),
    )
    parse_arguments_mock = mocker.patch("mount_efs.parse_arguments",
                                        return_value=("fs-deadbeef", "/",
                                                      "/mnt", options))
    bootstrap_tls_mock = mocker.patch("mount_efs.bootstrap_tls",
                                      side_effect=dummy_contextmanager)

    if tls:
        mocker.patch("mount_efs.verify_tlsport_can_be_connected",
                     return_value=True)
    mount_mock = mocker.patch("mount_efs.mount_nfs")

    mount_efs.main()

    utils.assert_called_once(bootstrap_logging_mock)
    utils.assert_called_once(get_dns_mock)
    utils.assert_called_once(parse_arguments_mock)
    utils.assert_called_once(mount_mock)

    if tls:
        utils.assert_called_once(bootstrap_tls_mock)
    else:
        utils.assert_not_called(bootstrap_tls_mock)