Skip to content

Commit

Permalink
(GH-1338) Support node definitions when applying manifests
Browse files Browse the repository at this point in the history
This adds support for node definitions from both `bolt apply` and within
apply blocks in a plan. Node definitions are still not allowed directly
in plans outside an apply block however, as there is no meaningful
behavior for them.
  • Loading branch information
nicklewis committed Jan 9, 2020
1 parent 391501e commit 09aed28
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

The new plan function, `file::join`, allows you to join file paths using the separator `/`.

* **Node definitions are supported when applying manifest code** ([#1338](https://github.com/puppetlabs/bolt/issues/1338))

Node definitions can now be used with `bolt apply` and within apply blocks in plans. This makes it easier to reuse existing Puppet codebases with Bolt.

### Bug fixes

* **The ssh configuration option `key-data` was not compatible with the `future` flag** ([#1504](https://github.com/puppetlabs/bolt/issues/1504))
Expand Down
1 change: 1 addition & 0 deletions lib/bolt/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def compile_catalog(request)
Puppet[:strict_variables] = options['strict_variables'] || false
ast = Puppet::Pops::Serialization::FromDataConverter.convert(pal_main)
compiler.evaluate(ast)
compiler.instance_variable_get(:@internal_compiler).send(:evaluate_ast_node)
compiler.compile_additions
compiler.with_json_encoding(&:encode)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/apply/basic/plans/node_default.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plan basic::node_default(TargetSpec $nodes) {
return apply($nodes) {
node default {
warn { "default node definition": }
}
}
}

9 changes: 9 additions & 0 deletions spec/fixtures/apply/basic/plans/node_definition.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plan basic::node_definition(TargetSpec $nodes) {
return apply($nodes) {
# We don't know the node name that will be used in the test, so we have to
# just match everything
node /.+/ {
warn { "named node definition": }
}
}
}
16 changes: 16 additions & 0 deletions spec/integration/apply_compile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ def get_notifies(result, future = false)
expect(warn.count).to eq(1)
end

it 'evaluates a node definition matching the node name' do
pending "puppet does not allow node definitions in plans"
result = run_cli_json(%w[plan run basic::node_definition] + config_flags)
report = result[0]['result']['report']
warn = report['catalog']['resources'].select { |r| r['type'] == 'Warn' }
expect(warn.count).to eq(1)
end

it 'evaluates a default node definition if none matches the node name' do
pending "puppet does not allow node definitions in plans"
result = run_cli_json(%w[plan run basic::node_default] + config_flags)
report = result[0]['result']['report']
warn = report['catalog']['resources'].select { |r| r['type'] == 'Warn' }
expect(warn.count).to eq(1)
end

it 'logs messages emitted during compilation' do
result = run_cli_json(%w[plan run basic::error] + config_flags)
expect(result[0]['status']).to eq('success')
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/apply_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ def task_plugin_inventory
expect(result['report']['resource_statuses']).to include('Notify[hello world]')
end

it "applies a node definition" do
results = run_cli_json(['apply', '-e', 'node default { notify { "hello world": } }'] + config_flags)
result = results[0]['result']
expect(result).not_to include('kind')
expect(result['report']).to include('status' => 'changed')
expect(result['report']['resource_statuses']).to include('Notify[hello world]')
end

it "fails if the manifest doesn't parse" do
expect { run_cli_json(['apply', '-e', 'include(basic'] + config_flags) }
.to raise_error(/Syntax error/)
Expand Down

0 comments on commit 09aed28

Please sign in to comment.