Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the timezone in timestamps #1333

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to use strftime("%Y-%m-%d %H:%M:%SZ"), where Z means Zulu aka UTC.

Ruby doesn't strictly care, and I must admit I find +00:00 better to read.



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