Skip to content

Commit

Permalink
Fixes to get flake8 and unit/functional tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cchurch committed Sep 18, 2016
1 parent f3a8eb9 commit b7a6aa0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 52 deletions.
3 changes: 1 addition & 2 deletions awx/main/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# All Rights Reserved.

import sys
import socket

from django.db import models

Expand All @@ -27,7 +26,7 @@ def me(self):
"""Return the currently active instance."""
# If we are running unit tests, return a stub record.
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
return self.model(id=1, primary=True,
return self.model(id=1,
hostname='localhost',
uuid='00000000-0000-0000-0000-000000000000')

Expand Down
2 changes: 1 addition & 1 deletion awx/main/socket_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def is_connected(self):
def port(self):
return {
'callbacks': os.environ.get('CALLBACK_CONSUMER_PORT',
settings.CALLBACK_CONSUMER_PORT),
getattr(settings, 'CALLBACK_CONSUMER_PORT', 'tcp://127.0.0.1:5557')),
'task_commands': settings.TASK_COMMAND_PORT,
'websocket': settings.SOCKETIO_NOTIFICATION_PORT,
'fact_cache': settings.FACT_CACHE_PORT,
Expand Down
5 changes: 3 additions & 2 deletions awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def post_run_hook(self, job, **kwargs):
update_inventory_computed_fields.delay(inventory.id, True)
# Update job event fields after job has completed (only when using REST
# API callback).
if not settings.CALLBACK_CONSUMER_PORT:
if not getattr(settings, 'CALLBACK_CONSUMER_PORT', None) and not getattr(settings, 'CALLBACK_QUEUE', None):
for job_event in job.job_events.order_by('pk'):
job_event.save(post_process=True)

Expand Down Expand Up @@ -1519,7 +1519,8 @@ def build_env(self, ad_hoc_command, **kwargs):
env['ANSIBLE_LOAD_CALLBACK_PLUGINS'] = '1'
env['REST_API_URL'] = settings.INTERNAL_API_URL
env['REST_API_TOKEN'] = ad_hoc_command.task_auth_token or ''
env['CALLBACK_CONSUMER_PORT'] = str(settings.CALLBACK_CONSUMER_PORT)
env['CALLBACK_QUEUE'] = settings.CALLBACK_QUEUE
env['CALLBACK_CONNECTION'] = settings.BROKER_URL
env['ANSIBLE_SFTP_BATCH_MODE'] = 'False'
if getattr(settings, 'JOB_CALLBACK_DEBUG', False):
env['JOB_CALLBACK_DEBUG'] = '2'
Expand Down
45 changes: 2 additions & 43 deletions awx/main/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import time
import urllib
from multiprocessing import Process
from subprocess import Popen
import re
import mock

Expand All @@ -31,7 +30,6 @@

# AWX
from awx.main.models import * # noqa
from awx.main.management.commands.run_callback_receiver import CallbackReceiver
from awx.main.management.commands.run_task_system import run_taskmanager
from awx.main.utils import get_ansible_version
from awx.main.task_engine import TaskEngager as LicenseWriter
Expand All @@ -45,45 +43,6 @@
command: test 1 = 1
'''

class QueueTestMixin(object):
def start_queue(self):
self.start_redis()
receiver = CallbackReceiver()
self.queue_process = Process(target=receiver.run_subscriber,
args=(False,))
self.queue_process.start()

def terminate_queue(self):
if hasattr(self, 'queue_process'):
self.queue_process.terminate()
self.stop_redis()

def start_redis(self):
if not getattr(self, 'redis_process', None):
# Centos 6.5 redis is runnable by non-root user but is not in a normal users path by default
env = dict(os.environ)
env['PATH'] = '%s:/usr/sbin/' % env['PATH']
self.redis_process = Popen('echo "port 16379" | redis-server - > /dev/null',
shell=True, executable='/bin/bash',
env=env)

def stop_redis(self):
if getattr(self, 'redis_process', None):
self.redis_process.kill()
self.redis_process = None


# The observed effect of not calling terminate_queue() if you call start_queue() are
# an hang on test cleanup database delete. Thus, to ensure terminate_queue() is called
# whenever start_queue() is called just inherit from this class when you want to use the queue.
class QueueStartStopTestMixin(QueueTestMixin):
def setUp(self):
super(QueueStartStopTestMixin, self).setUp()
self.start_queue()

def tearDown(self):
super(QueueStartStopTestMixin, self).tearDown()
self.terminate_queue()

class MockCommonlySlowTestMixin(object):
def __init__(self, *args, **kwargs):
Expand All @@ -92,7 +51,7 @@ def __init__(self, *args, **kwargs):
super(MockCommonlySlowTestMixin, self).__init__(*args, **kwargs)

ansible_version = get_ansible_version()
class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
class BaseTestMixin(MockCommonlySlowTestMixin):
'''
Mixin with shared code for use by all test cases.
'''
Expand Down Expand Up @@ -733,7 +692,7 @@ def setUp(self):
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
ANSIBLE_TRANSPORT='local',
DEBUG=True)
class BaseJobExecutionTest(QueueStartStopTestMixin, BaseLiveServerTest):
class BaseJobExecutionTest(BaseLiveServerTest):
'''
Base class for celery task tests.
'''
2 changes: 1 addition & 1 deletion awx/main/tests/factories/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def mk_instance(persisted=True):
if not persisted:
raise RuntimeError('creating an Instance requires persisted=True')
from django.conf import settings
return Instance.objects.get_or_create(uuid=settings.SYSTEM_UUID, primary=True, hostname="instance.example.org")
return Instance.objects.get_or_create(uuid=settings.SYSTEM_UUID, hostname="instance.example.org")


def mk_organization(name, description=None, persisted=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_process_facts_message_ansible_overwrite(fact_scans, fact_msg_ansible):
# Ensure that the message flows from the socket through to process_fact_message()
@pytest.mark.django_db
def test_run_receiver(mocker, fact_msg_ansible):
mocker.patch("awx.main.socket.Socket.listen", return_value=[fact_msg_ansible])
mocker.patch("awx.main.socket_queue.Socket.listen", return_value=[fact_msg_ansible])

receiver = FactCacheReceiver()
mocker.patch.object(receiver, 'process_fact_message', return_value=None)
Expand Down
2 changes: 1 addition & 1 deletion awx/main/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def user_project(user):

@pytest.fixture
def instance(settings):
return Instance.objects.create(uuid=settings.SYSTEM_UUID, primary=True, hostname="instance.example.org")
return Instance.objects.create(uuid=settings.SYSTEM_UUID, hostname="instance.example.org")

@pytest.fixture
def organization(instance):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ exclude=.tox,venv,awx/lib/site-packages,awx/plugins/inventory/ec2.py,awx/plugins

[flake8]
ignore=E201,E203,E221,E225,E231,E241,E251,E261,E265,E302,E303,E501,W291,W391,W293,E731,F405
exclude=.tox,venv,awx/lib/site-packages,awx/plugins/inventory,awx/ui,awx/api/urls.py,awx/main/migrations,awx/main/south_migrations,awx/main/tests/data,node_modules/,awx/projects/,tools/docker,awx/settings/local_settings.py
exclude=.tox,venv,awx/lib/site-packages,awx/plugins/inventory,awx/ui,awx/api/urls.py,awx/main/migrations,awx/main/south_migrations,awx/main/tests/data,node_modules/,awx/projects/,tools/docker,awx/settings/local_*.py

0 comments on commit b7a6aa0

Please sign in to comment.