puppet-retrospec 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/CHANGELOG.md +11 -0
  4. data/DEVELOPMENT.md +3 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +2 -0
  7. data/README.md +211 -273
  8. data/Rakefile +8 -8
  9. data/VERSION +1 -1
  10. data/lib/retrospec-puppet.rb +3 -3
  11. data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
  12. data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
  13. data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
  14. data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
  15. data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
  16. data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
  17. data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
  18. data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
  19. data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
  20. data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
  21. data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
  22. data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
  23. data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
  24. data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
  25. data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
  26. data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
  27. data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
  28. data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
  29. data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
  30. data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
  31. data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
  32. data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
  33. data/puppet-retrospec.gemspec +43 -4
  34. data/spec/fixtures/facts/oracle_controls.rb +38 -0
  35. data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
  36. data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
  37. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
  38. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
  39. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
  40. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
  41. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
  42. data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
  43. data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
  44. data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
  45. data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
  46. data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
  47. data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
  48. data/spec/fixtures/types/bmc.rb +102 -0
  49. data/spec/fixtures/types/bmcuser.rb +46 -0
  50. data/spec/fixtures/types/db_opatch.rb +93 -0
  51. data/spec/integration/retrospec_spec.rb +1 -3
  52. data/spec/spec_helper.rb +33 -6
  53. data/spec/unit/conditional_spec.rb +12 -15
  54. data/spec/unit/generators/fact_generater_spec.rb +49 -17
  55. data/spec/unit/generators/function_generator_spec.rb +301 -0
  56. data/spec/unit/generators/function_spec.rb +67 -0
  57. data/spec/unit/generators/parsers/fact_spec.rb +62 -0
  58. data/spec/unit/generators/parsers/provider_spec.rb +44 -0
  59. data/spec/unit/generators/parsers/type_spec.rb +93 -0
  60. data/spec/unit/generators/provider_generator_spec.rb +120 -0
  61. data/spec/unit/generators/schema_generator_spec.rb +122 -0
  62. data/spec/unit/generators/type_generator_spec.rb +173 -0
  63. data/spec/unit/module_spec.rb +7 -10
  64. data/spec/unit/plugin_spec.rb +213 -15
  65. data/spec/unit/puppet-retrospec_spec.rb +81 -100
  66. data/spec/unit/resource_spec.rb +16 -17
  67. data/spec/unit/spec_object_spec.rb +46 -0
  68. data/spec/unit/type_code_spec.rb +9 -11
  69. data/spec/unit/variable_store_spec.rb +41 -43
  70. metadata +54 -4
  71. data/spec/unit/generators/fact_spec.rb +0 -58
@@ -0,0 +1,118 @@
1
+ require_relative 'parsers/type'
2
+
3
+ module Retrospec
4
+ module Puppet
5
+ module Generators
6
+ class TypeGenerator < Retrospec::Plugins::V1::Plugin
7
+ attr_reader :template_dir, :context
8
+
9
+ # this is the list of core puppet types that cannot be recreated
10
+ CORE_TYPES = ["augeas", "computer", "cron", "exec", "file", "filebucket",
11
+ "group", "host", "interface", "k5login", "macauthorization", "mailalias",
12
+ "maillist", "mcx", "mount", "nagios_command", "nagios_contact",
13
+ "nagios_contactgroup", "nagios_host", "nagios_hostdependency",
14
+ "nagios_hostescalation", "nagios_hostextinfo", "nagios_hostgroup",
15
+ "nagios_service", "nagios_servicedependency",
16
+ "nagios_serviceescalation", "nagios_serviceextinfo",
17
+ "nagios_servicegroup", "nagios_timeperiod", "notify", "package",
18
+ "resources", "router", "schedule", "scheduled_task", "selboolean",
19
+ "selmodule", "service", "ssh_authorized_key", "sshkey", "stage",
20
+ "tidy", "user", "vlan", "yumrepo", "zfs", "zone", "zpool"]
21
+
22
+ # retrospec will initilalize this class so its up to you
23
+ # to set any additional variables you need to get the job done.
24
+ def initialize(module_path, spec_object = {})
25
+ super
26
+ # below is the Spec Object which serves as a context for template rendering
27
+ # you will need to initialize this object, so the erb templates can get the binding
28
+ # the SpecObject can be customized to your liking as its different for every plugin gem.
29
+ if CORE_TYPES.include?(spec_object[:name])
30
+ raise Retrospec::Puppet::Generators::CoreTypeException
31
+ end
32
+ @context = OpenStruct.new(:type_name => spec_object[:name], :parameters => spec_object[:parameters],
33
+ :properties => spec_object[:properties], :providers => spec_object[:providers])
34
+ end
35
+
36
+ def template_dir
37
+ external_templates = File.expand_path(File.join(config_data[:template_dir], 'types', 'type_template.rb.retrospec.erb'))
38
+ if File.exist?(external_templates)
39
+ File.join(config_data[:template_dir], 'types')
40
+ else
41
+ File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'templates', 'types'))
42
+ end
43
+ end
44
+ # used to display subcommand options to the cli
45
+ # the global options are passed in for your usage
46
+ # http://trollop.rubyforge.org
47
+ # all options here are available in the config passed into config object
48
+ # returns the parameters
49
+ def self.run_cli(global_opts, args=ARGV)
50
+ sub_command_opts = Trollop.options(args) do
51
+ banner <<-EOS
52
+ Generates a new type with the given name, parameters, and properties.
53
+
54
+ EOS
55
+ opt :name, 'The name of the type you wish to create', :type => :string, :required => true, :short => '-n'
56
+ opt :parameters, 'A list of parameters to initialize your type with', :type => :strings, :required => false,
57
+ :short => '-p', :default => ['name']
58
+ opt :properties, 'A list of properties to initialize your type with', :type => :strings, :required => false,
59
+ :short => '-a', :default => []
60
+ opt :providers, 'A list of providers to create and associate with this type', :type => :strings,
61
+ :default => ['default'], :required => false
62
+ end
63
+ unless sub_command_opts[:name]
64
+ Trollop.educate
65
+ exit 1
66
+ end
67
+ plugin_data = global_opts.merge(sub_command_opts)
68
+ plugin_data
69
+ end
70
+
71
+ def type_dir
72
+ @type_dir ||= File.join(module_path, 'lib', 'puppet', 'type')
73
+ end
74
+
75
+ def type_spec_dir
76
+ @type_spec_dir ||= File.join(module_path, 'spec', 'unit', 'puppet', 'type')
77
+ end
78
+
79
+ def type_name_path
80
+ File.join(type_dir, "#{type_name}.rb")
81
+ end
82
+
83
+ def type_name
84
+ context.type_name
85
+ end
86
+
87
+ def generate_provider_files
88
+ providers = context.providers
89
+ providers.each do |provider|
90
+ plugin_data = { :name => provider, :type => type_name, :template_dir => config_data[:template_dir] }
91
+ p = Retrospec::Puppet::Generators::ProviderGenerator.new(module_path, plugin_data)
92
+ p.generate_provider_files
93
+ end
94
+ end
95
+
96
+ def generate_type_files
97
+ safe_create_template_file(type_name_path, File.join(template_dir, 'type_template.rb.retrospec.erb'), context)
98
+ generate_provider_files
99
+ type_name_path
100
+ end
101
+
102
+ # this will look through all
103
+ def generate_type_spec_files
104
+ type_files = Dir.glob(File.join(type_dir, '**', '*.rb')).sort
105
+ spec_files = []
106
+ type_files.each do |type_file|
107
+ type_file_data = Retrospec::Puppet::Type.load_type(type_file)
108
+ # because many facts can be in a single file we want to create a unique file for each fact
109
+ type_spec_path = File.join(type_spec_dir, "#{type_file_data.name}_spec.rb")
110
+ spec_files << type_spec_path
111
+ safe_create_template_file(type_spec_path, File.join(template_dir, 'type_spec.rb.retrospec.erb'), type_file_data)
112
+ end
113
+ spec_files
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -1,10 +1,9 @@
1
1
  require 'fileutils'
2
2
 
3
3
  class Helpers
4
-
5
4
  def self.get_module_name
6
5
  module_name = nil
7
- Dir["manifests/*.pp"].entries.each do |manifest|
6
+ Dir['manifests/*.pp'].entries.each do |manifest|
8
7
  module_name = get_module_name_from_file(manifest)
9
8
  break unless module_name.nil?
10
9
  end
@@ -18,15 +17,12 @@ class Helpers
18
17
  tokens = p.fullscan
19
18
 
20
19
  i = tokens.index { |token| [:CLASS, :DEFINE].include? token.first }
21
- unless i.nil?
22
- module_name = tokens[i + 1].last[:value].split('::').first
23
- end
20
+ module_name = tokens[i + 1].last[:value].split('::').first unless i.nil?
24
21
 
25
22
  module_name
26
23
  end
27
24
 
28
25
  def self.is_module_dir?(dir)
29
- Dir[File.join(dir,"*")].entries.include? "manifests"
26
+ Dir[File.join(dir, '*')].entries.include? 'manifests'
30
27
  end
31
-
32
28
  end
@@ -1,8 +1,8 @@
1
1
  require 'retrospec/plugins/v1/module_helpers'
2
2
  require 'retrospec/plugins/v1'
3
3
  require 'retrospec/config'
4
- require_relative 'generators/fact_generator'
5
- require_relative 'generators/module_generator'
4
+ require_relative 'generators'
5
+ require_relative 'exceptions'
6
6
  require_relative 'spec_object'
7
7
  require 'erb'
8
8
  require_relative 'template_helpers'
@@ -21,11 +21,12 @@ module Retrospec
21
21
  module V1
22
22
  class Puppet < Retrospec::Plugins::V1::Plugin
23
23
  include Retrospec::Puppet::TemplateHelpers
24
- attr_reader :template_dir, :context, :manifest_dir, :manifest_files
24
+ attr_reader :template_dir, :context, :manifest_files
25
+ attr_accessor :manifest_dir
25
26
 
26
- def initialize(supplied_module_path=nil,config={})
27
+ def initialize(supplied_module_path = nil, config = {})
27
28
  super
28
- @manifest_dir = File.join(supplied_module_path,'manifests')
29
+ @manifest_dir = File.join(supplied_module_path, 'manifests')
29
30
  Utilities::PuppetModule.instance.future_parser = config_data[:enable_future_parser]
30
31
  # user supplied a template path or user wants to use local templates
31
32
  @template_dir = setup_user_template_dir(config_data[:template_dir], config_data[:scm_url], config_data[:ref])
@@ -34,9 +35,12 @@ module Retrospec
34
35
  def post_init
35
36
  # before we validate the module directory we should ensure the module exists by creating it
36
37
  # validation also occurs when setting the module path
38
+ # these are required because the puppet module creates a singleton with some cached values
39
+ Utilities::PuppetModule.instance.module_dir_name = File.basename(module_path)
40
+ Utilities::PuppetModule.instance.module_name = File.basename(module_path)
37
41
  Utilities::PuppetModule.instance.module_path = module_path
38
42
  Utilities::PuppetModule.create_tmp_module_path # this is required to finish initialization
39
- # setting the context is require to make other methods below work. #TODO lazy create the context
43
+ # setting the context is required to make other methods below work. #TODO lazy create the context
40
44
  @context = ::Retrospec::Puppet::SpecObject.new(module_path, Utilities::PuppetModule.instance, config_data)
41
45
  end
42
46
 
@@ -46,8 +50,22 @@ module Retrospec
46
50
  # anything since it is not mandatory
47
51
  # I thought about using the the module face to perform this generation but it seems like its not
48
52
  # supported at this time, and you can't specify the path to generate the module in
49
- def new_module(plugin_data)
50
- f = Retrospec::Puppet::Generators::ModuleGenerator.run_cli(plugin_data)
53
+ def new_module(plugin_data, args)
54
+ plugin_data = Retrospec::Puppet::Generators::ModuleGenerator.run_cli(plugin_data, args)
55
+ # the user passed in /tmp/test1 and the name is irrelevent
56
+ if ! File.exists?(plugin_data[:module_path])
57
+ plugin_data[:module_path] = File.join(plugin_data[:module_path])
58
+ # if the module path basename is the same as the module name
59
+ # this is a parent directory or the module already exists
60
+ elsif File.basename(plugin_data[:module_path]) != plugin_data[:name]
61
+ plugin_data[:module_path] = File.join(plugin_data[:module_path], plugin_data[:name])
62
+ end
63
+ # we need to set this because the this class is created before we created the new module directory
64
+ # so we now have to set the manifests and module directory
65
+ self.module_path = plugin_data[:module_path]
66
+ config_data[:module_path] = plugin_data[:module_path]
67
+ self.manifest_dir = File.join(plugin_data[:module_path], 'manifests')
68
+ f = Retrospec::Puppet::Generators::ModuleGenerator.new(plugin_data[:module_path], plugin_data)
51
69
  f.run(manifest_dir)
52
70
  end
53
71
 
@@ -57,65 +75,127 @@ module Retrospec
57
75
  # all options here are available in the config passed into the initialize code
58
76
  # this is the only entry point into the plugin
59
77
  def self.run_cli(global_opts, global_config, plugin_config, args=ARGV)
60
- template_dir = plugin_config['plugins::puppet::template_dir'] || File.expand_path('~/.retrospec/repos/retrospec-puppet-templates')
78
+ template_dir = ENV['RETROSPEC_TEMPLATES_DIR'] || plugin_config['plugins::puppet::template_dir'] || File.expand_path('~/.retrospec/repos/retrospec-puppet-templates')
61
79
  scm_url = ENV['RETROSPEC_PUPPET_SCM_URL'] || plugin_config['plugins::puppet::templates::url']
62
80
  scm_branch = ENV['RETROSPEC_PUPPET_SCM_BRANCH'] || plugin_config['plugins::puppet::templates::ref'] || 'master'
63
81
  future_parser = plugin_config['plugins::puppet::enable_future_parser'] || false
64
82
  beaker_tests = plugin_config['plugins::puppet::enable_beaker_tests'] || false
65
83
  # a list of subcommands for this plugin
66
- sub_commands = ['new_module', 'new_fact']
84
+ sub_commands = %w(new_module new_fact new_type new_provider new_function)
67
85
  if sub_commands.count > 0
68
86
  sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n"
69
87
  else
70
- sub_command_help = ""
88
+ sub_command_help = ''
71
89
  end
72
- plugin_opts = Trollop::options do
90
+ plugin_opts = Trollop.options(args) do
73
91
  version "Retrospec puppet plugin: #{Retrospec::Puppet::VERSION} (c) Corey Osman"
74
92
  banner <<-EOS
75
93
  Generates puppet rspec test code based on the classes and defines inside the manifests directory.\n
76
94
  #{sub_command_help}
77
95
 
78
96
  EOS
79
- opt :template_dir, "Path to templates directory (only for overriding Retrospec templates)", :type => :string,
97
+ opt :template_dir, 'Path to templates directory (only for overriding Retrospec templates)', :type => :string,
80
98
  :required => false, :default => template_dir
81
- opt :scm_url, "SCM url for retrospec templates", :type => :string, :required => false,
99
+ opt :scm_url, 'SCM url for retrospec templates', :type => :string, :required => false,
82
100
  :default => scm_url
83
- opt :branch, "Branch you want to use for the retrospec template repo", :type => :string, :required => false,
101
+ opt :branch, 'Branch you want to use for the retrospec template repo', :type => :string, :required => false,
84
102
  :default => scm_branch
85
- opt :enable_beaker_tests, "Enable the creation of beaker tests", :require => false, :type => :boolean, :default => beaker_tests
86
- opt :enable_future_parser, "Enables the future parser only during validation", :default => future_parser, :require => false, :type => :boolean
103
+ opt :enable_beaker_tests, 'Enable the creation of beaker tests', :require => false, :type => :boolean, :default => beaker_tests
104
+ opt :enable_future_parser, 'Enables the future parser only during validation', :default => future_parser, :require => false, :type => :boolean
87
105
  stop_on sub_commands
88
106
  end
89
107
  # the passed in options will always override the config file
90
- plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_opts)
108
+ plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_opts).merge(plugin_config)
91
109
  # define the default action to use the plugin here, the default is run
92
110
  sub_command = (args.shift || :run).to_sym
93
111
  # create an instance of this plugin
94
- plugin = self.new(plugin_data[:module_path],plugin_data)
112
+ plugin = new(plugin_data[:module_path], plugin_data)
95
113
  # check if the plugin supports the sub command
96
- if plugin.respond_to?(sub_command)
97
- case sub_command
114
+ begin
115
+ if plugin.respond_to?(sub_command)
116
+ case sub_command
98
117
  when :new_module
99
- plugin.send(sub_command, plugin_data)
100
- plugin.post_init # finish initialization
118
+ plugin.send(sub_command, plugin_data, args)
119
+ plugin.post_init # finish initialization
101
120
  when :run
102
121
  plugin.post_init # finish initialization
122
+ when :new_type
123
+ plugin.new_type(plugin_data, args)
124
+ when :new_function
125
+ plugin.new_function(plugin_data, args)
103
126
  when :new_fact
104
- plugin.new_fact(plugin_data)
127
+ plugin.new_fact(plugin_data, args)
128
+ when :new_provider
129
+ plugin.new_provider(plugin_data, args)
105
130
  else
106
131
  plugin.post_init # finish initialization
107
- plugin.send(sub_command, plugin_data[:module_path], plugin_data)
132
+ plugin.send(sub_command, plugin_data[:module_path], plugin_data, args)
133
+ end
134
+ plugin.send(:run)
135
+ else
136
+ puts "The subcommand #{sub_command} is not supported or valid".fatal
137
+ exit 1
108
138
  end
109
- plugin.send(:run)
110
- else
111
- puts "The subcommand #{sub_command} is not supported or valid"
139
+ rescue Retrospec::Puppet::InvalidModulePathError => e
140
+ exit 1
141
+ rescue Retrospec::Puppet::NoManifestDirError => e
142
+ exit 1
143
+ rescue Retrospec::Puppet::ParserError => e
144
+ exit 1
145
+ rescue Retrospec::Puppet::Generators::CoreTypeException => e
146
+ puts e.message.fatal
147
+ rescue Exception => e
112
148
  exit 1
113
149
  end
150
+ plugin_data
151
+ end
152
+
153
+ def new_schema(module_path, config, args=[])
154
+ plugin_data = Retrospec::Puppet::Generators::SchemaGenerator.run_cli(config, args)
155
+ plugin_data[:puppet_context] = context
156
+ s = Retrospec::Puppet::Generators::SchemaGenerator.new(plugin_data[:module_path], plugin_data)
157
+ s.generate_schema_file
158
+ end
159
+
160
+ def new_function(config, args)
161
+ plugin_data = Retrospec::Puppet::Generators::FunctionGenerator.run_cli(config, args)
162
+ f = Retrospec::Puppet::Generators::FunctionGenerator.new(plugin_data[:module_path], plugin_data)
163
+ post_init
164
+ f.generate_function_file
165
+ end
166
+
167
+ def function_spec_files(module_path, config)
168
+ f = Retrospec::Puppet::Generators::FunctionGenerator.new(module_path, config)
169
+ f.generate_spec_files
170
+ end
171
+
172
+ def new_provider(config, args)
173
+ plugin_data = Retrospec::Puppet::Generators::ProviderGenerator.run_cli(config, args)
174
+ p = Retrospec::Puppet::Generators::ProviderGenerator.new(plugin_data[:module_path], plugin_data)
175
+ post_init
176
+ p.generate_provider_files
177
+ end
178
+
179
+ def provider_spec_files(module_path, config)
180
+ t = Retrospec::Puppet::Generators::ProviderGenerator.new(module_path, config)
181
+ t.generate_provider_spec_files
182
+ end
183
+
184
+ def new_type(config, args)
185
+ plugin_data = Retrospec::Puppet::Generators::TypeGenerator.run_cli(config, args)
186
+ t = Retrospec::Puppet::Generators::TypeGenerator.new(plugin_data[:module_path], plugin_data)
187
+ post_init
188
+ t.generate_type_files
114
189
  end
115
190
 
116
- def new_fact(plugin_data)
117
- f = Retrospec::Puppet::Generators::FactGenerator.run_cli(plugin_data)
118
- post_init # finish initialization
191
+ def type_spec_files(module_path, config)
192
+ t = Retrospec::Puppet::Generators::TypeGenerator.new(module_path, config)
193
+ t.generate_type_spec_files
194
+ end
195
+
196
+ def new_fact(plugin_data, args)
197
+ f = Retrospec::Puppet::Generators::FactGenerator.run_cli(plugin_data, args)
198
+ post_init # finish initialization
119
199
  f.generate_fact_file
120
200
  end
121
201
 
@@ -139,10 +219,10 @@ Generates puppet rspec test code based on the classes and defines inside the man
139
219
 
140
220
  # runs a user defined hook called pre-hook
141
221
  def run_pre_hook
142
- hook_file = File.join(template_dir,'pre-hook')
143
- if File.exists?(hook_file)
222
+ hook_file = File.join(template_dir, 'pre-hook')
223
+ if File.exist?(hook_file)
144
224
  output = `#{hook_file} #{module_path}`
145
- if $?.success?
225
+ if $CHILD_STATUS.success?
146
226
  puts "Successfully ran hook: #{hook_file}".info
147
227
  puts output.info
148
228
  else
@@ -154,10 +234,10 @@ Generates puppet rspec test code based on the classes and defines inside the man
154
234
 
155
235
  # runs a user defined hook called post-hook
156
236
  def run_post_hook
157
- hook_file = File.join(template_dir,'post-hook')
158
- if File.exists?(hook_file)
237
+ hook_file = File.join(template_dir, 'post-hook')
238
+ if File.exist?(hook_file)
159
239
  output = `#{hook_file} #{module_path}`
160
- if $?.success?
240
+ if $CHILD_STATUS.success?
161
241
  puts "Successfully ran hook: #{hook_file}".info
162
242
  puts output.info
163
243
  else
@@ -172,15 +252,17 @@ Generates puppet rspec test code based on the classes and defines inside the man
172
252
  types = context.types
173
253
  safe_create_module_files
174
254
  fact(module_path, config_data)
255
+ type_spec_files(module_path, config_data)
256
+ provider_spec_files(module_path, config_data)
257
+ function_spec_files(module_path, config_data)
258
+ new_schema(module_path, config_data)
175
259
  Retrospec::Puppet::Generators::ModuleGenerator.generate_metadata_file(context.module_name, config_data)
176
260
  # a Type is nothing more than a defined type or puppet class
177
261
  # we could have named this manifest but there could be multiple types
178
262
  # in a manifest.
179
263
  types.each do |type|
180
264
  safe_create_resource_spec_files(type)
181
- if context.enable_beaker_tests?
182
- safe_create_acceptance_tests(type)
183
- end
265
+ safe_create_acceptance_tests(type) if context.enable_beaker_tests?
184
266
  end
185
267
  Utilities::PuppetModule.clean_tmp_modules_dir
186
268
  true
@@ -192,13 +274,13 @@ Generates puppet rspec test code based on the classes and defines inside the man
192
274
  # filenames must named how they would appear in the normal module path. The directory
193
275
  # structure where the file is contained
194
276
  def safe_create_module_files
195
- templates = Find.find(File.join(template_dir,'module_files')).sort
277
+ templates = Find.find(File.join(template_dir, 'module_files')).sort
196
278
  templates.each do |template|
197
279
  # need to remove the erb extension and rework the destination path
198
280
  if template =~ /nodesets|spec_helper_acceptance/ and !context.enable_beaker_tests?
199
281
  next
200
282
  else
201
- dest = template.gsub(File.join(template_dir,'module_files'), module_path)
283
+ dest = template.gsub(File.join(template_dir, 'module_files'), module_path)
202
284
  if File.symlink?(template)
203
285
  safe_create_symlink(template, dest)
204
286
  elsif File.directory?(template)
@@ -219,7 +301,7 @@ Generates puppet rspec test code based on the classes and defines inside the man
219
301
  end
220
302
 
221
303
  # Creates an associated spec file for each type and even creates the subfolders for nested classes one::two::three
222
- def safe_create_resource_spec_files(type,template=File.join(template_dir,'resource_spec_file.retrospec.erb'))
304
+ def safe_create_resource_spec_files(type, template = File.join(template_dir, 'resource_spec_file.retrospec.erb'))
223
305
  context.parameters = type.arguments
224
306
  context.type = type
225
307
  VariableStore.populate(type)
@@ -227,15 +309,15 @@ Generates puppet rspec test code based on the classes and defines inside the man
227
309
  # pass the type to the variable store and it will discover all the variables and try to resolve them.
228
310
  # this does not get deep nested conditional blocks
229
311
  context.resources += Conditional.all(type)
230
- dest = File.join(module_path,generate_file_path(type, false))
312
+ dest = File.join(module_path, generate_file_path(type, false))
231
313
  safe_create_template_file(dest, template, context)
232
314
  dest
233
315
  end
234
316
 
235
- def safe_create_acceptance_tests(type,template=File.join(template_dir,'acceptance_spec_test.retrospec.erb'))
317
+ def safe_create_acceptance_tests(type, template = File.join(template_dir, 'acceptance_spec_test.retrospec.erb'))
236
318
  @parameters = type.arguments
237
319
  @type = type
238
- dest = File.join(module_path,generate_file_path(type, true))
320
+ dest = File.join(module_path, generate_file_path(type, true))
239
321
  safe_create_template_file(dest, template, context)
240
322
  dest
241
323
  end
@@ -250,17 +332,17 @@ Generates puppet rspec test code based on the classes and defines inside the man
250
332
  hosts_dir = 'hosts'
251
333
  acceptance_dir = 'acceptance'
252
334
  case type.type
253
- when :hostclass
254
- type_dir_name = classes_dir
255
- when :definition
256
- type_dir_name = defines_dir
257
- when :node
258
- type_dir_name = hosts_dir
259
- else
260
- raise "#{type.type} retrospec does not support this resource type yet"
335
+ when :hostclass
336
+ type_dir_name = classes_dir
337
+ when :definition
338
+ type_dir_name = defines_dir
339
+ when :node
340
+ type_dir_name = hosts_dir
341
+ else
342
+ fail "#{type.type} retrospec does not support this resource type yet"
261
343
  end
262
344
  if is_acceptance_test
263
- type_dir_name = File.join('spec',acceptance_dir, type_dir_name)
345
+ type_dir_name = File.join('spec', acceptance_dir, type_dir_name)
264
346
  else
265
347
  type_dir_name = File.join('spec', type_dir_name)
266
348
  end
@@ -275,10 +357,10 @@ Generates puppet rspec test code based on the classes and defines inside the man
275
357
  # remove the last token since its the class name
276
358
  tokens.pop
277
359
  # so lets make a directory structure out of it
278
- dir_name = File.join(tokens) # config/server
279
- dir_name = File.join(type_dir_name,dir_name, file_name) # spec/classes/tomcat/config/server
360
+ dir_name = File.join(tokens) # config/server
361
+ dir_name = File.join(type_dir_name, dir_name, file_name) # spec/classes/tomcat/config/server
280
362
  else
281
- dir_name = File.join(type_dir_name,file_name)
363
+ dir_name = File.join(type_dir_name, file_name)
282
364
  end
283
365
  dir_name
284
366
  end
@@ -306,8 +388,7 @@ Generates puppet rspec test code based on the classes and defines inside the man
306
388
  def self.file_type
307
389
  '.pp'
308
390
  end
309
-
310
391
  end
311
392
  end
312
393
  end
313
- end
394
+ end