Clone cleaning and configure CI to run tests
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Benjamin Renard 2022-12-17 00:55:31 +01:00
parent 4161e4cd51
commit ab7e09d7b6
3 changed files with 30 additions and 10 deletions

3
.pylintrc Normal file
View File

@ -0,0 +1,3 @@
[MESSAGES CONTROL]
disable=consider-using-f-string,
invalid-name,

12
.woodpecker.yml Normal file
View File

@ -0,0 +1,12 @@
pipeline:
test-pylint:
group: test
image: pipelinecomponents/pylint
commands:
- pylint check_livestatus
test-flake8:
group: test
image: pipelinecomponents/flake8
commands:
- flake8 check_livestatus

View File

@ -14,7 +14,7 @@ DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 6557 DEFAULT_PORT = 6557
DEFAULT_TIMEOUT = 2 DEFAULT_TIMEOUT = 2
### MAIN #### # MAIN
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument( parser.add_argument(
@ -82,7 +82,9 @@ options = parser.parse_args()
# Initialize log # Initialize log
log = logging.getLogger() log = logging.getLogger()
logformat = logging.Formatter("%(asctime)s - " + os.path.basename(sys.argv[0]) + " - %(levelname)s - %(message)s") logformat = logging.Formatter(
"%(asctime)s - " + os.path.basename(sys.argv[0]) +
" - %(levelname)s - %(message)s")
if options.debug: if options.debug:
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
@ -111,7 +113,8 @@ try:
livestatus = socket.socket(socket.AF_INET, socket.SOCK_STREAM) livestatus = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
livestatus.connect((options.host, options.port)) livestatus.connect((options.host, options.port))
else: else:
parser.error('You must provide Livestatus UNIX socket path or host & port') parser.error(
'You must provide Livestatus UNIX socket path or host & port')
sys.exit(3) sys.exit(3)
livestatus.settimeout(options.timeout) livestatus.settimeout(options.timeout)
@ -121,23 +124,25 @@ try:
status = None status = None
if rawdata: if rawdata:
data = json.loads(rawdata) data = json.loads(rawdata)
assert isinstance(data, list) and len(data) == 2, "Invalid Livestatus return:\n%s" % data assert isinstance(data, list) and len(data) == 2, \
"Invalid Livestatus return:\n%s" % data
status = dict( status = dict(
(data[0][idx], value) (data[0][idx], value)
for idx, value in enumerate(data[1]) for idx, value in enumerate(data[1])
) )
except Exception: except Exception: # pylint: disable=broad-except
print( print(
'UNKNOWN - Fail to retreive status from Livestatus from %s\n\nException:\n%s' % 'UNKNOWN - Fail to retreive status from Livestatus '
'from %s\n\nException:\n%s' %
(peer, traceback.format_exc()) (peer, traceback.format_exc())
) )
sys.exit(2) sys.exit(2)
if isinstance(status, dict) and 'num_hosts' in status: if isinstance(status, dict) and 'num_hosts' in status:
print('OK - %s host(s) found\n' % status['num_hosts']) print('OK - %s host(s) found\n' % status['num_hosts'])
for key in sorted(status.keys()): for key in sorted(status.keys()):
print('%s: %s' % (key, status[key])) print('%s: %s' % (key, status[key]))
sys.exit(0) sys.exit(0)
print('UNKNOWN - Invalid Livestatus return\n\n%s' % data) print('UNKNOWN - Invalid Livestatus return\n\n%s' % data)
sys.exit(3) sys.exit(3)