Skip to content

Commit 5e6d445

Browse files
authored
Merge pull request #278 from puppetlabs/to_hiera_hash
Support `puppet device --resource ... --to_yaml` invocation; drop puppet4 and jruby 1.7 testing
2 parents 70ae4e9 + 3556851 commit 5e6d445

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

.travis.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ jobs:
1515
include:
1616
- rvm: 2.4.3
1717
env: PUPPET_GEM_VERSION='~> 5' SIMPLECOV=yes # 5.5
18-
- env: RVM="jruby-1.7.26" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug" SIMPLECOV=yes
19-
dist: trusty
20-
before_cache: pushd ~/.rvm && rm -rf archives rubies/ruby-2.2.7 rubies/ruby-2.3.4 && popd
21-
cache:
22-
bundler: true
23-
directories: [~/.rvm]
24-
before_install: rvm use jruby-1.7.26 --install --binary --fuzzy && gem install bundler -v '~> 1.7.0'
2518
# disable coverage on jruby9k as this confuses codecov
2619
- env: RVM="jruby-9.1.9.0" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug"
2720
dist: trusty
@@ -35,10 +28,6 @@ jobs:
3528
- rvm: 2.5.1
3629
env: CHECK=license_finder
3730
bundler_args: ""
38-
- rvm: 2.1.9
39-
env: PUPPET_GEM_VERSION='~> 4' SIMPLECOV=yes # 4.10
40-
before_install:
41-
- gem install bundler -v '< 2'
4231
- rvm: 2.5.7
4332
env: PUPPET_GEM_VERSION='~> 6' SIMPLECOV=yes # latest 6 release
4433
- rvm: 2.5.7
@@ -47,8 +36,6 @@ jobs:
4736
env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#master'
4837
- rvm: 2.4.3
4938
env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#5.5.x'
50-
- rvm: 2.1.9
51-
env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#4.10.x'
5239
notifications:
5340
slack:
5441
secure: aPXZYNow8LsmmlS8PQU3FjL0bc7FqUUA95d++wZfIu7YAjGboIUiekxYouQ0XnY+Aig8InvbTOIgBHgGNheyr/YFbFS90/jtulbF8oW7BitW+imgjeAHDCwlQZTCc4FFYde/2pI7QTT8H5NpLR9mKxlTU77Sqr8gFAIybuPdHcKMYQZdEZS07ma2pUp7+GyKS6PDQpzW2+mDCz/wfi3/JdsUvc0mclCZ8vxySc66j5P1E6nFDMzuakBOjwJHpgeDpreapbmSUQLAX0a3ZsFP+N+SNduLotlV2BWnJK2gcO6rGFP4Fz1D0bGXuBnYYdIiB+9OgI3wtXg9y1SifNHUG3IrOBAA8CGNyrebTGKtH0TS2O+HZLbaNX2g6udD5e3156vys9wScmJuQ/rSkVtQfXf1qUm5eijvlXI+DIbssbZHqm6QQGyM4p3NoULmNmF1C85bQoZ4GF7b1P/8mstsVE/HUfnzRPNbwD0r6j1aE/ck3PKMi7ZAhIi0Ja9RnAgP3wi0t62uERYcJGGYEycWohMWnrf2w6GFwGeuoiwAkASdHOLX0/AOMPc4mBOjlc621o8uYMrrZqfF5CrOAvJ151USSsWn2AhXaibIvnHo6X91paNvvNpU/GYu3CUAl6q8OhYovvjtRVPVnhs2DrpgoRB+6NWHnzjRG/wr6Z9U+vA=

appveyor.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ environment:
99
- RUBY_VERSION: 25-x64
1010
- PUPPET_GEM_VERSION: '~> 5.0'
1111
RUBY_VERSION: 24-x64
12-
- PUPPET_GEM_VERSION: '~> 4.0'
13-
RUBY_VERSION: 21-x64
1412

1513
install:
1614
- set PATH=C:\Ruby%RUBY_VERSION%\bin;C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%

lib/puppet/resource_api/glue.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def to_manifest
3535
end + ['}']).compact.join("\n")
3636
end
3737

38+
# Required to enable `puppet device --resource ... --to_yaml` workflow
39+
def to_hiera_hash
40+
to_hierayaml
41+
end
42+
3843
# Convert our resource to yaml for Hiera purposes.
3944
def to_hierayaml
4045
attributes = Hash[filtered_keys.map { |k| [k.to_s, values[k]] }]

spec/acceptance/device_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
expect(status).to eq 0
6464
end
6565

66+
it 'outputs resources as yaml' do
67+
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider --to_yaml")
68+
expected_values = 'device_provider: |2\n\s+wibble:\n\s+ensure: :present\n\s+string: sample\n\s+string_ro: fixed\n\s+string_param: default value'
69+
fiddle_deprecate_msg = "DL is deprecated, please use Fiddle\n"
70+
win32_deprecate_msg = ".*Struct layout is already defined for class Windows::ServiceStructs::SERVICE_STATUS_PROCESS.*\n"
71+
expect(stdout_str.strip).to match %r{\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z}
72+
expect(status).to eq 0
73+
end
74+
6675
it 'deals with canonicalized resources correctly' do
6776
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
6877
stdmatch = 'Notice: /Device_provider\[wibble\]/string: string changed \'sample\' to \'changed\''

spec/puppet/resource_api/glue_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
end
7575
end
7676

77+
describe '.to_hiera_hash' do
78+
it { expect(instance.to_hiera_hash).to eq " title:\n attr: value\n attr_ro: fixed\n" }
79+
80+
context 'when the title contains YAML special characters' do
81+
let(:title) { "foo:\nbar" }
82+
83+
it { expect(instance.to_hiera_hash).to eq " ? |-\n foo:\n bar\n : attr: value\n attr_ro: fixed\n" }
84+
end
85+
end
86+
7787
describe '.to_hash' do
7888
it { expect(instance.to_hash).to eq(namevarname: 'title', attr: 'value', attr_ro: 'fixed') }
7989
end

0 commit comments

Comments
 (0)