1 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 - name: clean the volume group of lvm
20 # _clean_lvm_volume_group removes all default LVM volumes
22 # Usage: _clean_lvm_volume_group $vg
23 function _clean_lvm_volume_group {
26 # Clean out existing volumes
30 # _remove_lvm_volume_group removes the volume group
32 # Usage: _remove_lvm_volume_group $vg
33 function _remove_lvm_volume_group {
36 # Remove the volume group
40 # _clean_lvm_backing_file() removes the backing file of the
43 # Usage: _clean_lvm_backing_file() $backing_file
44 function _clean_lvm_backing_file {
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
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
58 # clean_lvm_volume_group() cleans up the volume group and removes the
61 # Usage: clean_lvm_volume_group $vg
62 function clean_lvm_volume_group {
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
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
74 clean_lvm_volume_group {{opensds_volume_group}}
79 when: enabled_backend == "lvm"
82 - name: stop cinder-standalone service
83 shell: docker-compose down
86 chdir: "{{ cinder_data_dir }}/cinder/contrib/block-box"
87 when: enabled_backend == "cinder"
90 - name: clean the volume group of cinder
94 # _clean_lvm_volume_group removes all default LVM volumes
96 # Usage: _clean_lvm_volume_group $vg
97 function _clean_lvm_volume_group {
100 # Clean out existing volumes
104 # _remove_lvm_volume_group removes the volume group
106 # Usage: _remove_lvm_volume_group $vg
107 function _remove_lvm_volume_group {
110 # Remove the volume group
114 # _clean_lvm_backing_file() removes the backing file of the
117 # Usage: _clean_lvm_backing_file() $backing_file
118 function _clean_lvm_backing_file {
119 local backing_file=$1
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
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
132 # clean_lvm_volume_group() cleans up the volume group and removes the
135 # Usage: clean_lvm_volume_group $vg
136 function clean_lvm_volume_group {
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
148 clean_lvm_volume_group {{cinder_volume_group}}
151 executable: /bin/bash
153 when: enabled_backend == "cinder"