def test_get_csrs():
    module = DummyModule({})
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    output_file = os.path.join(ASSET_PATH, 'oc_csr_approve_pending.json')
    with open(output_file) as stdoutfile:
        oc_get_csr_out = stdoutfile.read()

    # mock oc get csr call to cluster
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_csr_out, '')
        csrs = approver.get_csrs()

    assert csrs[0]['kind'] == "CertificateSigningRequest"

    output_file = os.path.join(ASSET_PATH, 'openssl1.txt')
    with open(output_file) as stdoutfile:
        openssl_out = stdoutfile.read()

    # mock openssl req call.
    node_list = ['fedora2.mguginolocal.com']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, openssl_out, '')
        csr_dict = approver.process_csrs(csrs, "client")
    # actually run openssl req call.
    csr_dict = approver.process_csrs(csrs, "client")
    assert csr_dict['node-csr-TkefytQp8Dz4Xp7uzcw605MocvI0gWuEOGNrHhOjGNQ'] == 'fedora2.mguginolocal.com'
def test_get_ready_nodes_server():
    module = DummyModule({})
    nodes_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', nodes_list)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'ok', '')
        ready_nodes_server = approver.get_ready_nodes_server(nodes_list)
    assert ready_nodes_server == ['fedora1.openshift.io']
def test_get_ready_nodes_server():
    module = DummyModule({})
    nodes_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', nodes_list)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'ok', '')
        ready_nodes_server = approver.get_ready_nodes_server(nodes_list)
    assert ready_nodes_server == ['fedora1.openshift.io']
def test_approve_csrs():
    module = DummyModule({})
    csr_dict = {'csr-1': 'example.openshift.io'}
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'csr-1 ok', '')
        approver.approve_csrs(csr_dict, 'client')
    assert approver.result['client_approve_results'] == ['csr-1 ok']
def test_approve_csrs():
    module = DummyModule({})
    csr_dict = {'csr-1': 'example.openshift.io'}
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'csr-1 ok', '')
        approver.approve_csrs(csr_dict, 'client')
    assert approver.result['client_approve_results'] == ['csr-1 ok']
def test_get_csrs_server():
    module = DummyModule({})
    output_file = os.path.join(ASSET_PATH,
                               'oc_csr_server_multiple_pends_one_host.json')
    with open(output_file) as stdoutfile:
        oc_get_csr_out = stdoutfile.read()

    approver = CSRapprove(module, 'oc', '/dev/null', [])
    # mock oc get csr call to cluster
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_csr_out, '')
        csrs = approver.get_csrs()

    assert csrs[0]['kind'] == "CertificateSigningRequest"

    output_file = os.path.join(ASSET_PATH, 'openssl1.txt')
    with open(output_file) as stdoutfile:
        openssl_out = stdoutfile.read()

    nodename = 'fedora1.openshift.io'
    approver = CSRapprove(module, 'oc', '/dev/null', nodename)
    # mock openssl req call.
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, openssl_out, '')
        csr_dict = approver.process_csrs(csrs, "server")

    # actually run openssl req call.
    nodename = 'fedora1.openshift.io'
    approver = CSRapprove(module, 'oc', '/dev/null', nodename)
    csr_dict = approver.process_csrs(csrs, "server")
    assert csr_dict['csr-2cxkp'] == 'fedora1.openshift.io'
def test_get_ready_nodes():
    output_file = os.path.join(ASSET_PATH, 'oc_get_nodes.json')
    with open(output_file) as stdoutfile:
        oc_get_nodes_stdout = stdoutfile.read()

    module = DummyModule({})
    approver = CSRapprove(module, 'oc', '/dev/null', [])

    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_nodes_stdout, '')
        ready_nodes = approver.get_ready_nodes()
    assert ready_nodes == ['fedora1.openshift.io', 'fedora3.openshift.io']
Ejemplo n.º 8
0
def test_get_nodes():
    output_file = os.path.join(ASSET_PATH, 'oc_get_nodes.json')
    with open(output_file) as stdoutfile:
        oc_get_nodes_stdout = stdoutfile.read()

    module = DummyModule({})
    approver = CSRapprove(module, 'oc', '/dev/null', [])

    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_nodes_stdout, '')
        all_nodes = approver.get_nodes()
    assert all_nodes == ['fedora1.openshift.io', 'fedora2.openshift.io', 'fedora3.openshift.io']
def test_confirm_needed_requests_present():
    module = DummyModule({})
    csr_dict = {'some-csr': 'fedora1.openshift.io'}
    not_ready_nodes = ['host1']
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    with pytest.raises(Exception) as err:
        approver.confirm_needed_requests_present(not_ready_nodes, csr_dict)
        assert 'Exception: Could not find csr for nodes: host1' in str(err)

    not_ready_nodes = ['fedora1.openshift.io']
    # this should complete silently
    approver.confirm_needed_requests_present(not_ready_nodes, csr_dict)
def test_node_is_ready():
    module = DummyModule({})
    nodename = 'fedora1.openshift.io'
    approver = CSRapprove(module, 'oc', '/dev/null', nodename)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'ok', '')
        result = approver.node_is_ready(nodename)
    assert result is True

    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (1, 'stdout fail', 'stderr fail')
        result = approver.node_is_ready(nodename)
    assert result is False
Ejemplo n.º 11
0
def test_get_ready_nodes_server():
    module = DummyModule({})
    nodes_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', nodes_list)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, 'ok', '')
        ready_nodes_server = approver.get_ready_nodes_server(nodes_list)
    assert ready_nodes_server == ['fedora1.openshift.io']

    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (1, 'stdout fail', 'stderr fail')
        ready_nodes_server = approver.get_ready_nodes_server(nodes_list)
    raw_fails = ('fedora1.openshift.io', 1, 'stdout fail', 'stderr fail')
    assert approver.result['raw_failures'][0] == raw_fails
def test_process_csrs():
    module = DummyModule({})
    approver = CSRapprove(module, 'oc', '/dev/null', 'fedora1.openshift.io')
    output_file = os.path.join(ASSET_PATH, 'oc_csr_approve_pending.json')
    with open(output_file) as stdoutfile:
        oc_get_csr_out = stdoutfile.read()

    # mock oc get csr call to cluster
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_csr_out, '')
        csrs = approver.get_csrs()

    csr_dict = approver.process_csrs(csrs, "client")
    assert csr_dict == {
        'node-csr-TkefytQp8Dz4Xp7uzcw605MocvI0gWuEOGNrHhOjGNQ':
        'fedora1.openshift.io'
    }
def test_get_csrs_client():
    module = DummyModule({})
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    output_file = os.path.join(ASSET_PATH, 'oc_csr_approve_pending.json')
    with open(output_file) as stdoutfile:
        oc_get_csr_out = stdoutfile.read()

    # mock oc get csr call to cluster
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_csr_out, '')
        csrs = approver.get_csrs()

    assert csrs[0]['kind'] == "CertificateSigningRequest"

    output_file = os.path.join(ASSET_PATH, 'openssl1.txt')
    with open(output_file) as stdoutfile:
        openssl_out = stdoutfile.read()

    # mock openssl req call.
    nodename = 'fedora1.openshift.io'
    approver = CSRapprove(module, 'oc', '/dev/null', nodename)
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, openssl_out, '')
        csr_dict = approver.process_csrs(csrs, "client")
    # actually run openssl req call.
    csr_dict = approver.process_csrs(csrs, "client")
    assert csr_dict[
        'node-csr-TkefytQp8Dz4Xp7uzcw605MocvI0gWuEOGNrHhOjGNQ'] == 'fedora1.openshift.io'
def test_get_csrs_server():
    module = DummyModule({})
    output_file = os.path.join(ASSET_PATH, 'oc_csr_server_multiple_pends_one_host.json')
    with open(output_file) as stdoutfile:
        oc_get_csr_out = stdoutfile.read()

    approver = CSRapprove(module, 'oc', '/dev/null', [])
    # mock oc get csr call to cluster
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, oc_get_csr_out, '')
        csrs = approver.get_csrs()

    assert csrs[0]['kind'] == "CertificateSigningRequest"

    output_file = os.path.join(ASSET_PATH, 'openssl1.txt')
    with open(output_file) as stdoutfile:
        openssl_out = stdoutfile.read()

    node_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    # mock openssl req call.
    with patch(RUN_CMD_MOCK) as call_mock:
        call_mock.return_value = (0, openssl_out, '')
        csr_dict = approver.process_csrs(csrs, "server")

    # actually run openssl req call.
    node_list = ['fedora2.mguginolocal.com']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    csr_dict = approver.process_csrs(csrs, "server")
    assert csr_dict['csr-2cxkp'] == 'fedora2.mguginolocal.com'
Ejemplo n.º 15
0
def test_verify_server_csrs():
    module = DummyModule({})
    ready_nodes_server = ['fedora1.openshift.io']
    node_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    with patch('oc_csr_approve.CSRapprove.get_ready_nodes_server') as call_mock:
        call_mock.return_value = ready_nodes_server
        # This should silently return
        approver.verify_server_csrs()

    node_list = ['fedora1.openshift.io', 'fedora2.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    with patch('oc_csr_approve.CSRapprove.get_ready_nodes_server') as call_mock:
        call_mock.return_value = ready_nodes_server
        with pytest.raises(Exception) as err:
            approver.verify_server_csrs()
        assert 'after approving server certs: fedora2.openshift.io' in str(err)
def test_confirm_needed_requests_present():
    module = DummyModule({})
    csr_dict = {'some-csr': 'fedora1.openshift.io'}
    not_found_nodes = ['host1']
    approver = CSRapprove(module, 'oc', '/dev/null', [])
    with pytest.raises(Exception) as err:
        approver.confirm_needed_requests_present(not_found_nodes, csr_dict)
        assert 'Exception: Could not find csr for nodes: host1' in str(err)

    not_found_nodes = ['fedora1.openshift.io']
    # this should complete silently
    approver.confirm_needed_requests_present(not_found_nodes, csr_dict)
def test_verify_server_csrs():
    module = DummyModule({})
    ready_nodes_server = ['fedora1.openshift.io']
    node_list = ['fedora1.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    with patch('oc_csr_approve.CSRapprove.get_ready_nodes_server') as call_mock:
        call_mock.return_value = ready_nodes_server
        # This should silently return
        approver.verify_server_csrs()

    node_list = ['fedora1.openshift.io', 'fedora2.openshift.io']
    approver = CSRapprove(module, 'oc', '/dev/null', node_list)
    with patch('oc_csr_approve.CSRapprove.get_ready_nodes_server') as call_mock:
        call_mock.return_value = ready_nodes_server
        with pytest.raises(Exception) as err:
            approver.verify_server_csrs()
        assert 'after approving server certs: fedora2.openshift.io' in str(err)