Skip to content

Commit 53303c7

Browse files
authored
added a test case : syncing using ansible collections
Draft : WIP
1 parent 1100a9a commit 53303c7

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
- hosts: satellite6
2+
vars_files:
3+
- Downloads/satperf.yaml
4+
vars:
5+
test_sync_repositories_count: 8
6+
test_sync_repositories_product: "test_sync_repositories_product"
7+
test_sync_repositories_upstream_url_template: "https://galaxy.ansible.com/"
8+
test_sync_repositories_repo_template: "test_sync_repositories_repo*"
9+
test_sync_repositories_max_sync_secs: 3600
10+
test_sync_repositories_cv_template: "test_sync_repositories_cv*"
11+
test_sync_repositories_le: "test_sync_repositories_le"
12+
sat_user: admin
13+
sat_pass: changeme
14+
organization: Default Organization
15+
tasks:
16+
- name: "Create product"
17+
ansible.builtin.command:
18+
cmd: |
19+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" product create --organization "{{ organization }}" --name "{{ test_sync_repositories_product }}"
20+
register: create_product
21+
failed_when:
22+
- create_product.rc != 0
23+
- "'Name has already been taken for a product in this organization' not in create_product.stderr"
24+
changed_when:
25+
- create_product.rc == 0
26+
- "'Product created' in create_product.stdout"
27+
28+
- name: "Create requirements file"
29+
ansible.builtin.copy:
30+
dest: "/tmp/blabllbl"
31+
content: |
32+
---
33+
collections:
34+
- name: ansible.posix
35+
version: 1.5.4
36+
- name: ansible.utils
37+
version: 5.0.0
38+
- name: community.general
39+
version: 9.1.0
40+
...
41+
42+
- name: "Create repos"
43+
ansible.builtin.command:
44+
cmd: |
45+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" repository create --organization "{{ organization }}" --product "{{ test_sync_repositories_product }}" --content-type ansible_collection --url "{{ test_sync_repositories_upstream_url_template }}" --requirements "/tmp/blabllbl" --name "{{ test_sync_repositories_repo_template | replace('*', item) }}"
46+
register: create_repo
47+
loop: "{{ range(1, test_sync_repositories_count | int + 1) | list }}"
48+
49+
# Sync
50+
- name: "Start sync asynchronously"
51+
ansible.builtin.command:
52+
cmd: |
53+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" repository synchronize --organization "{{ organization }}" --product "{{ test_sync_repositories_product }}" --name "{{ test_sync_repositories_repo_template | replace('*', item) }}" --async
54+
loop: "{{ range(1, test_sync_repositories_count | int + 1) | list }}"
55+
register: start_sync
56+
ignore_errors: true
57+
58+
- name: "Check that start message is sane"
59+
ansible.builtin.assert:
60+
that: "'Repository is being synchronized in task' in item.stdout"
61+
msg: 'Pass'
62+
quiet: true
63+
loop: "{{ start_sync.results }}"
64+
loop_control:
65+
label: "{{ test_sync_repositories_repo_template | replace('*', item.item) }}"
66+
67+
- name: "Wait for synces to finish"
68+
ansible.builtin.command:
69+
cmd: |
70+
/root/wait-for-task.sh "{{ sat_user }}" "{{ sat_pass }}" "{{ item.stdout.split()[6].split('.')[0] }}" "{{ test_sync_repositories_max_sync_secs }}"
71+
loop: "{{ start_sync.results }}"
72+
loop_control:
73+
label: "{{ test_sync_repositories_repo_template | replace('*', item.item) }}"
74+
register: wait_sync
75+
ignore_errors: true
76+
77+
- name: "Print sync results"
78+
ansible.builtin.debug:
79+
msg: "SyncRepositories {{ item.stdout_lines[-2] }} to {{ item.stdout_lines[-1] }}"
80+
loop: "{{ wait_sync.results }}"
81+
when: "item.rc is defined and item.rc == 0"
82+
83+
- name: "Create lifecycle environment"
84+
ansible.builtin.command:
85+
cmd: |
86+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" lifecycle-environment create --organization "{{ organization }}" --prior Library --name "{{ test_sync_repositories_le }}"
87+
register: create_le
88+
89+
- name: "Create content views"
90+
ansible.builtin.command:
91+
cmd: |
92+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" content-view create --organization "{{ organization }}" --name "{{ test_sync_repositories_cv_template | replace('*', item) }}"
93+
register: create_cv
94+
loop: "{{ range(1, test_sync_repositories_count | int + 1) | list }}"
95+
96+
# Publish
97+
- name: "Publish content views"
98+
ansible.builtin.command:
99+
cmd: |
100+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" content-view publish --async --organization "{{ organization }}" --name "{{ test_sync_repositories_cv_template | replace('*', item) }}"
101+
register: start_publish
102+
loop: "{{ range(1, test_sync_repositories_count | int + 1) | list }}"
103+
104+
- name: "Wait for publish to finish"
105+
ansible.builtin.command:
106+
cmd: |
107+
/root/wait-for-task.sh "{{ sat_user }}" "{{ sat_pass }}" "{{ item.stdout.split()[7].split('.')[0] }}" "{{ test_sync_repositories_max_sync_secs }}"
108+
loop: "{{ start_publish.results }}"
109+
loop_control:
110+
label: "{{ test_sync_repositories_cv_template | replace('*', item.item) }}"
111+
register: wait_publish
112+
ignore_errors: true
113+
114+
- name: "Print publish results"
115+
ansible.builtin.debug:
116+
msg: "PublishContentViews {{ item.stdout_lines[-2] }} to {{ item.stdout_lines[-1] }}"
117+
loop: "{{ wait_publish.results }}"
118+
when: "item.rc is defined and item.rc == 0"
119+
120+
# Promote
121+
- name: "Promote content views"
122+
ansible.builtin.command:
123+
hammer -u "{{ sat_user }}" -p "{{ sat_pass }}" content-view version promote --async --organization "{{ organization }}" --content-view "{{ test_sync_repositories_cv_template | replace('*', item) }}" --version "1.0" --to-lifecycle-environment "{{ test_sync_repositories_le }}"
124+
register: start_promote
125+
loop: "{{ range(1, test_sync_repositories_count | int + 1) | list }}"
126+
127+
- name: "Wait for promote to finish"
128+
ansible.builtin.command:
129+
cmd: |
130+
/root/wait-for-task.sh "{{ sat_user }}" "{{ sat_pass }}" "{{ item.stdout.split()[7].split('.')[0] }}" "{{ test_sync_repositories_max_sync_secs }}"
131+
loop: "{{ start_promote.results }}"
132+
loop_control:
133+
label: "{{ test_sync_repositories_cv_template | replace('*', item.item) }}"
134+
register: wait_promote
135+
ignore_errors: true
136+
137+
- ansible.builtin.debug:
138+
var: wait_promote
139+
140+
- name: "Print promote results"
141+
ansible.builtin.debug:
142+
msg: "PromoteContentViews {{ item.stdout_lines[-2] }} to {{ item.stdout_lines[-1] }}"
143+
loop: "{{ wait_promote.results }}"
144+
when: "item.rc is defined and item.rc == 0"
145+
...

0 commit comments

Comments
 (0)