Пример #1
0
def test(bridge, sock):
    if not mosq_test.expect_packet(bridge, "connect", connect_packet):
        return 1
    bridge.send(connack_packet)

    mid = 0
    patterns = [
        "remote/topic/#",
        "remote2/topic/prefix/#",
        "remote3/topic/+/value",
        "remote4/tipic/+",
        "$SYS/broker/clients/total",
    ]
    for pattern in ("remote/topic/#", "remote2/topic/prefix/#", "remote3/topic/+/value"):
        mid += 1
        subscribe_packet = mosq_test.gen_subscribe(mid, pattern, 0)
        suback_packet = mosq_test.gen_suback(mid, 0)
        if not mosq_test.expect_packet(bridge, "subscribe", subscribe_packet):
            return 1
        bridge.send(suback_packet)

    mid += 1
    subscribe_packet = mosq_test.gen_subscribe(mid, "#", 0)
    suback_packet = mosq_test.gen_suback(mid, 0)
    sock.send(subscribe_packet)
    if not mosq_test.expect_packet(sock, "suback", suback_packet):
        return 1

    cases = [
        ('local/topic/something', 'remote/topic/something'),
        ('local/topic/some/t/h/i/n/g', 'remote/topic/some/t/h/i/n/g'),
        ('local/topic/value', 'remote/topic/value'),
        # Don't work, #40 must be fixed before
        # ('local/topic', 'remote/topic'),
        ('local2/topic/prefix/something', 'remote2/topic/prefix/something'),
        ('local3/topic/something/value', 'remote3/topic/something/value'),
        ('local4/topic/something', 'remote4/tipic/something'),
        ('test/mosquitto/orgclients/total', '$SYS/broker/clients/total'),
    ]

    for (local_topic, remote_topic) in cases:
        mid += 1
        remote_publish_packet = mosq_test.gen_publish(
            remote_topic, qos=0, mid=mid, payload=''
        )
        local_publish_packet = mosq_test.gen_publish(
            local_topic, qos=0, mid=mid, payload=''
        )

        bridge.send(remote_publish_packet)
        match = mosq_test.expect_packet(sock, "publish", local_publish_packet)
        if not match:
            print("Fail on cases local_topic=%r, remote_topic=%r" % (
                local_topic, remote_topic,
            ))
            return 1
    return 0
Пример #2
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234;
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("localhost", 1888))
        sock.settimeout(20)
        sock.send(connect_packet)

        if mosq_test.expect_packet(sock, "connack", connack_packet):
            sock.send(subscribe_packet)

            if mosq_test.expect_packet(sock, "suback", suback_packet):
                pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic])
                pub.wait()

                if mosq_test.expect_packet(sock, "publish", publish_packet):
                    sock.send(unsubscribe_packet)

                    if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
                        sock.send(subscribe_packet)

                        if mosq_test.expect_packet(sock, "suback", suback_packet):
                            if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
                                rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        if rc:
            (stdo, stde) = broker.communicate()
            print(stde)

    return rc
Пример #3
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234;
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    port = mosq_test.get_port()
    broker = subprocess.Popen(['../../src/mosquitto', '-p', str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
        sock.send(subscribe_packet)

        if mosq_test.expect_packet(sock, "suback", suback_packet):
            pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic, str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            pub.wait()
            (stdo, stde) = pub.communicate()

            if mosq_test.expect_packet(sock, "publish", publish_packet):
                sock.send(unsubscribe_packet)

                if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
                    sock.send(subscribe_packet)

                    if mosq_test.expect_packet(sock, "suback", suback_packet):
                        if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
                            rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        (stdo, stde) = broker.communicate()
        if rc:
            print(stde)
            print(stdo)
            raise

    return rc
Пример #4
0
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
mid = 16
connect_packet = mosq_test.gen_connect("retain-qos0-rep-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

publish_packet = mosq_test.gen_publish("retain/qos0/test", qos=0, payload="retained message", retain=True)
subscribe_packet = mosq_test.gen_subscribe(mid, "retain/qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)

unsub_mid = 13
unsubscribe_packet = mosq_test.gen_unsubscribe(unsub_mid, "retain/qos0/test/")
unsuback_packet = mosq_test.gen_unsuback(unsub_mid)

broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(20)
    sock.connect(("localhost", 1888))
    sock.send(connect_packet)
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
client_id = socket.gethostname()+".bridge_sample"
connect_packet = mosq_test.gen_connect(client_id, keepalive=keepalive, clean_session=False, proto_ver=128+3)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback_packet = mosq_test.gen_suback(mid, 2)

mid = 2
subscribe2_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback2_packet = mosq_test.gen_suback(mid, 2)

mid = 3
subscribe3_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback3_packet = mosq_test.gen_suback(mid, 2)

mid = 5
publish_packet = mosq_test.gen_publish("bridge/disconnect/test", qos=2, mid=mid, payload="disconnect-message")
publish_dup_packet = mosq_test.gen_publish("bridge/disconnect/test", qos=2, mid=mid, payload="disconnect-message", dup=True)
pubrec_packet = mosq_test.gen_pubrec(mid)
pubrel_packet = mosq_test.gen_pubrel(mid)
pubcomp_packet = mosq_test.gen_pubcomp(mid)
Пример #6
0
        f.write("port %d\n" % (port))
        f.write("auth_plugin c/auth_plugin.so\n")
        f.write("allow_anonymous false\n")

port = mosq_test.get_port()
conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port)

rc = 1
keepalive = 10
connect_packet = mosq_test.gen_connect("connect-uname-pwd-test", keepalive=keepalive, username="******")
connack_packet = mosq_test.gen_connack(rc=0)

mid = 53
subscribe_packet = mosq_test.gen_subscribe(mid, "qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)

mid_fail = 54
subscribe_packet_fail = mosq_test.gen_subscribe(mid_fail, "#", 0)
suback_packet_fail = mosq_test.gen_suback(mid_fail, 0x80)

broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)

try:
    sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
    sock.send(subscribe_packet)

    if mosq_test.expect_packet(sock, "suback", suback_packet):
        sock.send(subscribe_packet_fail)
        if mosq_test.expect_packet(sock, "suback", suback_packet_fail):
            rc = 0
Пример #7
0
import mosq_test

port = mosq_test.get_lib_port()

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subscribe-qos1-test",
                                       keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

disconnect_packet = mosq_test.gen_disconnect()

mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "qos1/test", 1)
suback_packet = mosq_test.gen_suback(mid, 1)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(10)
sock.bind(('', port))
sock.listen(5)

client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
Пример #8
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test",
                                           keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic,
                                                    qos=0,
                                                    retain=True,
                                                    payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'],
                              stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("localhost", 1888))
        sock.settimeout(20)
        sock.send(connect_packet)

        if mosq_test.expect_packet(sock, "connack", connack_packet):
            sock.send(subscribe_packet)

            if mosq_test.expect_packet(sock, "suback", suback_packet):
                pub = subprocess.Popen(
                    ['./03-pattern-matching-helper.py', pub_topic])
                pub.wait()

                if mosq_test.expect_packet(sock, "publish", publish_packet):
                    sock.send(unsubscribe_packet)

                    if mosq_test.expect_packet(sock, "unsuback",
                                               unsuback_packet):
                        sock.send(subscribe_packet)

                        if mosq_test.expect_packet(sock, "suback",
                                                   suback_packet):
                            if mosq_test.expect_packet(
                                    sock, "publish retained",
                                    publish_retained_packet):
                                rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        if rc:
            (stdo, stde) = broker.communicate()
            print(stde)

    return rc
Пример #9
0
keepalive = 60
connect_packet = mosq_test.gen_connect("retain-clear-test",
                                       keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

publish_packet = mosq_test.gen_publish("retain/clear/test",
                                       qos=0,
                                       payload="retained message",
                                       retain=True)
retain_clear_packet = mosq_test.gen_publish("retain/clear/test",
                                            qos=0,
                                            payload=None,
                                            retain=True)
mid_sub = 592
subscribe_packet = mosq_test.gen_subscribe(mid_sub, "retain/clear/test", 0)
suback_packet = mosq_test.gen_suback(mid_sub, 0)

mid_unsub = 593
unsubscribe_packet = mosq_test.gen_unsubscribe(mid_unsub, "retain/clear/test")
unsuback_packet = mosq_test.gen_unsuback(mid_unsub)

port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

try:
    sock = mosq_test.do_client_connect(connect_packet,
                                       connack_packet,
                                       timeout=4,
                                       port=port)
    # Send retained message
    sock.send(publish_packet)
Пример #10
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test",
                                           keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic,
                                                    qos=0,
                                                    retain=True,
                                                    payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    port = mosq_test.get_port()
    broker = subprocess.Popen(
        ['../../src/mosquitto', '-p', str(port)],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = mosq_test.do_client_connect(connect_packet,
                                           connack_packet,
                                           timeout=20,
                                           port=port)
        mosq_test.do_send_receive(sock, subscribe_packet, suback_packet,
                                  "suback")

        pub = subprocess.Popen(
            ['./03-pattern-matching-helper.py', pub_topic,
             str(port)],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        pub.wait()
        (stdo, stde) = pub.communicate()

        if mosq_test.expect_packet(sock, "publish", publish_packet):
            mosq_test.do_send_receive(sock, unsubscribe_packet,
                                      unsuback_packet, "unsuback")

            mosq_test.do_send_receive(sock, subscribe_packet, suback_packet,
                                      "suback")

            if mosq_test.expect_packet(sock, "publish retained",
                                       publish_retained_packet):
                rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        (stdo, stde) = broker.communicate()
        if rc:
            print(stde)
            print(stdo)
            raise

    return rc
Пример #11
0
def test(bridge, sock):
    if not mosq_test.expect_packet(bridge, "connect", connect_packet):
        return 1
    bridge.send(connack_packet)

    mid = 0
    patterns = [
        "remote/topic/#",
        "remote2/topic/prefix/#",
        "remote3/topic/+/value",
        "remote4/tipic/+",
        "$SYS/broker/clients/total",
    ]
    for pattern in ("remote/topic/#", "remote2/topic/prefix/#",
                    "remote3/topic/+/value"):
        mid += 1
        subscribe_packet = mosq_test.gen_subscribe(mid, pattern, 0)
        suback_packet = mosq_test.gen_suback(mid, 0)
        if not mosq_test.expect_packet(bridge, "subscribe", subscribe_packet):
            return 1
        bridge.send(suback_packet)

    mid += 1
    subscribe_packet = mosq_test.gen_subscribe(mid, "#", 0)
    suback_packet = mosq_test.gen_suback(mid, 0)
    sock.send(subscribe_packet)
    if not mosq_test.expect_packet(sock, "suback", suback_packet):
        return 1

    cases = [
        ('local/topic/something', 'remote/topic/something'),
        ('local/topic/some/t/h/i/n/g', 'remote/topic/some/t/h/i/n/g'),
        ('local/topic/value', 'remote/topic/value'),
        # Don't work, #40 must be fixed before
        # ('local/topic', 'remote/topic'),
        ('local2/topic/prefix/something', 'remote2/topic/prefix/something'),
        ('local3/topic/something/value', 'remote3/topic/something/value'),
        ('local4/topic/something', 'remote4/tipic/something'),
        ('test/mosquitto/orgclients/total', '$SYS/broker/clients/total'),
    ]

    for (local_topic, remote_topic) in cases:
        mid += 1
        remote_publish_packet = mosq_test.gen_publish(remote_topic,
                                                      qos=0,
                                                      mid=mid,
                                                      payload='')
        local_publish_packet = mosq_test.gen_publish(local_topic,
                                                     qos=0,
                                                     mid=mid,
                                                     payload='')

        bridge.send(remote_publish_packet)
        match = mosq_test.expect_packet(sock, "publish", local_publish_packet)
        if not match:
            print("Fail on cases local_topic=%r, remote_topic=%r" % (
                local_topic,
                remote_topic,
            ))
            return 1
    return 0
Пример #12
0
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
client_id = socket.gethostname() + ".bridge_sample"
connect_packet = mosq_test.gen_connect(client_id,
                                       keepalive=keepalive,
                                       clean_session=False,
                                       proto_ver=128 + 3)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback_packet = mosq_test.gen_suback(mid, 2)

mid = 3
subscribe2_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback2_packet = mosq_test.gen_suback(mid, 2)

mid = 4
subscribe3_packet = mosq_test.gen_subscribe(mid, "bridge/#", 2)
suback3_packet = mosq_test.gen_suback(mid, 2)

mid = 2
publish_packet = mosq_test.gen_publish("bridge/disconnect/test",
                                       qos=2,
                                       mid=mid,
                                       payload="disconnect-message")
publish_dup_packet = mosq_test.gen_publish("bridge/disconnect/test",
Пример #13
0
    os.path.abspath(
        os.path.join(
            os.path.split(inspect.getfile(inspect.currentframe()))[0], "..")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subhier-crash", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe1_packet = mosq_test.gen_subscribe(mid, "topic/a", 0)
suback1_packet = mosq_test.gen_suback(mid, 0)

mid = 2
subscribe2_packet = mosq_test.gen_subscribe(mid, "topic/b", 0)
suback2_packet = mosq_test.gen_suback(mid, 0)

mid = 3
unsubscribe1_packet = mosq_test.gen_unsubscribe(mid, "topic/a")
unsuback1_packet = mosq_test.gen_unsuback(mid)

disconnect_packet = mosq_test.gen_disconnect()

port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

Пример #14
0
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subhier-crash", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe1_packet = mosq_test.gen_subscribe(mid, "topic/a", 0)
suback1_packet = mosq_test.gen_suback(mid, 0)

mid = 2
subscribe2_packet = mosq_test.gen_subscribe(mid, "topic/b", 0)
suback2_packet = mosq_test.gen_suback(mid, 0)

mid = 3
unsubscribe1_packet = mosq_test.gen_unsubscribe(mid, "topic/a")
unsuback1_packet = mosq_test.gen_unsuback(mid)

disconnect_packet = mosq_test.gen_disconnect()


port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
Пример #15
0
def do_test(per_listener, username):
    conf_file = os.path.basename(__file__).replace('.py', '.conf')
    write_config(conf_file, port, per_listener)

    persistence_file = os.path.basename(__file__).replace('.py', '.db')
    try:
        os.remove(persistence_file)
    except OSError:
        pass

    acl_file = os.path.basename(__file__).replace('.py', '.acl')
    write_acl_1(acl_file, username)

    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("retain-check",
                                           keepalive=keepalive,
                                           username=username)
    connack_packet = mosq_test.gen_connack(rc=0)

    mid = 1
    publish_packet = mosq_test.gen_publish("test/topic",
                                           qos=0,
                                           payload="retained message",
                                           retain=True)
    subscribe_packet = mosq_test.gen_subscribe(mid, "test/topic", 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    pingreq_packet = mosq_test.gen_pingreq()
    pingresp_packet = mosq_test.gen_pingresp()

    broker = mosq_test.start_broker(filename=os.path.basename(__file__),
                                    use_conf=True,
                                    port=port)

    try:
        sock = mosq_test.do_client_connect(connect_packet,
                                           connack_packet,
                                           port=port)
        sock.send(publish_packet)
        sock.close()

        sock = mosq_test.do_client_connect(connect_packet,
                                           connack_packet,
                                           port=port)
        mosq_test.do_send_receive(sock, subscribe_packet, suback_packet,
                                  "suback 1")

        if mosq_test.expect_packet(sock, "publish", publish_packet):
            sock.close()

            # Remove "write" ability
            write_acl_2(acl_file, username)
            broker.terminate()
            broker.wait()

            broker = mosq_test.start_broker(
                filename=os.path.basename(__file__), use_conf=True, port=port)

            sock = mosq_test.do_client_connect(connect_packet,
                                               connack_packet,
                                               port=port)
            mosq_test.do_send_receive(sock, subscribe_packet, suback_packet,
                                      "suback 2")
            # If we receive the retained message here, it is a failure.
            mosq_test.do_send_receive(sock, pingreq_packet, pingresp_packet,
                                      "pingresp")
            rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        os.remove(conf_file)
        os.remove(acl_file)
        os.remove(persistence_file)
        (stdo, stde) = broker.communicate()
        if rc:
            print(stde)
            exit(rc)
Пример #16
0

port = mosq_test.get_port()
conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port)

rc = 1
keepalive = 10
connect_packet = mosq_test.gen_connect("connect-uname-pwd-test",
                                       keepalive=keepalive,
                                       username="******")
connack_packet = mosq_test.gen_connack(rc=0)

mid = 53
subscribe_packet = mosq_test.gen_subscribe(mid, "qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)

mid_fail = 54
subscribe_packet_fail = mosq_test.gen_subscribe(mid_fail, "#", 0)
suback_packet_fail = mosq_test.gen_suback(mid_fail, 0x80)

broker = mosq_test.start_broker(filename=os.path.basename(__file__),
                                use_conf=True,
                                port=port)

try:
    sock = mosq_test.do_client_connect(connect_packet,
                                       connack_packet,
                                       timeout=20,
                                       port=port)
    mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")