Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebased version of #64 #106

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ storage_safe_mode: true # fail instead of implicitly/automatically removing dev
storage_pool_defaults:
state: "present"
type: lvm
volumes: []

encryption: false
encryption_passphrase: null
Expand Down
15 changes: 14 additions & 1 deletion library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'''

import logging
import os
import traceback
import inspect

Expand Down Expand Up @@ -278,7 +279,7 @@ def _get_format(self):
fmt = get_format(self._volume['fs_type'],
mountpoint=self._volume.get('mount_point'),
label=self._volume['fs_label'],
options=self._volume['fs_create_options'])
create_options=self._volume['fs_create_options'])
if not fmt.supported or not fmt.formattable:
raise BlivetAnsibleError("required tools for file system '%s' are missing" % self._volume['fs_type'])

Expand Down Expand Up @@ -324,6 +325,8 @@ def _resize(self):
raise BlivetAnsibleError("volume '%s' cannot be resized from %s to %s: %s" % (self._device.name,
self._device.size,
size, str(e)))
elif size and self._device.size != size and not self._device.resizable:
yizhanglinux marked this conversation as resolved.
Show resolved Hide resolved
raise BlivetAnsibleError("volume '%s' cannot be resized from %s to %s" % (self._device.name, self._device.size, size))

def _reformat(self):
""" Schedule actions as needed to ensure the volume is formatted as specified. """
Expand All @@ -336,6 +339,8 @@ def _reformat(self):

if self._device.format.status and (self._device.format.mountable or self._device.format.type == "swap"):
self._device.format.teardown()
if not self._device.isleaf:
self._blivet.devicetree.recursive_remove(self._device, remove_device=False)
self._blivet.format_device(self._device, fmt)

def manage(self):
Expand All @@ -361,6 +366,9 @@ def manage(self):
if self._device.raw_device.exists:
self._reformat()

if self.ultimately_present and self._volume['mount_point'] and not self._device.format.mountable:
raise BlivetAnsibleError("volume '%s' has a mount point but no mountable file system" % self._volume['name'])

# schedule resize if appropriate
if self._device.raw_device.exists and self._volume['size']:
self._resize()
Expand Down Expand Up @@ -1039,6 +1047,11 @@ def update_fstab_identifiers(b, pools, volumes):
if device.format.type == 'swap':
device.format.setup()

if device.status:
volume['_kernel_device'] = os.path.realpath(device.path)
if device.raw_device.status:
volume['_raw_kernel_device'] = os.path.realpath(device.raw_device.path)


def activate_swaps(b, pools, volumes):
""" Activate all swaps specified as present. """
Expand Down
26 changes: 3 additions & 23 deletions tests/test-verify-volume-device.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
---

#
# MDRaid devices paths are returned as a symlinks. But sometimes we need their targets.
#
- name: (1/3) Process device path (set initial value)
set_fact:
storage_test_device_path: "{{ storage_test_volume._raw_device }}"

# realpath fails when given empty string; the task then returns completely different dict.
- block:
- name: (2/3) Process device path (get device file info)
command: realpath "{{ storage_test_volume._raw_device }}"
register: storage_test_realpath

- name: (3/3) Process device path (replace device with its target if it is a symlink)
set_fact:
storage_test_device_path: "{{ storage_test_realpath.stdout }}"
when: storage_test_device_path not in storage_test_blkinfo.info

when: storage_test_volume._device != ""

# name/path
# name/path (use raw_device; encryption layer is validated separately)
- name: See whether the device node is present
stat:
path: "{{ storage_test_volume._raw_device }}"
Expand All @@ -37,7 +17,7 @@

- name: Make sure we got info about this volume
assert:
that: "{{ storage_test_device_path in storage_test_blkinfo.info }}"
that: "{{ storage_test_volume._raw_device in storage_test_blkinfo.info }}"
msg: "Failed to gather info about volume '{{ storage_test_volume.name }}'"
when: _storage_test_volume_present

Expand All @@ -52,7 +32,7 @@

- name: Verify the volume's device type
assert:
that: "{{ storage_test_blkinfo.info[storage_test_device_path].type == st_volume_type }}"
that: "{{ storage_test_blkinfo.info[storage_test_volume._raw_device].type == st_volume_type }}"
when: _storage_test_volume_present

# disks
Expand Down
24 changes: 2 additions & 22 deletions tests/test-verify-volume-fs.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
---

#
# MDRaid devices paths are returned as a symlinks. But sometimes we need their targets.
#
- name: (1/3) Process device path (set initial value)
set_fact:
storage_test_device_path: "{{ storage_test_volume._device }}"

# realpath fails when given empty string; the task then returns completely different dict.
- block:
- name: (2/3) Process device path (get device file info)
command: realpath "{{ storage_test_volume._device }}"
register: storage_test_realpath

- name: (3/3) Process device path (replace device with its target if it is a symlink)
set_fact:
storage_test_device_path: "{{ storage_test_realpath.stdout }}"
when: storage_test_device_path not in storage_test_blkinfo.info

when: storage_test_volume._device != ""

# type
- name: Verify fs type
assert:
that: "{{ storage_test_blkinfo.info[storage_test_device_path].fstype == storage_test_volume.fs_type }}"
that: "{{ storage_test_blkinfo.info[storage_test_volume._device].fstype == storage_test_volume.fs_type }}"
when: storage_test_volume.fs_type and _storage_test_volume_present

# label
- name: Verify fs label
assert:
that: "{{ storage_test_blkinfo.info[storage_test_device_path].label == storage_test_volume.fs_label }}"
that: "{{ storage_test_blkinfo.info[storage_test_volume._device].label == storage_test_volume.fs_label }}"
when: _storage_test_volume_present
17 changes: 2 additions & 15 deletions tests/test-verify-volume-mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
#
# MDRaid devices paths are returned as a symlinks. But sometimes we need their targets.
#
- name: (1/3) Process device path (set initial value)
- name: Get expected mount device based on device type
set_fact:
storage_test_device_path: "{{ storage_test_volume._device }}"

# realpath fails when given empty string; the task then returns completely different dict.
- block:
- name: (2/3) Process device path (get device file info)
command: realpath "{{ storage_test_volume._device }}"
register: storage_test_realpath

- name: (3/3) Process device path (replace device with its target if it is a symlink)
set_fact:
storage_test_device_path: "{{ storage_test_realpath.stdout }}"
when: storage_test_device_path not in storage_test_blkinfo.info

when: storage_test_volume._device != ""
storage_test_device_path: "{{ storage_test_volume._kernel_device if _storage_test_volume_present and not storage_test_volume.encryption and storage_test_volume.raid_level else storage_test_volume._device }}"

- name: Set some facts
set_fact:
Expand Down