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

fix: Verify the presence of opkg cache files for update #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hurricos
Copy link

When openwrt_remote_opkg_lists_dir is placed at /tmp/opkg-lists (the default), it is recreated on each boot. However, when any opkg command is run -- including e.g. opkg list-installed -- that directory is created and left empty.

On such a router, the first time an opkg command is run, the openwrt_remote_opkg_lists_dir is given mtime <= 86400 (at least for the next 24h), suggesting to the default ansible-openwrt's tasks that an opkg update has been issued recently when one has not. This seems to happen when an Ansible check-mode run is performed right after a router is booted.

Correct this problem by verifying that there are actual opkg cache files. We assume (perhaps incorrectly) that all of the opkg cache files were created at the same time during the most recent successful opkg update run, if there are any, meaning they all have dates roughly matching that of their openwrt_remote_opkg_lists_dir. As a result, we do not need to check the age of those files.

This commit fixes issue #55:
#55

Signed-off-by: Martin Kennedy [email protected]

When openwrt_remote_opkg_lists_dir is placed at /tmp/opkg-lists (the
default), it is recreated on each boot. However, when any opkg command
is run -- including e.g. `opkg list-installed` -- that directory is
created and left empty.

On such a router, the first time an `opkg` command is run, the
openwrt_remote_opkg_lists_dir is given mtime <= 86400 (at least for
the next 24h), suggesting to the default ansible-openwrt's tasks that
an `opkg update` has been issued recently when one has not. This seems
to happen when an Ansible check-mode run is performed right after a
router is booted.

Correct this problem by verifying that there are actual opkg cache
files. We assume (perhaps incorrectly) that all of the opkg cache
files were created at the same time during the most recent successful
`opkg update` run, if there are any, meaning they all have dates
roughly matching that of their openwrt_remote_opkg_lists_dir. As a
result, we do not need to check the age of those files.

This commit fixes issue gekmihesg#55:
gekmihesg#55

Signed-off-by: Martin Kennedy <[email protected]>
@Hurricos Hurricos force-pushed the verify-opkg-cache-files branch from 7ee736a to 16f590e Compare December 21, 2022 17:52
@Hurricos
Copy link
Author

It appears we also need to do a:

diff --git a/ansible/roles/gekmihesg.openwrt/tasks/packages.yml b/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
index 10bd275..24839f9 100644
--- a/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
+++ b/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
@@ -5,6 +5,7 @@
   register: _opkg_lists
 
 - name: verify there are actual cache files
+  when: _opkg_lists.stat.exists
   command:
     cmd: "find {{ openwrt_remote_opkg_lists_dir }} -type f"
   register: _opkg_list_files

... because if /tmp/opkg-lists doesn't already exist, we can't find it.

By doing so, we'll incur a failure when it does not, causing the
opposite problem we were trying to fix in 16f590e (where if opkg
has *not* been run, we'll see failures).

Fixes: 16f590e ("fix: Verify the
presence of opkg cache files for update")
@Hurricos
Copy link
Author

Hurricos commented Mar 8, 2023

It appears we also need to do a:

diff --git a/ansible/roles/gekmihesg.openwrt/tasks/packages.yml b/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
index 10bd275..24839f9 100644
--- a/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
+++ b/ansible/roles/gekmihesg.openwrt/tasks/packages.yml
@@ -5,6 +5,7 @@
   register: _opkg_lists
 
 - name: verify there are actual cache files
+  when: _opkg_lists.stat.exists
   command:
     cmd: "find {{ openwrt_remote_opkg_lists_dir }} -type f"
   register: _opkg_list_files

... because if /tmp/opkg-lists doesn't already exist, we can't find it.

Done, as of 751edf0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant