Method: Onceover::Controlrepo#initialize

Defined in:
lib/onceover/controlrepo.rb

#initialize(opts = {}) ⇒ Controlrepo

End class methods



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/onceover/controlrepo.rb', line 90

def initialize(opts = {})
  # When we initialize the object it is going to set some instance vars

  # We want people to be able to run this from anywhere within the repo
  # so traverse up until we think we are in a controlrepo.
  if opts[:path]
    @root = opts[:path]
  else
    @root = Dir.pwd
    until File.exist?(File.expand_path('./environment.conf', @root)) do
      # Throw an exception if we can't go any further up
      throw "Could not file root of the controlrepo anywhere above #{Dir.pwd}" if @root == File.expand_path('../', @root)

      # Step up and try again
      @root = File.expand_path('../', @root)
    end
  end

  @onceover_yaml = ENV['ONCEOVER_YAML'] || opts[:onceover_yaml] || File.expand_path("#{@root}/spec/onceover.yaml")

  if File.exist?(@onceover_yaml) && _data = YAML.load_file(@onceover_yaml)
    opts.merge!(_data.fetch('opts',{})||{})
  end
  opts.fetch(:facts_dir,'').sub!(%r{^[^/.].+} ){|path| File.expand_path(path, @root)}
  opts.fetch(:facts_files,[]).map!{|path| path =~ %r{^[/.]} ? path : File.expand_path(path, @root)}

  @environmentpath  = opts[:environmentpath]  || 'etc/puppetlabs/code/environments'
  @puppetfile       = opts[:puppetfile]       || File.expand_path('./Puppetfile', @root)
  @environment_conf = opts[:environment_conf] || File.expand_path('./environment.conf', @root)
  @spec_dir         = opts[:spec_dir]         || File.expand_path('./spec', @root)
  @facts_dir        = opts[:facts_dir]        || File.expand_path('factsets', @spec_dir)
  _facts_dirs       = [@facts_dir, File.expand_path('../../factsets', __dir__)]
  _facts_files      = opts[:facts_files]      || _facts_dirs.map{|d| File.join(d, '*.json')}
  @facts_files      = _facts_files.map{|_path| Dir[_path]}.flatten

  @nodeset_file     = opts[:nodeset_file]     || File.expand_path('./spec/acceptance/nodesets/onceover-nodes.yml', @root)
  @role_regex       = opts[:role_regex]       ?  Regexp.new(opts[:role_regex]) : /role[s]?:{2}/
  @profile_regex    = opts[:profile_regex]    ?  Regexp.new(opts[:profile_regex]) : /profile[s]?:{2}/
  @tempdir          = opts[:tempdir]          || File.expand_path('./.onceover', @root)
  $temp_modulepath  = nil
  @opts             = opts
  logger.level = :debug if @opts[:debug]
  @@existing_controlrepo = self

  # Set the manifest option to the fully expanded path if it's used,
  # default to nil
  manifest = opts[:manifest] || config['manifest'] || nil
  if manifest
    @manifest = File.expand_path(manifest, @root)
  end
end