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 + +