aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/test.rb
blob: da4a4b54bc45033f0fbecc7a277057442c2b38d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module LeapCli; module Commands

  desc 'Run tests.'
  command :test do |test|
    test.desc 'Creates files needed to run tests.'
    test.command :init do |init|
      init.action do |global_options,options,args|
        generate_test_client_openvpn_configs
      end
    end

    test.desc 'Run tests.'
    test.command :run do |run|
      run.switch 'continue', :desc => 'Continue over errors and failures (default is --no-continue).', :negatable => true
      run.action do |global_options,options,args|
        manager.filter!(args).each_node do |node|
          ssh_connect(node) do |ssh|
            ssh.run(test_cmd(options))
          end
        end
      end
    end

    test.default_command :run
  end

  private

  def test_cmd(options)
    if options[:continue]
      "#{PUPPET_DESTINATION}/bin/run_tests --continue"
    else
      "#{PUPPET_DESTINATION}/bin/run_tests"
    end
  end

  #
  # generates a whole bunch of openvpn configs that can be used to connect to different openvpn gateways
  #
  def generate_test_client_openvpn_configs
    assert_config! 'provider.ca.client_certificates.unlimited_prefix'
    assert_config! 'provider.ca.client_certificates.limited_prefix'
    template = read_file! Path.find_file(:test_client_openvpn_template)
    manager.environments.each do |env|
      vpn_nodes = manager.nodes[:environment => env][:services => 'openvpn']['openvpn.allow_limited' => true]
      if vpn_nodes.any?
        generate_test_client_cert(provider.ca.client_certificates.limited_prefix) do |key, cert|
          write_file! [:test_openvpn_config, [env, 'limited'].compact.join('_')], Util.erb_eval(template, binding)
        end
      end
      vpn_nodes = manager.nodes[:environment => env][:services => 'openvpn']['openvpn.allow_unlimited' => true]
      if vpn_nodes.any?
        generate_test_client_cert(provider.ca.client_certificates.unlimited_prefix) do |key, cert|
          write_file! [:test_openvpn_config, [env, 'unlimited'].compact.join('_')], Util.erb_eval(template, binding)
        end
      end
    end
  end

end; end