Merge ~dashmage/charm-sysconfig:bug-2012581/clear-notification-fix into charm-sysconfig:master

Proposed by Ashley James
Status: Merged
Approved by: Eric Chen
Approved revision: 9dad38769b4bcc7b9072e6ae7c77a38d34fa59d9
Merged at revision: 6f88d54f4e62c85ea9fd2595ab45f3f6d3d64db0
Proposed branch: ~dashmage/charm-sysconfig:bug-2012581/clear-notification-fix
Merge into: charm-sysconfig:master
Diff against target: 32 lines (+3/-2)
2 files modified
src/lib/lib_sysconfig.py (+2/-1)
src/tests/functional/test_deploy.py (+1/-1)
Reviewer Review Type Date Requested Status
JamesLin Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Mert Kirpici (community) Approve
BootStack Reviewers Pending
BootStack Reviewers Pending
Review via email: mp+440819@code.launchpad.net

Commit message

Fix clear-notification action

- Also fixes broken functional tests

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Robert Gildein (rgildein) wrote :

LGTM, but can you add simple unit tests for those two functions. Thanks

Revision history for this message
JamesLin (jneo8) wrote :

One inline comment, could you also provide more information why this fix work?

review: Needs Information
Revision history for this message
Ashley James (dashmage) wrote :

> Why we need to flush local's unit data here? Also the previous line is `set`, flush after set look make not sense to me.
> Could you explain why we need to do this?

So without explicitly adding `unitdata.kv().flush()` it seems that the local unit's data is not being written to the DB. Without this line, when we try to get the value later, it's only returning `None`.

For the other line, `datetime.fromtimestamp` is the correct function to convert the POSIX timestamp (in float) to the local date.

Revision history for this message
Mert Kirpici (mertkirpici) wrote :

I verified that the action AND the functest was broken and now they both work properly with this change. Nice catch, thanks!

review: Approve
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Eric Chen (eric-chen) wrote :

> > Why we need to flush local's unit data here? Also the previous line is
> `set`, flush after set look make not sense to me.
> > Could you explain why we need to do this?
>
> So without explicitly adding `unitdata.kv().flush()` it seems that the local
> unit's data is not being written to the DB. Without this line, when we try to
> get the value later, it's only returning `None`.
>
> For the other line, `datetime.fromtimestamp` is the correct function to
> convert the POSIX timestamp (in float) to the local date.

https://github.com/juju/charm-helpers/blob/master/charmhelpers/core/unitdata.py#L165

Modifications are not persisted unless :meth:`flush` is called.

https://github.com/juju/charm-helpers/blob/master/charmhelpers/contrib/hardening/audits/file.py#L423
I can find similar usage here.

Revision history for this message
JamesLin (jneo8) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 6f88d54f4e62c85ea9fd2595ab45f3f6d3d64db0

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/lib/lib_sysconfig.py b/src/lib/lib_sysconfig.py
2index facdd53..1a9875a 100644
3--- a/src/lib/lib_sysconfig.py
4+++ b/src/lib/lib_sysconfig.py
5@@ -73,7 +73,7 @@ def clear_notification_time():
6 clear_notification_timestamp = unitdata.kv().get("clear-notification-timestamp")
7 if not clear_notification_timestamp:
8 return None
9- return datetime.fromordinal(clear_notification_timestamp)
10+ return datetime.fromtimestamp(clear_notification_timestamp, tz=timezone.utc)
11
12
13 def check_update_grub(tmp_output="/tmp/tmp_grub.cfg"):
14@@ -117,6 +117,7 @@ def clear_notification():
15 """
16 timestamp = datetime.now(timezone.utc)
17 unitdata.kv().set("clear-notification-timestamp", timestamp.timestamp())
18+ unitdata.kv().flush()
19 message = "Notifications cleared at {}".format(timestamp.isoformat())
20 hookenv.log(message, hookenv.DEBUG)
21
22diff --git a/src/tests/functional/test_deploy.py b/src/tests/functional/test_deploy.py
23index f1cd22b..c97845e 100644
24--- a/src/tests/functional/test_deploy.py
25+++ b/src/tests/functional/test_deploy.py
26@@ -307,7 +307,7 @@ async def test_clear_notification_persist_after_update_status(app, model):
27 unit = app.units[0]
28 action = await unit.run_action("clear-notification")
29 action = await action.wait()
30- action = await unit.run("./hooks/unpdate-status")
31+ action = await unit.run("JUJU_HOOK_NAME=update-status ./hooks/update-status")
32 await model.block_until(lambda: app.status == "active", timeout=TIMEOUT)
33
34

Subscribers

People subscribed via source and target branches

to all changes: