RIPE-NCC / ripe-atlas-cousteau

Python client for RIPE ATLAS API
GNU General Public License v3.0
65 stars 26 forks source link

Issue43 #44

Closed astrikos closed 7 years ago

astrikos commented 7 years ago

Hi @JonasGroeger, this is an attempt to solve your issue #43. Could you clone and checkout to this branch and give it a try after you install using python setup.py install. It would also be useful if you enable logging on the beginning of your script with something like:

import logging
logging.basicConfig(level=logging.DEBUG)
for handler in logging.root.handlers:
    handler.addFilter(logging.Filter('atlas-stream'))

This way you can see if you if and when you are disconnecting. Let me know if that works for you so I can merge and make a new release soon.

JonasGroeger commented 7 years ago

Hey @astrikos,

I'll be trying this when I find the time. Thanks so far :)

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.05%) to 83.915% when pulling 0c8a1a85dde4b249d2ebc59be48feb74bd772e4d on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.05%) to 83.915% when pulling 99e5ae4ed16af63409fe8de25d986e6e34d17df7 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.05%) to 83.915% when pulling 2c5d289a0fca3c29ce919e089f638c246f8753d6 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.05%) to 83.915% when pulling 4997ea8774302c2f0f5a352dafae57c68c603a66 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.05%) to 83.915% when pulling 4997ea8774302c2f0f5a352dafae57c68c603a66 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.4%) to 83.56% when pulling a3bb01a18c63369d4620efad14d678826dbfc226 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

JonasGroeger commented 7 years ago

I tested this with a small script with the measurement ID from the Issue #43.

Steps to reproduce:

  1. Start the script
  2. Check if data is incoming
  3. ifdown eth0
  4. Wait for some time
  5. ifup eth0

After 5., this output is generated:

DEBUG:atlas-stream:Disconnected from RIPE Atlas Stream
DEBUG:atlas-stream:Reconnected to RIPE Atlas Stream
DEBUG:atlas-stream:Trying to attach to existed subscriptions
DEBUG:atlas-stream:Subscribing to {'buffering': False, 'stream_type': 'result', 'msm': 4412911}
DEBUG:atlas-stream:Subscribed to subscription: {'buffering': False, 'stream_type': 'result', 'msm': 4412911}

After that, the streaming continues! Awesome! So this solves #43.

JonasGroeger commented 7 years ago

Will this go into 1.3.1?

JonasGroeger commented 7 years ago

@astrikos You still need to include this patch. Almost forgot :)

--- stream.py   2016-12-08 16:27:22.057539631 +0100
+++ stream.py   2016-12-08 16:27:11.669539432 +0100
@@ -56,7 +56,7 @@

     def on_atlas_subscribed(self, *args):
         LOG.debug("Subscribed to subscription: {}".format(args[0]))
-        hash_object = hashlib.sha1(str(args[0]))
+        hash_object = hashlib.sha1(str(args[0]).encode('utf-8'))
         hex_dig = hash_object.hexdigest()
         self.SUBSCRIPTIONS[hex_dig] = args[0]

else you will get

  File "/home/jgroeger/.virtualenvs/project/lib/python3.5/site-packages/ripe/atlas/cousteau/stream.py", line 59, in on_atlas_subscribed
    hash_object = hashlib.sha1(str(args[0]))
TypeError: Unicode-objects must be encoded before hashing
astrikos commented 7 years ago

okay covered that, with which subscription did you caused that? for a simple subscription in py2.7 it worked okay for me.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.4%) to 83.56% when pulling 09a4261aedc4e4378aca314afd4bb72981599ff2 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.4%) to 83.56% when pulling 09a4261aedc4e4378aca314afd4bb72981599ff2 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-2.4%) to 83.56% when pulling 09a4261aedc4e4378aca314afd4bb72981599ff2 on issue43 into fbab31f4c5fa24d875ff1ccb20fa7d4e0676be65 on master.

JonasGroeger commented 7 years ago

Those are a lot of coveralls reports :O

@astrikos I'm working on Python 3. Sure it works fine on Python 2 since there, the distinction between bytes and string it not that strict.

Python 3: https://repl.it/EmSt/0 Python 2: https://repl.it/EmSv/0

Onnce you explicitly encode the string as bytes it works with both versions of Python.

astrikos commented 7 years ago

Right, and since this file is not covered by any tests I missed it for py3. That's the reason also coveralls complains, there is no tests so the more we write to file the coverage drops. Anyway, I will try to write some tests as soon as I find some time. I am merging that now.