diff --git a/acceptance/tests/face/loadable_from_modules.rb b/acceptance/tests/face/loadable_from_modules.rb index 7ff598247..c1bb39037 100644 --- a/acceptance/tests/face/loadable_from_modules.rb +++ b/acceptance/tests/face/loadable_from_modules.rb @@ -1,85 +1,84 @@ test_name "Exercise loading a face from a module" # Because the module tool does not work on windows, we can't run this test there confine :except, :platform => 'windows' require 'puppet/acceptance/temp_file_utils' extend Puppet::Acceptance::TempFileUtils initialize_temp_dirs agents.each do |agent| - dev_modulepath = get_test_file_path(agent, 'dev/modules') - user_modulepath = get_test_file_path(agent, 'user/modules') + environmentpath = get_test_file_path(agent, 'environments') + dev_modulepath = "#{environmentpath}/dev/modules" # make sure that we use the modulepath from the dev environment puppetconf = get_test_file_path(agent, 'puppet.conf') + on agent, puppet("config", "set", "environmentpath", environmentpath, "--section", "main", "--config", puppetconf) on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf) - on agent, puppet("config", "set", "modulepath", user_modulepath, "--section", "user", "--config", puppetconf) - on agent, puppet("config", "set", "modulepath", dev_modulepath, "--section", "user", "--config", puppetconf) on agent, 'rm -rf helloworld' on agent, puppet("module", "generate", "puppetlabs-helloworld", "--skip-interview") mkdirs agent, 'helloworld/lib/puppet/application' mkdirs agent, 'helloworld/lib/puppet/face' # copy application, face, and utility module create_remote_file(agent, "helloworld/lib/puppet/application/helloworld.rb", <<'EOM') require 'puppet/face' require 'puppet/application/face_base' class Puppet::Application::Helloworld < Puppet::Application::FaceBase end EOM create_remote_file(agent, "helloworld/lib/puppet/face/helloworld.rb", <<'EOM') Puppet::Face.define(:helloworld, '0.1.0') do summary "Hello world face" description "This is the hello world face" action 'actionprint' do summary "Prints hello world from an action" when_invoked do |options| puts "Hello world from an action" end end action 'moduleprint' do summary "Prints hello world from a required module" when_invoked do |options| require 'puppet/helloworld.rb' Puppet::Helloworld.print end end end EOM create_remote_file(agent, "helloworld/lib/puppet/helloworld.rb", <<'EOM') module Puppet::Helloworld def print puts "Hello world from a required module" end module_function :print end EOM on agent, puppet('module', 'build', 'helloworld') on agent, puppet('module', 'install', '--ignore-dependencies', '--target-dir', dev_modulepath, 'helloworld/pkg/puppetlabs-helloworld-0.1.0.tar.gz') on(agent, puppet('help', '--config', puppetconf)) do assert_match(/helloworld\s*Hello world face/, stdout, "Face missing from list of available subcommands") end on(agent, puppet('help', 'helloworld', '--config', puppetconf)) do assert_match(/This is the hello world face/, stdout, "Descripion help missing") assert_match(/moduleprint\s*Prints hello world from a required module/, stdout, "help for moduleprint action missing") assert_match(/actionprint\s*Prints hello world from an action/, stdout, "help for actionprint action missing") end on(agent, puppet('helloworld', 'actionprint', '--config', puppetconf)) do assert_match(/^Hello world from an action$/, stdout, "face did not print hello world") end on(agent, puppet('helloworld', 'moduleprint', '--config', puppetconf)) do assert_match(/^Hello world from a required module$/, stdout, "face did not load module to print hello world") end end diff --git a/acceptance/tests/loader/func4x_loadable_from_modules.rb b/acceptance/tests/loader/func4x_loadable_from_modules.rb index c59f92764..33b3e49b3 100644 --- a/acceptance/tests/loader/func4x_loadable_from_modules.rb +++ b/acceptance/tests/loader/func4x_loadable_from_modules.rb @@ -1,83 +1,83 @@ test_name "Exercise a module with 4x function and 4x system function" # Purpose: # Test that a packed puppet can call a 4x system function, and that a 4x function in # a module can be called. # # Method: # * Manually construct a very simple module with a manifest that creates a file. # * The file has content that depends on logic that calls both a system function (reduce), and # a function supplied in the module (helloworld::mul10). # * The module is manually constructed to allow the test to also run on Windows where the module tool # is not supported. # * The module is included by calling 'include' from 'puppet apply'. # * Puppet apply is executed to generate the file with the content. # * The generated contents is asserted. # TODO: The test can be improved by adding yet another module that calls the function in helloworld. # TODO: The test can be improved to also test loading of a non namespaced function require 'puppet/acceptance/temp_file_utils' extend Puppet::Acceptance::TempFileUtils initialize_temp_dirs agents.each do |agent| # The modulepath to use in environment 'dev' envs_path = get_test_file_path(agent, 'environments') dev_modulepath = get_test_file_path(agent, 'environments/dev/modules') target_path = get_test_file_path(agent, 'output') mkdirs agent, target_path # make sure that we use the modulepath from the dev environment puppetconf = get_test_file_path(agent, 'puppet.conf') user = agent.puppet['user'] group = agent.puppet['group'] # Setting user/group ensures that when puppet apply's Configurer use()'s the # settings, that it doesn't default to owning them as root, which can have an # impact on following tests. + on agent, puppet("config", "set", "environmentpath", envs_path, "--section", "main", "--config", puppetconf) on agent, puppet("config", "set", "user", user, "--section", "main", "--config", puppetconf) on agent, puppet("config", "set", "group", group, "--section", "main", "--config", puppetconf) on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf) - on agent, puppet("config", "set", "environmentpath", envs_path, "--section", "main", "--config", puppetconf) # Where the functions in the written modules should go helloworld_functions = 'helloworld/lib/puppet/functions/helloworld' # Clean out the module that will be written to ensure no interference from a previous run on agent, "rm -rf #{File.join(dev_modulepath, 'helloworld')}" mkdirs agent, File.join(dev_modulepath, helloworld_functions) # Write a module # Write the function helloworld::mul10, that multiplies its argument by 10 create_remote_file(agent, File.join(dev_modulepath, helloworld_functions, "mul10.rb"), <<'SOURCE') Puppet::Functions.create_function(:'helloworld::mul10') do def mul10(x) x * 10 end end SOURCE # Write a manifest that calls a 4x function (reduce), and calls a function defined in the module # (helloworld::mul10). # mkdirs agent, File.join(dev_modulepath, "helloworld", "manifests") create_remote_file(agent, File.join(dev_modulepath, "helloworld", "manifests", "init.pp"), < 'file', mode => '0666', content => [1,2,3].reduce("Generated") |$memo, $n| { "${memo}, ${n} => ${helloworld::mul10($n)}" } } } SOURCE # Run apply to generate the file with the output on agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf) # Assert that the file was written with the generated content on(agent, "cat #{File.join(target_path, 'result.txt')}") do assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, stdout, "Generated the wrong content") end end