Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit config and tidy up #171

Merged
merged 5 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
python-version: ['2.x', '3.x']
name: Python ${{ matrix.python-version }} test
steps:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
Expand All @@ -20,14 +20,14 @@ jobs:
- name: Base requirements for SSM
run: pip install -r requirements.txt
- name: Additional requirements for the unit and coverage tests
run: pip install -r requirements-test.txt
run: pip install -r requirements-test.txt
- name: Pre-test set up
run: |
export TMPDIR=$PWD/tmp
mkdir $TMPDIR
export PYTHONPATH=$PYTHONPATH:`pwd -P`
cd test
- name: Run unit tests
run: coverage run --branch --source=ssm,bin -m unittest discover --buffer
run: coverage run --branch --source=ssm,bin -m unittest discover --buffer
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://pre-commit.com for more information
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
# Python related checks
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: name-tests-test
name: Check unit tests start with 'test_'
args: ['--django']
files: 'test/.*'
# Other checks
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
name: Force line endings to LF
args: ['--fix=lf']
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ if You agree to indemnify, defend, and hold each Contributor harmless for any li
incurred by, or claims asserted against, such Contributor by reason of your accepting
any such warranty or additional liability.

END OF TERMS AND CONDITIONS
END OF TERMS AND CONDITIONS
1 change: 0 additions & 1 deletion bin/apel-ssm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ case "$1" in
esac

exit $RETVAL

1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
coveralls<=1.2.0
mock
codecov
pre-commit
6 changes: 3 additions & 3 deletions ssm/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_protocol(cp, log):
# If the newer configuration setting 'protocol' is not set, use 'STOMP'
# for backwards compatability.
protocol = Ssm2.STOMP_MESSAGING
log.warn("No option set for 'protocol'. Defaulting to %s.", protocol)
log.warning("No option set for 'protocol'. Defaulting to %s.", protocol)
except ValueError:
log.critical("Invalid protocol '%s' set. Must be either '%s' or '%s'.",
protocol, Ssm2.STOMP_MESSAGING, Ssm2.AMS_MESSAGING)
Expand Down Expand Up @@ -315,7 +315,7 @@ def run_receiver(protocol, brokers, project, token, cp, log, dn_file):
ssm.send_ping()

except (NotConnectedException, AmsConnectionException) as error:
log.warn('Connection lost.')
log.warning('Connection lost.')
log.debug(error)
ssm.shutdown()
dc.close()
Expand Down Expand Up @@ -355,7 +355,7 @@ def get_dns(dn_file, log):
elif line.strip().startswith('/'):
dns.append(line.strip())
else:
log.warn('DN in incorrect format: %s', line)
log.warning('DN in incorrect format: %s', line)
finally:
if f is not None:
f.close()
Expand Down
22 changes: 11 additions & 11 deletions ssm/ssm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _handle_msg(self, text):
"""
if text is None or text == '':
warning = 'Empty text passed to _handle_msg.'
log.warn(warning)
log.warning(warning)
return None, None, warning
# if not text.startswith('MIME-Version: 1.0'):
# raise Ssm2Exception('Not a valid message.')
Expand All @@ -313,7 +313,7 @@ def _handle_msg(self, text):

if signer not in self._valid_dns:
warning = 'Signer not in valid DNs list: %s' % signer
log.warn(warning)
log.warning(warning)
return None, signer, warning
else:
log.info('Valid signer: %s', signer)
Expand All @@ -335,7 +335,7 @@ def _save_msg_to_queue(self, body, empaid):
# allows the msg to be reloaded if needed.
body = extracted_msg

log.warn("Message rejected: %s", err_msg)
log.warning("Message rejected: %s", err_msg)

name = self._rejectq.add({'body': body,
'signer': signer,
Expand Down Expand Up @@ -474,7 +474,7 @@ def send_all(self):
log.info('Found %s messages.', self._outq.count())
for msgid in self._outq:
if not self._outq.lock(msgid):
log.warn('Message was locked. %s will not be sent.', msgid)
log.warning('Message was locked. %s will not be sent.', msgid)
continue

text = self._outq.get(msgid)
Expand Down Expand Up @@ -514,7 +514,7 @@ def send_all(self):
# Remove empty dirs and unlock msgs older than 5 min (default)
self._outq.purge()
except OSError as e:
log.warn('OSError raised while purging message queue: %s', e)
log.warning('OSError raised while purging message queue: %s', e)

###########################################################################
# Connection handling methods
Expand Down Expand Up @@ -563,9 +563,9 @@ def handle_connect(self):
break
except ConnectFailedException as e:
# ConnectFailedException doesn't provide a message.
log.warn('Failed to connect to %s:%s.', host, port)
log.warning('Failed to connect to %s:%s.', host, port)
except Ssm2Exception as e:
log.warn('Failed to connect to %s:%s: %s', host, port, e)
log.warning('Failed to connect to %s:%s: %s', host, port, e)

if not self.connected:
raise Ssm2Exception('Attempts to start the SSM failed. The system will exit.')
Expand Down Expand Up @@ -660,7 +660,7 @@ def startup(self):
f.write('\n')
f.close()
except IOError as e:
log.warn('Failed to create pidfile %s: %s', self._pidfile, e)
log.warning('Failed to create pidfile %s: %s', self._pidfile, e)

self.handle_connect()

Expand All @@ -672,7 +672,7 @@ def shutdown(self):
if os.path.exists(self._pidfile):
os.remove(self._pidfile)
else:
log.warn('pidfile %s not found.', self._pidfile)
log.warning('pidfile %s not found.', self._pidfile)
except IOError as e:
log.warn('Failed to remove pidfile %s: %e', self._pidfile, e)
log.warn('SSM may not start again until it is removed.')
log.warning('Failed to remove pidfile %s: %e', self._pidfile, e)
log.warning('SSM may not start again until it is removed.')
2 changes: 1 addition & 1 deletion test/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_get_iffy_dns(self):
f.write(dn_text)
f.close()
ssm.agents.get_dns(self.tf_path, self.mock_log)
self.assertEqual(self.mock_log.warn.call_count, 2)
self.assertEqual(self.mock_log.warning.call_count, 2)

def tearDown(self):
os.remove(self.tf_path)
Expand Down