puppetbox 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 393f46fa2e8abcca2e2fd278c4c4732af09ba444
4
- data.tar.gz: 7dc52e48c12005dff1122fa6f900064f86b8bf16
3
+ metadata.gz: 6e98bf1892a07fa686429fd852a495629ebfde34
4
+ data.tar.gz: 34175eff6de51aefee73c7e22af3168ba131311c
5
5
  SHA512:
6
- metadata.gz: cb725f0228784ae8560c4f0de5a7bad886a1fa7a205c8c9185f9431240e8ffe3f98b5335d01c6bb3064b56d7200feddab0683bdfb7683ea673504a2a889e6938
7
- data.tar.gz: 45bae316cd000af9dc4f5b4a7936bdd10c58d56037181b80305148e0afec2387aa8e53d262710a550d37ac7ce61ce0fc3eb4d3c717316207e2cf835446095ebd
6
+ metadata.gz: b556b35aecb7a91ef65c2a34b9ce4e3e10ee6ec5fdf4354ed9e0e09461af5f8970b91405fef116aac92b429238e9afed998b92d6f98fad3fac23cbe871b04fbc
7
+ data.tar.gz: ce27a46a8dc3629fc82b60db99627a94433f160b2427d096c82d94af3b4626d39b383ce967b676e0491ebf28242f7958bfd84f4884bbb9755afba05a22b7665d
@@ -8,7 +8,9 @@ module PuppetBox
8
8
  class Vagrant
9
9
  WORKING_DIR_VAGRANT = "vagrant"
10
10
  PUPPET_CODE_MOUNT = "/etc/puppetlabs/code/environments/production"
11
- SPEC_ACCEPTANCE_MOUNT = "spec/acceptance:/acceptance"
11
+
12
+ # mount spec/accpetance into the same directory name inside the VM for simplicity
13
+ SPEC_ACCEPTANCE_MOUNT = "spec/acceptance:/spec/acceptance"
12
14
 
13
15
  def node_name
14
16
  @name
@@ -97,6 +99,33 @@ module PuppetBox
97
99
  self_test
98
100
  end
99
101
 
102
+ # Run a script on the VM by name. We pass in the script name and are able
103
+ # to run because the ./spec/acceptance directory is mounted inside the VM
104
+ #
105
+ # We can figure out windows/linux scripts based on the filename too
106
+ def run_setup_script(script_file)
107
+
108
+ if script_file =~ /.ps1$/
109
+ # powershell - not supported yet
110
+ raise("Windows not supported yet https://github.com/GeoffWilliams/puppetbox/issues/3")
111
+ else
112
+ # force absolute path
113
+ script_file = "/#{script_file}"
114
+
115
+ @logger.info("Running setup script #{script_file} on #{@name}")
116
+ status_code, messages = @vm.run("sudo -i #{script_file}")
117
+ status = (status_code == 0)
118
+ if status
119
+ @logger.info("setup script #{script_file} executed successfully")
120
+ else
121
+ # our tests are fubar if any setup script failed
122
+ message = messages.join("\n")
123
+ raise("setup script #{script_file} failed on #{node_name}: #{message}")
124
+ end
125
+ end
126
+ status
127
+ end
128
+
100
129
  def run_puppet_x2(puppet_class)
101
130
  # if you need to link a module into puppet's modulepath either do it
102
131
  # before running puppet (yet to be supported) or use the @config hash
@@ -7,7 +7,10 @@ require "puppetbox/report"
7
7
  module PuppetBox
8
8
  class PuppetBox
9
9
 
10
- WORKING_DIR = File.join(Dir.home, '.puppetbox')
10
+ WORKING_DIR = File.join(Dir.home, '.puppetbox')
11
+ ACCEPTANCE_TEST_DIR = "spec/acceptance"
12
+ ACCEPTANCE_DEFAULT = "__ALL__"
13
+ SETUP_SCRIPT_GLOB = "setup.*"
11
14
 
12
15
  def initialize(logger:nil, nodeset_file: nil, working_dir: nil)
13
16
  # The results of all tests on all driver instances
@@ -101,6 +104,57 @@ module PuppetBox
101
104
  @result_set.passed?
102
105
  end
103
106
 
107
+ # Sometimes you need to run a script before running a class, or just on
108
+ # particular host(s). Check for the presence of a bash or powershell script
109
+ # and execute it on the system under test. If there is an error fail all
110
+ # tests immediately since it means our test setup is invalid.
111
+ #
112
+ # Naming convention/example:
113
+ # └── SLES-12.1-64
114
+ # ├── __ALL__
115
+ # │   └── setup.sh
116
+ # └── role__puppet__master
117
+ # └── setup.sh
118
+ #
119
+ def setup_test(driver_instance, puppet_class)
120
+ script_filename_base = File.join(ACCEPTANCE_TEST_DIR, driver_instance.node_name)
121
+
122
+ # 1st choice - exact match on classname (with :: converted to __)
123
+ script_filename_class = File.join(
124
+ script_filename_base,
125
+ puppet_class.gsub(/::/,'__'),
126
+ SETUP_SCRIPT_GLOB
127
+ )
128
+ found = Dir.glob(script_filename_class)
129
+ if found.any?
130
+ script_target = found[0]
131
+ else
132
+ # 2nd choice - the __ALL__ directory
133
+ script_filename_default = File.join(
134
+ script_filename_base,
135
+ ACCEPTANCE_DEFAULT,
136
+ SETUP_SCRIPT_GLOB
137
+ )
138
+ found = Dir.glob(script_filename_default)
139
+ if found.any?
140
+ @logger.info(
141
+ "Using setup script from #{script_filename_default} on "\
142
+ "#{driver_instance.node_name} for #{puppet_class}, create "\
143
+ "#{script_filename_class} to override")
144
+ script_target = found[0]
145
+ else
146
+ script_target = false
147
+ @logger.info(
148
+ "No setup scripts found for #{driver_instance.node_name} and "\
149
+ "#{puppet_class} create #{script_filename_default} or "\
150
+ "#{script_filename_class} if required")
151
+ end
152
+ end
153
+ if script_target
154
+ driver_instance.run_setup_script(script_target)
155
+ end
156
+ end
157
+
104
158
  # Run puppet using `driver_instance` to execute
105
159
  def run_puppet(driver_instance, puppet_classes, logger:nil, reset_after_run:true)
106
160
  # use supplied logger in preference to the default puppetbox logger instance
@@ -118,6 +172,7 @@ module PuppetBox
118
172
  # per class on the self-test which we now know will succeed
119
173
  driver_instance.reset
120
174
  end
175
+ setup_test(driver_instance, puppet_class)
121
176
  logger.info("running test #{driver_instance.node_name} - #{puppet_class}")
122
177
  driver_instance.run_puppet_x2(puppet_class)
123
178
  @result_set.save(driver_instance.node_name, puppet_class, driver_instance.result)
@@ -1,3 +1,3 @@
1
1
  module PuppetBox
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams