Esempio n. 1
0
def test_clusterinit_invalid_cmd_list_failure4():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "discover, init", "cmk",
                                 "Never", "/etc/cmk", "/opt/bin", "4", "2", "",
                                 "", "vertical", "vertical", "default")
    expected_err_msg = "init command should be run and listed first."
    assert err.value.args[0] == expected_err_msg
Esempio n. 2
0
def test_clusterinit_invalid_cp_cores_failure2():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "init", "cmk", "Never",
                                 "/etc/cmk", "/opt/bin", "1", "10.5", "", "",
                                 "vertical", "vertical", "default")
    expected_err_msg = "num_cp_cores cores should be a positive integer."
    assert err.value.args[0] == expected_err_msg
Esempio n. 3
0
def test_clusterinit_invalid_cmd_list_failure2():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "fakecmd1, init", "cmk",
                                 "Never", ETC_CMK, OPT_BIN, "4", "2", "", "",
                                 "vertical", "vertical", "default", "-1")
    expected_err_msg = (ERR_MGS)
    assert err.value.args[0] == expected_err_msg
def test_clusterinit_invalid_image_pol():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "init", "cmk", "fakepol1",
                                 "/etc/cmk", "/opt/bin", "4", "2", "", "")
    expected_err_msg = ('Image pull policy should be one of '
                        '[\'Never\', \'IfNotPresent\', \'Always\']')
    assert err.value.args[0] == expected_err_msg
Esempio n. 5
0
def test_clusterinit_invalid_shared_cores_failure1():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "init", "cmk", "Never",
                                 ETC_CMK, OPT_BIN, "1", "2.5", "", "",
                                 "vertical", "vertical", "default", "-1")
    expected_err_msg = "num_shared_cores cores should be a positive integer."
    assert err.value.args[0] == expected_err_msg
Esempio n. 6
0
def main():
    setup_logging()

    args = docopt(__doc__, version="CMK v1.4.1")
    if args["cluster-init"]:
        clusterinit.cluster_init(args["--host-list"], args["--all-hosts"],
                                 args["--cmk-cmd-list"], args["--cmk-img"],
                                 args["--cmk-img-pol"], args["--conf-dir"],
                                 args["--install-dir"],
                                 args["--num-exclusive-cores"],
                                 args["--num-shared-cores"],
                                 args["--pull-secret"],
                                 args["--saname"], args["--exclusive-mode"],
                                 args["--shared-mode"], args["--namespace"],
                                 args["--excl-non-isolcpus"])
        return
    if args["init"]:
        init.init(args["--conf-dir"],
                  int(args["--num-exclusive-cores"]),
                  int(args["--num-shared-cores"]),
                  args["--exclusive-mode"],
                  args["--shared-mode"],
                  args["--excl-non-isolcpus"])
        return
    if args["discover"]:
        discover.discover(args["--conf-dir"])
        return
    if args["describe"]:
        describe.describe(args["--conf-dir"])
        return
    if args["isolate"]:
        isolate.isolate(args["--conf-dir"],
                        args["--pool"],
                        args["--no-affinity"],
                        args["<command>"],
                        args["<args>"],
                        args["--socket-id"])
        return
    if args["reconcile"]:
        reconcile.reconcile(args["--conf-dir"],
                            int(args["--interval"]),
                            args["--publish"])
        return
    if args["install"]:
        install.install(args["--install-dir"])
        return
    if args["uninstall"]:
        uninstall.uninstall(args["--install-dir"],
                            args["--conf-dir"],
                            args["--namespace"])
        return
    if args["node-report"]:
        nodereport.nodereport(args["--conf-dir"],
                              int(args["--interval"]),
                              args["--publish"])
        return
    if args["webhook"]:
        webhook.webhook(args["--conf-file"])
Esempio n. 7
0
def test_clusterinit_invalid_cmd_list_failure2():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "fakecmd1, init", "cmk",
                                 "Never", "/etc/cmk", "/opt/bin", "4", "2", "",
                                 "", "vertical", "vertical", "default")
    expected_err_msg = ("CMK command should be one of "
                        "['init', 'discover', 'install', 'reconcile', "
                        "'nodereport']")
    assert err.value.args[0] == expected_err_msg
def test_clusterinit_invalid_exclusive_cores_failure1():
    with pytest.raises(RuntimeError) as err:
        clusterinit.cluster_init("fakenode1", False, "init", "cmk", "Never",
                                 "/opt/bin", "-1", "2", "", "", "vertical",
                                 "vertical", "default", "-1", "fake-ca",
                                 "False")
    expected_err_msg = ("num_exclusive_cores cores should be a positive "
                        "integer.")
    assert err.value.args[0] == expected_err_msg
Esempio n. 9
0
def test_clusterinit_dont_pass_pull_secrets():
    mock = MagicMock()
    with patch('intel.k8s.client_from_config', MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, "init, discover, install",
                                 "cmk", "Never", "/etc/cmk", "/opt/bin", "4",
                                 "2", "", "", "vertical", "vertical")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "imagePullSecrets" not in pod_spec["spec"]
def test_clusterinit_dont_pass_pull_secrets():
    mock = MagicMock()
    with patch(CLIENT_CONFIG, MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, "init, discover, install",
                                 "cmk", "Never", "/opt/bin", "4", "2", "", "",
                                 "vertical", "vertical", "default", "-1",
                                 "fake-ca", "False")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "imagePullSecrets" not in pod_spec["spec"]
Esempio n. 11
0
def test_clusterinit_dont_pass_pull_secrets():
    mock = MagicMock()
    with patch(CLIENT_CONFIG, MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, INIT_DISCOVER_INSTALL,
                                 "cmk", "Never", ETC_CMK, OPT_BIN, "4", "2",
                                 "", "", "vertical", "vertical", "default",
                                 "-1")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "imagePullSecrets" not in pod_spec["spec"]
Esempio n. 12
0
def test_clusterinit_dont_pass_serviceaccountname():
    mock = MagicMock()
    with patch('intel.k8s.client_from_config', MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, "init, discover, install",
                                 "cmk", "Never", "/etc/cmk", "/opt/bin", "4",
                                 "2", "", "", "vertical", "vertical")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "serviceAccountName" in pod_spec["spec"]
        sa_name_in_spec = pod_spec["spec"]["serviceAccountName"]
        assert sa_name_in_spec == ""
def test_clusterinit_dont_pass_serviceaccountname():
    mock = MagicMock()
    with patch(CLIENT_CONFIG, MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, "init, discover, install",
                                 "cmk", "Never", "/opt/bin", "4", "2", "", "",
                                 "vertical", "vertical", "default", "-1",
                                 "fake-ca", "False")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "serviceAccountName" in pod_spec["spec"]
        sa_name_in_spec = pod_spec["spec"]["serviceAccountName"]
        assert sa_name_in_spec == ""
Esempio n. 14
0
def test_clusterinit_dont_pass_serviceaccountname():
    mock = MagicMock()
    with patch(CLIENT_CONFIG, MagicMock(return_value=mock)):
        clusterinit.cluster_init("fakenode1", False, INIT_DISCOVER_INSTALL,
                                 "cmk", "Never", ETC_CMK, OPT_BIN, "4", "2",
                                 "", "", "vertical", "vertical", "default",
                                 "-1")
        called_methods = mock.method_calls
        params = called_methods[0][1]
        pod_spec = params[1]
        assert "serviceAccountName" in pod_spec["spec"]
        sa_name_in_spec = pod_spec["spec"]["serviceAccountName"]
        assert sa_name_in_spec == ""
def test_clusterinit_pass_pull_secrets():
    mock = MagicMock()
    with patch('intel.k8s.client_from_config', MagicMock(return_value=mock)):
        with patch('intel.clusterinit.wait_for_pod_phase',
                   MagicMock(return_value=True)):
            clusterinit.cluster_init("fakenode1", False,
                                     "init, discover, install", "cmk", "Never",
                                     "/etc/cmk", "/opt/bin", "4", "2",
                                     "supersecret", "")
            called_methods = mock.method_calls
            params = called_methods[0][1]
            pod_spec = params[1]
            assert "imagePullSecrets" in pod_spec["spec"]
            secrets = pod_spec["spec"]["imagePullSecrets"]
            assert len(secrets) == 1
            assert secrets[0]["name"] == "supersecret"
Esempio n. 16
0
def main():
    setup_logging()

    args = docopt(__doc__, version="CMK v1.0.1")
    if args["cluster-init"]:
        clusterinit.cluster_init(args["--host-list"], args["--all-hosts"],
                                 args["--cmk-cmd-list"], args["--cmk-img"],
                                 args["--cmk-img-pol"], args["--conf-dir"],
                                 args["--install-dir"], args["--num-dp-cores"],
                                 args["--num-cp-cores"], args["--pull-secret"],
                                 args["--saname"])
        return
    if args["init"]:
        init.init(args["--conf-dir"], int(args["--num-dp-cores"]),
                  int(args["--num-cp-cores"]))
        return
    if args["discover"]:
        discover.discover(args["--conf-dir"])
        return
    if args["describe"]:
        describe.describe(args["--conf-dir"])
        return
    if args["isolate"]:
        isolate.isolate(args["--conf-dir"], args["--pool"],
                        args["--no-affinity"], args["<command>"],
                        args["<args>"])
        return
    if args["reconcile"]:
        reconcile.reconcile(args["--conf-dir"], int(args["--interval"]),
                            args["--publish"])
        return
    if args["install"]:
        install.install(args["--install-dir"])
        return
    if args["uninstall"]:
        uninstall.uninstall(args["--install-dir"], args["--conf-dir"])
        return
    if args["node-report"]:
        nodereport.nodereport(args["--conf-dir"], int(args["--interval"]),
                              args["--publish"])
        return