Skip to content

Commit

Permalink
chore: fix flak8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
houqp authored and jrgp committed Mar 3, 2017
1 parent e2e8ef0 commit dea6d55
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 205 deletions.
2 changes: 1 addition & 1 deletion .ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pushd ${TRAVIS_BUILD_DIR}
make serve &
iris-sender ./configs/config.dev.yaml &

make test
make check
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ serve:
-e CONFIG=./configs/config.dev.yaml \
iris_api.wrappers.gunicorn:application

sender:
iris-sender configs/config.dev.yaml

test:
make unit
make e2e
Expand All @@ -15,6 +18,10 @@ e2e:
unit:
py.test test

check:
flake8
make test

unit-cov:
py.test --cov-report term-missing --cov=iris_api test

Expand Down
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pytest-mock==1.5.0
pytest-cov
# for py26 mock dep
ordereddict
flake8
1 change: 1 addition & 0 deletions docker/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ def main():

os.execv('/usr/bin/uwsgi', ['', '--yaml', '/home/iris/daemons/uwsgi.yaml:prod'])


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'oauth2client==1.4.12',
'slackclient==0.16',
'PyYAML==3.11',
'gevent==1.0.2',
'gevent==1.1.2',
'falcon==1.1.0',
'ujson==1.35',
'requests==2.9.1',
Expand Down
26 changes: 13 additions & 13 deletions src/iris_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ def load_config_file(config_path):
if 'init_config_hook' in config:
try:
module = config['init_config_hook']
logging.info('Bootstrapping config using %s' % module)
logger.info('Bootstrapping config using %s', module)
getattr(import_module(module), module.split('.')[-1])(config)
except ImportError:
logger.exception('Failed loading config hook %s' % module)
logger.exception('Failed loading config hook %s', module)

return config

Expand Down Expand Up @@ -1126,8 +1126,8 @@ def on_get(self, req, resp):

connection = db.engine.raw_connection()
escaped_params = {
'mode_change': connection.escape(auditlog.MODE_CHANGE),
'target_change': connection.escape(auditlog.TARGET_CHANGE)
'mode_change': connection.escape(auditlog.MODE_CHANGE),
'target_change': connection.escape(auditlog.TARGET_CHANGE)
}

query = message_query % ', '.join(message_columns[f] % escaped_params for f in fields)
Expand All @@ -1153,7 +1153,7 @@ class Notifications(object):
def __init__(self, config):
master_sender = config['sender'].get('master_sender', config['sender'])
self.sender_addr = (master_sender['host'], master_sender['port'])
logging.info('Sender used for notifications: %s:%s', *self.sender_addr)
logger.info('Sender used for notifications: %s:%s', *self.sender_addr)

def on_post(self, req, resp):
message = ujson.loads(req.context['body'])
Expand Down Expand Up @@ -2201,8 +2201,8 @@ class ReprioritizationMode(object):
def on_delete(self, req, resp, username, src_mode_name):
session = db.Session()
affected_rows = session.execute(delete_reprioritization_settings_query, {
'target_name': username,
'mode_name': src_mode_name,
'target_name': username,
'mode_name': src_mode_name,
}).rowcount
session.commit()
session.close()
Expand Down Expand Up @@ -2236,12 +2236,12 @@ class Stats(object):

def on_get(self, req, resp):
queries = {
'total_plans': 'SELECT COUNT(*) FROM `plan`',
'total_incidents': 'SELECT COUNT(*) FROM `incident`',
'total_messages_sent': 'SELECT COUNT(*) FROM `message`',
'total_incidents_today': 'SELECT COUNT(*) FROM `incident` WHERE `created` >= CURDATE()',
'total_messages_sent_today': 'SELECT COUNT(*) FROM `message` WHERE `sent` >= CURDATE()',
'total_active_users': 'SELECT COUNT(*) FROM `target` WHERE `type_id` = (SELECT `id` FROM `target_type` WHERE `name` = "user") AND `active` = TRUE',
'total_plans': 'SELECT COUNT(*) FROM `plan`',
'total_incidents': 'SELECT COUNT(*) FROM `incident`',
'total_messages_sent': 'SELECT COUNT(*) FROM `message`',
'total_incidents_today': 'SELECT COUNT(*) FROM `incident` WHERE `created` >= CURDATE()',
'total_messages_sent_today': 'SELECT COUNT(*) FROM `message` WHERE `sent` >= CURDATE()',
'total_active_users': 'SELECT COUNT(*) FROM `target` WHERE `type_id` = (SELECT `id` FROM `target_type` WHERE `name` = "user") AND `active` = TRUE',
}

stats = {}
Expand Down
18 changes: 18 additions & 0 deletions src/iris_api/bin/iris_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ def iris_ctl(ctx):
@click.pass_context
def app(ctx):
pass


iris_ctl.add_command(app)


@click.group('import')
@click.pass_context
def app_import(ctx):
pass


app.add_command(app_import)


Expand Down Expand Up @@ -73,6 +77,8 @@ def sample_context(ctx, app, sample_context, config):
(sample_ctx, app))
conn.commit()
click.echo(click.style('All done!', fg='green'))


app_import.add_command(sample_context)


Expand All @@ -95,6 +101,8 @@ def context_template(ctx, app, context_template, config):
(tpl_content, app))
conn.commit()
click.echo(click.style('All done!', fg='green'))


app_import.add_command(context_template)


Expand All @@ -118,13 +126,17 @@ def summary_template(ctx, app, summary_template, config):
(tpl_content, app))
conn.commit()
click.echo(click.style('All done!', fg='green'))


app_import.add_command(summary_template)


@click.group()
@click.pass_context
def template(ctx):
pass


iris_ctl.add_command(template)


Expand Down Expand Up @@ -168,13 +180,17 @@ def delete_template(ctx, template, config):
else:
conn.commit()
click.echo(click.style('All done!', fg='green'))


template.add_command(delete_template)


@click.group()
@click.pass_context
def plan(ctx):
pass


iris_ctl.add_command(plan)


Expand Down Expand Up @@ -223,6 +239,8 @@ def delete_plan(ctx, plan, config):
else:
conn.commit()
click.echo(click.style('All done!', fg='green'))


plan.add_command(delete_plan)


Expand Down
15 changes: 7 additions & 8 deletions src/iris_api/bin/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See LICENSE in the project root for license information.

from gevent import monkey, sleep, spawn, queue
monkey.patch_all()
monkey.patch_all() # NOQA

import logging
import sys
Expand All @@ -24,6 +24,8 @@
from iris_api import cache as api_cache
from iris_api.sender.quota import ApplicationQuota
from pymysql import DataError
# queue for sending messages
from iris_api.sender.shared import send_queue

# sql

Expand Down Expand Up @@ -202,9 +204,6 @@
# Quota object used for rate limiting
quota = None

# queue for sending messages
from iris_api.sender.shared import send_queue

default_sender_metrics = {
'email_cnt': 0, 'email_total': 0, 'email_fail': 0, 'email_sent': 0, 'email_max': 0,
'email_min': 0, 'email_avg': 0, 'im_cnt': 0, 'im_total': 0, 'im_fail': 0, 'im_sent': 0,
Expand Down Expand Up @@ -931,7 +930,7 @@ def gwatch_renewer():
logger.info('[*] gmail watcher loop finished')

# only renew every 8 hours
sleep(60*60*8)
sleep(60 * 60 * 8)


def prune_old_audit_logs_worker():
Expand All @@ -943,7 +942,7 @@ def prune_old_audit_logs_worker():
cursor.close()
connection.close()
logger.info('Ran task to prune old audit logs. Waiting 4 hours until next run.')
sleep(60*60*4)
sleep(60 * 60 * 4)


def mock_gwatch_renewer():
Expand Down Expand Up @@ -973,8 +972,8 @@ def init_sender(config):

if should_skip_send:
config['vendors'] = [{
'type': 'iris_dummy',
'name': 'iris dummy vendor'
'type': 'iris_dummy',
'name': 'iris dummy vendor'
}]

global quota
Expand Down
2 changes: 1 addition & 1 deletion src/iris_api/bin/sync_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See LICENSE in the project root for license information.

from gevent import monkey, sleep, spawn
monkey.patch_all()
monkey.patch_all() # NOQA

import sys
import logging
Expand Down
2 changes: 1 addition & 1 deletion src/iris_api/plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def handle_response(self, mode, msg_id, source, content, batch=False):
self.name, mode, msg_id, content)
cmd, args = parse_response(content)
if batch:
cmd = 'batch_'+cmd
cmd = 'batch_' + cmd
return self.process_command(msg_id, source, mode, cmd, args)

def process_iris_claim(self, msg_id, source, mode, cmd, args=None):
Expand Down
4 changes: 0 additions & 4 deletions src/iris_api/sender/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

import logging
logger = logging.getLogger(__name__)

# FIXME: remove this when we move to py27
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
logging.getLogger('requests').setLevel(logging.WARNING)


Expand Down
34 changes: 17 additions & 17 deletions src/iris_api/sender/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ def notify_incident(self, application, limit, duration, plan_name, wait_time):

# Make a new incident
incident_data = {
'plan_name': plan_name,
'created': datetime.utcnow(),
'sender_app_id': self.iris_application['id'],
'context': ujson.dumps({
'quota_breach': {
'application': application,
'limit': limit,
'duration': duration
}
})
'plan_name': plan_name,
'created': datetime.utcnow(),
'sender_app_id': self.iris_application['id'],
'context': ujson.dumps({
'quota_breach': {
'application': application,
'limit': limit,
'duration': duration
}
})
}

incident_id = session.execute(create_incident_query, incident_data).lastrowid
Expand Down Expand Up @@ -225,12 +225,12 @@ def notify_target(self, application, limit, duration, target_name, target_role):

for username in targets:
message = {
'application': self.iris_application['name'],
'priority_id': priority['id'],
'target': username,
'subject': 'Application %s exceeding message quota' % application,
'body': ('Hi %s\n\nYour application %s is currently exceeding its soft quota of %s messages per %s minutes.\n\n'
'If this continues, your messages will eventually be dropped on the floor and an Iris incident will be raised.\n\n'
'Regards,\nIris') % (username, application, limit, duration, )
'application': self.iris_application['name'],
'priority_id': priority['id'],
'target': username,
'subject': 'Application %s exceeding message quota' % application,
'body': ('Hi %s\n\nYour application %s is currently exceeding its soft quota of %s messages per %s minutes.\n\n'
'If this continues, your messages will eventually be dropped on the floor and an Iris incident will be raised.\n\n'
'Regards,\nIris') % (username, application, limit, duration, )
}
send_queue.put(message)
4 changes: 2 additions & 2 deletions src/iris_api/vendors/iris_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class iris_slack(object):
supports = frozenset([
# TODO: Uncomment this after getting auth permission
# SLACK_SUPPORT
# TODO: Uncomment this after getting auth permission
# SLACK_SUPPORT
])

def __init__(self, config):
Expand Down
4 changes: 2 additions & 2 deletions src/iris_api/vendors/iris_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class iris_smtp(object):
def __init__(self, config):
self.config = config
self.modes = {
EMAIL_SUPPORT: self.send_email,
IM_SUPPORT: self.send_email,
EMAIL_SUPPORT: self.send_email,
IM_SUPPORT: self.send_email,
}
self.mx_sorted = []

Expand Down
4 changes: 2 additions & 2 deletions src/iris_api/vendors/iris_twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def __init__(self, config):
self.config['proxy']['port'],
proxy_rdns=True)
self.modes = {
SMS_SUPPORT: self.send_sms,
CALL_SUPPORT: self.send_call,
SMS_SUPPORT: self.send_sms,
CALL_SUPPORT: self.send_call,
}

def get_twilio_client(self):
Expand Down
Loading

0 comments on commit dea6d55

Please sign in to comment.