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

absolute_base_dir, 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
73
74
75
76
77
78
# 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 = File.join(ref_dir, 'chef-zero.log')
  @fsroot = File.join(ref_dir, 'root')
  @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
  if TasteTester::Config.bundle
    @bundle_dir = File.join(@fsroot, 'organizations/chef/file_store')
    FileUtils.mkpath(@bundle_dir)
  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 ||
                  @state.bundle != TasteTester::Config.bundle

  # 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
    @addrs = ['127.0.0.1']
    @host = 'localhost'
  else
    @addrs = ['::', '0.0.0.0']
    begin
      @host = TasteTester::Config.my_hostname || Socket.gethostname
    rescue StandardError
      logger.error('Unable to find fqdn')
      exit 1
    end
  end
end

Instance Attribute Details

#bundle_dirObject

Returns the value of attribute bundle_dir.



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

def bundle_dir
  @bundle_dir
end

#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)


137
138
139
140
141
142
143
144
# File 'lib/taste_tester/server.rb', line 137

def self.running?
  if TasteTester::State.port
    return chef_zero_running?(TasteTester::State.port,
                              TasteTester::Config.use_ssl)
  end

  false
end

Instance Method Details

#last_upload_timeObject



129
130
131
# File 'lib/taste_tester/server.rb', line 129

def last_upload_time
  @state.last_upload_time
end

#last_upload_time=(time) ⇒ Object



133
134
135
# File 'lib/taste_tester/server.rb', line 133

def last_upload_time=(time)
  @state.last_upload_time = time
end

#latest_uploaded_refObject



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

def latest_uploaded_ref
  @state.ref
end

#latest_uploaded_ref=(ref) ⇒ Object



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

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

#portObject



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

def port
  @state.port
end

#port=(port) ⇒ Object



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

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

#restartObject



103
104
105
106
107
108
109
110
111
# File 'lib/taste_tester/server.rb', line 103

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/taste_tester/server.rb', line 80

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



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

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