Class: InfraTestingHelpers::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/infra_testing_helpers/box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Box

Returns a new instance of Box.



4
5
6
7
# File 'lib/infra_testing_helpers/box.rb', line 4

def initialize(name)
  @name = name
  @applied = false
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/infra_testing_helpers/box.rb', line 9

def name
  @name
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/infra_testing_helpers/box.rb', line 19

def applied?
  @applied
end

#apply(manifest) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/infra_testing_helpers/box.rb', line 11

def apply(manifest)
  manifest.manifest_file do |file|
    exit_code = run_command("sudo puppet apply --detailed-exitcode --modulepath #{manifest.module_path} #{file}")
    raise PuppetApplyFailed unless exit_code == 0 or exit_code == 2
    @applied = true
  end
end

#run_command(command, opts = {}) ⇒ Object



24
25
26
27
28
# File 'lib/infra_testing_helpers/box.rb', line 24

def run_command(command, opts = {})
  stdin = opts[:stdin] ? " << EOF\n#{opts[:stdin]}\nEOF" : ""
  system "vagrant ssh #{@name} --command \"#{command}\"#{stdin}"
  $?.exitstatus
end