Skip to content

Commit

Permalink
ruff'ing the qa folder
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 25, 2024
1 parent 1a76755 commit 9dadff8
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 49 deletions.
17 changes: 12 additions & 5 deletions qa/bin/functional
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import subprocess
from enum import Enum


INTERPRETER = os.environ.get('INTERPRETER', "")
INTERPRETER = os.environ.get('INTERPRETER', '')
if not INTERPRETER:
INTERPRETER = os.environ.get('__PYVENV_LAUNCHER__', sys.executable)

Expand Down Expand Up @@ -392,7 +392,7 @@ class EncodingTests(Tests):

def client(self, nick):
if not self.enable_by_nick(nick):
sys.exit("no such test")
sys.exit('no such test')
test = self.get_by_nick(nick)

config = {
Expand All @@ -403,7 +403,7 @@ class EncodingTests(Tests):
'exabgp_api_cli=false',
'exabgp_debug_rotate=true',
'exabgp_debug_configuration=true',
'exabgp_tcp_bind=\'\'',
"exabgp_tcp_bind=''",
'exabgp_tcp_port=%d' % test.conf['port'],
'INTERPRETER=%s' % INTERPRETER,
]
Expand All @@ -415,7 +415,7 @@ class EncodingTests(Tests):

def server(self, nick):
if not self.enable_by_nick(nick):
sys.exit("no such test")
sys.exit('no such test')
test = self.get_by_nick(nick)

config = {
Expand Down Expand Up @@ -580,7 +580,14 @@ class DecodingTests(Tests):
if message == 'open':
cmd = [Path.EXABGP, 'decode', '--%s' % test.conf['type'], test.conf['packet']]
elif message in ['update', 'nlri']:
cmd = [Path.EXABGP, 'decode', '-f', test.conf['family'], '--%s' % test.conf['type'], test.conf['packet']]
cmd = [
Path.EXABGP,
'decode',
'-f',
test.conf['family'],
'--%s' % test.conf['type'],
test.conf['packet'],
]
else:
raise ValueError(f'invalid message type: {message}')
test.run(cmd)
Expand Down
26 changes: 21 additions & 5 deletions qa/bin/functional-3.6
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ class CI(dict):
def make(cls):
for filename in Path.ALL_CI:
name, extension = os.path.splitext(filename.split('/')[-1])
if name in ['api-reload', 'api-notification', 'conf-ebgp', 'conf-ipself6', 'conf-cap-software-version', 'conf-hostname', 'api-rr']:
if name in [
'api-reload',
'api-notification',
'conf-ebgp',
'conf-ipself6',
'conf-cap-software-version',
'conf-hostname',
'api-rr',
]:
continue
nick = Identifier.get(name)
with open(filename, 'r') as reader:
Expand Down Expand Up @@ -308,7 +316,11 @@ class Command(dict):
@classmethod
def explain(cls, index):
print(
EXPLAIN % {'client': cls.client(index), 'server': cls.server(index),}
EXPLAIN
% {
'client': cls.client(index),
'server': cls.server(index),
}
)
sys.exit(1)

Expand All @@ -328,7 +340,7 @@ class Command(dict):
'exabgp_api_cli=false',
'exabgp_debug_rotate=true',
'exabgp_debug_configuration=true',
'exabgp_tcp_bind=\'\'',
"exabgp_tcp_bind=''",
'exabgp_tcp_port=%d' % test['port'],
'INTERPRETER=%s ' % os.environ.get('__PYVENV_LAUNCHER__', sys.executable),
]
Expand All @@ -349,7 +361,11 @@ class Command(dict):
sys.exit('you need to have root privileges to bind to port 79')

config = {
'env': ' \\\n '.join(['exabgp_tcp_port=%d' % test['port'],]),
'env': ' \\\n '.join(
[
'exabgp_tcp_port=%d' % test['port'],
]
),
'interpreter': os.environ.get('__PYVENV_LAUNCHER__', sys.executable),
'bgp': Path.BGP,
'msg': test['msg'],
Expand Down Expand Up @@ -523,4 +539,4 @@ if __name__ == '__main__':
if vars(parsed):
parsed.func(parsed)
else:
parser.print_help()
parser.print_help()
22 changes: 11 additions & 11 deletions qa/sbin/bgp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def print_payload(prefix, header, body):


def print_rule(prefix, rule):
print_tab(prefix,f'{rule[:32]}:{rule[32:36]}:{rule[36:38]}:{rule[38:]}')
print_tab(prefix, f'{rule[:32]}:{rule[32:36]}:{rule[36:38]}:{rule[38:]}')


def print_tab(prefix, rule):
Expand Down Expand Up @@ -136,7 +136,7 @@ def find_exabgp_pid():
processes = []
cmdlines = []

for line in os.popen("/bin/ps x"):
for line in os.popen('/bin/ps x'):
low = line.strip().lower()
if not low:
continue
Expand Down Expand Up @@ -374,19 +374,19 @@ class Message:
open = (
self.header
+ self.body[0:1]
+ pack("!H", asn)
+ pack('!H', asn)
+ self.body[3:8]
+ pack("!H", byte_id)[1:]
+ pack('!H', byte_id)[1:]
+ self.body[9:10]
+ opt_params[: offset + 2 + 2]
+ pack("!I", asn)
+ pack('!I', asn)
+ opt_params[offset + 2 + 2 + 4 :]
)
return self._add_capa66(add_capa66, open)
offset += param_len + 2

# No "Support for 4 octet AS number capability" found simply replace the 16-bit ASN number field.
open = self.header + self.body[0:1] + pack("!H", asn) + self.body[3:8] + pack("!H", byte_id)[1:] + self.body[9:]
open = self.header + self.body[0:1] + pack('!H', asn) + self.body[3:8] + pack('!H', byte_id)[1:] + self.body[9:]
return self._add_capa66(add_capa66, open)


Expand Down Expand Up @@ -506,7 +506,7 @@ class Checker(object):
if msg.is_route_refresh():
for header, body in self.updates_seen:
print_payload('rr sent', header, body)
writer.write(Message(header,body).packet())
writer.write(Message(header, body).packet())
writer.write(Message.keepalive())

def perform_actions_if_required(self, writer, msg):
Expand Down Expand Up @@ -542,7 +542,7 @@ class Checker(object):
if check == received:
self.messages.remove(check)
if msg.is_update() and not msg.is_eor():
self.updates_seen.append((msg.header,msg.body))
self.updates_seen.append((msg.header, msg.body))

self.perform_actions_if_required(writer, msg)
return True
Expand Down Expand Up @@ -628,7 +628,6 @@ class BGPProtocol(asyncio.Protocol):
sys.exit(1)
self.writer.close()


def handle_open(self, msg):
option_asn = self.service.options['asn']
option_capa66 = self.service.options['send-unknown-capability']
Expand Down Expand Up @@ -669,7 +668,7 @@ class BGPProtocol(asyncio.Protocol):
return FSM.MSG

if self.service.options['echo']:
print_payload(f'echo\'d #{self.counter}', header, body)
print_payload(f"echo'd #{self.counter}", header, body)
self.writer.write(header + body)
return FSM.MSG

Expand All @@ -687,6 +686,7 @@ class BGPProtocol(asyncio.Protocol):

return FSM.MSG


def parse_cmdline():
port = os.environ.get('exabgp.tcp.port', os.environ.get('exabgp_tcp_port', '179'))

Expand Down Expand Up @@ -793,7 +793,7 @@ async def main(options, checker, queue):
port = options['port']
sock.bind((host, port))
except PermissionError as exc:
flushed(f"could not bind to {host}:{port}")
flushed(f'could not bind to {host}:{port}')
flushed(exc)
sys.exit(1)

Expand Down
36 changes: 30 additions & 6 deletions qa/sbin/bgp-3.6
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ def cdr_to_length(cidr):
class BGPHandler(asyncore.dispatcher_with_send):
counter = 0

keepalive = bytearray([0xFF,] * 16 + [0x0, 0x13, 0x4])
keepalive = bytearray(
[
0xFF,
]
* 16
+ [0x0, 0x13, 0x4]
)

_name = {
b'\x01': 'OPEN',
Expand All @@ -79,7 +85,7 @@ class BGPHandler(asyncore.dispatcher_with_send):

processes = []

for line in os.popen("/bin/ps x"):
for line in os.popen('/bin/ps x'):
low = line.strip().lower()
if not low:
continue
Expand Down Expand Up @@ -250,9 +256,14 @@ class BGPHandler(asyncore.dispatcher_with_send):
if self.options['send-default-route']:
self.send(
bytearray(
[0xFF,] * 16
[
0xFF,
]
* 16
+ [0x00, 0x31]
+ [0x02,]
+ [
0x02,
]
+ [0x00, 0x00]
+ [0x00, 0x15]
+ []
Expand Down Expand Up @@ -376,7 +387,10 @@ class BGPHandler(asyncore.dispatcher_with_send):
elif self.messages:
message = self.messages[0].upper()
if message.startswith('F' * 32):
self.announce('expected : %s:%s:%s:%s' % (message[:32], message[32:36], message[36:38], message[38:]))
self.announce(
'expected : %s:%s:%s:%s'
% (message[:32], message[32:36], message[36:38], message[38:])
)
else:
self.announce('expected : %s' % message)
else:
Expand All @@ -401,7 +415,17 @@ class BGPHandler(asyncore.dispatcher_with_send):
if self.options['send-notification']:
notification = b'closing session because we can'
self.send(
bytearray([0xFF,] * 16 + [0x00, 19 + 2 + len(notification)] + [0x03] + [0x06] + [0x00]) + notification
bytearray(
[
0xFF,
]
* 16
+ [0x00, 19 + 2 + len(notification)]
+ [0x03]
+ [0x06]
+ [0x00]
)
+ notification
)

_decoder = {
Expand Down
15 changes: 12 additions & 3 deletions qa/self/api/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import sys

match = {
0: ['neighbor 127.0.0.1 update start',] * 20,
0: [
'neighbor 127.0.0.1 update start',
]
* 20,
1: [
'neighbor 127.0.0.1 announced route %d%d.0.0.0/8 next-hop 1.1.1.1 origin igp as-path [ 1 2 3 4 ] med 100'
% (number, number)
Expand All @@ -25,8 +28,14 @@
(25, 65, 'l2vpn vpls'),
)
],
2: ['neighbor 127.0.0.1 update end',] * 20,
3: ['',] * 20,
2: [
'neighbor 127.0.0.1 update end',
]
* 20,
3: [
'',
]
* 20,
}

count = 0
Expand Down
3 changes: 1 addition & 2 deletions qa/self/big/api-internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import sys
import time
import random


def write(data):
Expand All @@ -14,7 +13,7 @@ def main():
count = 0

ip = {}
nexthop = "1.2.3.4"
nexthop = '1.2.3.4'

for ip1 in range(0, 223):
generated = '%d.0.0.0/8' % (ip1)
Expand Down
3 changes: 1 addition & 2 deletions qa/self/flow/flow-change.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3

from __future__ import print_function
import os
import sys
import time

flow = "flow route { match { source 10.0.0.1/32; destination 10.0.0.2/32; destination-port =3128; protocol tcp; } then { discard; } }"
flow = 'flow route { match { source 10.0.0.1/32; destination 10.0.0.2/32; destination-port =3128; protocol tcp; } then { discard; } }'

# When the parent dies we are seeing continual newlines, so we only access so many before stopping
counter = 1
Expand Down
6 changes: 3 additions & 3 deletions qa/self/flow/log-syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

def _prefixed(level, message):
now = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
return "%s %-8s %-6d %s" % (now, level, os.getpid(), message)
return '%s %-8s %-6d %s' % (now, level, os.getpid(), message)


syslog.openlog("ExaBGP")
syslog.openlog('ExaBGP')

# When the parent dies we are seeing continual newlines, so we only access so many before stopping
counter = 0

while True:
try:
line = sys.stdin.readline().strip()
if line == "":
if line == '':
counter += 1
if counter > 100:
break
Expand Down
2 changes: 1 addition & 1 deletion qa/self/load/api-internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def write(data):

def main():
if len(sys.argv) < 2:
print("%s <number of routes> <updates per second thereafter>")
print('%s <number of routes> <updates per second thereafter>')
sys.exit(1)

initial = sys.argv[1]
Expand Down
4 changes: 1 addition & 3 deletions qa/self/operational/operational-print.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env python3

import os
import sys
import time

# When the parent dies we are seeing continual newlines, so we only access so many before stopping
counter = 0

while True:
try:
line = sys.stdin.readline().strip()
if line == "":
if line == '':
counter += 1
if counter > 100:
break
Expand Down
1 change: 0 additions & 1 deletion qa/self/operational/operational-send.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

from __future__ import print_function
import os
import sys
import time

Expand Down
Loading

0 comments on commit 9dadff8

Please sign in to comment.