Recreate cinder LVM loopback device on startup

Add a systemd service that creates the loopback device required by
cinder's iSCSI backend on system startup.

This patch also consolidates the host_prep_tasks for the HA and non-HA
versions of the cinder-volume service. The list of tasks is identical,
and rather than repeating it in each template, the tasks are defined
once in cinder-common.yaml.

NOTE: This backport does not set the 'setype' when creating cinder's
persistent directories. Setting the 'setype' is required only in later
releases.

Closes-Bug: #1581092
Change-Id: Icc04003a9e90b66720d968c6c8f1c687156b677e
(cherry picked from commit 2040d4f284)
This commit is contained in:
Alan Bishop 2018-08-28 14:27:57 -04:00
parent e6c4d950af
commit 5ef1ade753
3 changed files with 84 additions and 118 deletions

View File

@ -40,6 +40,14 @@ parameters:
default: []
description: list of optional environment variables
type: comma_delimited_list
CinderEnableIscsiBackend:
default: true
description: Whether to enable or not the Iscsi backend for Cinder
type: boolean
CinderLVMLoopDeviceSize:
default: 10280
description: The size of the loopback file used by the cinder LVM driver.
type: number
resources:
@ -47,6 +55,80 @@ resources:
type: ./containers-common.yaml
outputs:
cinder_volume_host_prep_tasks:
description: Host prep tasks for the cinder-volume service (HA or non-HA)
value:
- name: create persistent directories
file:
path: "{{ item }}"
state: directory
with_items:
- /var/log/containers/cinder
- /var/lib/cinder
- name: cinder logs readme
copy:
dest: /var/log/cinder/readme.txt
content: |
Log files from cinder containers can be found under
/var/log/containers/cinder and /var/log/containers/httpd/cinder-api.
ignore_errors: true
- name: ensure ceph configurations exist
file:
path: /etc/ceph
state: directory
- name: cinder_enable_iscsi_backend fact
set_fact:
cinder_enable_iscsi_backend: {get_param: CinderEnableIscsiBackend}
- when: cinder_enable_iscsi_backend
block:
- name: cinder create LVM volume group dd
command:
list_join:
- ''
- - 'dd if=/dev/zero of=/var/lib/cinder/cinder-volumes bs=1 count=0 seek='
- str_replace:
template: VALUE
params:
VALUE: {get_param: CinderLVMLoopDeviceSize}
- '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
fi
args:
executable: /bin/bash
creates: /dev/loop2
- 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
[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'
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
- name: cinder enable the LVM losetup service
systemd:
name: cinder-lvm-losetup
enabled: yes
daemon_reload: yes
cinder_volume_volumes:
description: Volumes for the cinder-volume container (HA or non-HA)
value:

View File

@ -45,15 +45,6 @@ parameters:
default: {}
description: Parameters specific to the role
type: json
# custom parameters for the Cinder volume role
CinderEnableIscsiBackend:
default: true
description: Whether to enable or not the Iscsi backend for Cinder
type: boolean
CinderLVMLoopDeviceSize:
default: 10280
description: The size of the loopback file used by the cinder LVM driver.
type: number
UpgradeRemoveUnusedPackages:
default: false
description: Remove package if the service is being disabled during upgrade
@ -172,56 +163,7 @@ outputs:
test: /openstack/healthcheck
volumes: {get_attr: [CinderCommon, cinder_volume_volumes]}
environment: {get_attr: [CinderCommon, cinder_volume_environment]}
host_prep_tasks:
- name: create persistent directories
file:
path: "{{ item }}"
state: directory
with_items:
- /var/log/containers/cinder
- /var/lib/cinder
- name: cinder logs readme
copy:
dest: /var/log/cinder/readme.txt
content: |
Log files from cinder containers can be found under
/var/log/containers/cinder and /var/log/containers/httpd/cinder-api.
ignore_errors: true
- name: ensure ceph configurations exist
file:
path: /etc/ceph
state: directory
- name: cinder_enable_iscsi_backend fact
set_fact:
cinder_enable_iscsi_backend: {get_param: CinderEnableIscsiBackend}
- name: cinder create LVM volume group dd
command:
list_join:
- ''
- - 'dd if=/dev/zero of=/var/lib/cinder/cinder-volumes bs=1 count=0 seek='
- str_replace:
template: VALUE
params:
VALUE: {get_param: CinderLVMLoopDeviceSize}
- 'M'
args:
creates: /var/lib/cinder/cinder-volumes
when: cinder_enable_iscsi_backend
- 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
fi
args:
executable: /bin/bash
creates: /dev/loop2
when: cinder_enable_iscsi_backend
host_prep_tasks: {get_attr: [CinderCommon, cinder_volume_host_prep_tasks]}
upgrade_tasks:
- when: step|int == 0
tags: common

View File

@ -36,15 +36,6 @@ parameters:
default: {}
description: Parameters specific to the role
type: json
# custom parameters for the Cinder volume role
CinderEnableIscsiBackend:
default: true
description: Whether to enable or not the Iscsi backend for Cinder
type: boolean
CinderLVMLoopDeviceSize:
default: 10280
description: The size of the loopback file used by the cinder LVM driver.
type: number
ConfigDebug:
default: false
description: Whether to run config management (e.g. Puppet) in debug mode.
@ -237,56 +228,7 @@ outputs:
- ''
- - 'TRIPLEO_DEPLOY_IDENTIFIER='
- {get_param: DeployIdentifier}
host_prep_tasks:
- name: create persistent directories
file:
path: "{{ item }}"
state: directory
with_items:
- /var/log/containers/cinder
- /var/lib/cinder
- name: cinder logs readme
copy:
dest: /var/log/cinder/readme.txt
content: |
Log files from cinder containers can be found under
/var/log/containers/cinder and /var/log/containers/httpd/cinder-api.
ignore_errors: true
- name: ensure ceph configurations exist
file:
path: /etc/ceph
state: directory
- name: cinder_enable_iscsi_backend fact
set_fact:
cinder_enable_iscsi_backend: {get_param: CinderEnableIscsiBackend}
- name: cinder create LVM volume group dd
command:
list_join:
- ''
- - 'dd if=/dev/zero of=/var/lib/cinder/cinder-volumes bs=1 count=0 seek='
- str_replace:
template: VALUE
params:
VALUE: {get_param: CinderLVMLoopDeviceSize}
- 'M'
args:
creates: /var/lib/cinder/cinder-volumes
when: cinder_enable_iscsi_backend
- 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
fi
args:
executable: /bin/bash
creates: /dev/loop2
when: cinder_enable_iscsi_backend
host_prep_tasks: {get_attr: [CinderCommon, cinder_volume_host_prep_tasks]}
update_tasks:
- name: Cinder-Volume fetch and retag container image for pacemaker
when: step|int == 2