Class: Kitchen::Provisioner::Cfengine

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/cfengine.rb

Instance Method Summary collapse

Instance Method Details

#cfengine_quick_install_urlObject



115
116
117
118
119
120
121
# File 'lib/kitchen/provisioner/cfengine.rb', line 115

def cfengine_quick_install_url
  if config[:cfenging_type] == "community"
    config[:cfengine_community_quick_install_url]
  else
    config[:cfengine_enterprise_quick_install_url]
  end
end

#create_sandboxObject



24
25
26
27
# File 'lib/kitchen/provisioner/cfengine.rb', line 24

def create_sandbox
  super
  prepare_files
end

#init_commandObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kitchen/provisioner/cfengine.rb', line 34

def init_command
  if config[:cfengine_policy_server_address] == ""
    "      if [ ! -e \"/var/cfengine/policy_server.dat\" ]\n        then\n        LANG=en /sbin/ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }' | head -n 1 | xargs \#{sudo('/var/cfengine/bin/cf-agent')} --bootstrap\n      fi\n    INIT\n  else\n    <<-INIT\n      if [ ! -e \"/var/cfengine/policy_server.dat\" ]\n        then\n        \#{sudo('/var/cfengine/bin/cf-agent')} --bootstrap \#{config[:cfengine_policy_server_address]}\n      fi\n    INIT\n  end\nend\n"

#install_busserObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/kitchen/provisioner/cfengine.rb', line 100

def install_busser
  "  # install chef omnibus so that busser works as this is needed to run tests :(\n  # TODO: work out how to install enough ruby and set\n  # busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the\n  # whole chef client\n  if [ ! -d \"/opt/chef\" ]\n    then\n    echo \"-----> Installing Chef Omnibus to install busser to run tests\"\n    do_download \#{config[:chef_omnibus_url]} /tmp/install.sh\n    \#{sudo('sh')} /tmp/install.sh\n  fi\n  INSTALL\nend\n"

#install_cfengineObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/kitchen/provisioner/cfengine.rb', line 89

def install_cfengine
  "  if [ ! -d \"/var/cfengine\" ]\n    then\n    echo \"-----> Installing cfengine (\#{config[:cfenging_type]})\"\n    do_download \#{cfengine_quick_install_url} /tmp/install.sh\n    \#{sudo('sh')} /tmp/install.sh\n  fi\n  INSTALL\nend\n"

#install_commandObject



29
30
31
32
# File 'lib/kitchen/provisioner/cfengine.rb', line 29

def install_command
  lines = [Kitchen::Util.shell_helpers, install_cfengine, install_busser]
  lines.join("\n")
end

#prepare_commandObject



52
53
54
55
56
57
58
# File 'lib/kitchen/provisioner/cfengine.rb', line 52

def prepare_command
  "    \#{sudo('cp')} -rf \#{config[:root_path]}/* /var/cfengine\n    \#{sudo('/var/cfengine/bin/cf-agent')} -KI -f failsafe.cf\n    sleep 5\n  PREP\nend\n"

#prepare_filesObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/kitchen/provisioner/cfengine.rb', line 78

def prepare_files
  return unless config[:cfengine_files]

  info("Preparing cfengine files")
  debug("Using cfengine files from #{config[:cfengine_files]}")

  tmpdata_dir = File.join(sandbox_path, "cfengine_files")
  FileUtils.mkdir_p(tmpdata_dir)
  FileUtils.cp_r(Dir.glob("#{config[:cfengine_files]}/*"), tmpdata_dir)
end

#run_commandObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/kitchen/provisioner/cfengine.rb', line 60

def run_command
  cmd = [sudo("/var/cfengine/bin/cf-agent"), config[:cf_agent_args]]
  cmd << "-f" << config[:run_list] if config[:run_list].length > 0
  cmd = cmd.join(" ").strip
  if config[:cf_agent_runs].to_i > 1
    cmd = "      r=1\n      while [ $r -le \#{config[:cf_agent_runs]} ]\n      do\n        /bin/echo \"-----> cf-agent run $r\"\n        \#{cmd}\n        r=`expr $r + 1`\n      done\n    RUN\n  end\n  return cmd\nend\n"