From 34ecd4e5b625787e49d9c08920de22e4c005f768 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 29 Jul 2015 14:53:26 -0400 Subject: [PATCH 1/4] use python2.6 safe unittest2 --- awx/main/tests/commands/commands_monolithic.py | 5 +---- awx/main/tests/commands/run_fact_cache_receiver.py | 2 +- awx/main/tests/fact/fact_api.py | 2 +- awx/main/tests/tasks.py | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/awx/main/tests/commands/commands_monolithic.py b/awx/main/tests/commands/commands_monolithic.py index 233af5dcad..7e591d65d2 100644 --- a/awx/main/tests/commands/commands_monolithic.py +++ b/awx/main/tests/commands/commands_monolithic.py @@ -11,7 +11,7 @@ import sys import tempfile import time import urlparse -import unittest +import unittest2 as unittest # Django import django @@ -26,9 +26,6 @@ from django.test.utils import override_settings from awx.main.models import * # noqa from awx.main.tests.base import BaseTest, BaseLiveServerTest -if not hasattr(unittest, 'skipIf'): - import unittest2 as unittest - __all__ = ['CreateDefaultOrgTest', 'DumpDataTest', 'CleanupDeletedTest', 'CleanupJobsTest', 'CleanupActivityStreamTest', 'InventoryImportTest'] diff --git a/awx/main/tests/commands/run_fact_cache_receiver.py b/awx/main/tests/commands/run_fact_cache_receiver.py index 0940c05e4e..b0fe0aa2bb 100644 --- a/awx/main/tests/commands/run_fact_cache_receiver.py +++ b/awx/main/tests/commands/run_fact_cache_receiver.py @@ -5,7 +5,7 @@ import time from datetime import datetime import mock -import unittest +import unittest2 as unittest from copy import deepcopy from mock import MagicMock diff --git a/awx/main/tests/fact/fact_api.py b/awx/main/tests/fact/fact_api.py index 7c54868be2..157cec3757 100644 --- a/awx/main/tests/fact/fact_api.py +++ b/awx/main/tests/fact/fact_api.py @@ -2,7 +2,7 @@ # All Rights Reserved # Python -import unittest +import unittest2 as unittest # Django from django.core.urlresolvers import reverse diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index a14b6d02a7..7a3730f774 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -8,7 +8,7 @@ import os import shutil import subprocess import tempfile -import unittest +import unittest2 as unittest # Django from django.conf import settings From 456f460ed9e879262e6534dd3849d9f203e9901e Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 29 Jul 2015 16:16:00 -0400 Subject: [PATCH 2/4] add path needed for unittest to find redis on centos 6.5 --- awx/main/tests/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 84bbb8082d..171cb68a94 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -56,8 +56,12 @@ class QueueTestMixin(object): 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('redis-server --port 16379 > /dev/null', - shell=True, executable='/bin/bash') + shell=True, executable='/bin/bash', + env=env) def stop_redis(self): if getattr(self, 'redis_process', None): From b0f55c832ddf406e6894e10562e5f2352b383722 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 30 Jul 2015 08:37:21 -0400 Subject: [PATCH 3/4] invoke redis in a way that works on centos and ubuntu --- awx/main/tests/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 171cb68a94..5e3669df9e 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -59,7 +59,7 @@ class QueueTestMixin(object): # 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('redis-server --port 16379 > /dev/null', + self.redis_process = Popen('echo "port 16379" | redis-server - > /dev/null', shell=True, executable='/bin/bash', env=env) From f64a48a98f4cc8eacd6c7666e4459113cf98c6a6 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 30 Jul 2015 13:40:31 -0400 Subject: [PATCH 4/4] python 2.6 safe total_seconds --- awx/fact/tests/models/fact/fact_simple.py | 9 ++++++++- awx/main/management/commands/workload_generator.py | 7 +------ awx/main/utils.py | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/awx/fact/tests/models/fact/fact_simple.py b/awx/fact/tests/models/fact/fact_simple.py index d04d02638f..142accdbd3 100644 --- a/awx/fact/tests/models/fact/fact_simple.py +++ b/awx/fact/tests/models/fact/fact_simple.py @@ -16,6 +16,13 @@ from awx.fact.tests.base import BaseFactTest, FactScanBuilder, TEST_FACT_PACKAGE __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): def test_create_host(self): host = FactHost(hostname='hosty', inventory_id=1) @@ -72,7 +79,7 @@ class FactTest(BaseFactTest): t1 = now() (f_obj, v_obj) = Fact.add_fact(host=host, timestamp=timestamp, module='packages', fact=data) t2 = now() - diff = (t2 - t1).total_seconds() + diff = timedelta_total_seconds(t2 - t1) print("add_fact save time: %s (s)" % diff) # Note: 20 is realllly high. This should complete in < 2 seconds self.assertLessEqual(diff, 20) diff --git a/awx/main/management/commands/workload_generator.py b/awx/main/management/commands/workload_generator.py index 3eb8fc6660..658d5c7228 100644 --- a/awx/main/management/commands/workload_generator.py +++ b/awx/main/management/commands/workload_generator.py @@ -18,6 +18,7 @@ import mongoengine # awx from awx.fact.models.fact import * # noqa from awx.main.models import * # noqa +from awx.main.utils import timedelta_total_seconds TEST_FACT_ANSIBLE = { "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): def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db): self.db = raw_db diff --git a/awx/main/utils.py b/awx/main/utils.py index 1d07e5f4f7..de020b145f 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -511,3 +511,11 @@ def timestamp_apiformat(timestamp): if timestamp.endswith('+00:00'): timestamp = timestamp[:-6] + 'Z' 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 + +