flatpak: add tests in CI, add no_dependencies parameter (#2751) (#2754)

* Similar version restrictions than flatpak_remote tests.

* ...

* Try to work around missing dependencies.

* Revert "Try to work around missing dependencies."

This reverts commit 66a4e38566.

* Add changelog.

* App8 -> App2; make sure that there are two apps App1 and App2.

* Fix forgotten variabe.

* Remove test notices.

* Seems like flatpak no longer supports file:// URLs.

The tests would need to be rewritten to offer the URL via http:// instead.

* Try local HTTP server for URL tests.

* ...

* Lint, add status check.

* Add boilerplate.

* Add 'ps aux'.

* Surrender to -f.

* Work around apparent flatpak bug.

* Fix YAML.

* Improve condition.

* Make sure test reruns behave better.

(cherry picked from commit bb37b67166)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2021-06-08 09:14:10 +02:00 committed by GitHub
parent dbc0fe8859
commit ac543f5ef0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 255 additions and 140 deletions

View file

@ -6,27 +6,6 @@
# Copyright: (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ATTENTION CONTRIBUTORS!
#
# TL;DR: Run this module's integration tests manually before opening a pull request
#
# Long explanation:
# The integration tests for this module are currently NOT run on the Ansible project's continuous
# delivery pipeline. So please: When you make changes to this module, make sure that you run the
# included integration tests manually for both Python 2 and Python 3:
#
# Python 2:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 2.7 flatpak
# Python 3:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 3.6 flatpak
#
# Because of external dependencies, the current integration tests are somewhat too slow and brittle
# to be included right now. I have plans to rewrite the integration tests based on a local flatpak
# repository so that they can be included into the normal CI pipeline.
# //oolongbrothers
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
@ -60,18 +39,28 @@ options:
name:
description:
- The name of the flatpak to manage.
- When used with I(state=present), I(name) can be specified as an C(http(s)) URL to a
- When used with I(state=present), I(name) can be specified as a URL to a
C(flatpakref) file or the unique reverse DNS name that identifies a flatpak.
- Both C(https://) and C(http://) URLs are supported.
- When supplying a reverse DNS name, you can use the I(remote) option to specify on what remote
to look for the flatpak. An example for a reverse DNS name is C(org.gnome.gedit).
- When used with I(state=absent), it is recommended to specify the name in the reverse DNS
format.
- When supplying an C(http(s)) URL with I(state=absent), the module will try to match the
- When supplying a URL with I(state=absent), the module will try to match the
installed flatpak based on the name of the flatpakref to remove it. However, there is no
guarantee that the names of the flatpakref file and the reverse DNS name of the installed
flatpak do match.
type: str
required: true
no_dependencies:
description:
- If installing runtime dependencies should be omitted or not
- This parameter is primarily implemented for integration testing this module.
There might however be some use cases where you would want to have this, like when you are
packaging your own flatpaks.
type: bool
default: false
version_added: 3.2.0
remote:
description:
- The flatpak remote (repository) to install the flatpak from.
@ -94,10 +83,11 @@ EXAMPLES = r'''
name: https://s3.amazonaws.com/alexlarsson/spotify-repo/spotify.flatpakref
state: present
- name: Install the gedit flatpak package
- name: Install the gedit flatpak package without dependencies (not recommended)
community.general.flatpak:
name: https://git.gnome.org/browse/gnome-apps-nightly/plain/gedit.flatpakref
state: present
no_dependencies: true
- name: Install the gedit package from flathub for current user
community.general.flatpak:
@ -153,18 +143,21 @@ from ansible.module_utils.basic import AnsibleModule
OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
def install_flat(module, binary, remote, name, method):
def install_flat(module, binary, remote, name, method, no_dependencies):
"""Add a new flatpak."""
global result
flatpak_version = _flatpak_version(module, binary)
command = [binary, "install", "--{0}".format(method)]
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
noninteractive_arg = "-y"
command += ["-y"]
else:
noninteractive_arg = "--noninteractive"
command += ["--noninteractive"]
if no_dependencies:
command += ["--no-deps"]
if name.startswith('http://') or name.startswith('https://'):
command = [binary, "install", "--{0}".format(method), noninteractive_arg, name]
command += [name]
else:
command = [binary, "install", "--{0}".format(method), noninteractive_arg, remote, name]
command += [remote, name]
_flatpak_command(module, module.check_mode, command)
result['changed'] = True
@ -279,6 +272,7 @@ def main():
choices=['user', 'system']),
state=dict(type='str', default='present',
choices=['absent', 'present']),
no_dependencies=dict(type='bool', default=False),
executable=dict(type='path', default='flatpak')
),
supports_check_mode=True,
@ -287,6 +281,7 @@ def main():
name = module.params['name']
state = module.params['state']
remote = module.params['remote']
no_dependencies = module.params['no_dependencies']
method = module.params['method']
executable = module.params['executable']
binary = module.get_bin_path(executable, None)
@ -301,7 +296,7 @@ def main():
module.fail_json(msg="Executable '%s' was not found on the system." % executable, **result)
if state == 'present' and not flatpak_exists(module, binary, name, method):
install_flat(module, binary, remote, name, method)
install_flat(module, binary, remote, name, method, no_dependencies)
elif state == 'absent' and flatpak_exists(module, binary, name, method):
uninstall_flat(module, binary, name, method)