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, project_mount_point) ⇒ Box

Returns a new instance of Box.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


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

def applied?
  @applied
end

#apply(manifest) ⇒ Object

Raises:



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

def apply(manifest)
  exit_code = run_command("sudo puppet apply --detailed-exitcode --modulepath #{@project_mount_point}/#{manifest.module_path}", :stdin => manifest.puppet_code)
  raise PuppetApplyFailed unless exit_code == 0 or exit_code == 2
  @applied = true
end

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



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

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