tests: enable shellcheck for shell-based plugins and flake8 for python-based plugins

Many plugins are still failing these tests.
These expected failures are listed in a file
(t/test-exception-wrapper.expected-failures)
A wrapper script is used for running the tests and comparing the result
with the expectation (based on the file being listed in the above file).

This allows to test all new plugins, while ignoring all known failures.
This commit is contained in:
Lars Kruse 2019-08-12 06:01:49 +02:00
parent 53860136a5
commit e5abdeeb12
4 changed files with 599 additions and 21 deletions

View File

@ -5,7 +5,9 @@ addons:
packages:
- devscripts
- python
- python-flake8
- python3
- python3-flake8
- ruby
- php-cli
- gawk

55
t/test-exception-wrapper Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
#
# Run a check for a given file. A failure is tolerated (and expected), if the filename is listed
# in a file containing expected failures.
#
# Parameters: SHELL_DIALECT SCRIPT_FILENAME
#
# See EXPECTED_FAILURES_LIST_FILENAME for the filename pattern of a file, containing the relative
# names of all scripts, that are expected to fail. This wrapper script will fail, if the exit
# status of the test does not match the expectated result (i.e. it fails but should pass or it
# passes while being listed in the EXPECTED_FAILURES_LIST_FILENAME file).
#
set -eu
[ $# -lt 2 ] && echo >&2 "Insufficient number of arguments: expecting SCRIPT_FILENAME and one or more COMMAND tokens" && exit 1
SCRIPT_FILENAME="$1"
shift
EXPECTED_FAILURES_LIST_FILENAME="$0.expected-failures"
REPOSITORY_DIR=$(cd "$(dirname "$0")/.." && pwd)
[ ! -e "$SCRIPT_FILENAME" ] && echo >&2 "Failed to find script: $SCRIPT_FILENAME" && exit 3
# determine, whether the script is mentioned in the exclusion file
relative_script_filename=$(realpath --relative-to "$REPOSITORY_DIR" "$SCRIPT_FILENAME")
if grep --quiet --line-regexp --fixed-strings --no-messages "$relative_script_filename" "$EXPECTED_FAILURES_LIST_FILENAME"; then
is_expected_to_fail=1
else
is_expected_to_fail=0
fi
# check the returncode of the test
if "$@" "$SCRIPT_FILENAME"; then
has_failed=0
else
has_failed=1
fi
# complain, if the result did not meet our expectation
if [ "$is_expected_to_fail" = "$has_failed" ]; then
# the check returned the expected result
exit 0
elif [ "$has_failed" = "1" ]; then
echo >&2 "ERROR: the script '$SCRIPT_FILENAME' should pass the test, but it failed"
exit 4
else
echo >&2 "ERROR: the script '$SCRIPT_FILENAME' was expected to fail the test, but it passed"
exit 5
fi

View File

@ -0,0 +1,492 @@
plugins/accounting/accounting_
plugins/amavis/amavis_awk
plugins/amavis/amavis-debian
plugins/amule/amule_queue
plugins/amule/amule_shares
plugins/amule/amule_transfers
plugins/amule/amule_uptime
plugins/apache/apache_cache_disk_count
plugins/apache/apache_memmory
plugins/apache/apache_servers
plugins/apache/apache_threads
plugins/apache/apache_tmemmory
plugins/apache/apache_users
plugins/apache/page_load
plugins/apache/qpid_bytedepth
plugins/apache/qpid_discardsring
plugins/apache/qpid_enqueuebytes
plugins/apache/qpid_enqueuecount
plugins/apache/qpid_msgdepth
plugins/apt/deb_packages/deb_packages.py
plugins/arangodb/arangodb_
plugins/arp/arp_
plugins/arp/arp_bsd_
plugins/asterisk/asterisk_channels
plugins/asterisk/asterisk_inuse
plugins/backuppc/backuppc
plugins/battery/acpi-battery
plugins/battery/battery_
plugins/bigbrother/b3error_
plugins/bind/bind9_resolver_stats
plugins/bind/bind9_server_stats
plugins/bind/bind9_socket_stats
plugins/bsd/df_abs_bsd
plugins/bsd/df_bsd
plugins/bsd/freebsd_hdd_power_state
plugins/bsd/spamd-blacklist-bsd
plugins/bsd/spamd-tarpit-bsd
plugins/cacti/cacti-host
plugins/cacti/cacti_poller_time
plugins/cacti/cacti_rrds
plugins/celery/celery_tasks
plugins/celery/celery_tasks_states
plugins/ceph/ceph-osd-info
plugins/change.org/changeorg_signature_count
plugins/chat/tinychat_users_
plugins/cherokee/munin-plugin-for-cherokee
plugins/chilli/chilli_sessions_
plugins/chrony/chrony
plugins/clamav/clamav
plugins/condor/condor_activity_
plugins/condor/condor_ops_
plugins/condor/condor_queue_
plugins/condor/condor_states_
plugins/courier/courier_log
plugins/cpu/cpu_
plugins/cpu/cpuload_
plugins/cpu/cpuutil
plugins/cpu/multicpu1sec
plugins/cpu/process_count
plugins/cpu/process_cpushare
plugins/currency/bitcoin/btcguild_hashrate_
plugins/currency/bitcoin/slush_hashrate_
plugins/currency/bitcoin/slush_reward_
plugins/currency/ethereum/ethermine_hashrate_
plugins/currency/nanopool/nanopool_
plugins/currency/zcash/zcash_flypool_hashrate_
plugins/cyrus/cyrus-imapd
plugins/db2/db2_cnx
plugins/dhcp/dhcpd-pools
plugins/disk/df_with_nfs
plugins/disk/dm_cache_occupancy_
plugins/disk/dm_cache_statistics_
plugins/disk/du
plugins/disk/du_multidirs
plugins/disk/du_pattern
plugins/disk/e2
plugins/disk/file_age
plugins/disk/freedisk
plugins/disk/hdsentinel
plugins/disk/iostat-xfrs
plugins/disk/log_sizes
plugins/disk/lvm_
plugins/disk/lvm_snap_used
plugins/disk/megaraid-hdd-temperature-using-megacli
plugins/disk/quota2percent_
plugins/disk/raid-mismatch-count
plugins/disk/scsi_queue
plugins/disk/snmp__areca_
plugins/disk/useddisk
plugins/disk/xfs_frag
plugins/dkim/dkimproxy_mails
plugins/dovecot/dovecot
plugins/dovecot/dovecot_stats_
plugins/dspam/dspam_
plugins/dspam/dspam_activity
plugins/dvb/2wcomdsr_
plugins/dvb/femon
plugins/ejabberd/ejabberd_resources_
plugins/emc/emc_vnx_block_lun_perfdata
plugins/emc/emc_vnx_file_
plugins/fan/dell_fans
plugins/fan/ibmfan
plugins/fax/faxstat
plugins/firebird/firebird
plugins/freeradius/freeradius
plugins/freeradius/freeradius_queue
plugins/ftp/pure-ftpd
plugins/ftp/pure-ftpd-bw
plugins/ftp/pureftpd_count
plugins/ftp/pure-ftpd-logs
plugins/ftp/vsftpd-rel
plugins/games/cstat
plugins/git/git_commit_behind
plugins/glance/glance_size_
plugins/glance/glance_status
plugins/glassfish/glassfish_counters_
plugins/google/googlecode
plugins/google/google-rank
plugins/gpu/amd_gpu_
plugins/gunicorn/gunicorn_memory_status
plugins/gunicorn/gunicorn_status
plugins/haproxy/haproxy_abort_backend
plugins/haproxy/haproxy_active_backend
plugins/haproxy/haproxy-bytes
plugins/haproxy/haproxy_bytes_backend
plugins/haproxy/haproxy_bytes_compressor_backend
plugins/haproxy/haproxy_bytes_compressor_frontend
plugins/haproxy/haproxy_bytes_frontend
plugins/haproxy/haproxy-connection-errors
plugins/haproxy/haproxy_denied_backend
plugins/haproxy/haproxy_denied_frontend
plugins/haproxy/haproxy-downtime
plugins/haproxy/haproxy-errors
plugins/haproxy/haproxy_errors_backend
plugins/haproxy/haproxy_errors_frontend
plugins/haproxy/haproxy-failed-checks
plugins/haproxy/haproxy_queue_backend
plugins/haproxy/haproxy_rate_backend
plugins/haproxy/haproxy_rate_frontend
plugins/haproxy/haproxy_reqrate_frontend
plugins/haproxy/haproxy_response_compressor_backend
plugins/haproxy/haproxy_response_compressor_frontend
plugins/haproxy/haproxy-response-errors
plugins/haproxy/haproxy_responses_backend
plugins/haproxy/haproxy_responses_frontend
plugins/haproxy/haproxy-sessions
plugins/haproxy/haproxy_sessions_backend
plugins/haproxy/haproxy-sessions-by-servers
plugins/haproxy/haproxy_sessions_frontend
plugins/haproxy/haproxy_sessions_total_backend
plugins/haproxy/haproxy_sessions_total_frontend
plugins/haproxy/haproxy_warnings_backend
plugins/harddisks/powered_up_
plugins/horde/horde
plugins/http/http_pagespeed
plugins/http/http_responsecode
plugins/http/vhost_requests_
plugins/http/wget_page
plugins/i2p/i2p_
plugins/icecast/icecast_
plugins/icecast/icecast2
plugins/icecast/icecast2_
plugins/icecast/icecast2_all
plugins/icecast/icecast2_stats_
plugins/imapproxy/imapproxy_multi
plugins/ip6/ip6_
plugins/ipvs/ipvs_active
plugins/ipvs/ipvs_bps
plugins/ipvs/ipvs_conn
plugins/ipvs/ipvs_cps
plugins/isp/internode_usage
plugins/jmx/plugin/jmx_
plugins/jvm/jstat__gccount
plugins/jvm/jstat__gctime
plugins/jvm/jstat__heap
plugins/keystone/keystone_stats
plugins/libvirt/kvm_cpu
plugins/libvirt/kvm_io
plugins/libvirt/kvm_mem
plugins/libvirt/kvm_net
plugins/libvirt/munin-libvirtpy
plugins/lighttpd/lighttpd_
plugins/logins/logins
plugins/logs/service_events
plugins/lxc/lxc_cpu
plugins/lxc/lxc_cpu_time
plugins/lxc/lxc_net
plugins/lxc/lxc_proc
plugins/lxd/lxd_disk
plugins/lxd/lxd_mem
plugins/mail/imap_bandwidth
plugins/mail/mail_connections
plugins/mailman/mailman-queue-check
plugins/mail/postfwd-rbl
plugins/memory/kmemsum
plugins/memory/multimemory
plugins/memory/proc_mem
plugins/memory/proc_memory_status
plugins/mixminion/mixminion
plugins/mod_jk/mod_jk
plugins/moinmoin/moinoin_pages
plugins/mongodb/mongo_btree
plugins/mongodb/mongo_collection_
plugins/mongodb/mongo_conn
plugins/mongodb/mongo_lag
plugins/mongodb/mongo_lock
plugins/mongodb/mongo_mem
plugins/mongodb/mongo_ops
plugins/mumble/mumble_users
plugins/mumble/murmur-stats
plugins/munin/healthcheck_log
plugins/munin/healthcheck_process
plugins/munin/healthcheck_url
plugins/munin/update
plugins/mysql/hs_read
plugins/mysql/hs_write
plugins/mysql/mysql_aggregate_
plugins/mysql/mysql_report
plugins/mysql/mysql_size_ondisk
plugins/mythtv/dvb-signal
plugins/netapp/snmp__netapp_cifs
plugins/netapp/snmp__netapp_cpu
plugins/network/bgpd
plugins/network/brc_rssi
plugins/network/ddclient
plugins/network/denyhosts
plugins/network/ethtool_
plugins/network/fwbuilder_
plugins/network/hfsc
plugins/network/hfsc_sep
plugins/network/hostsdeny
plugins/network/host_traffic
plugins/network/if1sec_
plugins/network/ifem_
plugins/network/if_uptime
plugins/network/iperf_
plugins/network/ip_forward_
plugins/network/ipfwcnt_
plugins/network/ipfwnat_
plugins/network/ipt_accounting_
plugins/network/ipt_basic_
plugins/network/ldap_connections
plugins/network/linux_if/linux_if
plugins/network/mtr100_
plugins/network/netatalk
plugins/network/netatalk3
plugins/network/net_hosts_
plugins/network/nsd3
plugins/network/olsrd
plugins/network/packetloss
plugins/network/proc_netstat
plugins/network/psad
plugins/network/shorewall_
plugins/network/shorewall_acc
plugins/network/shorewall-accounting_
plugins/network/smtp_hello_
plugins/network/sockstat
plugins/network/tc_
plugins/network/tc_drops_
plugins/network/tc_packets_
plugins/network/traffic
plugins/network/traffic_ipt
plugins/network/transmission
plugins/network/umts_sig
plugins/network/upnpc_
plugins/network/vnstat
plugins/network/vnstat_
plugins/nfs/nfsv4
plugins/nginx/nginx-cache-multi_
plugins/nginx/nginx_upstream
plugins/nginx/nginx_vhost_traffic
plugins/nginx/nginx_working_set
plugins/nova/nova_floating_ips
plugins/nova/nova_instance_
plugins/nova/nova_instance_launched
plugins/nova/nova_instance_timing
plugins/nova/nova_services
plugins/ntp/ntpdate_
plugins/ntp/ntp_kernel_pll_prec
plugins/ntp/ntp_pool_score_
plugins/openntpd/openntp_offset
plugins/openvz/openvz_
plugins/oracle/oracle_connections
plugins/oracle/oracle_sysstat
plugins/ossec/ossec_active_response
plugins/ossec/ossec_agents
plugins/ossec/ossec_alerts
plugins/other/beanstalkd
plugins/other/cm2
plugins/other/earthquakes-stronger-than-m4-and-m5-plus-solar-act
plugins/other/foldingathome_activecpu
plugins/other/globesurfer
plugins/other/hookbox
plugins/other/listeners
plugins/other/pid
plugins/other/s9y
plugins/other/services
plugins/pdns/pdns_errors
plugins/pdns/pdns_queries
plugins/pdns/pdns_rec_qtypes
plugins/pf/pf
plugins/pf/pf_bytes
plugins/pf/pf_ipv4_ipv6_packets
plugins/pf/pf_openbsd
plugins/pf/pf_packets
plugins/pf/pf_states
plugins/php/eaccelerator
plugins/php/eaccelerator-python
plugins/php/php5-fpm_status
plugins/php/php_apc_
plugins/php/php-cgi
plugins/php/php_errors_
plugins/php/php_opcache
plugins/php/php_sessions
plugins/php/php_time_execution
plugins/ping/fping_
plugins/ping/pinger
plugins/ping/ping_host
plugins/ping/ping-with-ceil
plugins/poseidon/snmp__poseidon-sensors
plugins/postfix/greyfix
plugins/postfix/policyd-spf-python
plugins/postfix/postfix_filtered
plugins/postfix/postfix_filtered_awk
plugins/postfix/postfix_mailfiltered
plugins/postfix/postfix_mailqueue_
plugins/postfix/postfix_mail_stats
plugins/postfix/postfix_mail_stats1
plugins/postfix/postfix-policyd
plugins/postfix/postfix-queue-size
plugins/postfix/postfix-rbl-blocked-mails
plugins/postfix/postgrey
plugins/postgresql/pgbouncer_client_connections
plugins/postgresql/pgbouncer_maxwait
plugins/postgresql/pgbouncer_server_connections
plugins/postgresql/postgresql_active_backends
plugins/postgresql/postgresql_active_backends_by_database
plugins/postgresql/postgresql_active_locks
plugins/postgresql/postgresql_database_ratio
plugins/postgresql/postgresql_database_size
plugins/postgresql/postgresql_tablespace_size
plugins/postgresql/postgres_queries2_
plugins/postgresql/slony_lag_events_
plugins/postgresql/slony_lag_time
plugins/postgresql/slony_lag_time_
plugins/power5/consumed_cpu_cycles
plugins/power5/cpu_entitlemens
plugins/power5/cpu_in_lpar
plugins/power5/weight_of_a_lpar
plugins/power/apc_status
plugins/power/eatonups_
plugins/powermta/pmta_
plugins/powermta/powermta_vmta_recpients
plugins/power/nut
plugins/printer/dell_5310n_health_
plugins/printer/dell_5310n_pages_
plugins/printer/hp2600_count_
plugins/printer/hp2600_status_
plugins/printer/oki_c5500_health_
plugins/printer/oki_c5500_pages_
plugins/printer/toshiba_5520c_byfunction_black_
plugins/printer/toshiba_5520c_byfunction_fullcolor_
plugins/printer/toshiba_5520c_print_
plugins/printer/toshiba_5520c_scan_
plugins/printer/xerox-wc3220
plugins/printer/xerox-wc7232-consumables
plugins/puma/puma_
plugins/qmail/qmailconn
plugins/qmail/queuestats
plugins/qmail/spamdyke
plugins/rabbitmq/rabbitmq_consumers
plugins/rabbitmq/rabbitmq_messages
plugins/rabbitmq/rabbitmq_messages_unacknowledged
plugins/rabbitmq/rabbitmq_messages_uncommitted
plugins/rabbitmq/rabbitmq_queue_memory
plugins/radiator/radiator_acct_lag
plugins/radiator/radiator_acct_ppm
plugins/radiator/radiator_auth_lag
plugins/radiator/radiator_auth_ppm
plugins/raspberry-pi/cpu_freq_1sec
plugins/requesttracker/rt_ticket_loadtime
plugins/rethinkdb/rethinkdb_node_io
plugins/riak/riak_fsm_time_95
plugins/riak/riak_memory
plugins/riak/riak_node
plugins/router/arris-tm502g_
plugins/router/bbox
plugins/router/cisco-epc3010_
plugins/router/conexant_adsl
plugins/router/dartybox
plugins/router/dsl-connection-speed
plugins/router/dsl-stats
plugins/router/freeboxuptime
plugins/router/motorola_sb6141
plugins/router/snmp__juniper
plugins/router/snmp__juniper_spu
plugins/router/speedport_300
plugins/rsync/rsyncd_bytes
plugins/rsync/rsyncd_count
plugins/sar/iostat-cputps-average
plugins/scalix/scalix_clients
plugins/scalix/scalix_processes
plugins/scalix/scalix_queues
plugins/senderbase/senderbase
plugins/senderscore/senderscore
plugins/sensors/alertme_keyfobsathome
plugins/sensors/alertme_power
plugins/sensors/cleware
plugins/sensors/nvclock
plugins/sensors/sequoia_websens
plugins/sge/sge_job_stats
plugins/sge/sge_queue_
plugins/sge/sge_queue_xml_
plugins/smstools/smstools_
plugins/snmp/snmp__airport
plugins/snmp/snmp___bri_se_
plugins/snmp/snmp__brocade_ifs
plugins/snmp/snmp__fn
plugins/snmp/snmp__webthermometer
plugins/solaris/io_disk
plugins/solaris/zones_cpu
plugins/solaris/zones_mem
plugins/solr/solr
plugins/solr/solr4_
plugins/solr/solrmulticore
plugins/spamassasin/sa-learn
plugins/sphinx/sphinx_documents
plugins/squid/squid_efficiency
plugins/squid/squid_times
plugins/ssh/hostdenied
plugins/ssh/openssh-denyhosts
plugins/ssh/sshd_log
plugins/streaming/packetship_
plugins/swift/swift-async_
plugins/swift/swift-quarantined_
plugins/swift/swift-replication-time_
plugins/synology/snmp__synology
plugins/system/auth
plugins/system/blockhosts
plugins/systemd/systemd_units
plugins/system/file_length_
plugins/system/read_serial_temperature
plugins/tarsnap/tarsnap
plugins/tcp/tcp-retransmissions
plugins/tcp/tcp-states
plugins/tinydns/tinydns
plugins/tinydns/tinydns_err
plugins/tor/tor_
plugins/tor/tor_traffic
plugins/trafic_ro/trafic_ro_24h
plugins/tv/hdhomerun_
plugins/twemproxy/nutcracker_requests_
plugins/unicorn/unicorn_
plugins/user/membyuser
plugins/user/multipsu
plugins/user/system_users
plugins/uwsgi/uwsgi_
plugins/varnish/varnish_devicedetect
plugins/vmware/esxcli_env_
plugins/vmware/esxi
plugins/vmware/esxi__sensors
plugins/vmware/vm_cpu_load
plugins/vpn/openvpn_as_mtime
plugins/vpn/openvpn_as_traffic
plugins/vpn/openvpn_as_ttime
plugins/vpn/openvpn_as_users
plugins/vserver/vserver_limit_hits
plugins/vserver/vserver_limits
plugins/vserver/vserver_procs
plugins/weather/openweather_
plugins/websphere/webspherelogin
plugins/wifi/ath9k_
plugins/wifi/wifi_signal
plugins/wordpress/wordpress
plugins/wordpress/wordpress-multisite
plugins/wordpress/wordpress-mu-or-network
plugins/wowza/wowza-media-server
plugins/xastir/xastir
plugins/yum/yum_activity
plugins/zfs/zfsarcstats-counters
plugins/zfs/zfs_cache_efficiency
plugins/zfs/zfs_list
plugins/zfs/zfsonlinux_stats_
plugins/zfs/zfs_stats_
plugins/zfs/zlist
plugins/zfs/zpool_iostat
plugins/zimbra/zimbra-mailboxsizes
plugins/znc/znc_logs.py
plugins/zope/zeomonitor
plugins/zope/zope_cache_parameters
plugins/zope/zope_conflict_errors
plugins/zope/zope_db_activity

View File

@ -25,7 +25,7 @@ sub wanted {
&& process_file( $_, $name, $interpreter, $arguments );
}
File::Find::find( { wanted => \&wanted }, 'plugins' );
File::Find::find( { wanted => \&wanted, no_chdir => 1 }, 'plugins' );
sub hashbang {
my ($filename) = @_;
@ -64,7 +64,7 @@ sub process_file {
}
elsif ( $interpreter =~ m{/bin/sh} ) {
subtest $filename => sub {
plan tests => 2;
plan tests => 3;
run_check(
{ command => [ 'sh', '-n', $file ],
description => 'sh syntax check'
@ -89,6 +89,11 @@ sub process_file {
description => 'checkbashisms'
}
);
run_check(
{ command => [ 't/test-exception-wrapper', $file, 'shellcheck', '--exclude=SC1090,SC2009,SC2126,SC2230', '--shell=dash' ],
description => 'shellcheck'
}
);
};
}
elsif ( $interpreter =~ m{/bin/ksh} ) {
@ -101,19 +106,27 @@ sub process_file {
}
);
run_check(
{ command => [ 'shellcheck', $file ],
{ command => [ 't/test-exception-wrapper', $file, 'shellcheck', '--shell=ksh' ],
description => 'shellcheck'
}
);
}
}
elsif ( $interpreter =~ m{bash} ) {
run_check(
{ command => [ 'bash', '-n', $file ],
description => 'bash syntax check',
filename => $filename
}
);
subtest $filename => sub {
plan tests => 2;
run_check(
{ command => [ 'bash', '-n', $file ],
description => 'bash syntax check',
filename => $filename
}
);
run_check(
{ command => [ 't/test-exception-wrapper', $file, 'shellcheck', '--exclude=SC1090,SC2009,SC2126,SC2230', '--shell=bash' ],
description => 'shellcheck'
}
);
}
}
elsif ( $interpreter =~ m{/bin/zsh} ) {
run_check(
@ -139,20 +152,36 @@ sub process_file {
);
}
elsif ( $interpreter =~ m{python3} ) {
run_check(
{ command => [ 'python3', '-m', 'py_compile', $file ],
description => 'python3 compile',
filename => $filename
}
);
subtest $filename => sub {
plan tests => 2;
run_check(
{ command => [ 'python3', '-m', 'py_compile', $file ],
description => 'python3 compile',
filename => $filename
}
);
run_check(
{ command => [ 't/test-exception-wrapper', $file, 'python3', '-m', 'flake8' ],
description => 'python3-flake8'
}
);
}
}
elsif ( $interpreter =~ m{python} ) {
run_check(
{ command => [ 'python', '-m', 'py_compile', $file ],
description => 'python compile',
filename => $filename
}
);
subtest $filename => sub {
plan tests => 2;
run_check(
{ command => [ 'python', '-m', 'py_compile', $file ],
description => 'python compile',
filename => $filename
}
);
run_check(
{ command => [ 't/test-exception-wrapper', $file, 'python', '-m', 'flake8' ],
description => 'python-flake8'
}
);
}
}
elsif ( $interpreter =~ m{php} ) {
run_check(