Merge pull request #345 from chrismeyersfsu/fix-centos_6.5

unittest works on centos 6.5
This commit is contained in:
Matthew Jones
2015-08-05 19:43:57 -04:00
8 changed files with 27 additions and 16 deletions

View File

@@ -16,6 +16,13 @@ from awx.fact.tests.base import BaseFactTest, FactScanBuilder, TEST_FACT_PACKAGE
__all__ = ['FactHostTest', 'FactTest', 'FactGetHostVersionTest', 'FactGetHostTimelineTest'] __all__ = ['FactHostTest', 'FactTest', 'FactGetHostVersionTest', 'FactGetHostTimelineTest']
# damn you python 2.6
def timedelta_total_seconds(timedelta):
return (
timedelta.microseconds + 0.0 +
(timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6
class FactHostTest(BaseFactTest): class FactHostTest(BaseFactTest):
def test_create_host(self): def test_create_host(self):
host = FactHost(hostname='hosty', inventory_id=1) host = FactHost(hostname='hosty', inventory_id=1)
@@ -72,7 +79,7 @@ class FactTest(BaseFactTest):
t1 = now() t1 = now()
(f_obj, v_obj) = Fact.add_fact(host=host, timestamp=timestamp, module='packages', fact=data) (f_obj, v_obj) = Fact.add_fact(host=host, timestamp=timestamp, module='packages', fact=data)
t2 = now() t2 = now()
diff = (t2 - t1).total_seconds() diff = timedelta_total_seconds(t2 - t1)
print("add_fact save time: %s (s)" % diff) print("add_fact save time: %s (s)" % diff)
# Note: 20 is realllly high. This should complete in < 2 seconds # Note: 20 is realllly high. This should complete in < 2 seconds
self.assertLessEqual(diff, 20) self.assertLessEqual(diff, 20)

View File

@@ -18,6 +18,7 @@ import mongoengine
# awx # awx
from awx.fact.models.fact import * # noqa from awx.fact.models.fact import * # noqa
from awx.main.models import * # noqa from awx.main.models import * # noqa
from awx.main.utils import timedelta_total_seconds
TEST_FACT_ANSIBLE = { TEST_FACT_ANSIBLE = {
"ansible_swapfree_mb" : 4092, "ansible_swapfree_mb" : 4092,
@@ -198,12 +199,6 @@ EXPERIMENT_DEFAULT = {
] ]
} }
# damn you python 2.6
def timedelta_total_seconds(timedelta):
return (
timedelta.microseconds + 0.0 +
(timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6
class Experiment(object): class Experiment(object):
def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db): def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db):
self.db = raw_db self.db = raw_db

View File

@@ -56,8 +56,12 @@ class QueueTestMixin(object):
def start_redis(self): def start_redis(self):
if not getattr(self, 'redis_process', None): if not getattr(self, 'redis_process', None):
self.redis_process = Popen('redis-server --port 16379 > /dev/null', # Centos 6.5 redis is runnable by non-root user but is not in a normal users path by default
shell=True, executable='/bin/bash') 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): def stop_redis(self):
if getattr(self, 'redis_process', None): if getattr(self, 'redis_process', None):

View File

@@ -11,7 +11,7 @@ import sys
import tempfile import tempfile
import time import time
import urlparse import urlparse
import unittest import unittest2 as unittest
# Django # Django
import django import django
@@ -26,9 +26,6 @@ from django.test.utils import override_settings
from awx.main.models import * # noqa from awx.main.models import * # noqa
from awx.main.tests.base import BaseTest, BaseLiveServerTest from awx.main.tests.base import BaseTest, BaseLiveServerTest
if not hasattr(unittest, 'skipIf'):
import unittest2 as unittest
__all__ = ['CreateDefaultOrgTest', 'DumpDataTest', 'CleanupDeletedTest', __all__ = ['CreateDefaultOrgTest', 'DumpDataTest', 'CleanupDeletedTest',
'CleanupJobsTest', 'CleanupActivityStreamTest', 'CleanupJobsTest', 'CleanupActivityStreamTest',
'InventoryImportTest'] 'InventoryImportTest']

View File

@@ -5,7 +5,7 @@
import time import time
from datetime import datetime from datetime import datetime
import mock import mock
import unittest import unittest2 as unittest
from copy import deepcopy from copy import deepcopy
from mock import MagicMock from mock import MagicMock

View File

@@ -2,7 +2,7 @@
# All Rights Reserved # All Rights Reserved
# Python # Python
import unittest import unittest2 as unittest
# Django # Django
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse

View File

@@ -8,7 +8,7 @@ import os
import shutil import shutil
import subprocess import subprocess
import tempfile import tempfile
import unittest import unittest2 as unittest
# Django # Django
from django.conf import settings from django.conf import settings

View File

@@ -511,3 +511,11 @@ def timestamp_apiformat(timestamp):
if timestamp.endswith('+00:00'): if timestamp.endswith('+00:00'):
timestamp = timestamp[:-6] + 'Z' timestamp = timestamp[:-6] + 'Z'
return timestamp return timestamp
# damn you python 2.6
def timedelta_total_seconds(timedelta):
return (
timedelta.microseconds + 0.0 +
(timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6