Commit 4ad201cd authored by Łukasz Nowak's avatar Łukasz Nowak

all: flake8ize

parent 7f6bdd71
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from cryptography import x509 from cryptography import x509
from cryptography.hazmat.primitives.serialization import Encoding
from threading import local from threading import local
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
import caucase.exceptions import caucase.exceptions
......
...@@ -31,7 +31,6 @@ import requests ...@@ -31,7 +31,6 @@ import requests
import requests.exceptions import requests.exceptions
import shutil import shutil
import signal import signal
import sys
import tarfile import tarfile
import tempfile import tempfile
import time import time
...@@ -62,6 +61,7 @@ def findFreeTCPPort(ip=''): ...@@ -62,6 +61,7 @@ def findFreeTCPPort(ip=''):
s.bind((ip, 0)) s.bind((ip, 0))
return str(s.getsockname()[1]) return str(s.getsockname()[1])
def retry(callback, try_count=10, try_delay=0.1): def retry(callback, try_count=10, try_delay=0.1):
""" """
Poll <callback> every <try_delay> for <try_count> times or until it returns Poll <callback> every <try_delay> for <try_count> times or until it returns
...@@ -75,6 +75,7 @@ def retry(callback, try_count=10, try_delay=0.1): ...@@ -75,6 +75,7 @@ def retry(callback, try_count=10, try_delay=0.1):
time.sleep(try_delay) time.sleep(try_delay)
return result return result
def canConnect(caucase_url): def canConnect(caucase_url):
""" """
Returns True if a connection can be established to given address, False Returns True if a connection can be established to given address, False
...@@ -97,13 +98,15 @@ class KedifaMixin(object): ...@@ -97,13 +98,15 @@ class KedifaMixin(object):
_clean_caucased_snapshot = None _clean_caucased_snapshot = None
class KedifaCaucaseMixin(KedifaMixin): class KedifaCaucaseMixin(KedifaMixin):
def _startCaucaseServer(self, argv=(), timeout=10): def _startCaucaseServer(self, argv=(), timeout=10):
""" """
Start caucased server Start caucased server
""" """
ip, port = os.environ['SLAPOS_TEST_IPV6'],\ ip, port = os.environ[
findFreeTCPPort(os.environ['SLAPOS_TEST_IPV6']) 'SLAPOS_TEST_IPV6'], findFreeTCPPort(os.environ['SLAPOS_TEST_IPV6'])
self.caucase_runtime = caucase_runtime = multiprocessing.Process( self.caucase_runtime = caucase_runtime = multiprocessing.Process(
target=caucase.http.main, target=caucase.http.main,
kwargs=dict( kwargs=dict(
...@@ -120,8 +123,8 @@ class KedifaCaucaseMixin(KedifaMixin): ...@@ -120,8 +123,8 @@ class KedifaCaucaseMixin(KedifaMixin):
if not retry( if not retry(
lambda: ( lambda: (
self.assertTrue(caucase_runtime.is_alive()) or self.assertTrue(
canConnect(self.caucase_url) caucase_runtime.is_alive()) or canConnect(self.caucase_url)
), ),
try_count=timeout * 10, try_count=timeout * 10,
): ):
...@@ -141,7 +144,6 @@ class KedifaCaucaseMixin(KedifaMixin): ...@@ -141,7 +144,6 @@ class KedifaCaucaseMixin(KedifaMixin):
if caucase_runtime.is_alive(): if caucase_runtime.is_alive():
raise ValueError('%r does not wish to die' % (caucase_runtime, )) raise ValueError('%r does not wish to die' % (caucase_runtime, ))
def createKey(self): def createKey(self):
key = rsa.generate_private_key( key = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend()) public_exponent=65537, key_size=2048, backend=default_backend())
...@@ -207,7 +209,7 @@ class KedifaCaucaseMixin(KedifaMixin): ...@@ -207,7 +209,7 @@ class KedifaCaucaseMixin(KedifaMixin):
self.pem = certificate_pem + key_pem self.pem = certificate_pem + key_pem
def setUpCaucase(self): def setUpCaucase(self):
global _clean_caucased_snapshot # pylint: disable=global-statement global _clean_caucased_snapshot # pylint: disable=global-statement
self.caucased = os.path.join(self.testdir, 'caucased') self.caucased = os.path.join(self.testdir, 'caucased')
self.caucase_db = os.path.join(self.caucased, 'caucase.sqlite') self.caucase_db = os.path.join(self.caucased, 'caucase.sqlite')
self.caucase_service = os.path.join(self.testdir, 'service') self.caucase_service = os.path.join(self.testdir, 'service')
...@@ -402,13 +404,14 @@ class KedifaIntegrationTest(KedifaCaucaseMixin, unittest.TestCase): ...@@ -402,13 +404,14 @@ class KedifaIntegrationTest(KedifaCaucaseMixin, unittest.TestCase):
def assertLastLogEntry(self, entry): def assertLastLogEntry(self, entry):
tries_left = 5 # try few times, as server can store the log line a bit tries_left = 5 # try few times, as server can store the log line a bit
# later # later
while True: while True:
with open(self.logfile) as fh: with open(self.logfile) as fh:
last_log_line = fh.readlines()[-1] last_log_line = fh.readlines()[-1]
try: try:
self.assertTrue( self.assertTrue(
entry in last_log_line, '%r not found in %r' % (entry, last_log_line)) entry in last_log_line, '%r not found in %r' % (
entry, last_log_line))
except AssertionError: except AssertionError:
if tries_left == 0: if tries_left == 0:
raise raise
......
...@@ -86,7 +86,7 @@ class Updater(object): ...@@ -86,7 +86,7 @@ class Updater(object):
except IOError: except IOError:
current = '' current = ''
if not(certificate): if not (certificate):
if fallback and not fallback_overridden: if fallback and not fallback_overridden:
certificate = fallback certificate = fallback
elif not current and master_content is not None: elif not current and master_content is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment