Class: Voxpupuli::Acceptance::Fixtures
- Inherits:
-
Object
- Object
- Voxpupuli::Acceptance::Fixtures
- Defined in:
- lib/voxpupuli/acceptance/fixtures.rb
Class Method Summary collapse
-
.build_modules(modulepath, destination, logger = nil) ⇒ Hash<String=>String>
Build modules in the given sources.
-
.install_fixture_modules_on(hosts, modulepath, logger = nil) ⇒ Object
Install fixture modules on the given hosts.
-
.install_modules_on(hosts, modules, logger = nil) ⇒ Object
Install modules on a number of hosts.
-
.temp_dir_on(host, &block) ⇒ Object
Create a temporary directory on the host, similar to Dir.mktmpdir but on a remote host.
-
.valid_directory_name?(directory_name, metadata_name) ⇒ Boolean
Validate a directory name matches its metadata name.
Class Method Details
.build_modules(modulepath, destination, logger = nil) ⇒ Hash<String=>String>
Build modules in the given sources.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/voxpupuli/acceptance/fixtures.rb', line 37 def build_modules(modulepath, destination, logger = nil) modulepath = [modulepath] if modulepath.is_a?(String) modules = {} modulepath.each do |dir| Dir[File.join(dir, '*', 'metadata.json')].each do || path = File.dirname() name = File.basename(path) next if modules.include?(name) builder = Puppet::Modulebuilder::Builder.new(File.realpath(path), destination, logger) unless valid_directory_name?(name, builder.['name']) warning = "Directory name of #{path} doesn't match metadata name #{builder.['name']}" if logger logger.warn(warning) else STDERR.puts(warning) end end modules[name] = builder.build end end modules end |
.install_fixture_modules_on(hosts, modulepath, logger = nil) ⇒ Object
Install fixture modules on the given hosts
16 17 18 19 20 21 22 23 24 |
# File 'lib/voxpupuli/acceptance/fixtures.rb', line 16 def install_fixture_modules_on(hosts, modulepath, logger = nil) Dir.mktmpdir do |destination| modules = build_modules(modulepath, destination, logger) install_modules_on(hosts, modules, logger) end nil end |
.install_modules_on(hosts, modules, logger = nil) ⇒ Object
Install modules on a number of hosts
This is done by iterating over every host. On that host a temporary directory is created. Each module is copied there and installed by force.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/voxpupuli/acceptance/fixtures.rb', line 78 def install_modules_on(hosts, modules, logger = nil) hosts.each do |host| logger.debug("Installing modules on #{host}") if logger temp_dir_on(host) do |target_dir| modules.each do |name, source_path| target_file = File.join(target_dir, File.basename(source_path)) logger.debug("Copying module #{name} from #{source_path} to #{target_file}") if logger scp_to(host, source_path, target_file) on host, "puppet module install --force --ignore-dependencies '#{target_file}'" end end end nil end |
.temp_dir_on(host, &block) ⇒ Object
Create a temporary directory on the host, similar to Dir.mktmpdir but on a remote host.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/voxpupuli/acceptance/fixtures.rb', line 104 def temp_dir_on(host, &block) result = on host, "mktemp -d" raise "Could not create directory" unless result.success? dir = result.stdout.strip begin yield dir ensure on host, "rm -rf #{dir}" end nil end |
.valid_directory_name?(directory_name, metadata_name) ⇒ Boolean
Validate a directory name matches its metadata name.
This is useful to detect misconfigurations in fixture set ups.
136 137 138 139 |
# File 'lib/voxpupuli/acceptance/fixtures.rb', line 136 def valid_directory_name?(directory_name, ) normalized = .tr('/', '-').split('-').last normalized == directory_name end |