mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-07-08 11:39:02 +00:00
kopia: Add kopia_repository module (#11752)
* Add kopia module util * fix pipeline suggestions * add kopia repository module * apply code review changes * remove kopia_runner instance unit test * update botmeta with kopia * refactor docs and redundant state * add kopia_info module and fix kopia_repository check mode support - Add kopia_info module for read-only repository information gathering (kopia repository status, kopia repository throttle get) following the pacemaker_info pattern with ModuleHelper and info_module fragment - Add _fmt_throttle to _kopia.py and register throttle format in kopia_runner; remove throttle_operation get option from kopia_repository per Ansible best practices (info ops belong in _info modules) - Add throttle suboption dict to kopia_repository with all seven kopia repository throttle set flags - Fix check_mode: support from full to actually full by implementing _predict_value() in kopia_repository; previously check_mode_skip caused changed to always be false in check mode - Add check mode test cases to test_kopia_repository.yaml covering created and disconnected states for both connected and disconnected initial conditions - Add BOTMETA.yml entry and full test fixture for kopia_info * apply code review suggestions
This commit is contained in:
parent
580e8ad3f9
commit
d4031f36e4
10 changed files with 1378 additions and 0 deletions
11
tests/unit/plugins/modules/test_kopia_repository.py
Normal file
11
tests/unit/plugins/modules/test_kopia_repository.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2026, Dexter Le <dextersydney2001@gmail.com>
|
||||
# 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
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import kopia_repository
|
||||
|
||||
from .uthelper import RunCommandMock, UTHelper
|
||||
|
||||
UTHelper.from_module(kopia_repository, __name__, mocks=[RunCommandMock])
|
||||
346
tests/unit/plugins/modules/test_kopia_repository.yaml
Normal file
346
tests/unit/plugins/modules/test_kopia_repository.yaml
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
# Copyright (c) 2026, Dexter Le <dextersydney2001@gmail.com>
|
||||
# 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
|
||||
|
||||
---
|
||||
anchors:
|
||||
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
|
||||
status_ok: &status-ok
|
||||
command: [/testbin/kopia, repository, status, --config-file=/etc/kopia/root.config]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "Connected to repository."
|
||||
err: ''
|
||||
status_empty: &status-empty
|
||||
command: [/testbin/kopia, repository, status, --config-file=/etc/kopia/root.config]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ''
|
||||
err: 'repository not connected'
|
||||
|
||||
test_cases:
|
||||
- id: create_s3
|
||||
input:
|
||||
state: created
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: s3
|
||||
bucket: my-bucket
|
||||
access_key: myaccesskey
|
||||
secret_access_key: mysecretkey
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-empty
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- create
|
||||
- s3
|
||||
- --bucket=my-bucket
|
||||
- --access-key=myaccesskey
|
||||
- --secret-access-key=mysecretkey
|
||||
- --password=secret
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: create_s3_already_exists
|
||||
input:
|
||||
state: created
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: s3
|
||||
bucket: my-bucket
|
||||
access_key: myaccesskey
|
||||
secret_access_key: mysecretkey
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- create
|
||||
- s3
|
||||
- --bucket=my-bucket
|
||||
- --access-key=myaccesskey
|
||||
- --secret-access-key=mysecretkey
|
||||
- --password=secret
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ''
|
||||
err: 'already exists'
|
||||
- *status-ok
|
||||
|
||||
- id: create_filesystem
|
||||
input:
|
||||
state: created
|
||||
password: secret
|
||||
backend:
|
||||
provider: filesystem
|
||||
path: /mnt/backup/kopia
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/kopia, repository, status]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ''
|
||||
err: 'repository not connected'
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- create
|
||||
- filesystem
|
||||
- --path=/mnt/backup/kopia
|
||||
- --password=secret
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- command: [/testbin/kopia, repository, status]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "Connected to repository."
|
||||
err: ''
|
||||
|
||||
- id: connect_server
|
||||
input:
|
||||
state: connected
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
url: https://kopia.example.com:51515
|
||||
fingerprint_tls: "AA:BB:CC:DD"
|
||||
backend:
|
||||
provider: server
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-empty
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- connect
|
||||
- --password=secret
|
||||
- --server-cert-fingerprint=AA:BB:CC:DD
|
||||
- --url=https://kopia.example.com:51515
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: connect_azure
|
||||
input:
|
||||
state: connected
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: azure
|
||||
container: my-container
|
||||
storage_account: myaccount
|
||||
storage_key: mykey
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-empty
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- connect
|
||||
- azure
|
||||
- --container=my-container
|
||||
- --storage-account=myaccount
|
||||
- --storage-key=mykey
|
||||
- --password=secret
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: disconnect
|
||||
input:
|
||||
state: disconnected
|
||||
config: /etc/kopia/root.config
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- disconnect
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-empty
|
||||
|
||||
- id: sync_s3
|
||||
input:
|
||||
state: synced
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: s3
|
||||
bucket: my-sync-bucket
|
||||
access_key: myaccesskey
|
||||
secret_access_key: mysecretkey
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- sync-to
|
||||
- s3
|
||||
- --bucket=my-sync-bucket
|
||||
- --access-key=myaccesskey
|
||||
- --secret-access-key=mysecretkey
|
||||
- --password=secret
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: throttle_set
|
||||
input:
|
||||
state: throttled
|
||||
config: /etc/kopia/root.config
|
||||
throttle:
|
||||
upload_bytes_per_second: 1048576
|
||||
download_bytes_per_second: 5242880
|
||||
concurrent_reads: 4
|
||||
concurrent_writes: 2
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- throttle
|
||||
- set
|
||||
- --download-bytes-per-second
|
||||
- "5242880"
|
||||
- --upload-bytes-per-second
|
||||
- "1048576"
|
||||
- --concurrent-reads
|
||||
- "4"
|
||||
- --concurrent-writes
|
||||
- "2"
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: throttle_set_rate_limits
|
||||
input:
|
||||
state: throttled
|
||||
config: /etc/kopia/root.config
|
||||
throttle:
|
||||
read_requests_per_second: 10.0
|
||||
write_requests_per_second: 5.0
|
||||
list_requests_per_second: 2.5
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
- command:
|
||||
- /testbin/kopia
|
||||
- repository
|
||||
- throttle
|
||||
- set
|
||||
- --read-requests-per-second
|
||||
- "10.0"
|
||||
- --write-requests-per-second
|
||||
- "5.0"
|
||||
- --list-requests-per-second
|
||||
- "2.5"
|
||||
- --config-file=/etc/kopia/root.config
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- *status-ok
|
||||
|
||||
- id: check_mode_create_not_exists
|
||||
flags: {check: true}
|
||||
input:
|
||||
state: created
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: s3
|
||||
bucket: my-bucket
|
||||
access_key: myaccesskey
|
||||
secret_access_key: mysecretkey
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-empty
|
||||
|
||||
- id: check_mode_create_already_exists
|
||||
flags: {check: true}
|
||||
input:
|
||||
state: created
|
||||
password: secret
|
||||
config: /etc/kopia/root.config
|
||||
backend:
|
||||
provider: s3
|
||||
bucket: my-bucket
|
||||
access_key: myaccesskey
|
||||
secret_access_key: mysecretkey
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
|
||||
- id: check_mode_disconnect_connected
|
||||
flags: {check: true}
|
||||
input:
|
||||
state: disconnected
|
||||
config: /etc/kopia/root.config
|
||||
output:
|
||||
changed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-ok
|
||||
|
||||
- id: check_mode_disconnect_not_connected
|
||||
flags: {check: true}
|
||||
input:
|
||||
state: disconnected
|
||||
config: /etc/kopia/root.config
|
||||
output:
|
||||
changed: false
|
||||
mocks:
|
||||
run_command:
|
||||
- *status-empty
|
||||
11
tests/unit/plugins/modules/test_kopia_repository_info.py
Normal file
11
tests/unit/plugins/modules/test_kopia_repository_info.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2026, Dexter Le <dextersydney2001@gmail.com>
|
||||
# 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
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import kopia_repository_info
|
||||
|
||||
from .uthelper import RunCommandMock, UTHelper
|
||||
|
||||
UTHelper.from_module(kopia_repository_info, __name__, mocks=[RunCommandMock])
|
||||
73
tests/unit/plugins/modules/test_kopia_repository_info.yaml
Normal file
73
tests/unit/plugins/modules/test_kopia_repository_info.yaml
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# Copyright (c) 2026, Dexter Le <dextersydney2001@gmail.com>
|
||||
# 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
|
||||
|
||||
---
|
||||
anchors:
|
||||
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
|
||||
|
||||
test_cases:
|
||||
- id: info_connected
|
||||
input:
|
||||
config: /etc/kopia/root.config
|
||||
output:
|
||||
changed: false
|
||||
repository_status: |-
|
||||
Connected to repository: s3:/my-bucket/
|
||||
Config file: /etc/kopia/root.config
|
||||
throttle: |-
|
||||
upload-bytes-per-second: 0
|
||||
download-bytes-per-second: 0
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/kopia, repository, status, --config-file=/etc/kopia/root.config]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: |-
|
||||
Connected to repository: s3:/my-bucket/
|
||||
Config file: /etc/kopia/root.config
|
||||
err: ''
|
||||
- command: [/testbin/kopia, repository, throttle, get, --config-file=/etc/kopia/root.config]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: |-
|
||||
upload-bytes-per-second: 0
|
||||
download-bytes-per-second: 0
|
||||
err: ''
|
||||
|
||||
- id: info_not_connected
|
||||
input:
|
||||
config: /etc/kopia/root.config
|
||||
output:
|
||||
failed: true
|
||||
msg: "kopia repository status failed with error (rc=1): repository not connected"
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/kopia, repository, status, --config-file=/etc/kopia/root.config]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ''
|
||||
err: 'repository not connected'
|
||||
|
||||
- id: info_no_config
|
||||
input: {}
|
||||
output:
|
||||
changed: false
|
||||
repository_status: "Connected to repository: filesystem:/mnt/backup/kopia"
|
||||
throttle: |-
|
||||
upload-bytes-per-second: 1048576
|
||||
download-bytes-per-second: 5242880
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/kopia, repository, status]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "Connected to repository: filesystem:/mnt/backup/kopia"
|
||||
err: ''
|
||||
- command: [/testbin/kopia, repository, throttle, get]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: |-
|
||||
upload-bytes-per-second: 1048576
|
||||
download-bytes-per-second: 5242880
|
||||
err: ''
|
||||
Loading…
Add table
Add a link
Reference in a new issue