mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
opkg: fix bug when update_cache=true (#6119)
* opkg: fix bug when update_cache=true * add changelog fragment
This commit is contained in:
parent
03084d1133
commit
345a69304a
3 changed files with 59 additions and 8 deletions
2
changelogs/fragments/6119-opkg-update.yaml
Normal file
2
changelogs/fragments/6119-opkg-update.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- opkg - fixes bug when using ``update_cache=true`` (https://github.com/ansible-collections/community.general/issues/6004).
|
|
@ -148,6 +148,11 @@ class Opkg(StateModuleHelper):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.vars.update_cache:
|
||||||
|
rc, dummy, dummy = self.runner("update_cache").run()
|
||||||
|
if rc != 0:
|
||||||
|
self.do_raise("could not update package db")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def split_name_and_version(package):
|
def split_name_and_version(package):
|
||||||
""" Split the name and the version when using the NAME=VERSION syntax """
|
""" Split the name and the version when using the NAME=VERSION syntax """
|
||||||
|
@ -164,10 +169,6 @@ class Opkg(StateModuleHelper):
|
||||||
return want_installed == has_package
|
return want_installed == has_package
|
||||||
|
|
||||||
def state_present(self):
|
def state_present(self):
|
||||||
if self.vars.update_cache:
|
|
||||||
dummy, rc, dummy = self.runner("update_cache").run()
|
|
||||||
if rc != 0:
|
|
||||||
self.do_raise("could not update package db")
|
|
||||||
with self.runner("state force package") as ctx:
|
with self.runner("state force package") as ctx:
|
||||||
for package in self.vars.name:
|
for package in self.vars.name:
|
||||||
pkg_name, pkg_version = self.split_name_and_version(package)
|
pkg_name, pkg_version = self.split_name_and_version(package)
|
||||||
|
@ -176,16 +177,14 @@ class Opkg(StateModuleHelper):
|
||||||
if not self._package_in_desired_state(pkg_name, want_installed=True, version=pkg_version):
|
if not self._package_in_desired_state(pkg_name, want_installed=True, version=pkg_version):
|
||||||
self.do_raise("failed to install %s" % package)
|
self.do_raise("failed to install %s" % package)
|
||||||
self.vars.install_c += 1
|
self.vars.install_c += 1
|
||||||
|
if self.verbosity >= 4:
|
||||||
|
self.vars.run_info = ctx.run_info
|
||||||
if self.vars.install_c > 0:
|
if self.vars.install_c > 0:
|
||||||
self.vars.msg = "installed %s package(s)" % (self.vars.install_c)
|
self.vars.msg = "installed %s package(s)" % (self.vars.install_c)
|
||||||
else:
|
else:
|
||||||
self.vars.msg = "package(s) already present"
|
self.vars.msg = "package(s) already present"
|
||||||
|
|
||||||
def state_absent(self):
|
def state_absent(self):
|
||||||
if self.vars.update_cache:
|
|
||||||
dummy, rc, dummy = self.runner("update_cache").run()
|
|
||||||
if rc != 0:
|
|
||||||
self.do_raise("could not update package db")
|
|
||||||
with self.runner("state force package") as ctx:
|
with self.runner("state force package") as ctx:
|
||||||
for package in self.vars.name:
|
for package in self.vars.name:
|
||||||
package, dummy = self.split_name_and_version(package)
|
package, dummy = self.split_name_and_version(package)
|
||||||
|
@ -194,6 +193,8 @@ class Opkg(StateModuleHelper):
|
||||||
if not self._package_in_desired_state(package, want_installed=False):
|
if not self._package_in_desired_state(package, want_installed=False):
|
||||||
self.do_raise("failed to remove %s" % package)
|
self.do_raise("failed to remove %s" % package)
|
||||||
self.vars.remove_c += 1
|
self.vars.remove_c += 1
|
||||||
|
if self.verbosity >= 4:
|
||||||
|
self.vars.run_info = ctx.run_info
|
||||||
if self.vars.remove_c > 0:
|
if self.vars.remove_c > 0:
|
||||||
self.vars.msg = "removed %s package(s)" % (self.vars.remove_c)
|
self.vars.msg = "removed %s package(s)" % (self.vars.remove_c)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -150,6 +150,54 @@ TEST_CASES = [
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
ModuleTestCase(
|
||||||
|
id="install_vim_updatecache",
|
||||||
|
input={"name": "vim-fuller", "state": "present", "update_cache": True},
|
||||||
|
output={
|
||||||
|
"msg": "installed 1 package(s)"
|
||||||
|
},
|
||||||
|
run_command_calls=[
|
||||||
|
RunCmdCall(
|
||||||
|
command=["/testbin/opkg", "update"],
|
||||||
|
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
||||||
|
rc=0,
|
||||||
|
out="",
|
||||||
|
err="",
|
||||||
|
),
|
||||||
|
RunCmdCall(
|
||||||
|
command=["/testbin/opkg", "list-installed", "vim-fuller"],
|
||||||
|
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
||||||
|
rc=0,
|
||||||
|
out="",
|
||||||
|
err="",
|
||||||
|
),
|
||||||
|
RunCmdCall(
|
||||||
|
command=["/testbin/opkg", "install", "vim-fuller"],
|
||||||
|
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
||||||
|
rc=0,
|
||||||
|
out=(
|
||||||
|
"Multiple packages (libgcc1 and libgcc1) providing same name marked HOLD or PREFER. Using latest.\n"
|
||||||
|
"Installing vim-fuller (9.0-1) to root...\n"
|
||||||
|
"Downloading https://downloads.openwrt.org/snapshots/packages/x86_64/packages/vim-fuller_9.0-1_x86_64.ipk\n"
|
||||||
|
"Installing terminfo (6.4-2) to root...\n"
|
||||||
|
"Downloading https://downloads.openwrt.org/snapshots/packages/x86_64/base/terminfo_6.4-2_x86_64.ipk\n"
|
||||||
|
"Installing libncurses6 (6.4-2) to root...\n"
|
||||||
|
"Downloading https://downloads.openwrt.org/snapshots/packages/x86_64/base/libncurses6_6.4-2_x86_64.ipk\n"
|
||||||
|
"Configuring terminfo.\n"
|
||||||
|
"Configuring libncurses6.\n"
|
||||||
|
"Configuring vim-fuller.\n"
|
||||||
|
),
|
||||||
|
err="",
|
||||||
|
),
|
||||||
|
RunCmdCall(
|
||||||
|
command=["/testbin/opkg", "list-installed", "vim-fuller"],
|
||||||
|
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
||||||
|
rc=0,
|
||||||
|
out="vim-fuller - 9.0-1 \n", # This output has the extra space at the end, to satisfy the behaviour of Yocto/OpenEmbedded's opkg
|
||||||
|
err="",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
TEST_CASES_IDS = [item.id for item in TEST_CASES]
|
TEST_CASES_IDS = [item.id for item in TEST_CASES]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue