Module: KpnSpecMethods

Defined in:
lib/kpn_spec_methods.rb,
lib/kpn_spec_methods/version.rb

Overview

Static functions previously located in spec_helper_acceptance_methods.rb

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.clone_dependent_modulesObject

Fetches all modules from the fixtures file



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kpn_spec_methods.rb', line 5

def self.clone_dependent_modules
  fixtures = YAML.load_file('.fixtures.yml')['fixtures']
  fixtures['repositories'].each do |module_name, value|
    ssh_link =
      if value.is_a?(Hash)
        value['repo']
      else
        value
      end
    ref =
      if value.is_a?(Hash) and value.has_key?('ref')
        value['ref']
      else
        'master'
      end
    system("git clone --branch #{ref} #{ssh_link} spec/fixtures/modules/#{module_name}")
  end
end

.compress_copy_dependent_modulesObject

Quicker way to copy modules by archiving



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kpn_spec_methods.rb', line 51

def self.compress_copy_dependent_modules
  # Determine OS family for tar or zip usage
  os = host_inventory['facter']['kernel']
  if os == 'windows'
    compress_command = 'cd spec/fixtures/modules/; /usr/bin/zip -qr ../../../archive/modules.zip * -x *.git* ;cd -'
    extract_command = 'powershell.exe -nologo -noprofile -command "& { Add-Type -A \'System.IO.Compression.FileSystem\'; [IO.Compression.ZipFile]::ExtractToDirectory(\'C:\ProgramData\PuppetLabs\ccode\modules\modulesarchive\modules.zip\', \'C:\ProgramData\PuppetLabs\ccode\modules\\\'); }"'
  elsif os == 'Linux'
    compress_command = "cd spec/fixtures/modules/; /usr/bin/tar -cf ../../../archive/modules.tar * --exclude='*.git'; cd -"
    extract_command = 'tar -xf /etc/puppetlabs/code/modules/modulesarchive/modules.tar -C /etc/puppetlabs/code/modules/; rm -rf /etc/puppetlabs/code/modules/modulesarchive'
  else
    # Switch to old transfer if os is not found
    print "\033[31m Warning: OS family fact could not be determined for module copying \n"
    print "\033[31m Switching to sluggish old transfer... \n"
    install_dependent_modules
    return
  end

  # Archive the cloned modules
  system('mkdir archive') unless File.directory?('archive')
  system(compress_command)

  # Copy the archive to machine
  copy_module_to(hosts, source: 'archive', module_name: 'modulesarchive') if File.file?('archive/modules.tar' || 'archive/modules.zip')
  hosts.each do |host|
    on host, extract_command
  end
end

.install_dependent_modulesObject

Standard way to copy modules by individual file transfer



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kpn_spec_methods.rb', line 25

def self.install_dependent_modules
  fixtures = YAML.load_file('.fixtures.yml')['fixtures']
  fixtures['repositories'].each do |module_name, value|
    # Check metadata.json and only copy modules that support target OS
    copy_module = true
    if File.file?("./spec/fixtures/modules/#{module_name}/metadata.json")
       = JSON.parse(File.open("./spec/fixtures/modules/#{module_name}/metadata.json").read)
      if .key?("operatingsystem_support") and ["operatingsystem_support"].select { |os| os["operatingsystem"].downcase == fact('osfamily').downcase }.count == 0
        copy_module = false
      end
    end
    if copy_module
      copy_module_to(hosts, :source => "./spec/fixtures/modules/#{module_name}", :module_name => module_name)
    end
  end
end

.log_msg(msg) ⇒ Object



42
43
44
# File 'lib/kpn_spec_methods.rb', line 42

def self.log_msg(msg)
  default.logger.notify "# #{msg}"
end

.log_title(msg) ⇒ Object



46
47
48
# File 'lib/kpn_spec_methods.rb', line 46

def self.log_title(msg)
  default.logger.notify "###### #{msg} ######"
end