Update stor4nfv install scripts according to opensds aruba release
[stor4nfv.git] / ci / ansible / roles / cleaner / scenarios / backend.yml
1 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 ---
16 - name: clean the volume group of lvm
17   shell:
18     _raw_params: |
19
20       # _clean_lvm_volume_group removes all default LVM volumes
21       #
22       # Usage: _clean_lvm_volume_group $vg
23       function _clean_lvm_volume_group {
24           local vg=$1
25
26           # Clean out existing volumes
27           sudo lvremove -f $vg
28       }
29
30       # _remove_lvm_volume_group removes the volume group
31       #
32       # Usage: _remove_lvm_volume_group $vg
33       function _remove_lvm_volume_group {
34           local vg=$1
35
36           # Remove the volume group
37           sudo vgremove -f $vg
38       }
39
40       # _clean_lvm_backing_file() removes the backing file of the
41       # volume group
42       #
43       # Usage: _clean_lvm_backing_file() $backing_file
44       function _clean_lvm_backing_file {
45           local backing_file=$1
46
47           # If the backing physical device is a loop device, it was probably setup by DevStack
48           if [[ -n "$backing_file" ]] && [[ -e "$backing_file" ]]; then
49               local vg_dev
50               vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'.img'/ { print $1}')
51               if [[ -n "$vg_dev" ]]; then
52                   sudo losetup -d $vg_dev
53               fi
54               rm -f $backing_file
55           fi
56       }
57
58       # clean_lvm_volume_group() cleans up the volume group and removes the
59       # backing file
60       #
61       # Usage: clean_lvm_volume_group $vg
62       function clean_lvm_volume_group {
63           local vg=$1
64
65           _clean_lvm_volume_group $vg
66           _remove_lvm_volume_group $vg
67           # if there is no logical volume left, it's safe to attempt a cleanup
68           # of the backing file
69           if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then
70               _clean_lvm_backing_file {{ opensds_work_dir }}/volumegroups/${vg}.img
71           fi
72       }
73
74       clean_lvm_volume_group {{opensds_volume_group}}
75
76   args:
77     executable: /bin/bash
78   become: true
79   when: enabled_backend == "lvm"
80   ignore_errors: yes
81
82 - name: stop cinder-standalone service
83   shell: docker-compose down
84   become: true
85   args:
86     chdir: "{{ cinder_data_dir }}/cinder/contrib/block-box"
87   when: enabled_backend == "cinder"
88   ignore_errors: yes
89
90 - name: clean the volume group of cinder
91   shell:
92     _raw_params: |
93
94       # _clean_lvm_volume_group removes all default LVM volumes
95       #
96       # Usage: _clean_lvm_volume_group $vg
97       function _clean_lvm_volume_group {
98           local vg=$1
99
100           # Clean out existing volumes
101           sudo lvremove -f $vg
102       }
103
104       # _remove_lvm_volume_group removes the volume group
105       #
106       # Usage: _remove_lvm_volume_group $vg
107       function _remove_lvm_volume_group {
108           local vg=$1
109
110           # Remove the volume group
111           sudo vgremove -f $vg
112       }
113
114       # _clean_lvm_backing_file() removes the backing file of the
115       # volume group
116       #
117       # Usage: _clean_lvm_backing_file() $backing_file
118       function _clean_lvm_backing_file {
119           local backing_file=$1
120
121           # If the backing physical device is a loop device, it was probably setup by DevStack
122           if [[ -n "$backing_file" ]] && [[ -e "$backing_file" ]]; then
123               local vg_dev
124               vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'.img'/ { print $1}')
125               if [[ -n "$vg_dev" ]]; then
126                   sudo losetup -d $vg_dev
127               fi
128               rm -f $backing_file
129           fi
130       }
131
132       # clean_lvm_volume_group() cleans up the volume group and removes the
133       # backing file
134       #
135       # Usage: clean_lvm_volume_group $vg
136       function clean_lvm_volume_group {
137           local vg=$1
138
139           _clean_lvm_volume_group $vg
140           _remove_lvm_volume_group $vg
141           # if there is no logical volume left, it's safe to attempt a cleanup
142           # of the backing file
143           if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then
144               _clean_lvm_backing_file {{ cinder_data_dir }}/${vg}.img
145           fi
146       }
147
148       clean_lvm_volume_group {{cinder_volume_group}}
149
150   args:
151     executable: /bin/bash
152   become: true
153   when: enabled_backend == "cinder"
154   ignore_errors: yes