flake8 fixes

This commit is contained in:
Chris Meyers
2015-04-03 14:55:37 -04:00
parent f5600be39e
commit a769af0e83
8 changed files with 53 additions and 59 deletions

View File

@@ -3,17 +3,13 @@
import logging import logging
from datetime import datetime from datetime import datetime
import json
from django.core.management.base import NoArgsCommand from django.core.management.base import NoArgsCommand
from awx.main.models import * # noqa from awx.main.models import * # noqa
from awx.main.socket import Socket from awx.main.socket import Socket
import pymongo _MODULES = ['packages', 'services', 'files']
from pymongo import MongoClient
_MODULES = [ 'packages', 'services', 'files' ]
logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver') logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver')
class FactCacheReceiver(object): class FactCacheReceiver(object):
@@ -49,10 +45,10 @@ class FactCacheReceiver(object):
try: try:
host = FactHost.objects.get(hostname=hostname) host = FactHost.objects.get(hostname=hostname)
except FactHost.DoesNotExist as e: except FactHost.DoesNotExist:
host = FactHost(hostname=hostname) host = FactHost(hostname=hostname)
host.save() host.save()
except FactHost.MultipleObjectsReturned as e: except FactHost.MultipleObjectsReturned:
query = "db['fact_host'].find(hostname=%s)" % hostname 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)) print('Database inconsistent. Multiple FactHost "%s" exist. Try the query %s to find the records.' % (hostname, query))
return return

View File

@@ -1,15 +1,15 @@
from mongoengine import Document, DynamicDocument, DateTimeField, ReferenceField, StringField from mongoengine import Document, DynamicDocument, DateTimeField, ReferenceField, StringField
class FactHost(Document): 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 # TODO: Consider using hashed index on hostname. django-mongo may not support this but
# executing raw js will # executing raw js will
meta = { meta = {
'indexes': [ 'indexes': [
'hostname' 'hostname'
] ]
} }
class Fact(DynamicDocument): class Fact(DynamicDocument):
timestamp = DateTimeField(required=True) timestamp = DateTimeField(required=True)

View File

@@ -49,7 +49,7 @@ class MongoDBRequired(django.test.TestCase):
try: try:
self.db = get_db() self.db = get_db()
self.db.connection.drop_database(settings.MONGO_DB) self.db.connection.drop_database(settings.MONGO_DB)
except ConnectionError as e: except ConnectionError:
self.skipTest('MongoDB connection failed') self.skipTest('MongoDB connection failed')
class QueueTestMixin(object): class QueueTestMixin(object):

View File

@@ -2,4 +2,4 @@
# All Rights Reserved # All Rights Reserved
from awx.main.tests.commands.run_fact_cache_receiver import * # noqa from awx.main.tests.commands.run_fact_cache_receiver import * # noqa
from awx.main.tests.commands.commands_monolithic import * # noqa from awx.main.tests.commands.commands_monolithic import * # noqa

View File

@@ -5,16 +5,15 @@
import time import time
from datetime import datetime from datetime import datetime
import mock import mock
import json
import unittest import unittest
from copy import deepcopy from copy import deepcopy
from mock import Mock, MagicMock from mock import MagicMock
# AWX # AWX
from awx.main.tests.base import BaseTest, MongoDBRequired from awx.main.tests.base import BaseTest, MongoDBRequired
from awx.main.tests.commands.base import BaseCommandMixin from awx.main.tests.commands.base import BaseCommandMixin
from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver, _MODULES from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver
from awx.main.models.fact import * from awx.main.models.fact import * # noqa
__all__ = ['RunFactCacheReceiverUnitTest', 'RunFactCacheReceiverFunctionalTest'] __all__ = ['RunFactCacheReceiverUnitTest', 'RunFactCacheReceiverFunctionalTest']
@@ -27,28 +26,28 @@ TEST_MSG_BASE = {
TEST_MSG_MODULES = { TEST_MSG_MODULES = {
'packages': { 'packages': {
"accountsservice": [ "accountsservice": [
{ {
"architecture": "amd64", "architecture": "amd64",
"name": "accountsservice", "name": "accountsservice",
"source": "apt", "source": "apt",
"version": "0.6.35-0ubuntu7.1" "version": "0.6.35-0ubuntu7.1"
} }
], ],
"acpid": [ "acpid": [
{ {
"architecture": "amd64", "architecture": "amd64",
"name": "acpid", "name": "acpid",
"source": "apt", "source": "apt",
"version": "1:2.0.21-1ubuntu2" "version": "1:2.0.21-1ubuntu2"
} }
], ],
"adduser": [ "adduser": [
{ {
"architecture": "all", "architecture": "all",
"name": "adduser", "name": "adduser",
"source": "apt", "source": "apt",
"version": "3.113+nmu3ubuntu3" "version": "3.113+nmu3ubuntu3"
} }
], ],
}, },
'services': [ 'services': [
@@ -135,7 +134,7 @@ class RunFactCacheReceiverUnitTest(BaseTest, MongoDBRequired):
# Ensure that the message flows from the socket through to process_fact_message() # Ensure that the message flows from the socket through to process_fact_message()
@mock.patch('awx.main.socket.Socket.listen') @mock.patch('awx.main.socket.Socket.listen')
def test_run_receiver(self, listen_mock): def test_run_receiver(self, listen_mock):
listen_mock.return_value = [ TEST_MSG ] listen_mock.return_value = [TEST_MSG]
receiver = FactCacheReceiver() receiver = FactCacheReceiver()
receiver.process_fact_message = MagicMock(name='process_fact_message') receiver.process_fact_message = MagicMock(name='process_fact_message')

View File

@@ -3,7 +3,6 @@
# Python # Python
from datetime import datetime from datetime import datetime
from mongoengine.connection import get_db
from mongoengine import connect from mongoengine import connect
# Django # Django
@@ -11,7 +10,7 @@ from django.conf import settings
# AWX # AWX
from awx.main.tests.base import BaseTest, MongoDBRequired from awx.main.tests.base import BaseTest, MongoDBRequired
from awx.main.models.fact import * from awx.main.models.fact import * # noqa
__all__ = ['DBTransformTest'] __all__ = ['DBTransformTest']
@@ -75,4 +74,4 @@ class DBTransformTest(BaseTest, MongoDBRequired):
def test_key_transform_dollar_on_retreive(self): def test_key_transform_dollar_on_retreive(self):
self.create_dollar_fact() self.create_dollar_fact()
self.check_transform() self.check_transform()

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015 Ansible, Inc. # Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved # All Rights Reserved
from awx.main.tests.models.fact import * # noqa from awx.main.tests.models.fact import * # noqa

View File

@@ -7,7 +7,7 @@ from datetime import datetime
# Django # Django
# AWX # AWX
from awx.main.models.fact import * from awx.main.models.fact import * # noqa
from awx.main.tests.base import BaseTest, MongoDBRequired from awx.main.tests.base import BaseTest, MongoDBRequired
__all__ = ['FactHostTest', 'FactTest'] __all__ = ['FactHostTest', 'FactTest']
@@ -20,28 +20,28 @@ TEST_FACT_DATA = {
'module': 'packages', 'module': 'packages',
'fact': { 'fact': {
"accountsservice": [ "accountsservice": [
{ {
"architecture": "amd64", "architecture": "amd64",
"name": "accountsservice", "name": "accountsservice",
"source": "apt", "source": "apt",
"version": "0.6.35-0ubuntu7.1" "version": "0.6.35-0ubuntu7.1"
} }
], ],
"acpid": [ "acpid": [
{ {
"architecture": "amd64", "architecture": "amd64",
"name": "acpid", "name": "acpid",
"source": "apt", "source": "apt",
"version": "1:2.0.21-1ubuntu2" "version": "1:2.0.21-1ubuntu2"
} }
], ],
"adduser": [ "adduser": [
{ {
"architecture": "all", "architecture": "all",
"name": "adduser", "name": "adduser",
"source": "apt", "source": "apt",
"version": "3.113+nmu3ubuntu3" "version": "3.113+nmu3ubuntu3"
} }
], ],
}, },
} }