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

Allow for lvs to be created on specific pv #335

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ The following parameters are available in the `logical_volume` type.
* [`name`](#-logical_volume--name)
* [`no_sync`](#-logical_volume--no_sync)
* [`persistent`](#-logical_volume--persistent)
* [`physical_volume`](#-logical_volume--physical_volume)
* [`poolmetadatasize`](#-logical_volume--poolmetadatasize)
* [`provider`](#-logical_volume--provider)
* [`range`](#-logical_volume--range)
Expand Down Expand Up @@ -844,6 +845,10 @@ An optimization in lvcreate, at least on Linux.

Set to true to make the block device persistent

##### <a name="-logical_volume--physical_volume"></a>`physical_volume`

Create this logical volume on the specified physical volume

##### <a name="-logical_volume--poolmetadatasize"></a>`poolmetadatasize`

Change the size of logical volume pool metadata
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def create
end

args.push('--yes') if @resource[:yes_flag]
args.push(@resource[:physical_volume]) if @resource[:physical_volume]
lvcreate(*args)
end

Expand Down
18 changes: 18 additions & 0 deletions lib/puppet/type/logical_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ def insync?(is)
end
end

newparam(:physical_volume) do
desc 'The name of the physical volume on which this logical volume will be created'
validate do |val|
unless val.is_a?(::String) || val.is_a?(::Array)
raise ArgumentError, "physical_volume should be String or Array: #{val}"
end
end

munge do |val|
case val
when ::String
[val]
else
val
end
end
end

newproperty(:stripes) do
desc 'The number of stripes to allocate for the new logical volume.'
validate do |value|
Expand Down
4 changes: 4 additions & 0 deletions manifests/logical_volume.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#
# @param yes_flag If set to true, do not prompt for confirmation interactively but always assume the answer yes.
#
# @param physical_volume Create this logical volume on the specified physical volume
#
define lvm::logical_volume (
String[1] $volume_group,
Optional[String[1]] $size = undef,
Expand Down Expand Up @@ -91,6 +93,7 @@
Optional[Variant[String[1], Integer]] $region_size = undef,
Optional[Enum['anywhere', 'contiguous', 'cling', 'inherit', 'normal']] $alloc = undef,
Boolean $yes_flag = false,
Optional[Variant[Array[String],String]] $physical_volume = undef,
) {
$lvm_device_path = "/dev/${volume_group}/${name}"

Expand Down Expand Up @@ -153,6 +156,7 @@
region_size => $region_size,
alloc => $alloc,
yes_flag => $yes_flag,
physical_volume => $physical_volume,
}

if $createfs {
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/type/logical_volume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
}.not_to raise_error
end

it 'raises an ArgumentError when the physical volume is neither string nor array' do

Check failure on line 188 in spec/unit/type/logical_volume_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Puppet::Type::Logical_volume raises an ArgumentError when the physical volume is neither string nor array Failure/Error: expect { resource = Puppet::Type.type(:logical_volume).new( name: 'john', ensure: :present, volume_group: 'ernie', size: '10M', physical_volume: 42, ) }.to raise_error(Puppet::ResourceError, 'physical_volume should be String or Array: 42') expected Puppet::ResourceError with "physical_volume should be String or Array: 42", got #<Puppet::ResourceError: Parameter physical_volume failed on Logical_volume[john]: physical_volume should be String or Array: 42> with backtrace: # ./lib/puppet/type/logical_volume.rb:126:in `block (3 levels) in <top (required)>' # ./spec/unit/type/logical_volume_spec.rb:190:in `new' # ./spec/unit/type/logical_volume_spec.rb:190:in `block (3 levels) in <top (required)>' # ./spec/unit/type/logical_volume_spec.rb:189:in `block (2 levels) in <top (required)>' # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `load' # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `<top (required)>' # /opt/hostedtoolcache/Ruby/2.7.8/x64/bin/bundle:23:in `load' # /opt/hostedtoolcache/Ruby/2.7.8/x64/bin/bundle:23:in `<main>'

Check failure on line 188 in spec/unit/type/logical_volume_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Logical_volume raises an ArgumentError when the physical volume is neither string nor array Failure/Error: expect { resource = Puppet::Type.type(:logical_volume).new( name: 'john', ensure: :present, volume_group: 'ernie', size: '10M', physical_volume: 42, ) }.to raise_error(Puppet::ResourceError, 'physical_volume should be String or Array: 42') expected Puppet::ResourceError with "physical_volume should be String or Array: 42", got #<Puppet::ResourceError: Parameter physical_volume failed on Logical_volume[john]: physical_volume should be String or Array: 42> with backtrace: # ./lib/puppet/type/logical_volume.rb:126:in `block (3 levels) in <top (required)>' # ./spec/unit/type/logical_volume_spec.rb:190:in `new' # ./spec/unit/type/logical_volume_spec.rb:190:in `block (3 levels) in <top (required)>' # ./spec/unit/type/logical_volume_spec.rb:189:in `block (2 levels) in <top (required)>' # ./vendor/bundle/ruby/3.2.0/bin/rspec:25:in `load' # ./vendor/bundle/ruby/3.2.0/bin/rspec:25:in `<top (required)>' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli.rb:492:in `exec' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/cli.rb:28:in `start' # /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors' # /opt/hostedtoolcache/Ruby/3.2.4/x64/bin/bundle:25:in `load' # /opt/hostedtoolcache/Ruby/3.2.4/x64/bin/bundle:25:in `<main>'
expect {
resource = Puppet::Type.type(:logical_volume).new(
name: 'john',
ensure: :present,
volume_group: 'ernie',
size: '10M',
physical_volume: 42,
)
}.to raise_error(Puppet::ResourceError,
'physical_volume should be String or Array: 42')
end

it 'invalid number of stripes raises error' do
expect {
resource = Puppet::Type.type(:logical_volume).new(
Expand Down
Loading