[train-squash] Remove hardcoded reference to cinder LVM loopback device
Backport note: In CentOS 7, losetup does not include the -n option. We therefore use a slightly different way to get the same output in this backport. This is a squash commit of the following patches: Rename loopback creates file We are hitting bug[1] and it looks like because /dev/loop2 file already exists the ansible task which creates loop didn't trigger. Creating file with different name "/dev/loop2cinder" to pass the issue[1] [1] https://bugs.launchpad.net/tripleo/+bug/1872881 Change-Id: I4e18bee7864b71afca387fbea5857c9530faa2fc Partial-Bug: #1872881 (cherry picked from commitf85caaf411
) Remove hardcoded reference to cinder LVM loopback device Replace hardcoded reference to "/dev/loop2" by allowing losetup to dynamically choose the next available loopback device number. Eliminate hiera data that set cinder_lvm_loop_device_size. This is not needed because the associated file is created by a host prep task, and the puppet code will be removed by https://review.opendev.org/720139. Closes-Bug: #1872881 Change-Id: Ia0302d1d55dcb8333d7db9713822075d32cd852a (cherry picked from commit502947b4be
) Improve the cinder LVM loopback device setup The current implementation has the following issues: 1. It uses two tasks to get the loopback device information, and another to set a fact which is only used in the same play, which is unnecessary. This can all be done in a single task without the fact setting. 2. The setup of the loopback device is not idempotent. If any of the tasks fail, another device will be setup and the the tasks will continue to fail because it cannot handle multiple value returns. 3. The LVM PV & VG are setup using a shell task. This could be done using an Ansible module instead, which also makes the task idempotent. 4. The oneshot systemd unit starts very late in the boot cycle. It can be set to start much sooner, ensuring that the cinder-volume service starts successfully sooner. 5. The oneshot systemd unit starts a bash subshell unnecessarily. This patch aims to resolve all these issues, improving the execution time and idempotency of these tasks. Closes-Bug: #1873899 Change-Id: I9421cf54f498b3f99a7e5afa11425a0b2419b399 (cherry picked from commit580aca40e5
) [cinder-lvm] Resolve issue when there are multiple loop devices If a deployment fails, there may end up being multiple loopback devices pointing to the same image file. This currently breaks the systemd unit file because it cannot handle starting two devices properly. We only need one device, so just in case this situation arises, we now ensure that anything more than the first device is ignored when running 'Get or create LVM loopback device'. Change-Id: I012ee9c60bce4148da8ec6fe077ee20cfe34d555 Related-bug: #1873899 (cherry picked from commitd9152a601e
)
This commit is contained in:
parent
9e93d28d31
commit
b938f7cd9e
|
@ -106,36 +106,47 @@ outputs:
|
|||
- 'M'
|
||||
args:
|
||||
creates: /var/lib/cinder/cinder-volumes
|
||||
- name: cinder create LVM volume group
|
||||
shell: |
|
||||
if ! losetup /dev/loop2; then
|
||||
losetup /dev/loop2 /var/lib/cinder/cinder-volumes
|
||||
fi
|
||||
if ! pvdisplay | grep cinder-volumes; then
|
||||
pvcreate /dev/loop2
|
||||
fi
|
||||
if ! vgdisplay | grep cinder-volumes; then
|
||||
vgcreate cinder-volumes /dev/loop2
|
||||
- name: Get or create LVM loopback device
|
||||
shell: |-
|
||||
exit_code=0
|
||||
existing_device=$(losetup -j /var/lib/cinder/cinder-volumes -l -O NAME | tail -n-1)
|
||||
if [[ -z "${existing_device}" ]]; then
|
||||
losetup -f /var/lib/cinder/cinder-volumes --show
|
||||
exit_code=2
|
||||
else
|
||||
echo ${existing_device%$'\n'*}
|
||||
fi
|
||||
exit ${exit_code}
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: /dev/loop2
|
||||
register: _loopback_device
|
||||
changed_when: _loopback_device.rc == 2
|
||||
failed_when: _loopback_device.rc not in [0,2]
|
||||
- name: Create LVM volume group
|
||||
lvg:
|
||||
vg: "cinder-volumes"
|
||||
pvs: "{{ _loopback_device.stdout }}"
|
||||
state: present
|
||||
- name: cinder create service to run losetup for LVM on startup
|
||||
copy:
|
||||
dest: /etc/systemd/system/cinder-lvm-losetup.service
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Cinder LVM losetup
|
||||
After=syslog.target
|
||||
DefaultDependencies=no
|
||||
Conflicts=umount.target
|
||||
Requires=lvm2-lvmetad.service systemd-udev-settle.service
|
||||
Before=local-fs.target umount.target
|
||||
After=lvm2-lvmetad.service systemd-udev-settle.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash -c '/sbin/losetup /dev/loop2 || /sbin/losetup /dev/loop2 /var/lib/cinder/cinder-volumes'
|
||||
ExecStop=/bin/bash -c '/sbin/losetup -d /dev/loop2'
|
||||
ExecStart=/sbin/losetup {{ _loopback_device.stdout }} /var/lib/cinder/cinder-volumes
|
||||
ExecStop=/sbin/losetup -d {{ _loopback_device.stdout }}
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=local-fs-pre.target
|
||||
- name: cinder enable the LVM losetup service
|
||||
systemd:
|
||||
name: cinder-lvm-losetup
|
||||
|
|
|
@ -92,10 +92,6 @@ parameters:
|
|||
default: iscsi
|
||||
description: Whether to use TCP ('iscsi') or iSER RDMA ('iser') for iSCSI
|
||||
type: string
|
||||
CinderLVMLoopDeviceSize:
|
||||
default: 10280
|
||||
description: The size of the loopback file used by the cinder LVM driver.
|
||||
type: number
|
||||
CinderNfsAvailabilityZone:
|
||||
default: ''
|
||||
description: >
|
||||
|
@ -212,7 +208,6 @@ outputs:
|
|||
tripleo::profile::base::cinder::volume::nfs::cinder_nfs_snapshot_support: {get_param: CinderNfsSnapshotSupport}
|
||||
tripleo::profile::base::cinder::volume::nfs::cinder_nas_secure_file_operations: {get_param: CinderNasSecureFileOperations}
|
||||
tripleo::profile::base::cinder::volume::nfs::cinder_nas_secure_file_permissions: {get_param: CinderNasSecureFilePermissions}
|
||||
tripleo::profile::base::cinder::volume::iscsi::cinder_lvm_loop_device_size: {get_param: CinderLVMLoopDeviceSize}
|
||||
tripleo::profile::base::cinder::volume::iscsi::cinder_iscsi_helper: {get_param: CinderISCSIHelper}
|
||||
tripleo::profile::base::cinder::volume::iscsi::cinder_iscsi_protocol: {get_param: CinderISCSIProtocol}
|
||||
tripleo::profile::base::cinder::volume::rbd::cinder_rbd_ceph_conf:
|
||||
|
|
Loading…
Reference in New Issue