Пример #1
0
    def test_read_labels(self, mock_subproc):
        self.init()
        common_test.set_kube_mock(mock_subproc)

        for (i, ct_data) in read_labels_test_data.items():
            common_test.do_start_test("kube:read-labels", i, ct_data)

            (ret, labels) = kube_commands.kube_read_labels()
            if common_test.RETVAL in ct_data:
                assert ret == ct_data[common_test.RETVAL]

            if common_test.PROC_KILLED in ct_data:
                assert (common_test.procs_killed == ct_data[
                    common_test.PROC_KILLED])

            if (common_test.POST in ct_data
                    and (ct_data[common_test.POST] != labels)):
                print("expect={} labels={} mismatch".format(
                    json.dumps(ct_data[common_test.POST], indent=4),
                    json.dumps(labels, indent=4)))
                assert False

        # Exercist through main
        common_test.do_start_test("kube:main:read-labels", 0,
                                  read_labels_test_data[0])
        with patch('sys.argv', "kube_commands get-labels".split()):
            ret = kube_commands.main()
            assert ret == 0

        # Exercist through main with no args
        common_test.do_start_test("kube:main:none", 0,
                                  read_labels_test_data[0])
        with patch('sys.argv', "kube_commands".split()):
            ret = kube_commands.main()
            assert ret == -1
Пример #2
0
    def test_join(self, mock_subproc):
        self.init()
        common_test.set_kube_mock(mock_subproc)

        for (i, ct_data) in join_test_data.items():
            lock_file = ""
            common_test.do_start_test("kube:join", i, ct_data)

            if not ct_data.get(common_test.NO_INIT, False):
                os.system("rm -f {}".format(KUBE_ADMIN_CONF))

            if ct_data.get(common_test.FAIL_LOCK, False):
                lock_file = kube_commands.LOCK_FILE
                kube_commands.LOCK_FILE = "/xxx/yyy/zzz"

            args = ct_data[common_test.ARGS]
            (ret, _,
             _) = kube_commands.kube_join_master(args[0], args[1], args[2],
                                                 args[3])
            if common_test.RETVAL in ct_data:
                assert ret == ct_data[common_test.RETVAL]

            if lock_file:
                kube_commands.LOCK_FILE = lock_file

        # Exercist through main is_connected
        common_test.do_start_test("kube:main:is_connected", 0,
                                  join_test_data[0])
        with patch('sys.argv', "kube_commands connected".split()):
            ret = kube_commands.main()
            assert ret == 1

        # test to_str()
        f = "abcd"
        f == kube_commands.to_str(str.encode(f))