From 74027265b17ac8817260882f11d9915bd82eff48 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Mon, 12 Mar 2018 15:06:32 +0000 Subject: [PATCH] Convert role to use a common systemd role(s) This removes the systemd service templates and tasks from this role and leverages a common systemd roles instead. This change removes a lot of code duplication across all governed projects without sacrificing features or functionality. The intention of this change is to ensure uniformity and reduce the maintenance burden on the community when sweeping changes are needed. * To ensure we're using the extra data-disks correctly the bootstrap role has been updated to correctly handle mounts using systemd mount units and oneshot services. * This change sets the container path accordingly allowing an extra physical datadisk to be used for all of our container backends. * The gate test functionality can now be used with all of our container storage backends. This makes it possible for folks using all of our available options, [dir, machinectl, btrfs, lvm, zfs] to test an integrated build of OSA by simply setting the `lxc_container_backing_store` just as it would be done in a production deployment. Depends-On: https://review.openstack.org//555614 Change-Id: I0dc6daabad6c071ec7f9013a1e1eb0b3e594b544 Co-Authored-By: Markos Chandras Signed-off-by: Kevin Carter --- ansible-role-requirements.yml | 12 ++ scripts/scripts-library.sh | 21 +-- tests/roles/bootstrap-host/defaults/main.yml | 50 +++++-- .../tasks/check-requirements.yml | 6 +- tests/roles/bootstrap-host/tasks/main.yml | 51 +++++-- .../bootstrap-host/tasks/prepare_ceph.yml | 52 ++++--- .../tasks/prepare_data_disk.yml | 129 ++++++++++++++---- .../tasks/prepare_loopback_btrfs.yml | 39 ++++++ .../tasks/prepare_loopback_cinder.yml | 77 ++++++----- .../tasks/prepare_loopback_machines.yml | 20 ++- .../tasks/prepare_loopback_nova.yml | 22 +-- .../tasks/prepare_loopback_swap.yml | 56 +++----- .../tasks/prepare_loopback_swift.yml | 41 +++--- .../tasks/prepare_loopback_zfs.yml | 37 +++++ .../templates/user_variables.aio.yml.j2 | 2 +- tests/roles/bootstrap-host/vars/redhat.yml | 2 - tests/roles/bootstrap-host/vars/suse.yml | 1 - tests/roles/bootstrap-host/vars/ubuntu.yml | 4 +- 18 files changed, 425 insertions(+), 197 deletions(-) create mode 100644 tests/roles/bootstrap-host/tasks/prepare_loopback_btrfs.yml create mode 100644 tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml diff --git a/ansible-role-requirements.yml b/ansible-role-requirements.yml index f908bbb6e5..6fdb65bf21 100644 --- a/ansible-role-requirements.yml +++ b/ansible-role-requirements.yml @@ -206,3 +206,15 @@ src: https://git.openstack.org/openstack/openstack-ansible-nspawn_hosts scm: git version: master +- name: systemd_service + src: https://git.openstack.org/openstack/ansible-role-systemd_service + scm: git + version: master +- name: systemd_mount + src: https://git.openstack.org/openstack/ansible-role-systemd_mount + scm: git + version: master +- name: systemd_networkd + src: https://git.openstack.org/openstack/ansible-role-systemd_networkd + scm: git + version: master diff --git a/scripts/scripts-library.sh b/scripts/scripts-library.sh index 218576adfa..3c101b6ffb 100755 --- a/scripts/scripts-library.sh +++ b/scripts/scripts-library.sh @@ -321,14 +321,19 @@ function get_instance_info { esac # Storage reports - btrfs filesystem usage /var/lib/machines > \ - "/openstack/log/instance-info/machines_usage_${TS}.log" || true - btrfs filesystem show /var/lib/machines >> \ - "/openstack/log/instance-info/machines_show_${TS}.log" || true - btrfs filesystem df /var/lib/machines >> \ - "/openstack/log/instance-info/machines_df_${TS}.log" || true - btrfs qgroup show --human-readable -pcre --iec /var/lib/machines >> \ - "/openstack/log/instance-info/machines_quotas_${TS}.log" || true + for dir_name in lxc machines; do + btrfs filesystem usage /var/lib/${dir_name} > \ + "/openstack/log/instance-info/btrfs_${dir_name}_usage_${TS}.log" || true + btrfs filesystem show /var/lib/${dir_name} > \ + "/openstack/log/instance-info/btrfs_${dir_name}_show_${TS}.log" || true + btrfs filesystem df /var/lib/${dir_name} > \ + "/openstack/log/instance-info/btrfs_${dir_name}_df_${TS}.log" || true + btrfs qgroup show --human-readable -pcre --iec /var/lib/${dir_name} > \ + "/openstack/log/instance-info/btrfs_${dir_name}_quotas_${TS}.log" || true + done + + zfs list > "/openstack/log/instance-info/zfs_lxc_${TS}.log" || true + df -h > "/openstack/log/instance-info/report_fs_df_${TS}.log" || true } diff --git a/tests/roles/bootstrap-host/defaults/main.yml b/tests/roles/bootstrap-host/defaults/main.yml index 2426911668..6070d3218d 100644 --- a/tests/roles/bootstrap-host/defaults/main.yml +++ b/tests/roles/bootstrap-host/defaults/main.yml @@ -57,22 +57,16 @@ bootstrap_user_variables_extra_templates: - src: user_variables_octavia.yml.j2 dest: user_variables_octavia.yml -## Swap memory -# If there is no swap memory present, the bootstrap will create a loopback disk -# for the purpose of having swap memory available. Swap is required for some of -# the services deployed and is useful for AIO's built with less than 16GB memory. -# By default the swap size is set to 8GB unless the host memory is less than 8GB, -# in which case it is set to 4GB. -bootstrap_host_swap_size: "{% if ansible_memory_mb['real']['total'] < 8*1024 %}4{% else %}8{% endif %}" - ## Loopback volumes # Sparse loopback disks are used for the containers if there is no secondary # disk available to partition for btrfs. They are also used for Ceph, Cinder, # Swift and Nova (instance storage). # The size of the loopback volumes can be customized here (in gigabytes). # -# Size of the machines loopback disk in gigabytes (GB). -bootstrap_host_loopback_machines_size: 128 +# Boolean option to deploy the loopback disk for Swap +bootstrap_host_loopback_swap: yes +# Size of the Swap loopback disk in gigabytes (GB). +bootstrap_host_loopback_swap_size: 4096 # # Boolean option to deploy the loopback disk for Cinder bootstrap_host_loopback_cinder: yes @@ -88,7 +82,22 @@ bootstrap_host_loopback_swift_size: 1024 bootstrap_host_loopback_nova: yes # Size of the Nova loopback disk in gigabytes (GB). bootstrap_host_loopback_nova_size: 1024 - +# +# Boolean option to deploy the loopback disk for machines +bootstrap_host_loopback_machines: yes +# Size of the machines loopback disk in gigabytes (GB). +bootstrap_host_loopback_machines_size: 128 +# +# Boolean option to deploy the loopback disk for btrfs +bootstrap_host_loopback_btrfs: yes +# Size of the btrfs loopback disk in gigabytes (GB). +bootstrap_host_loopback_btrfs_size: 1024 +# +# Boolean option to deploy the loopback disk for btrfs +bootstrap_host_loopback_zfs: yes +# Size of the btrfs loopback disk in gigabytes (GB). +bootstrap_host_loopback_zfs_size: 1024 +# # Boolean option to deploy the OSD loopback disks and cluster UUID for Ceph bootstrap_host_ceph: "{{ (bootstrap_host_scenario == 'ceph') | bool }}" # Size of the Ceph OSD loopbacks @@ -210,7 +219,8 @@ bridge_iptables_rules: | # WARNING: The data on a secondary storage device specified here will # be destroyed and repartitioned. # -# Specify the secondary disk device to use. +# Specify the secondary disk device to use. When the data disk is in use, no NOT +# set the full path to the device. IE: "/dev/xvde" should be "xvde". bootstrap_host_data_disk_device: null # # Boolean value to force the repartitioning of the secondary device. @@ -219,6 +229,19 @@ bootstrap_host_data_disk_device_force: no # If the storage capacity on this device is greater than or equal to this # size (in GB), the bootstrap process will use it. bootstrap_host_data_disk_min_size: 50 +# +# Set the data disk formats table. If the backing store is set to lvm the option +# the partition will not actually be formatted however for parted, ext2 is used. +bootstrap_host_data_disk2_formats: + machinectl: btrfs + zfs: zfs + btrfs: btrfs + dir: ext4 + lvm: ext2 + +bootstrap_host_data_disk2_fs: "{{ bootstrap_host_data_disk2_formats[lxc_container_backing_store] }}" +bootstrap_host_data_disk2_path: "{{ (lxc_container_backing_store == 'machinectl' or container_tech == 'nspawn') | ternary('/var/lib/machines', '/var/lib/lxc') }}" + # Boolean option to build Amphora image and certs bootstrap_host_octavia: "{{ (bootstrap_host_scenario in ['octavia', 'translations']) | bool }}" @@ -232,3 +255,6 @@ bootstrap_host_octavia: "{{ (bootstrap_host_scenario in ['octavia', 'translation # Set the container technology in service. Options are nspawn and lxc. container_tech: "{{ ('nspawn' in bootstrap_host_scenario) | ternary('nspawn', 'lxc') }}" + +# Set the lxc backing store for the job +lxc_container_backing_store: machinectl diff --git a/tests/roles/bootstrap-host/tasks/check-requirements.yml b/tests/roles/bootstrap-host/tasks/check-requirements.yml index 9d46209b50..5f10aa5b8c 100644 --- a/tests/roles/bootstrap-host/tasks/check-requirements.yml +++ b/tests/roles/bootstrap-host/tasks/check-requirements.yml @@ -34,7 +34,8 @@ else df -BK / | awk '!/^Filesystem/ {print $4}' | sed 's/K//' fi - when: bootstrap_host_data_disk_device == None + when: + - bootstrap_host_data_disk_device == None changed_when: false register: root_space_available tags: @@ -62,7 +63,8 @@ - name: Calculate data disk size set_fact: host_data_disk_size_bytes: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}" - when: bootstrap_host_data_disk_device != None + when: + - bootstrap_host_data_disk_device != None tags: - check-disk-size diff --git a/tests/roles/bootstrap-host/tasks/main.yml b/tests/roles/bootstrap-host/tasks/main.yml index e2533014a4..df77299339 100644 --- a/tests/roles/bootstrap-host/tasks/main.yml +++ b/tests/roles/bootstrap-host/tasks/main.yml @@ -46,27 +46,47 @@ # Prepare the data disk, if one is provided - include: prepare_data_disk.yml - when: bootstrap_host_data_disk_device != None + when: + - bootstrap_host_data_disk_device != None tags: - prepare-data-disk -# Prepare the Machines storage loopback disk -# This is only necessary when there is no secondary disk -# available to partition for btrfs -- include: prepare_loopback_machines.yml - when: - - bootstrap_host_data_disk_device == None - tags: - - prepare-loopback-machines - # Prepare the swap space loopback disk # This is only necessary if there isn't swap already - include: prepare_loopback_swap.yml static: no when: + - bootstrap_host_loopback_swap | bool - ansible_swaptotal_mb < 1 tags: - - prepare-loopback-swap + - prepare-loopback + +# Prepare the Machines storage loopback disk +- include: prepare_loopback_machines.yml + when: + - bootstrap_host_loopback_machines | bool + - bootstrap_host_data_disk_device == None + - lxc_container_backing_store == 'machinectl' or container_tech == 'nspawn' + tags: + - prepare-loopback + +# Prepare the zfs storage loopback disk +- include: prepare_loopback_zfs.yml + when: + - bootstrap_host_loopback_zfs | bool + - bootstrap_host_data_disk_device == None + - lxc_container_backing_store == 'zfs' + tags: + - prepare-loopback + +# Prepare the btrfs storage loopback disk +- include: prepare_loopback_btrfs.yml + when: + - bootstrap_host_loopback_btrfs | bool + - bootstrap_host_data_disk_device == None + - lxc_container_backing_store == 'btrfs' + tags: + - prepare-loopback # Prepare the Cinder LVM VG loopback disk # This is only necessary if bootstrap_host_loopback_cinder is set to yes @@ -74,21 +94,21 @@ when: - bootstrap_host_loopback_cinder | bool tags: - - prepare-loopback-cinder + - prepare-loopback # Prepare the Nova instance storage loopback disk - include: prepare_loopback_nova.yml when: - bootstrap_host_loopback_nova | bool tags: - - prepare-loopback-nova + - prepare-loopback # Prepare the Swift data storage loopback disks - include: prepare_loopback_swift.yml when: - bootstrap_host_loopback_swift | bool tags: - - prepare-loopback-swift + - prepare-loopback # Prepare the Ceph cluster UUID and loopback disks - include: prepare_ceph.yml @@ -121,6 +141,7 @@ # Put the OpenStack-Ansible configuration for an All-In-One on the host - include: prepare_aio_config.yml - when: bootstrap_host_aio_config | bool + when: + - bootstrap_host_aio_config | bool tags: - prepare-aio-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_ceph.yml b/tests/roles/bootstrap-host/tasks/prepare_ceph.yml index efaba66b61..dd35070162 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_ceph.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_ceph.yml @@ -19,34 +19,44 @@ creates: "/openstack/{{ item }}.img" with_items: "{{ ceph_osd_images }}" register: ceph_create - changed_when: false tags: - ceph-file-create -- name: Create the ceph loopback device - command: losetup -f /openstack/{{ item.item }}.img --show - with_items: "{{ ceph_create.results }}" - register: ceph_create_loopback - when: not item|skipped +- name: Run the systemd service role + include_role: + name: systemd_service + private: true + vars: + systemd_services: + - service_name: "loop-{{ loopback_var }}" + config_overrides: + Unit: + Description: no + After: systemd-udev-settle.service + Service: + RemainAfterExit: yes + service_type: oneshot + execstarts: + - /bin/bash -c "/sbin/losetup $(/sbin/losetup -f) /openstack/{{ loopback_var }}.img" + execstops: + - /bin/bash -c "losetup -d $(losetup -l | awk '/{{ loopback_var }}.img/ {print $1}')" + enabled: yes + state: started + systemd_tempd_prefix: openstack + with_items: "{{ ceph_osd_images }}" + loop_control: + loop_var: loopback_var + tags: + - ceph-config + +- name: Get loopback device + shell: "losetup -l | awk '/{{ item }}.img/ {print $1}'" changed_when: false + register: ceph_create_loopback + with_items: "{{ ceph_osd_images }}" tags: - skip_ansible_lint -- name: Ensure that rc.local exists - file: - path: "{{ rc_local }}" - state: touch - mode: "u+x" - tags: - - ceph-rc-file - -- name: Create ceph loopback at boot time - lineinfile: - dest: "{{ rc_local }}" - line: "losetup -f /openstack/{{ item }}.img" - insertbefore: "{{ rc_local_insert_before }}" - with_items: "{{ ceph_osd_images }}" - # TODO(logan): Move these vars to user_variables.ceph.yml.j2 once LP #1649381 # is fixed and eliminate this task. - name: Write ceph cluster config diff --git a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml index 0d4bc9a516..149a3fe1b7 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml @@ -27,6 +27,13 @@ tags: - check-data-disk-partitions +- name: Set bootstrap host data disk fact + set_fact: + bootstrap_host_data_disk_device_force: true + _bootstrap_host_data_disk_device: "{{ (bootstrap_host_data_disk_device | regex_replace('!','/')).strip() }}" + when: + - data_disk_partitions.rc == 1 + - name: Dismount and remove fstab entries for anything on the data disk device mount: name: "{{ item.mount }}" @@ -34,46 +41,112 @@ fstype: ext4 state: absent when: - - data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool + - bootstrap_host_data_disk_device_force | bool - item.device | search(bootstrap_host_data_disk_device) with_items: - "{{ ansible_mounts }}" - name: Partition the whole data disk for our usage command: "{{ item }}" - when: data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool + when: + - bootstrap_host_data_disk_device_force | bool with_items: - - "parted --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mklabel gpt" - - "parted --align optimal --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mkpart openstack-data1 ext4 0% 40%" - - "parted --align optimal --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mkpart openstack-data2 btrfs 40% 100%" + - "parted --script /dev/{{ _bootstrap_host_data_disk_device }} mklabel gpt" + - "parted --align optimal --script /dev/{{ _bootstrap_host_data_disk_device }} mkpart openstack-data1 ext4 0% 40%" + - "parted --align optimal --script /dev/{{ _bootstrap_host_data_disk_device }} mkpart openstack-data2 {{ bootstrap_host_data_disk2_fs }} 40% 100%" tags: - create-data-disk-partitions -- name: Format the partitions +- name: Format the partition 1 filesystem: - fstype: "{{ item.fstype }}" - dev: "{{ item.dev }}" - when: data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool - with_items: - - dev: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}1" - fstype: "ext4" - - dev: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}2" - fstype: "btrfs" + fstype: ext4 + dev: "/dev/{{ _bootstrap_host_data_disk_device }}1" + when: + - bootstrap_host_data_disk_device_force | bool tags: - format-data-partitions -- name: Create the mount points, fstab entries and mount the file systems - mount: - name: "{{ item.mount_point }}" - src: "{{ item.device }}" - fstype: "{{ item.fstype }}" - state: mounted - with_items: - - mount_point: /openstack - device: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}1" - fstype: ext4 - - mount_point: /var/lib/machines - device: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}2" - fstype: btrfs +- name: Format the partition 2 + filesystem: + fstype: "{{ bootstrap_host_data_disk2_fs }}" + dev: "/dev/{{ _bootstrap_host_data_disk_device }}2" + when: + - bootstrap_host_data_disk_device_force | bool + - lxc_container_backing_store != 'lvm' + - lxc_container_backing_store != 'zfs' tags: - - mount-data-partitions + - format-data-partitions + +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/dev/{{ _bootstrap_host_data_disk_device }}1" + where: "/openstack" + type: "ext4" + state: 'started' + enabled: true + tags: + - data-config + +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/dev/{{ _bootstrap_host_data_disk_device }}2" + where: "{{ bootstrap_host_data_disk2_path }}" + type: "{{ bootstrap_host_data_disk2_fs }}" + state: 'started' + enabled: true + when: + - lxc_container_backing_store != 'lvm' + - lxc_container_backing_store != 'zfs' + tags: + - data-config + +- name: Create the ZFS pool + command: zpool create osa-test-pool "/dev/{{ _bootstrap_host_data_disk_device }}2" + args: + creates: /osa-test-pool + when: + - bootstrap_host_data_disk_device_force | bool + - lxc_container_backing_store == 'zfs' + +- name: Create the ZFS pool/lxc volume + shell: "(zfs list | grep lxc) || zfs create -o mountpoint=/var/lib/lxc osa-test-pool/lxc" + when: + - bootstrap_host_data_disk_device_force | bool + - lxc_container_backing_store == 'zfs' + tags: + - skip_ansible_lint + +- name: Make LVM physical volume on the cinder device + shell: "pvcreate /dev/{{ _bootstrap_host_data_disk_device }}2 && touch /openstack/lxc.pvcreate" + args: + creates: "/openstack/lxc.pvcreate" + when: + - lxc_container_backing_store == 'lvm' + tags: + - skip_ansible_lint + - data-config + +- name: Run pvscan + command: "pvscan" + changed_when: false + when: + - lxc_container_backing_store == 'lvm' + tags: + - cinder-lvm-pv + +- name: Add cinder-volumes volume group + lvg: + vg: lxc + pvs: "/dev/{{ _bootstrap_host_data_disk_device }}2" + when: + - lxc_container_backing_store == 'lvm' + tags: + - data-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_btrfs.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_btrfs.yml new file mode 100644 index 0000000000..362f00581b --- /dev/null +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_btrfs.yml @@ -0,0 +1,39 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Create sparse lxc-btrfs file + command: "truncate -s {{ bootstrap_host_loopback_btrfs_size }}G /openstack/lxc-btrfs.img" + args: + creates: /openstack/lxc-btrfs.img + +- name: Format the lxc-btrfs file + filesystem: + fstype: btrfs + dev: /openstack/lxc-btrfs.img + +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/openstack/lxc-btrfs.img" + where: "/var/lib/lxc" + options: "loop" + type: "btrfs" + state: 'started' + enabled: true + tags: + - lxc-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_cinder.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_cinder.yml index 38fd224cc2..55e8f2812b 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_cinder.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_cinder.yml @@ -21,45 +21,51 @@ tags: - cinder-file-create -- name: Get a loopback device for cinder file - command: losetup -f - when: cinder_create | changed +- name: Run the systemd service role + include_role: + name: systemd_service + private: true + vars: + systemd_services: + - service_name: "loop-cinder" + config_overrides: + Unit: + Description: no + After: systemd-udev-settle.service + Before: lvm2-activation-early.service + Wants: systemd-udev-settle.service + Service: + RemainAfterExit: yes + service_type: oneshot + execstarts: + - /bin/bash -c "/sbin/losetup $(/sbin/losetup -f) /openstack/cinder.img" + - /sbin/pvscan + execstops: + - /bin/bash -c "losetup -d $(losetup -l | awk '/cinder.img/ {print $1}')" + enabled: yes + state: started + systemd_tempd_prefix: openstack + tags: + - cinder-config + +- name: Get loopback device + shell: "losetup -l | awk '/cinder.img/ {print $1}'" + changed_when: false register: cinder_losetup tags: - - cinder-device-get - -- name: Create the loopback device - command: "losetup {{ cinder_losetup.stdout }} /openstack/cinder.img" - when: cinder_create | changed - tags: - - cinder-device-create - -- name: Ensure that rc.local exists - file: - path: "{{ rc_local }}" - state: touch - mode: "u+x" - tags: - - cinder-rc-file - -# As the cinder loopback is an LVM VG, it needs to be mounted differently -# to the other loopback files. It requires the use of rc.local to attach -# the loopback device on boot so that the VG becomes available immediately -# after the boot process completes. -- name: Create loopback devices at boot time - lineinfile: - dest: "{{ rc_local }}" - line: "losetup $(losetup -f) /openstack/cinder.img" - insertbefore: "{{ rc_local_insert_before }}" - tags: - - cinder-rc-config + - skip_ansible_lint - name: Make LVM physical volume on the cinder device - command: "{{ item }}" - when: cinder_create | changed - with_items: - - "pvcreate {{ cinder_losetup.stdout }}" - - "pvscan" + shell: "pvcreate {{ cinder_losetup.stdout }} && touch /openstack/cinder.pvcreate" + args: + creates: "/openstack/cinder.pvcreate" + tags: + - skip_ansible_lint + - cinder-lvm-pv + +- name: Run pvscan + command: "pvscan" + changed_when: false tags: - cinder-lvm-pv @@ -67,6 +73,5 @@ lvg: vg: cinder-volumes pvs: "{{ cinder_losetup.stdout }}" - when: cinder_create | changed tags: - cinder-lvm-vg diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_machines.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_machines.yml index 36ad49d499..969248f1c9 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_machines.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_machines.yml @@ -27,11 +27,17 @@ tags: - machines-format-file -- name: Create the mount points, fstab entries and mount the file systems - mount: - name: /var/lib/machines - src: /openstack/machines.img - fstype: btrfs - state: mounted +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/openstack/machines.img" + where: "/var/lib/machines" + options: "loop" + type: "btrfs" + state: 'started' + enabled: true tags: - - machines-file-mount + - machines-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_nova.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_nova.yml index 37a6f899de..298920ebdd 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_nova.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_nova.yml @@ -17,7 +17,6 @@ command: "truncate -s {{ bootstrap_host_loopback_nova_size }}G /openstack/nova.img" args: creates: /openstack/nova.img - register: nova_create tags: - nova-file-create @@ -25,15 +24,20 @@ filesystem: fstype: ext4 dev: /openstack/nova.img - when: nova_create | changed tags: - nova-format-file -- name: Create the mount points, fstab entries and mount the file systems - mount: - name: /var/lib/nova/instances - src: /openstack/nova.img - fstype: ext4 - state: mounted +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/openstack/nova.img" + where: "/var/lib/nova/instances" + options: "loop" + type: "ext4" + state: 'started' + enabled: true tags: - - nova-file-mount + - nova-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml index 8143b6ebb1..a1578f59a5 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml @@ -14,55 +14,35 @@ # limitations under the License. - name: Create swap file - command: "{{ swap_create_command }}" + command: "dd if=/dev/zero of=/openstack/swap.img bs=1M count={{ bootstrap_host_loopback_swap_size }}" args: creates: /openstack/swap.img register: swap_create tags: - swap-file-create -- name: Set swap file permissions to 0600 - file: - path: /openstack/swap.img - mode: 0600 - tags: - - swap-permissions - - name: Format the swap file command: mkswap /openstack/swap.img - when: swap_create | changed + when: + - swap_create | changed tags: - swap-format - -- name: Ensure that the swap file entry is in /etc/fstab - mount: - name: none - src: /openstack/swap.img - fstype: swap - opts: sw - passno: 0 - dump: 0 - state: present - tags: - - swap-fstab - -- name: Bring swap file online - shell: | - return_code=0 - if ! grep /openstack/swap.img /proc/swaps; then - swapon /openstack/swap.img - return_code=2 - fi - exit ${return_code} - register: _set_swap_online - changed_when: _set_swap_online.rc == 2 - failed_when: _set_swap_online.rc not in [0, 2] - # We skip ansible lint testing for this task as it fails with - # ANSIBLE0014 Environment variables don't work as part of command - # which is nonsense. - tags: - skip_ansible_lint - - swap-online + +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/openstack/swap.img" + priority: "0" + options: "%%" + type: "swap" + state: 'started' + enabled: true + tags: + - swap-config - name: Set system swappiness sysctl: diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_swift.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_swift.yml index 4901942da2..e573b9074a 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_swift.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_swift.yml @@ -21,7 +21,6 @@ - 'swift1' - 'swift2' - 'swift3' - register: swift_create tags: - swift-file-create @@ -30,7 +29,6 @@ fstype: xfs opts: '-K' dev: "/openstack/{{ item }}.img" - when: swift_create | changed with_items: - 'swift1' - 'swift2' @@ -38,18 +36,29 @@ tags: - swift-format-file -- name: Create the Swift mount points, fstab entries and mount the file systems - mount: - name: "/srv/{{ item }}.img" - src: "/openstack/{{ item }}.img" - fstype: xfs - opts: 'loop,noatime,nodiratime,nobarrier,logbufs=8' - passno: 0 - dump: 0 - state: mounted - with_items: - - 'swift1' - - 'swift2' - - 'swift3' +- name: Run the systemd mount role + include_role: + name: systemd_mount + private: true + vars: + systemd_mounts: + - what: "/openstack/swift1.img" + where: "/srv/swift1.img" + options: "loop,noatime,nodiratime,nobarrier,logbufs=8" + type: "xfs" + state: 'started' + enabled: true + - what: "/openstack/swift2.img" + where: "/srv/swift2.img" + options: "loop,noatime,nodiratime,nobarrier,logbufs=8" + type: "xfs" + state: 'started' + enabled: true + - what: "/openstack/swift3.img" + where: "/srv/swift3.img" + options: "loop,noatime,nodiratime,nobarrier,logbufs=8" + type: "xfs" + state: 'started' + enabled: true tags: - - swift-file-mount + - swift-config diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml new file mode 100644 index 0000000000..6975f113b6 --- /dev/null +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml @@ -0,0 +1,37 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Install zfs packages + package: + name: "{{ packages_install_zfs }}" + state: present + update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" + tags: + - install-packages + +- name: Create sparse ZFS backing file + command: "truncate -s {{ bootstrap_host_loopback_zfs_size }}G /openstack/lxc-zfs.img" + args: + creates: /openstack/lxc-zfs.img + +- name: Create the ZFS pool + command: zpool create osa-test-pool /openstack/lxc-zfs.img + args: + creates: /osa-test-pool + +- name: Create the ZFS pool/lxc volume + shell: "(zfs list | grep lxc) || zfs create -o mountpoint=/var/lib/lxc osa-test-pool/lxc" + tags: + - skip_ansible_lint diff --git a/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 b/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 index b523c41b04..3f4d80afa9 100644 --- a/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 +++ b/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 @@ -163,7 +163,7 @@ cache_timeout: {{ cache_timeout }} # The container backing store is set to 'machinectl' to speed up the # AIO build time. Options are: [machinectl, overlayfs, btrfs, zfs, dir, lvm] -lxc_container_backing_store: "machinectl" +lxc_container_backing_store: "{{ lxc_container_backing_store }}" ## Enable LBaaSv2 in the AIO neutron_plugin_base: diff --git a/tests/roles/bootstrap-host/vars/redhat.yml b/tests/roles/bootstrap-host/vars/redhat.yml index 187321a5d5..86c3013541 100644 --- a/tests/roles/bootstrap-host/vars/redhat.yml +++ b/tests/roles/bootstrap-host/vars/redhat.yml @@ -33,7 +33,5 @@ packages_install: packages_remove: [] -swap_create_command: "dd if=/dev/zero of=/openstack/swap.img bs=1M count={{ (bootstrap_host_swap_size | int) * 1024 }}" rc_local: /etc/rc.d/rc.local rc_local_insert_before: "^touch /var/lock/subsys/local$" - diff --git a/tests/roles/bootstrap-host/vars/suse.yml b/tests/roles/bootstrap-host/vars/suse.yml index 17636f99b9..bf5a5f36e9 100644 --- a/tests/roles/bootstrap-host/vars/suse.yml +++ b/tests/roles/bootstrap-host/vars/suse.yml @@ -35,6 +35,5 @@ packages_install: packages_remove: [] -swap_create_command: "dd if=/dev/zero of=/openstack/swap.img bs=1M count={{ (bootstrap_host_swap_size | int) * 1024 }}" rc_local: /etc/rc.d/boot.local rc_local_insert_before: EOF diff --git a/tests/roles/bootstrap-host/vars/ubuntu.yml b/tests/roles/bootstrap-host/vars/ubuntu.yml index 2f2d35a651..1863c24752 100644 --- a/tests/roles/bootstrap-host/vars/ubuntu.yml +++ b/tests/roles/bootstrap-host/vars/ubuntu.yml @@ -36,10 +36,12 @@ packages_install: - vlan - xfsprogs +packages_install_zfs: + - zfsutils-linux + packages_remove: - libmysqlclient18 - mysql-common -swap_create_command: "fallocate -l {{ bootstrap_host_swap_size }}G /openstack/swap.img" rc_local: /etc/rc.local rc_local_insert_before: "^exit 0$"