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.



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

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 => 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
      logger.error('Unable to find fqdn')
      exit 1
    end
  end
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#userObject

Returns the value of attribute user.



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

def user
  @user
end

Class Method Details

.running?Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#latest_uploaded_refObject



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

def latest_uploaded_ref
  @state.ref
end

#latest_uploaded_ref=(ref) ⇒ Object



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

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

#portObject



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

def port
  @state.port
end

#port=(port) ⇒ Object



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

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

#restartObject



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

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



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

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



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

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