Showing with 35 additions and 11 deletions.
  1. +8 −0 CHANGELOG.md
  2. +6 −1 lib/puppet/provider/zpool/zpool.rb
  3. +1 −1 metadata.json
  4. +9 −9 spec/acceptance/tests/zpool/basic_tests_spec.rb
  5. +1 −0 spec/unit/provider/zfs/zfs_spec.rb
  6. +10 −0 spec/unit/provider/zpool/zpool_spec.rb
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).

## [1.0.5](https://github.com/puppetlabs/puppetlabs-zfs_core/tree/1.0.5) (2020-04-01)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-zfs_core/compare/1.0.4...1.0.5)

### Fixed

- \(MODULES-10592\) Fix `zpool status` parsing on Linux [\#27](https://github.com/puppetlabs/puppetlabs-zfs_core/pull/27) ([GabrielNagy](https://github.com/GabrielNagy))

## [1.0.4](https://github.com/puppetlabs/puppetlabs-zfs_core/tree/1.0.4) (2019-11-06)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-zfs_core/compare/1.0.3...1.0.4)
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/provider/zpool/zpool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def process_zpool_data(pool_array)
sym = (value =~ %r{^mirror}) ? :mirror : :raidz
pool[:raid_parity] = 'raidz2' if value =~ %r{^raidz2}
else
tmp << value
# get full drive name if the value is a partition (Linux only)
tmp << if Facter.value(:kernel) == 'Linux' && value =~ %r{/dev/(:?[a-z]+1|disk/by-id/.+-part1)$}
execute("lsblk -p -no pkname #{value}").chomp
else
value
end
sym = :disk if value == pool_array.first
end

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-zfs_core",
"version": "1.0.4",
"version": "1.0.5",
"author": "puppetlabs",
"summary": "Manage zfs. Create destroy and set properties on zfs instances.",
"license": "Apache-2.0",
Expand Down
18 changes: 9 additions & 9 deletions spec/acceptance/tests/zpool/basic_tests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

# ZPool: verify puppet resource reports on the disk array
on(agent, puppet('resource zpool tstpool')) do
assert_match(%r{ensure => 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{ensure\s+=> 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{disk +=> .'.+dsk1 .+dsk2'.}, @result.stdout, "err: #{agent}")
end

Expand Down Expand Up @@ -75,8 +75,8 @@

# ZPool: verify puppet resource reports on the mirror
on(agent, puppet('resource zpool tstpool')) do
assert_match(%r{ensure => 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{mirror => \['/ztstpool/dsk1 /ztstpool/dsk2 /ztstpool/dsk3'\]}, @result.stdout, "err: #{agent}")
assert_match(%r{ensure\s+=> 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{mirror\s+=> \['/ztstpool/dsk1 /ztstpool/dsk2 /ztstpool/dsk3'\]}, @result.stdout, "err: #{agent}")
end

# ZPool: remove zpool in preparation for multiple mirrors
Expand Down Expand Up @@ -106,8 +106,8 @@

# ZPool: verify puppet resource reports on both mirrors
on(agent, puppet('resource zpool tstpool')) do
assert_match(%r{ensure => 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{mirror => \['/ztstpool/dsk1 /ztstpool/dsk2', '/ztstpool/dsk3 /ztstpool/dsk5'\]}, @result.stdout, "err: #{agent}")
assert_match(%r{ensure\s+=> 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{mirror\s+=> \['/ztstpool/dsk1 /ztstpool/dsk2', '/ztstpool/dsk3 /ztstpool/dsk5'\]}, @result.stdout, "err: #{agent}")
end

# ZPool: remove zpool in preparation for raidz test
Expand Down Expand Up @@ -135,8 +135,8 @@

# ZPool: verify puppet reports on the raidz pool
on(agent, puppet('resource zpool tstpool')) do
assert_match(%r{ensure => 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{raidz => \['/ztstpool/dsk1 /ztstpool/dsk2 /ztstpool/dsk3'\]}, @result.stdout, "err: #{agent}")
assert_match(%r{ensure\s+=> 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{raidz\s+=> \['/ztstpool/dsk1 /ztstpool/dsk2 /ztstpool/dsk3'\]}, @result.stdout, "err: #{agent}")
end

# ZPool: remove zpool in preparation for multiple raidz pools
Expand Down Expand Up @@ -166,8 +166,8 @@

# ZPool: verify puppet resource reports on both raidz
on(agent, puppet('resource zpool tstpool')) do
assert_match(%r{ensure => 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{raidz => \['/ztstpool/dsk1 /ztstpool/dsk2', '/ztstpool/dsk3 /ztstpool/dsk5'\]}, @result.stdout, "err: #{agent}")
assert_match(%r{ensure\s+=> 'present'}, @result.stdout, "err: #{agent}")
assert_match(%r{raidz\s+=> \['/ztstpool/dsk1 /ztstpool/dsk2', '/ztstpool/dsk3 /ztstpool/dsk5'\]}, @result.stdout, "err: #{agent}")
end

# ZPool: remove
Expand Down
1 change: 1 addition & 0 deletions spec/unit/provider/zfs/zfs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

before(:each) do
allow(provider.class).to receive(:which).with('zfs') { zfs }
allow(Facter).to receive(:value).with(:kernel).and_return('Linux')
end

context '.instances' do
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/provider/zpool/zpool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

before(:each) do
allow(provider.class).to receive(:which).with('zpool') { zpool }
allow(Facter).to receive(:value).with(:kernel).and_return('Linux')
end

context '#current_pool' do
Expand Down Expand Up @@ -59,6 +60,15 @@
end
end

describe 'when there are full path disks on Linux' do
it 'munges partitions into disk names' do
allow(provider).to receive(:execute).with('lsblk -p -no pkname /dev/sdc1').and_return('/dev/sdc')
allow(provider).to receive(:execute).with('lsblk -p -no pkname /dev/disk/by-id/disk_serial-0:0-part1').and_return('/dev/disk/by-id/disk_serial-0:0')
zpool_data = ['foo', '/dev/sdc1', '/dev/disk/by-id/disk_serial-0:0-part1']
expect(provider.process_zpool_data(zpool_data)[:disk]).to eq(['/dev/sdc /dev/disk/by-id/disk_serial-0:0'])
end
end

describe 'when there is a spare' do
it 'adds the spare disk to the hash' do
zpool_data.concat ['spares', 'spare_disk']
Expand Down