Пример #1
0
        def process_function():

            # connect to signal to properly terminate process
            global call_for_object_proceed
            call_for_object_proceed = True

            def exit(signum, frame):
                global call_for_object_proceed
                call_for_object_proceed = False

            signal.signal(signal.SIGTERM, exit)

            import ubus
            ubus.connect(UBUSD_TEST_SOCKET_PATH)
            args = [
                ('callee_object', 'method1', {
                    'first': 1
                }),
                ('callee_object', 'method2', {
                    'second': 2
                }),
                ('callee_object', 'method3', {}),
            ]
            while call_for_object_proceed:
                for arg in args:
                    try:
                        ubus.call(*arg)
                    except RuntimeError as e:
                        pass
                    guard.touch()
                    time.sleep(0.05)
Пример #2
0
def test_call_max_min_number(ubusd_test, responsive_object, disconnect_after):
    path = UBUSD_TEST_SOCKET_PATH
    data1 = {"number": 2**32}
    data2 = {"number": -(2**32)}

    with CheckRefCount(path, data1, data2):

        ubus.connect(socket_path=path)
        res = ubus.call("responsive_object", "number", data1)
        assert res[0] == {"number": 2**31 - 1, "passed": True}
        res = ubus.call("responsive_object", "number", data2)
        assert res[0] == {"number": -(2**31), "passed": True}

        del res
        ubus.disconnect()
Пример #3
0
        def process_function():

            # connect to signal to properly terminate process
            global calls_extensive_proceed
            calls_extensive_proceed = True

            def exit(signum, frame):
                global calls_extensive_proceed
                calls_extensive_proceed = False

            signal.signal(signal.SIGTERM, exit)

            import ubus
            ubus.connect(UBUSD_TEST_SOCKET_PATH)
            while calls_extensive_proceed:
                for i in range(20):
                    try:
                        ubus.call('extensive_object_%d' % i, 'method', {})
                        time.sleep(0.1)
                    except RuntimeError as e:
                        pass
                    guard.touch()
Пример #4
0
def test_call(ubusd_test, responsive_object, disconnect_after):
    path = UBUSD_TEST_SOCKET_PATH

    ubus_object = "responsive_object"
    method1 = "respond"
    method2 = "multi_respond"
    data = {"first": "1", "second": False, "third": 22}

    with CheckRefCount(path, ubus_object, method1, method2):

        ubus.connect(socket_path=path)
        res = ubus.call(ubus_object, method1, data)
        assert len(res) == 1
        assert res[0] == {
            "first": "1",
            "second": False,
            "third": 22,
            "passed": True
        }

        res = ubus.call(ubus_object, method1, data, timeout=200)
        assert len(res) == 1
        assert res[0] == {
            "first": "1",
            "second": False,
            "third": 22,
            "passed": True
        }

        res = ubus.call(ubus_object, method2, {})
        assert len(res) == 3
        assert res[0] == {"passed1": True}
        assert res[1] == {"passed1": True, "passed2": True}
        assert res[2] == {"passed1": True, "passed2": True, "passed3": True}

        del res
        ubus.disconnect()
Пример #5
0
    def __load_conf(file, connectubus):
        if connectubus:
            try:
                ubus.connect()
            except:
                #print("Can't connect to ubus")
                journal.WriteLog(module_name, "Normal", "error",
                                 "Can't connect to ubus")

        mailsender.confName = file

        confvalues = ubus.call("uci", "get", {"config": mailsender.confName})
        for confdict in list(confvalues[0]['values'].values()):
            if confdict['.name'] == 'ConnectionSettings':
                if mailsender.smtp_server != confdict['smtp_server_address']:
                    mailsender.smtp_server = confdict['smtp_server_address']

                if mailsender.smtp_port != confdict['smtp_server_port']:
                    mailsender.smtp_port = confdict['smtp_server_port']

                if mailsender.smtp_enc != bool(
                        int(confdict['smtp_server_encryption_enabled'])):
                    mailsender.smtp_enc = bool(
                        int(confdict['smtp_server_encryption_enabled']))

                if mailsender.auth != bool(
                        int(confdict['smtp_server_authentication_enabled'])):
                    mailsender.auth = bool(
                        int(confdict['smtp_server_authentication_enabled']))

                if mailsender.auth_login != confdict[
                        'smtp_server_authentication_login']:
                    mailsender.auth_login = confdict[
                        'smtp_server_authentication_login']

                if mailsender.auth_password != confdict[
                        'smtp_server_authentication_password']:
                    mailsender.auth_password = confdict[
                        'smtp_server_authentication_password']

        if connectubus:
            ubus.disconnect()
Пример #6
0
def test_unicode(ubusd_test, responsive_object, disconnect_after):
    path = UBUSD_TEST_SOCKET_PATH
    data = {
        "first": u"Příliš žluťoučký kůň úpěl ďábelské ódy.",
        "second": True,
        "third": 20
    }

    with CheckRefCount(path, data):

        ubus.connect(socket_path=path)
        res = ubus.call("responsive_object", "respond", data)
        assert res[0] == {
            "first": u"Příliš žluťoučký kůň úpěl ďábelské ódy.",
            "second": True,
            "third": 20,
            "passed": True
        }

        del res
        ubus.disconnect()
Пример #7
0
def call(obj, func, params):
    logger.debug("Calling function '%s'.'%s' with params '%s'" % (obj, func, json.dumps(params)))
    return ubus.call(obj, func, params)
Пример #8
0
def test_call_failed(ubusd_test, responsive_object, disconnect_after):
    path = UBUSD_TEST_SOCKET_PATH

    args1 = (
        [],
        ("responsive_object", ),
        (
            "responsive_object",
            "respond",
        ),
        (
            "responsive_object",
            "respond",
            4,
        ),
        ("responsive_object", "respond", {
            "first": "test",
            "second": True,
            "third": 56
        }, "x"),
        ("responsive_object", "respond", {
            "first": "test",
            "second": True,
            "third": 56
        }, -1),
    )
    args2 = (
        (
            "responsive_object",
            "respond",
            {
                "first": 6,
                "second": True,
                "third": 56
            },
        ),
        (
            "responsive_object",
            "respond",
            {
                "first": "test",
                "third": 56
            },
        ),
        ("responsive_object", "respond", {
            "first": "test",
            "second": True,
            "third": 56,
            "x": 1
        }),
        ("responsive_object", "fail", {
            "first": "test",
            "second": True,
            "third": 56,
            "x": 1
        }),
        ("responsive_object", "fail", {}),
    )
    args3 = (("responsive_object", "respond", {
        "first": "test",
        "second": True,
        "third": 56
    }, 2**64), )
    with CheckRefCount(path, *(args1 + args2 + args3)):

        with pytest.raises(RuntimeError):
            ubus.objects(*args1[0])

        ubus.connect(path)
        for arg in args1:
            with pytest.raises(TypeError):
                ubus.call(*arg)

        for arg in args2:
            with pytest.raises(RuntimeError):
                ubus.call(*arg)

        for arg in args3:
            with pytest.raises(OverflowError):
                ubus.call(*arg)

        ubus.disconnect()
        del arg
Пример #9
0
def call(obj, func, params):
    logger.debug("Calling function '%s'.'%s' with params '%s'" %
                 (obj, func, json.dumps(params)))
    return ubus.call(obj, func, params)