Class: TasteTester::Server

Inherits:
Object
  • Object
show all
Extended by:
BetweenMeals::Util
Includes:
Config, Logging
Defined in:
lib/taste_tester/server.rb

Overview

Stateless chef-zero server management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#formatter, formatterproc=, logger, #logger, use_log_formatter=, verbosity=

Methods included from Config

chef_port, cookbooks, databags, relative_cookbook_dirs, relative_databag_dir, relative_role_dir, roles, testing_end_time

Constructor Details

#initializeServer

Returns a new instance of Server.



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
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/taste_tester/server.rb', line 35

def initialize
  @state = TasteTester::State.new
  @ref_file = TasteTester::Config.ref_file
  ref_dir = File.dirname(File.expand_path(@ref_file))
  @log_file = "#{ref_dir}/chef-zero.log"
  @zero_path = TasteTester::Config.chef_zero_path
  unless File.directory?(ref_dir)
    begin
      FileUtils.mkpath(ref_dir)
    rescue StandardError => e
      logger.warn("Chef temp dir #{ref_dir} missing and can't be created")
      logger.warn(e)
    end
  end

  @user = ENV['USER']

  # SSL and logging are obvious, but SSH is also required since it
  # determines if we listen only on localhost or not
  @need_restart = @state.ssl != TasteTester::Config.use_ssl ||
                  @state.logging != TasteTester::Config.chef_zero_logging ||
                  @state.ssh != TasteTester::Config.use_ssh_tunnels

  # If we are using SSH tunneling listen on localhost, otherwise listen
  # on all addresses - both v4 and v6. Note that on localhost, ::1 is
  # v6-only, so we default to 127.0.0.1 instead.
  if TasteTester::Config.use_ssh_tunnels
    @addr = '127.0.0.1'
    @host = 'localhost'
  else
    @addr = '::'
    begin
      @host = TasteTester::Config.my_hostname || Socket.gethostname
    rescue StandardError
      logger.error('Unable to find fqdn')
      exit 1
    end
  end
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



33
34
35
# File 'lib/taste_tester/server.rb', line 33

def host
  @host
end

#userObject

Returns the value of attribute user.



33
34
35
# File 'lib/taste_tester/server.rb', line 33

def user
  @user
end

Class Method Details

.running?Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
# File 'lib/taste_tester/server.rb', line 124

def self.running?
  if TasteTester::State.port
    return port_open?(TasteTester::State.port)
  end
  false
end

Instance Method Details

#latest_uploaded_refObject



116
117
118
# File 'lib/taste_tester/server.rb', line 116

def latest_uploaded_ref
  @state.ref
end

#latest_uploaded_ref=(ref) ⇒ Object



120
121
122
# File 'lib/taste_tester/server.rb', line 120

def latest_uploaded_ref=(ref)
  @state.ref = ref
end

#portObject



108
109
110
# File 'lib/taste_tester/server.rb', line 108

def port
  @state.port
end

#port=(port) ⇒ Object



112
113
114
# File 'lib/taste_tester/server.rb', line 112

def port=(port)
  @state.port = port
end

#restartObject



98
99
100
101
102
103
104
105
106
# File 'lib/taste_tester/server.rb', line 98

def restart
  logger.warn('Restarting taste-tester server')
  if TasteTester::Server.running?
    stop_chef_zero
    @state.ref = nil
  end
  write_config
  start_chef_zero
end

#startObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/taste_tester/server.rb', line 75

def start
  if TasteTester::Server.running?
    if @need_restart
      logger.warn('Restarting taste-tester server for config change')
      stop_chef_zero
      @need_restart = false
    else
      return
    end
  else
    logger.warn('Starting taste-tester server')
  end
  @state.wipe
  write_config
  start_chef_zero
end

#stopObject



92
93
94
95
96
# File 'lib/taste_tester/server.rb', line 92

def stop
  logger.warn('Stopping taste-tester server')
  @state.wipe
  stop_chef_zero
end