diff --git a/awx/main/management/commands/run_fact_cache_receiver.py b/awx/main/management/commands/run_fact_cache_receiver.py index f31a8495a1..9ab51a0c93 100644 --- a/awx/main/management/commands/run_fact_cache_receiver.py +++ b/awx/main/management/commands/run_fact_cache_receiver.py @@ -3,17 +3,13 @@ import logging from datetime import datetime -import json from django.core.management.base import NoArgsCommand from awx.main.models import * # noqa from awx.main.socket import Socket -import pymongo -from pymongo import MongoClient - -_MODULES = [ 'packages', 'services', 'files' ] +_MODULES = ['packages', 'services', 'files'] logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver') class FactCacheReceiver(object): @@ -49,10 +45,10 @@ class FactCacheReceiver(object): try: host = FactHost.objects.get(hostname=hostname) - except FactHost.DoesNotExist as e: + except FactHost.DoesNotExist: host = FactHost(hostname=hostname) host.save() - except FactHost.MultipleObjectsReturned as e: + except FactHost.MultipleObjectsReturned: query = "db['fact_host'].find(hostname=%s)" % hostname print('Database inconsistent. Multiple FactHost "%s" exist. Try the query %s to find the records.' % (hostname, query)) return diff --git a/awx/main/models/fact.py b/awx/main/models/fact.py index b97b11d7e3..6e482a0b80 100644 --- a/awx/main/models/fact.py +++ b/awx/main/models/fact.py @@ -1,15 +1,15 @@ from mongoengine import Document, DynamicDocument, DateTimeField, ReferenceField, StringField class FactHost(Document): - hostname = StringField(max_length=100, required=True, unique=True) + hostname = StringField(max_length=100, required=True, unique=True) # TODO: Consider using hashed index on hostname. django-mongo may not support this but # executing raw js will - meta = { + meta = { 'indexes': [ - 'hostname' + 'hostname' ] - } + } class Fact(DynamicDocument): timestamp = DateTimeField(required=True) diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 6cbbb068da..7f96c818cc 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -49,7 +49,7 @@ class MongoDBRequired(django.test.TestCase): try: self.db = get_db() self.db.connection.drop_database(settings.MONGO_DB) - except ConnectionError as e: + except ConnectionError: self.skipTest('MongoDB connection failed') class QueueTestMixin(object): diff --git a/awx/main/tests/commands/__init__.py b/awx/main/tests/commands/__init__.py index 0be275c8b8..7a1446f52a 100644 --- a/awx/main/tests/commands/__init__.py +++ b/awx/main/tests/commands/__init__.py @@ -2,4 +2,4 @@ # All Rights Reserved from awx.main.tests.commands.run_fact_cache_receiver import * # noqa -from awx.main.tests.commands.commands_monolithic import * # noqa \ No newline at end of file +from awx.main.tests.commands.commands_monolithic import * # noqa diff --git a/awx/main/tests/commands/run_fact_cache_receiver.py b/awx/main/tests/commands/run_fact_cache_receiver.py index 99f0e33a8a..d57dde93c7 100644 --- a/awx/main/tests/commands/run_fact_cache_receiver.py +++ b/awx/main/tests/commands/run_fact_cache_receiver.py @@ -5,16 +5,15 @@ import time from datetime import datetime import mock -import json import unittest from copy import deepcopy -from mock import Mock, MagicMock +from mock import MagicMock # AWX from awx.main.tests.base import BaseTest, MongoDBRequired from awx.main.tests.commands.base import BaseCommandMixin -from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver, _MODULES -from awx.main.models.fact import * +from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver +from awx.main.models.fact import * # noqa __all__ = ['RunFactCacheReceiverUnitTest', 'RunFactCacheReceiverFunctionalTest'] @@ -27,28 +26,28 @@ TEST_MSG_BASE = { TEST_MSG_MODULES = { 'packages': { "accountsservice": [ - { - "architecture": "amd64", - "name": "accountsservice", - "source": "apt", - "version": "0.6.35-0ubuntu7.1" - } + { + "architecture": "amd64", + "name": "accountsservice", + "source": "apt", + "version": "0.6.35-0ubuntu7.1" + } ], "acpid": [ - { - "architecture": "amd64", - "name": "acpid", - "source": "apt", - "version": "1:2.0.21-1ubuntu2" - } + { + "architecture": "amd64", + "name": "acpid", + "source": "apt", + "version": "1:2.0.21-1ubuntu2" + } ], "adduser": [ - { - "architecture": "all", - "name": "adduser", - "source": "apt", - "version": "3.113+nmu3ubuntu3" - } + { + "architecture": "all", + "name": "adduser", + "source": "apt", + "version": "3.113+nmu3ubuntu3" + } ], }, 'services': [ @@ -135,7 +134,7 @@ class RunFactCacheReceiverUnitTest(BaseTest, MongoDBRequired): # Ensure that the message flows from the socket through to process_fact_message() @mock.patch('awx.main.socket.Socket.listen') def test_run_receiver(self, listen_mock): - listen_mock.return_value = [ TEST_MSG ] + listen_mock.return_value = [TEST_MSG] receiver = FactCacheReceiver() receiver.process_fact_message = MagicMock(name='process_fact_message') diff --git a/awx/main/tests/dbtransform.py b/awx/main/tests/dbtransform.py index 164e177e13..1c18098118 100644 --- a/awx/main/tests/dbtransform.py +++ b/awx/main/tests/dbtransform.py @@ -3,7 +3,6 @@ # Python from datetime import datetime -from mongoengine.connection import get_db from mongoengine import connect # Django @@ -11,7 +10,7 @@ from django.conf import settings # AWX from awx.main.tests.base import BaseTest, MongoDBRequired -from awx.main.models.fact import * +from awx.main.models.fact import * # noqa __all__ = ['DBTransformTest'] @@ -75,4 +74,4 @@ class DBTransformTest(BaseTest, MongoDBRequired): def test_key_transform_dollar_on_retreive(self): self.create_dollar_fact() - self.check_transform() \ No newline at end of file + self.check_transform() diff --git a/awx/main/tests/models/__init__.py b/awx/main/tests/models/__init__.py index 4ca3023f38..a4959c9e29 100644 --- a/awx/main/tests/models/__init__.py +++ b/awx/main/tests/models/__init__.py @@ -1,4 +1,4 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved -from awx.main.tests.models.fact import * # noqa \ No newline at end of file +from awx.main.tests.models.fact import * # noqa diff --git a/awx/main/tests/models/fact.py b/awx/main/tests/models/fact.py index 1f400080cb..9dbbd23b54 100644 --- a/awx/main/tests/models/fact.py +++ b/awx/main/tests/models/fact.py @@ -7,7 +7,7 @@ from datetime import datetime # Django # AWX -from awx.main.models.fact import * +from awx.main.models.fact import * # noqa from awx.main.tests.base import BaseTest, MongoDBRequired __all__ = ['FactHostTest', 'FactTest'] @@ -20,28 +20,28 @@ TEST_FACT_DATA = { 'module': 'packages', 'fact': { "accountsservice": [ - { - "architecture": "amd64", - "name": "accountsservice", - "source": "apt", - "version": "0.6.35-0ubuntu7.1" - } + { + "architecture": "amd64", + "name": "accountsservice", + "source": "apt", + "version": "0.6.35-0ubuntu7.1" + } ], "acpid": [ - { - "architecture": "amd64", - "name": "acpid", - "source": "apt", - "version": "1:2.0.21-1ubuntu2" - } + { + "architecture": "amd64", + "name": "acpid", + "source": "apt", + "version": "1:2.0.21-1ubuntu2" + } ], "adduser": [ - { - "architecture": "all", - "name": "adduser", - "source": "apt", - "version": "3.113+nmu3ubuntu3" - } + { + "architecture": "all", + "name": "adduser", + "source": "apt", + "version": "3.113+nmu3ubuntu3" + } ], }, }