8000 Adding integration tests for testing the 'mode' arg of the apt_repository module by caphrim007 · Pull Request #58369 · ansible/ansible · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding integration tests for testing the 'mode' arg of the apt_repository module #58369

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/integration/targets/apt_repository/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@

- include: 'apt.yml'
when: ansible_distribution in ('Ubuntu')

- include: mode.yaml
when: ansible_distribution in ('Ubuntu')
tags:
- test_apt_repository_mode
130 changes: 130 additions & 0 deletions test/integration/targets/apt_repository/tasks/mode.yaml
F5BB
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---

# These tests are likely slower than they should be, since each
# invocation of apt_repository seems to end up querying for
# lots (all?) configured repos.

- set_fact:
test_repo_spec: "deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main"
test_repo_path: /etc/apt/sources.list.d/apt_postgresql_org_pub_repos_apt.list

- include: mode_cleanup.yaml

- name: Add GPG key to verify signatures
apt_key:
id: 7FCC7D46ACCC4CF8
keyserver: keyserver.ubuntu.com

- name: Mode specified as yaml literal 0600
apt_repository:
repo: "{{ test_repo_spec }}"
state: present
mode: 0600
register: mode_given_results

- name: Gather mode_given_as_literal_yaml stat
stat:
path: "{{ test_repo_path }}"
register: mode_given_yaml_literal_0600

- name: Show mode_given_yaml_literal_0600
debug:
var: mode_given_yaml_literal_0600

- include: mode_cleanup.yaml

- name: Assert mode_given_yaml_literal_0600 is correct
assert:
that: "mode_given_yaml_literal_0600.stat.mode == '0600'"

- name: No mode specified
apt_repository:
repo: "{{ test_repo_spec }}"
state: present
register: no_mode_results

- name: Gather no mode stat
stat:
path: "{{ test_repo_path }}"
register: no_mode_stat

- name: Show no mode stat
debug:
var: no_mode_stat

- include: mode_cleanup.yaml

- name: Assert no_mode_stat is correct
assert:
that: "no_mode_stat.stat.mode == '0644'"

- name: Mode specified as string 0600
apt_repository:
repo: "{{ test_repo_spec }}"
state: present
mode: "0600"
register: mode_given_string_results

- name: Gather mode_given_string stat
stat:
path: "{{ test_repo_path }}"
register: mode_given_string_stat

- name: Show mode_given_string_stat
debug:
var: mode_given_string_stat

- include: mode_cleanup.yaml

- name: Mode specified as string 600
apt_repository:
repo: "{{ test_repo_spec }}"
state: present
mode: "600"
register: mode_given_string_600_results

- name: Gather mode_given_600_string stat
stat:
path: "{{ test_repo_path }}"
register: mode_given_string_600_stat

- name: Show mode_given_string_stat
debug:
var: mode_given_string_600_stat

- include: mode_cleanup.yaml

- name: Assert mode is correct
assert:
that: "mode_given_string_600_stat.stat.mode == '0600'"

- name: Mode specified as yaml literal 600
apt_repository:
repo: "{{ test_repo_spec }}"
state: present
mode: 600
register: mode_given_short_results

- name: Gather mode_given_yaml_literal_600 stat
stat:
path: "{{ test_repo_path }}"
register: mode_given_yaml_literal_600

- name: Show mode_given_yaml_literal_600
debug:
var: mode_given_yaml_literal_600

- include: mode_cleanup.yaml

# a literal 600 as the mode will fail currently, in the sense that it
# doesn't guess and consider 600 and 0600 to be the same, and will instead
# intepret literal 600 as the decimal 600 (and thereby octal 1130).
# The literal 0600 can be interpreted as octal correctly. Note that
# a decimal 644 is octal 420. The default perm is 0644 so a mis intrpretation
# of 644 was previously resulting in a default file mode of 0420.
# 'mode: 600' is likely not what a user meant but there isnt enough info
# to determine that. Note that a string arg of '600' will be intrepeted as 0600.
# See https://github.com/ansible/ansible/issues/16370
- name: Assert mode_given_yaml_literal_600 is correct
assert:
that: "mode_given_yaml_literal_600.stat.mode == '1130'"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# tasks to cleanup after creating a repo file, specifically for testing the 'mode' arg

- name: Delete existing repo
file:
path: "{{ test_repo_path }}"
state: absent
0