Browse code

apt: disable ubuntu repos to not change test env

(cherry picked from commit 0c86df33a48200904450de95a6ab309e0fc4cee5)

Martin Krizek authored on 2018/11/14 20:12:57
Showing 4 changed files
... ...
@@ -1,2 +1 @@
1 1
 apt_foreign_arch: i386
2
-hello_old_version: 2.6-1
... ...
@@ -16,6 +16,14 @@
16 16
 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
17 17
 
18 18
 - block:
19
+  - include: 'apt.yml'
20
+
21
+  - include: 'apt-multiarch.yml'
22
+    when:
23
+      - ansible_userspace_architecture != apt_foreign_arch
24
+
25
+  - include: 'apt-builddep.yml'
26
+
19 27
   - block:
20 28
       - include: 'repo.yml'
21 29
     always:
... ...
@@ -26,52 +34,5 @@
26 26
           name: "{{ repodir }}"
27 27
           state: absent
28 28
 
29
-  - include: 'apt.yml'
30
-
31
-  - include: 'apt-multiarch.yml'
32
-    when:
33
-      - ansible_userspace_architecture != apt_foreign_arch
34
-
35
-  - include: 'apt-builddep.yml'
36
-
37
-  - include: "upgrade.yml aptitude_present={{ True | bool }} upgrade_type=dist force_apt_get={{ False | bool }}"
38
-
39
-  - name: Check if aptitude is installed
40
-    command: dpkg-query --show --showformat='${db:Status-Abbrev}' aptitude
41
-    register: aptitude_status
42
-
43
-  - name: Remove aptitude, if installed, to test fall-back to apt-get
44
-    apt:
45
-      pkg: aptitude
46
-      state: absent
47
-    when:
48
-      - aptitude_status.stdout.find('ii') != -1
49
-
50
-  - include: "upgrade.yml aptitude_present={{ False | bool }} upgrade_type={{ item.upgrade_type }} force_apt_get={{ item.force_apt_get }}"
51
-    with_items:
52
-      - { upgrade_type: safe, force_apt_get: False }
53
-      - { upgrade_type: full, force_apt_get: False }
54
-      - { upgrade_type: safe, force_apt_get: True }
55
-      - { upgrade_type: full, force_apt_get: True }
56
-
57
-  - name: (Re-)Install aptitude, run same tests again
58
-    apt:
59
-      pkg: aptitude
60
-      state: present
61
-
62
-  - include: "upgrade.yml aptitude_present={{ True | bool }} upgrade_type={{ item.upgrade_type }} force_apt_get={{ item.force_apt_get }}"
63
-    with_items:
64
-      - { upgrade_type: safe, force_apt_get: False }
65
-      - { upgrade_type: full, force_apt_get: False }
66
-      - { upgrade_type: safe, force_apt_get: True }
67
-      - { upgrade_type: full, force_apt_get: True }
68
-
69
-  - name: Remove aptitude if not originally present
70
-    apt:
71
-      pkg: aptitude
72
-      state: absent
73
-    when:
74
-      - aptitude_status.stdout.find('ii') == -1
75
-
76 29
   when:
77 30
     - ansible_distribution in ('Ubuntu', 'Debian')
... ...
@@ -33,12 +33,64 @@
33 33
         - "apt_result is success"
34 34
         - "dpkg_result is success"
35 35
         - "'1.0.1' in dpkg_result.stdout"
36
+  always:
37
+    - name: Clean up
38
+      apt:
39
+        name: foo
40
+        state: absent
41
+        allow_unauthenticated: yes
42
+
36 43
 
37
-  # https://github.com/ansible/ansible/issues/35900
38
-  - name: Clean up
44
+# https://github.com/ansible/ansible/issues/30638
45
+- block:
46
+  - name: Fail to install foo=1.0.1 since foo is not installed and only_upgrade is set
39 47
     apt:
40
-      name: foo
41
-      state: absent
48
+      name: foo=1.0.1
49
+      state: installed
50
+      only_upgrade: yes
51
+      allow_unauthenticated: yes
52
+    ignore_errors: yes
53
+    register: apt_result
54
+
55
+  - name: Check that foo was not upgraded
56
+    assert:
57
+      that:
58
+        - "apt_result is not changed"
59
+
60
+  - apt:
61
+      name: foo=1.0.0
62
+      allow_unauthenticated: yes
63
+
64
+  - name: Upgrade foo to 1.0.1
65
+    apt:
66
+      name: foo=1.0.1
67
+      state: installed
68
+      only_upgrade: yes
69
+      allow_unauthenticated: yes
70
+    register: apt_result
71
+
72
+  - name: Check install with dpkg
73
+    shell: dpkg-query -l foo
74
+    register: dpkg_result
75
+
76
+  - name: Check if install was successful
77
+    assert:
78
+      that:
79
+        - "apt_result is success"
80
+        - "dpkg_result is success"
81
+        - "'1.0.1' in dpkg_result.stdout"
82
+  always:
83
+    - name: Clean up
84
+      apt:
85
+        name: foo
86
+        state: absent
87
+        allow_unauthenticated: yes
88
+
89
+
90
+# https://github.com/ansible/ansible/issues/35900
91
+- block:
92
+  - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env
93
+    command: mv /etc/apt/sources.list /etc/apt/sources.list.backup
42 94
 
43 95
   - name: Install foobar, installs foo as a dependency
44 96
     apt:
... ...
@@ -61,14 +113,21 @@
61 61
       that:
62 62
         - "dpkg_result is failed"
63 63
 
64
-  # https://github.com/ansible/ansible/issues/26298
65
-  - name: Clean up
66
-    apt:
67
-      name: "{{ item }}"
68
-      state: absent
69
-    with_items:
70
-      - foo
71
-      - foobar
64
+  always:
65
+    - name: Clean up
66
+      apt:
67
+        pkg: foo,foobar
68
+        state: absent
69
+        autoclean: yes
70
+
71
+    - name: Restore ubuntu repos
72
+      command: mv /etc/apt/sources.list.backup /etc/apt/sources.list
73
+
74
+
75
+# https://github.com/ansible/ansible/issues/26298
76
+- block:
77
+  - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env
78
+    command: mv /etc/apt/sources.list /etc/apt/sources.list.backup
72 79
 
73 80
   - name: Install foobar, installs foo as a dependency
74 81
     apt:
... ...
@@ -141,50 +200,54 @@
141 141
       that:
142 142
         - "autoclean_result is not changed"
143 143
 
144
-  # https://github.com/ansible/ansible/issues/30638
145
-  - name: Fail to install foo=1.0.1 since foo is not installed and only_upgrade is set
146
-    apt:
147
-      name: foo=1.0.1
148
-      state: installed
149
-      only_upgrade: yes
150
-      allow_unauthenticated: yes
151
-    ignore_errors: yes
152
-    register: apt_result
144
+  always:
145
+    - name: Clean up
146
+      apt:
147
+        pkg: foo,foobar
148
+        state: absent
149
+        autoclean: yes
153 150
 
154
-  - name: Check that foo was not upgraded
155
-    assert:
156
-      that:
157
-        - "apt_result is not changed"
151
+    - name: Restore ubuntu repos
152
+      command: mv /etc/apt/sources.list.backup /etc/apt/sources.list
158 153
 
159
-  - apt:
160
-      name: foo=1.0.0
161
-      allow_unauthenticated: yes
162 154
 
163
-  - name: Upgrade foo to 1.0.1
164
-    apt:
165
-      name: foo=1.0.1
166
-      state: installed
167
-      only_upgrade: yes
168
-      allow_unauthenticated: yes
169
-    register: apt_result
155
+- name: Upgrades
156
+  block:
157
+    - include: "upgrade.yml aptitude_present={{ True | bool }} upgrade_type=dist force_apt_get={{ False | bool }}"
170 158
 
171
-  - name: Check install with dpkg
172
-    shell: dpkg-query -l foo
173
-    register: dpkg_result
174
-
175
-  - name: Check if install was successful
176
-    assert:
177
-      that:
178
-        - "apt_result is success"
179
-        - "dpkg_result is success"
180
-        - "'1.0.1' in dpkg_result.stdout"
159
+    - name: Check if aptitude is installed
160
+      command: dpkg-query --show --showformat='${db:Status-Abbrev}' aptitude
161
+      register: aptitude_status
181 162
 
182
-  always:
183
-    - name: Clean up
163
+    - name: Remove aptitude, if installed, to test fall-back to apt-get
184 164
       apt:
185
-        name: "{{ item }}"
165
+        pkg: aptitude
186 166
         state: absent
187
-        allow_unauthenticated: yes
167
+      when:
168
+        - aptitude_status.stdout.find('ii') != -1
169
+
170
+    - include: "upgrade.yml aptitude_present={{ False | bool }} upgrade_type={{ item.upgrade_type }} force_apt_get={{ item.force_apt_get }}"
188 171
       with_items:
189
-        - foo
190
-        - foobar
172
+        - { upgrade_type: safe, force_apt_get: False }
173
+        - { upgrade_type: full, force_apt_get: False }
174
+        - { upgrade_type: safe, force_apt_get: True }
175
+        - { upgrade_type: full, force_apt_get: True }
176
+
177
+    - name: (Re-)Install aptitude, run same tests again
178
+      apt:
179
+        pkg: aptitude
180
+        state: present
181
+
182
+    - include: "upgrade.yml aptitude_present={{ True | bool }} upgrade_type={{ item.upgrade_type }} force_apt_get={{ item.force_apt_get }}"
183
+      with_items:
184
+        - { upgrade_type: safe, force_apt_get: False }
185
+        - { upgrade_type: full, force_apt_get: False }
186
+        - { upgrade_type: safe, force_apt_get: True }
187
+        - { upgrade_type: full, force_apt_get: True }
188
+
189
+    - name: Remove aptitude if not originally present
190
+      apt:
191
+        pkg: aptitude
192
+        state: absent
193
+      when:
194
+        - aptitude_status.stdout.find('ii') == -1
... ...
@@ -1,61 +1,72 @@
1
-#### Tests for upgrade/download functions in modules/packaging/os/apt.py ####
2
-- name: download and install old version of hello
3
-  apt: "deb=https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/apt/hello_{{ hello_old_version }}_amd64.deb"
4
-
5
-- name: check hello version
6
-  shell: dpkg -s hello | grep Version | awk '{print $2}'
7
-  register: hello_version
8
-
9
-- name: ensure the correct version of hello has been installed
10
-  assert:
11
-    that:
12
-      - "{{ hello_version.stdout }}=={{ hello_old_version }}"
13
-
14
-- name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version, force_apt_get: {{force_apt_get}}"
15
-  apt:
16
-    upgrade: "{{ upgrade_type }}"
17
-    force_apt_get: "{{ force_apt_get }}"
18
-  register: upgrade_result
19
-
20
-- name: check hello version
21
-  shell: dpkg -s hello | grep Version | awk '{print $2}'
22
-  register: hello_version
23
-
24
-- name: check that warning is not given when force_apt_get set
25
-  assert:
26
-    that:
27
-      - "'warnings' not in upgrade_result"
28
-  when:
29
-    - force_apt_get
30
-
31
-- name: check that warning is given when aptitude not found and force_apt_get not set
32
-  assert:
33
-    that:
34
-      - "'Could not find aptitude. Using apt-get instead' in upgrade_result.warnings[0]"
35
-  when:
36
-    - not aptitude_present
37
-    - not force_apt_get
38
-
39
-- name: check that old version upgraded correctly
40
-  assert:
41
-    that:
42
-      - "{{ hello_version.stdout }}!={{ hello_old_version }}"
43
-      - "{{ hello_version.changed }}"
44
-
45
-- name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version (Idempotant)"
46
-  apt:
47
-    upgrade: "{{ upgrade_type }}"
48
-    force_apt_get: "{{ force_apt_get }}"
49
-  register: second_upgrade_result
50
-
51
-- name: check that nothing has changed (Idempotant)
52
-  assert:
53
-    that:
54
-      - "second_upgrade_result.changed == false"
55
-
56
-- name: remove hello
57
-  apt:
58
-    pkg: hello
59
-    state: absent
60
-    autoclean: yes
1
+- block:
2
+  - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env
3
+    command: mv /etc/apt/sources.list /etc/apt/sources.list.backup
4
+
5
+  - name: install foo-1.0.0
6
+    apt:
7
+      name: foo=1.0.0
8
+      state: present
9
+      allow_unauthenticated: yes
10
+
11
+  - name: check foo version
12
+    shell: dpkg -s foo | grep Version | awk '{print $2}'
13
+    register: foo_version
14
+
15
+  - name: ensure the correct version of foo has been installed
16
+    assert:
17
+      that:
18
+        - "'1.0.0' in foo_version.stdout"
19
+
20
+  - name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version, force_apt_get: {{force_apt_get}}"
21
+    apt:
22
+      upgrade: "{{ upgrade_type }}"
23
+      force_apt_get: "{{ force_apt_get }}"
24
+      force: yes
25
+    register: upgrade_result
26
+
27
+  - name: check foo version
28
+    shell: dpkg -s foo | grep Version | awk '{print $2}'
29
+    register: foo_version
30
+
31
+  - name: check that warning is not given when force_apt_get set
32
+    assert:
33
+      that:
34
+        - "'warnings' not in upgrade_result"
35
+    when:
36
+      - force_apt_get
37
+
38
+  - name: check that warning is given when aptitude not found and force_apt_get not set
39
+    assert:
40
+      that:
41
+        - "'Could not find aptitude. Using apt-get instead' in upgrade_result.warnings[0]"
42
+    when:
43
+      - not aptitude_present
44
+      - not force_apt_get
45
+
46
+  - name: check that old version upgraded correctly
47
+    assert:
48
+      that:
49
+        - "'1.0.0' not in foo_version.stdout"
50
+        - "{{ foo_version.changed }}"
51
+
52
+  - name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version (Idempotant)"
53
+    apt:
54
+      upgrade: "{{ upgrade_type }}"
55
+      force_apt_get: "{{ force_apt_get }}"
56
+      force: yes
57
+    register: second_upgrade_result
58
+
59
+  - name: check that nothing has changed (Idempotant)
60
+    assert:
61
+      that:
62
+        - "second_upgrade_result.changed == false"
63
+
64
+  always:
65
+    - name: Clean up
66
+      apt:
67
+        pkg: foo,foobar
68
+        state: absent
69
+        autoclean: yes
70
+
71
+    - name: Restore ubuntu repos
72
+      command: mv /etc/apt/sources.list.backup /etc/apt/sources.list