forked from puppetlabs/puppet
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request puppetlabs#5691 from thallgren/issues/pup-7305/hie…
…ra-file-cache (PUP-7305) Add file cache to Hiera
- Loading branch information
Showing
12 changed files
with
371 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
require 'fileutils' | ||
|
||
class Benchmarker | ||
include FileUtils | ||
|
||
def initialize(target, size) | ||
@target = target | ||
@size = size > 1000 ? size : 1000 | ||
end | ||
|
||
def setup | ||
require 'puppet' | ||
@config = File.join(@target, 'puppet.conf') | ||
Puppet.initialize_settings(['--config', @config]) | ||
envs = Puppet.lookup(:environments) | ||
@node = Puppet::Node.new('testing', :environment => envs.get('benchmarking')) | ||
end | ||
|
||
def run(args=nil) | ||
@size.times do | ||
@compiler = Puppet::Parser::Compiler.new(@node) | ||
@compiler.compile do |catalog| | ||
scope = @compiler.topscope | ||
scope['confdir'] = 'test' | ||
hiera_func = @compiler.loaders.puppet_system_loader.load(:function, 'hiera_include') | ||
hiera_func.call(scope, 'common_entry') | ||
catalog | ||
end | ||
end | ||
end | ||
|
||
def generate | ||
env_dir = File.join(@target, 'environments', 'benchmarking') | ||
manifests_dir = File.join(env_dir, 'manifests') | ||
dummy_class_manifest = File.join(manifests_dir, 'foo.pp') | ||
hiera_yaml = File.join(@target, 'hiera.yaml') | ||
datadir = File.join(@target, 'data') | ||
localdir = File.dirname(File.realpath(__FILE__)) | ||
common_yaml = File.join(datadir, 'common.yaml') | ||
groups_yaml = File.join(datadir, 'groups.yaml') | ||
|
||
mkdir_p(env_dir) | ||
mkdir_p(manifests_dir) | ||
mkdir_p(datadir) | ||
|
||
File.open(hiera_yaml, 'w') do |f| | ||
f.puts(<<-YAML) | ||
--- | ||
:backends: yaml | ||
:yaml: | ||
:datadir: #{datadir} | ||
:hierarchy: | ||
- common | ||
- groups | ||
:logger: noop | ||
YAML | ||
end | ||
|
||
File.open(groups_yaml, 'w') do |f| | ||
f.puts(<<-YAML) | ||
--- | ||
puppet: | ||
staff: | ||
groups: | ||
YAML | ||
|
||
0.upto(50).each do |i| | ||
f.puts(" group#{i}:") | ||
0.upto(125).each do |j| | ||
f.puts(" - user#{j}") | ||
end | ||
end | ||
end | ||
|
||
File.open(dummy_class_manifest, 'w') do |f| | ||
f.puts("class dummy_class { }") | ||
end | ||
|
||
File.open(common_yaml, 'w') do |f| | ||
f.puts(<<-YAML) | ||
common_entry: | ||
- dummy_class | ||
YAML | ||
end | ||
|
||
templates = File.dirname(File.realpath(__FILE__)) | ||
|
||
render(File.join(templates, 'puppet.conf.erb'), | ||
File.join(@target, 'puppet.conf'), | ||
:location => @target) | ||
end | ||
|
||
def render(erb_file, output_file, bindings) | ||
site = ERB.new(File.read(erb_file)) | ||
File.open(output_file, 'w') do |fh| | ||
fh.write(site.result(OpenStruct.new(bindings).instance_eval { binding })) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Benchmark scenario: Large nested hierarchy dataset, many compilations, one lookup per compile | ||
Benchmark target: hiera include. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
confdir = <%= location %> | ||
vardir = <%= location %> | ||
codedir = <%= location %> | ||
environmentpath = <%= File.join(location, 'environments') %> | ||
environment_timeout = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.