add collections

This commit is contained in:
Gary Kwok
2024-02-01 11:40:42 +08:00
parent 0715d7c475
commit 7af4c56c96
3198 changed files with 455118 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
skip/aix
skip/freebsd
skip/osx
skip/macos
skip/rhel
needs/root

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env python
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import posixpath
import sys
try:
from http.server import SimpleHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
except ImportError:
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from urllib import unquote
# Argument parsing
if len(sys.argv) != 4:
print('Syntax: {0} <bind> <port> <path>'.format(sys.argv[0]))
sys.exit(-1)
HOST, PORT, PATH = sys.argv[1:4]
PORT = int(PORT)
# The HTTP request handler
class Handler(SimpleHTTPRequestHandler):
def translate_path(self, path):
# Modified from Python 3.6's version of SimpleHTTPRequestHandler
# to support using another base directory than CWD.
# abandon query parameters
path = path.split('?', 1)[0]
path = path.split('#', 1)[0]
# Don't forget explicit trailing slash when normalizing. Issue17324
trailing_slash = path.rstrip().endswith('/')
try:
path = unquote(path, errors='surrogatepass')
except (UnicodeDecodeError, TypeError) as exc:
path = unquote(path)
path = posixpath.normpath(path)
words = path.split('/')
words = filter(None, words)
path = PATH
for word in words:
if os.path.dirname(word) or word in (os.curdir, os.pardir):
# Ignore components that are not a simple file/directory name
continue
path = os.path.join(path, word)
if trailing_slash:
path += '/'
return path
# Run simple HTTP server
httpd = HTTPServer((HOST, PORT), Handler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()

View File

@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_flatpak_remote

View File

@@ -0,0 +1,197 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# - Tests with absent flatpak --------------------------------------------------
# state=present on absent flatpak
- name: Test addition of absent flatpak (check mode)
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: present
register: addition_result
check_mode: true
- name: Verify addition of absent flatpak test result (check mode)
assert:
that:
- addition_result is changed
msg: "Adding an absent flatpak shall mark module execution as changed"
- name: Test non-existent idempotency of addition of absent flatpak (check mode)
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: present
register: double_addition_result
check_mode: true
- name: Verify non-existent idempotency of addition of absent flatpak test result (check mode)
assert:
that:
- double_addition_result is changed
msg: |
Adding an absent flatpak a second time shall still mark module execution
as changed in check mode
# state=absent on absent flatpak
- name: Test removal of absent flatpak check mode
flatpak:
name: com.dummy.App1
state: absent
register: removal_result
check_mode: true
- name: Verify removal of absent flatpak test result (check mode)
assert:
that:
- removal_result is not changed
msg: "Removing an absent flatpak shall mark module execution as not changed"
# state=present with url on absent flatpak
- name: Test addition of absent flatpak with url (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: dummy-remote
state: present
register: url_addition_result
check_mode: true
- name: Verify addition of absent flatpak with url test result (check mode)
assert:
that:
- url_addition_result is changed
msg: "Adding an absent flatpak from URL shall mark module execution as changed"
- name: Test non-existent idempotency of addition of absent flatpak with url (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: dummy-remote
state: present
register: double_url_addition_result
check_mode: true
- name: >
Verify non-existent idempotency of additionof absent flatpak with url test
result (check mode)
assert:
that:
- double_url_addition_result is changed
msg: |
Adding an absent flatpak from URL a second time shall still mark module execution
as changed in check mode
# state=absent with url on absent flatpak
- name: Test removal of absent flatpak with url not doing anything (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent
register: url_removal_result
check_mode: true
- name: Verify removal of absent flatpak with url test result (check mode)
assert:
that:
- url_removal_result is not changed
msg: "Removing an absent flatpak shall mark module execution as not changed"
# - Tests with present flatpak -------------------------------------------------
# state=present on present flatpak
- name: Test addition of present flatpak (check mode)
flatpak:
name: com.dummy.App2
remote: dummy-remote
state: present
register: addition_present_result
check_mode: true
- name: Verify addition test result of present flatpak (check mode)
assert:
that:
- addition_present_result is not changed
msg: "Adding an present flatpak shall mark module execution as not changed"
# state=absent on present flatpak
- name: Test removal of present flatpak (check mode)
flatpak:
name: com.dummy.App2
state: absent
register: removal_present_result
check_mode: true
- name: Verify removal of present flatpak test result (check mode)
assert:
that:
- removal_present_result is changed
msg: "Removing a present flatpak shall mark module execution as changed"
- name: Test non-existent idempotency of removal (check mode)
flatpak:
name: com.dummy.App2
state: absent
register: double_removal_present_result
check_mode: true
- name: Verify non-existent idempotency of removal (check mode)
assert:
that:
- double_removal_present_result is changed
msg: |
Removing a present flatpak a second time shall still mark module execution
as changed in check mode
# state=present with url on present flatpak
- name: Test addition with url of present flatpak (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: dummy-remote
state: present
register: url_addition_present_result
check_mode: true
- name: Verify addition with url of present flatpak test result (check mode)
assert:
that:
- url_addition_present_result is not changed
msg: "Adding a present flatpak from URL shall mark module execution as not changed"
# state=absent with url on present flatpak
- name: Test removal with url of present flatpak (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
state: absent
register: url_removal_present_result
check_mode: true
- name: Verify removal with url of present flatpak test result (check mode)
assert:
that:
- url_removal_present_result is changed
msg: "Removing an absent flatpak shall mark module execution as not changed"
- name: Test non-existent idempotency of removal with url of present flatpak (check mode)
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: dummy-remote
state: absent
register: double_url_removal_present_result
check_mode: true
- name: >
Verify non-existent idempotency of installation with url of present
flatpak test result (check mode)
assert:
that:
- double_url_removal_present_result is changed
msg: Removing an absent flatpak a second time shall still mark module execution as changed

View File

@@ -0,0 +1,64 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) 2018, Alexander Bethke <oolongbrothers@gmx.net>
# Copyright (c) 2018, Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- import_tasks: setup.yml
become: true
# executable override
- name: Test executable override
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: present
executable: nothing-that-exists
ignore_errors: true
register: executable_override_result
- name: Verify executable override test result
assert:
that:
- executable_override_result is failed
- executable_override_result is not changed
msg: "Specifying non-existing executable shall fail module execution"
- import_tasks: check_mode.yml
become: false
- import_tasks: test.yml
become: false
vars:
method: user
- import_tasks: test.yml
become: true
vars:
method: system
always:
- name: Check HTTP server status
async_status:
jid: "{{ webserver_status.ansible_job_id }}"
ignore_errors: true
- name: List processes
command: ps aux
- name: Stop HTTP server
command: >-
pkill -f -- '{{ remote_tmp_dir }}/serve.py'
when: |
ansible_distribution == 'Fedora' or
ansible_distribution == 'Ubuntu' and not ansible_distribution_major_version | int < 16

View File

@@ -0,0 +1,68 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Install flatpak on Fedora
dnf:
name: flatpak
state: present
become: true
when: ansible_distribution == 'Fedora'
- block:
- name: Activate flatpak ppa on Ubuntu
apt_repository:
repo: ppa:alexlarsson/flatpak
state: present
mode: '0644'
when: ansible_lsb.major_release | int < 18
- name: Install flatpak package on Ubuntu
apt:
name: flatpak
state: present
when: ansible_distribution == 'Ubuntu'
- name: Install dummy remote for user
flatpak_remote:
name: dummy-remote
state: present
flatpakrepo_url: /tmp/flatpak/repo/dummy-repo.flatpakrepo
method: user
- name: Install dummy remote for system
flatpak_remote:
name: dummy-remote
state: present
flatpakrepo_url: /tmp/flatpak/repo/dummy-repo.flatpakrepo
method: system
- name: Remove (if necessary) flatpak for testing check mode on absent flatpak
flatpak:
name:
- com.dummy.App1
- com.dummy.App3
remote: dummy-remote
state: absent
no_dependencies: true
- name: Add flatpak for testing check mode on present flatpak
flatpak:
name: com.dummy.App2
remote: dummy-remote
state: present
no_dependencies: true
- name: Copy HTTP server
copy:
src: serve.py
dest: '{{ remote_tmp_dir }}/serve.py'
mode: '0755'
- name: Start HTTP server
command: '{{ ansible_python.executable }} {{ remote_tmp_dir }}/serve.py 127.0.0.1 8000 /tmp/flatpak/'
async: 120
poll: 0
register: webserver_status

View File

@@ -0,0 +1,289 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# state=present
- name: Test addition - {{ method }}
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: addition_result
- name: Verify addition test result - {{ method }}
assert:
that:
- addition_result is changed
msg: "state=present shall add flatpak when absent"
- name: Test idempotency of addition - {{ method }}
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: double_addition_result
- name: Verify idempotency of addition test result - {{ method }}
assert:
that:
- double_addition_result is not changed
msg: "state=present shall not do anything when flatpak is already present"
# state=absent
- name: Test removal - {{ method }}
flatpak:
name: com.dummy.App1
state: absent
method: "{{ method }}"
no_dependencies: true
register: removal_result
- name: Verify removal test result - {{ method }}
assert:
that:
- removal_result is changed
msg: "state=absent shall remove flatpak when present"
- name: Test idempotency of removal - {{ method }}
flatpak:
name: com.dummy.App1
state: absent
method: "{{ method }}"
no_dependencies: true
register: double_removal_result
- name: Verify idempotency of removal test result - {{ method }}
assert:
that:
- double_removal_result is not changed
msg: "state=absent shall not do anything when flatpak is not present"
# state=present with url as name
- name: Test addition with url - {{ method }}
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: url_addition_result
- name: Verify addition test result - {{ method }}
assert:
that:
- url_addition_result is changed
msg: "state=present with url as name shall add flatpak when absent"
- name: Test idempotency of addition with url - {{ method }}
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: double_url_addition_result
- name: Verify idempotency of addition with url test result - {{ method }}
assert:
that:
- double_url_addition_result is not changed
msg: "state=present with url as name shall not do anything when flatpak is already present"
# state=absent with url as name
- name: Test removal with url - {{ method }}
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent
method: "{{ method }}"
no_dependencies: true
register: url_removal_result
ignore_errors: true
- name: Verify removal test result failed - {{ method }}
# It looks like flatpak has a bug when the hostname contains a port. If this is the case, it emits
# the following message, which we check for. If another error happens, we fail.
# Upstream issue: https://github.com/flatpak/flatpak/issues/4307
# (The second message happens with Ubuntu 18.04.)
assert:
that:
- >-
url_removal_result.msg in [
"error: Invalid branch 127.0.0.1:8000: Branch can't contain :",
"error: Invalid id http:: Name can't contain :",
]
when: url_removal_result is failed
- when: url_removal_result is not failed
block:
- name: Verify removal test result - {{ method }}
assert:
that:
- url_removal_result is changed
msg: "state=absent with url as name shall remove flatpak when present"
- name: Test idempotency of removal with url - {{ method }}
flatpak:
name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent
method: "{{ method }}"
no_dependencies: true
register: double_url_removal_result
- name: Verify idempotency of removal with url test result - {{ method }}
assert:
that:
- double_url_removal_result is not changed
msg: "state=absent with url as name shall not do anything when flatpak is not present"
- name: Make sure flatpak is really gone - {{ method }}
flatpak:
name: com.dummy.App1
state: absent
method: "{{ method }}"
no_dependencies: true
# state=present with list of packages
- name: Test addition with list - {{ method }}
flatpak:
name:
- com.dummy.App1
- http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: addition_result
- name: Verify addition with list test result - {{ method }}
assert:
that:
- addition_result is changed
msg: "state=present shall add flatpak when absent"
- name: Test idempotency of addition with list - {{ method }}
flatpak:
name:
- com.dummy.App1
- http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: double_addition_result
- name: Verify idempotency of addition with list test result - {{ method }}
assert:
that:
- double_addition_result is not changed
msg: "state=present shall not do anything when flatpak is already present"
- name: Test addition with list partially installed - {{ method }}
flatpak:
name:
- com.dummy.App1
- http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
- com.dummy.App3
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: addition_result
- name: Verify addition with list partially installed test result - {{ method }}
assert:
that:
- addition_result is changed
msg: "state=present shall add flatpak when absent"
- name: Test idempotency of addition with list partially installed - {{ method }}
flatpak:
name:
- com.dummy.App1
- http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
- com.dummy.App3
remote: dummy-remote
state: present
method: "{{ method }}"
no_dependencies: true
register: double_addition_result
- name: Verify idempotency of addition with list partially installed test result - {{ method }}
assert:
that:
- double_addition_result is not changed
msg: "state=present shall not do anything when flatpak is already present"
# state=absent with list of packages
- name: Test removal with list - {{ method }}
flatpak:
name:
- com.dummy.App1
- com.dummy.App2
state: absent
method: "{{ method }}"
register: removal_result
- name: Verify removal with list test result - {{ method }}
assert:
that:
- removal_result is changed
msg: "state=absent shall remove flatpak when present"
- name: Test idempotency of removal with list - {{ method }}
flatpak:
name:
- com.dummy.App1
- com.dummy.App2
state: absent
method: "{{ method }}"
register: double_removal_result
- name: Verify idempotency of removal with list test result - {{ method }}
assert:
that:
- double_removal_result is not changed
msg: "state=absent shall not do anything when flatpak is not present"
- name: Test removal with list partially removed - {{ method }}
flatpak:
name:
- com.dummy.App1
- com.dummy.App2
- com.dummy.App3
state: absent
method: "{{ method }}"
register: removal_result
- name: Verify removal with list partially removed test result - {{ method }}
assert:
that:
- removal_result is changed
msg: "state=absent shall remove flatpak when present"
- name: Test idempotency of removal with list partially removed - {{ method }}
flatpak:
name:
- com.dummy.App1
- com.dummy.App2
- com.dummy.App3
state: absent
method: "{{ method }}"
register: double_removal_result
- name: Verify idempotency of removal with list partially removed test result - {{ method }}
assert:
that:
- double_removal_result is not changed
msg: "state=absent shall not do anything when flatpak is not present"