Skip to content

Commit

Permalink
Specify the timezone in timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jan 3, 2022
1 parent 336b4c8 commit 12e202f
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1171-timezone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- callback plugin - include timezone information in the callback reported data (https://github.com/theforeman/foreman-ansible-modules/issues/1171)
4 changes: 3 additions & 1 deletion plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ def get_time():
def get_now():
"""
Return the current timestamp as a string to be sent over the network.
The time is always in UTC *with* timezone information, so that Ruby
DateTime can easily parse it.
"""
return datetime.utcnow().isoformat()
return datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S+00:00")


class CallbackModule(CallbackBase):
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/foreman/testhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"reporter": "ansible",
"status": {
"applied": 5,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/foreman/testhostA.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"reporter": "ansible",
"status": {
"applied": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/foreman/testhostB.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"reporter": "ansible",
"status": {
"applied": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/proxy/testhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"results": [
{
"failed": false,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/proxy/testhostA.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"results": [
{
"failed": false,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/callback/dir_store/proxy/testhostB.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"total": 1
}
},
"reported_at": "2000-01-01 12:00:00.0000",
"reported_at": "2000-01-01 12:00:00+00:00",
"results": [
{
"failed": false,
Expand Down
1 change: 1 addition & 0 deletions tests/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def run_callback(tmpdir, report_type, vcrmode):
assert len(tmpdir.listdir()) > 0, "Directory with results is empty"
for real_file in tmpdir.listdir(sort=True):
contents = real_file.read()
contents = re.sub(r"\d+-\d+-\d+ \d+:\d+:\d+\+\d+:\d+", "2000-01-01 12:00:00+00:00", contents)
contents = re.sub(r"\d+-\d+-\d+[ T]\d+:\d+:\d+\.\d+", "2000-01-01 12:00:00.0000", contents)
contents = re.sub(r"\d+:\d+:\d+\.\d+", "12:00:00.0000", contents)
if report_type == "foreman":
Expand Down

0 comments on commit 12e202f

Please sign in to comment.