Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/parted/tasks/main.yml

raw
1 # Copyright (c) 2021, Alexei Znamensky
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 - name: Install parted
6 package:
7 name: parted
8 state: present
9 when: ansible_facts.os_family == 'Alpine'
10
11 - name: Create empty file
12 community.general.filesize:
13 path: /bigfile
14 size: 1GiB
15 notify: Remove file
16
17 - name: Obtain loop device name
18 command:
19 cmd: losetup -f
20 changed_when: false
21 register: losetup_name
22
23 - name: Create loopback device
24 command:
25 cmd: losetup -f /bigfile
26 changed_when: true
27 register: losetup_cmd
28 notify: Remove loopback device
29
30 - name: Create first partition
31 community.general.parted:
32 device: "{{ losetup_name.stdout }}"
33 number: 1
34 state: present
35 fs_type: ext4
36 part_end: "50%"
37 register: partition1
38
39 - name: Make filesystem
40 community.general.filesystem:
41 device: "{{ losetup_name.stdout }}p1"
42 fstype: ext4
43 register: fs1_succ
44
45 - name: Make filesystem (fail)
46 community.general.filesystem:
47 device: "{{ losetup_name.stdout }}p2"
48 fstype: ext4
49 ignore_errors: true
50 register: fs_fail
51
52 - name: Create second partition
53 community.general.parted:
54 device: "{{ losetup_name.stdout }}"
55 number: 2
56 state: present
57 fs_type: ext4
58 part_start: "{{ partition1.partitions[0].end + 1 }}KiB"
59 part_end: "100%"
60 register: partition2
61
62 - name: Make filesystem
63 community.general.filesystem:
64 device: "{{ losetup_name.stdout }}p2"
65 fstype: ext4
66 register: fs2_succ
67
68 - name: Remove first partition
69 community.general.parted:
70 device: "{{ losetup_name.stdout }}"
71 number: 1
72 state: absent
73 register: partition_rem1
74
75 - name: Assert results
76 assert:
77 that:
78 - partition1 is changed
79 - fs1_succ is changed
80 - fs_fail is failed
81 - fs_fail is not changed
82 - partition2 is changed
83 - partition2.partitions | length == 2
84 - fs2_succ is changed
85 - partition_rem1 is changed
86 - partition_rem1.partitions | length == 1
87
88 - name: Get partition info with unit_preserve_case=true
89 community.general.parted:
90 device: "{{ losetup_name.stdout }}"
91 state: info
92 unit: KiB
93 unit_preserve_case: true
94 register: info_preserve_true
95
96 - name: Get partition info with unit_preserve_case=false
97 community.general.parted:
98 device: "{{ losetup_name.stdout }}"
99 state: info
100 unit: KiB
101 unit_preserve_case: false
102 register: info_preserve_false
103
104 - name: Assert unit_preserve_case results
105 assert:
106 that:
107 - info_preserve_true.disk.unit == "KiB"
108 - info_preserve_true.partitions[0].unit == "KiB"
109 - info_preserve_false.disk.unit == "kib"
110 - info_preserve_false.partitions[0].unit == "kib"
111
112 - name: Use returned unit as input (round-trip) - regression test for issue 1860
113 community.general.parted:
114 device: "{{ losetup_name.stdout }}"
115 state: info
116 unit: "{{ info_preserve_true.disk.unit }}"
117 unit_preserve_case: true
118 register: info_roundtrip
119
120 - name: Assert round-trip succeeds and unit is consistent
121 assert:
122 that:
123 - info_roundtrip.disk.unit == info_preserve_true.disk.unit