gaptool-server 0.6.0.beta1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f07c5a5a5853295749abfb9e33430dd54ad1678b
4
- data.tar.gz: 1b6082b74ddbe7bcd38efaa24a73b75ecc58f2e5
3
+ metadata.gz: e207c02d589d8bfb58e728c7b9b62aa529a4dafa
4
+ data.tar.gz: a260e393c04319f65e9d805c5b2efd67834dc264
5
5
  SHA512:
6
- metadata.gz: 9e86ef3243630f8e5633721d7c69c29471b887285c3156bc6984118f843aa9aff5ebd13bc9d92fedd2c0896500ca9944fff58a3849ab369fd04dd0e15b9c9051
7
- data.tar.gz: 44d38d87ccfc61820177391152663335f6a2f2c30ba8d268852ca7d7b2810001e248f5090069482e2c158d031bb07beffb4543858c4eedca4f986450ac39904a
6
+ metadata.gz: 029ec75667629cab21f13458344987e3c76430e9d7aba798b92d088bccdf0e0b339bb8f374ea1db7db30839b83ec5de7bb4f1621855db260b57f0ac7e0fab924
7
+ data.tar.gz: e80e3092bfd5d8fa3ae1fe44c09ed21a09a97794c1ee968b8fd395c7304554b8cceea10634abcd904a8375c6511cee49222f50be72e6f4f9dfa171b8580447f1
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'shellwords'
5
5
  require 'rspec/core/rake_task'
6
6
  require_relative 'lib/helpers/redis'
7
7
  require_relative 'lib/helpers/init'
8
+ require_relative 'lib/helpers/rehash'
8
9
 
9
10
  DH = Gaptool::Data
10
11
  $stdout.sync = true
@@ -20,15 +21,17 @@ end
20
21
 
21
22
  Dir.glob('tasks/*.rb').each { |r| load r}
22
23
 
23
- desc "Start the shell"
24
- task :shell do
25
- exec "racksh #{Shellwords.join(ARGV[1..-1])}"
26
- end
27
- task :sh => :shell
24
+ unless File.exists?('/.dockerenv')
25
+ desc "Start the shell"
26
+ task :shell do
27
+ exec "racksh #{Shellwords.join(ARGV[1..-1])}"
28
+ end
29
+ task :sh => :shell
28
30
 
29
- desc "Start the HTTP server"
30
- task :server do
31
- exec "unicorn #{Shellwords.join(ARGV[1..-1])}"
31
+ desc "Start the HTTP server"
32
+ task :server do
33
+ exec "unicorn #{Shellwords.join(ARGV[1..-1])}"
34
+ end
32
35
  end
33
36
 
34
37
  task :help do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0.beta1
1
+ 0.6.0
@@ -13,15 +13,15 @@ puts "Removing cruft"
13
13
  # First, remove cruft. Like all servers created but never registered, etc
14
14
  ['instance:*', '_*', 'apikey:*', 'service:*', 'running', 'ec2*',
15
15
  'failover', 'capacity', 'sg:*'].each do |pattern|
16
- $redis.keys(pattern).each do |key|
17
- $redis.del key
16
+ $redis.redis.keys(pattern).each do |key|
17
+ $redis.redis.del key
18
18
  end
19
19
  end
20
20
 
21
21
  puts "Migrating roles..."
22
- $redis.keys('role:*').each do |key|
22
+ $redis.redis.keys('role:*').each do |key|
23
23
  puts " - #{key}"
24
- data = $redis.hgetall(key)
24
+ data = $redis.redis.hgetall(key)
25
25
  role = key.sub('role:', '')
26
26
  unless data['ami'].nil?
27
27
  # We didn't have per-regin ami in roles, so
@@ -33,37 +33,40 @@ $redis.keys('role:*').each do |key|
33
33
  end
34
34
 
35
35
  puts "Migrating ami info to role..."
36
- $redis.keys('amis:*').each do |key|
36
+ $redis.redis.keys('amis:*').each do |key|
37
37
  role = key.sub("amis:", '')
38
38
  puts " - #{key}"
39
- amis = $redis.hgetall(key)
39
+ amis = $redis.redis.hgetall(key)
40
40
  roledata = DH.get_role_data(role)
41
41
  roledata['amis'] = amis.merge(roledata['amis'] || {})
42
42
  DH.save_role_data(role, roledata)
43
- $redis.del(key)
43
+ $redis.redis.del(key)
44
44
  end
45
45
 
46
46
  puts "Migrating apps..."
47
- $redis.keys('app:*').each do |key|
47
+ $redis.redis.keys('app:*').each do |key|
48
48
  puts " - #{key}"
49
49
  appname = key.sub('app:', '')
50
- role = $redis.hget(key, "role")
50
+ role = $redis.redis.hget(key, "role")
51
51
  if role.nil? || appname.nil?
52
52
  puts "Missing info for app: #{appname} role: #{role}"
53
53
  end
54
- $redis.del(key)
54
+ $redis.redis.del(key)
55
55
  DH.add_app(appname, role) unless role.nil?
56
56
  end
57
57
 
58
58
  puts "Migrating instances..."
59
- $redis.keys('host:*').each do |key|
59
+ $redis.redis.keys('host:*').each do |key|
60
60
  puts " - #{key}"
61
61
  pfx, role, env, iid = key.split(':')
62
- data = $redis.hgetall(key)
62
+ data = $redis.redis.hgetall(key)
63
63
  data['role'] = role
64
64
  data['environment'] = env
65
+ unless data['chef_runlist'].nil?
66
+ data['chef_runlist'] = JSON.parse data['chef_runlist']
67
+ end
65
68
  DH.addserver(iid, data, nil)
66
- $redis.del(key)
69
+ $redis.redis.del(key)
67
70
  # remove stale keys from hsh
68
71
  $redis.hdel "instance:#{iid}", ["capacity", "mirror", "secret", 'instance']
69
72
  end
@@ -84,6 +87,7 @@ $redis.smembers('instances').each do |inst|
84
87
  end
85
88
 
86
89
  puts "Rename old config keys"
90
+ $redis.redis.rename('config', 'gt:config')
87
91
  $redis.hset('config', 'chef_repo', $redis.hget('config', 'chefrepo'))
88
92
  $redis.hset('config', 'chef_branch', $redis.hget('config', 'chefbranch'))
89
93
 
@@ -93,4 +97,17 @@ puts "Removing old config keys"
93
97
  $redis.hdel 'config', key
94
98
  end
95
99
 
100
+ unless ARGV[0].nil?
101
+ puts "Updating GT_URL to #{ARGV[0]}"
102
+ $redis.hset('config', 'url', ARGV[0])
103
+ end
104
+
105
+ puts "Namespace remaining keys"
106
+ ['users', 'amis'].each { |k| $redis.redis.rename(k, "gt:#{k}")}
107
+
108
+ puts "Removing out-of-namespace keys"
109
+ $redis.redis.keys('*').select { |k| !k.start_with? ('gt:')}.each do |k|
110
+ $redis.redis.del(k)
111
+ end
112
+
96
113
  $redis.save
data/lib/app.rb CHANGED
@@ -54,6 +54,15 @@ class GaptoolServer < Sinatra::Application
54
54
  raise Unauthenticated unless user[:key] == env['HTTP_X_GAPTOOL_KEY']
55
55
  end
56
56
  end
57
+
58
+ after do
59
+ # Fix for old versions of gaptool-api
60
+ if request.preferred_type.to_str == "application/json"
61
+ content_type "application/json"
62
+ else
63
+ content_type 'text/html'
64
+ end
65
+ end
57
66
  end
58
67
 
59
68
  require_relative 'helpers/init'
data/lib/helpers/data.rb CHANGED
@@ -44,6 +44,11 @@ module Gaptool
44
44
  end
45
45
  end
46
46
 
47
+ def self.set_server_data_attr(instance, attr, value)
48
+ return if value.nil? || (value.is_a?(String) && value.empty?) || !!value == value
49
+ $redis.hset("instance:#{instance}", attr, value)
50
+ end
51
+
47
52
  def self.save_server_data(instance, data)
48
53
 
49
54
  unless data['chef_runlist'].nil?
@@ -97,8 +102,23 @@ module Gaptool
97
102
  $redis.hget('config', key)
98
103
  end
99
104
 
105
+ def self.ensure_config(key, default)
106
+ cur = get_config(key)
107
+ cur = set_config(key, default) if cur.nil? || cur.empty?
108
+ cur
109
+ end
110
+
100
111
  def self.set_config(key, value)
101
112
  $redis.hset('config', key, value)
113
+ value
114
+ end
115
+
116
+ def self.del_config(key)
117
+ $redis.hdel('config', key)
118
+ end
119
+
120
+ def self.get_all_configs
121
+ $redis.hgetall('config')
102
122
  end
103
123
 
104
124
  def self.get_server_data(instance, opts={})
@@ -235,6 +255,13 @@ module Gaptool
235
255
  $redis.smembers("role:#{role}:apps")
236
256
  end
237
257
 
258
+ def self.stringify_apps(rs)
259
+ unless rs['apps'].nil?
260
+ rs['apps'] = rs['apps'].to_json
261
+ end
262
+ rs
263
+ end
264
+
238
265
  def self.useradd(user, key=nil)
239
266
  key = SecureRandom.hex(64) unless key
240
267
  $redis.hset('users', user, key)
data/lib/helpers/ec2.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'aws-sdk'
1
2
  require 'securerandom'
2
3
 
3
4
  # encoding: utf-8
@@ -45,14 +46,25 @@ module Gaptool
45
46
  end
46
47
 
47
48
  def self.create_ec2_instance(ec2opts, data)
48
- return "i-test#{SecureRandom.hex(2)}" if ENV['DRYRUN']
49
- configure_ec2 data['zone'].chop
49
+ if ENV['DRYRUN']
50
+ id = "i-test#{SecureRandom.hex(2)}"
51
+ return {id: id,
52
+ hostname: "test-#{id}.#{data[:zone].chop}.compute.amazonaws.com",
53
+ launch_time: Time.now.to_s}
54
+ end
55
+ configure_ec2 data[:zone].chop
50
56
  ec2 = AWS::EC2.new
51
57
 
52
- instance = ec2.instances.create(opts)
58
+ instance = ec2.instances.create(ec2opts)
53
59
  instance.add_tag('Name', value: "#{data[:role]}-#{data[:env]}-#{instance.id}")
54
60
  instance.add_tag('gaptool', :value => "yes")
55
- instance.id
61
+ launch_time = instance.launch_time.to_s
62
+ launch_time = launch_time.empty? ? Time.now.to_s : launch_time
63
+ {
64
+ id: instance.id,
65
+ hostname: instance.public_dns_name,
66
+ launch_time: launch_time
67
+ }
56
68
  end
57
69
 
58
70
  def self.terminate_ec2_instance(zone, id)
@@ -73,7 +85,7 @@ module Gaptool
73
85
  ec2 = AWS::EC2.new
74
86
  instance = ec2.instances[id]
75
87
  return {
76
- dns_name: instance.dns_name
88
+ hostname: instance.dns_name
77
89
  }
78
90
  end
79
91
  end
data/lib/helpers/redis.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'redis'
2
+ require 'redis-namespace'
2
3
 
3
4
  # docker links support
4
5
  unless ENV['REDIS_PORT_6379_TCP_ADDR'].nil?
@@ -12,8 +13,11 @@ ENV['REDIS_PORT'] = '6379' unless ENV['REDIS_PORT']
12
13
  ENV['REDIS_PASS'] = nil unless ENV['REDIS_PASS']
13
14
  ENV['REDIS_DB'] = '0' unless ENV['REDIS_DB']
14
15
 
15
- $redis = Redis.new(:host => ENV['REDIS_HOST'],
16
- :port => ENV['REDIS_PORT'].to_i,
17
- :password => ENV['REDIS_PASS'],
18
- :db => ENV['REDIS_DB'].to_i)
16
+ prefix = ENV.fetch('REDIS_PREFIX', 'gt')
19
17
 
18
+ conn = Redis.new(:host => ENV['REDIS_HOST'],
19
+ :port => ENV['REDIS_PORT'].to_i,
20
+ :password => ENV['REDIS_PASS'],
21
+ :db => ENV['REDIS_DB'].to_i)
22
+
23
+ $redis = Redis::Namespace.new(prefix, redis: conn)
@@ -1,15 +1,16 @@
1
+ require_relative "ec2"
2
+ require_relative "data"
3
+
1
4
  module Gaptool
2
5
  module EC2
3
6
  def self.rehash()
4
- servers.each do |inst|
5
- rmserver inst
7
+ Gaptool::Data::servers.each do |inst|
8
+ Gaptool::Data::rmserver inst
6
9
  end
7
- layout = roles()
8
- puts layout
9
- zones.each do |zone|
10
- @ec2 = AWS::EC2.new(:access_key_id => $redis.hget('config', 'aws_id'),
11
- :secret_access_key => $redis.hget('config', 'aws_secret'),
12
- :ec2_endpoint => "ec2.#{zone}.amazonaws.com")
10
+ roles = Gaptool::Data::roles
11
+ Gaptool::Data::zones.each do |zone|
12
+ Gaptool::EC2::configure_ec2 zone
13
+ @ec2 = AWS::EC2.new
13
14
  ilist = []
14
15
  @ec2.instances.each do |instance|
15
16
  if instance.tags['gaptool'] == 'yes' && instance.status == :running
@@ -18,18 +19,17 @@ module Gaptool
18
19
  end
19
20
  ilist.each do |instance|
20
21
  puts " - #{instance.tags['Name']}"
21
- role, environment, iid = instance.tags['Name'].split('-')
22
+ role, environment, iid = instance.tags['Name'].split('-', 3)
22
23
  data = {
23
24
  "zone"=> instance.availability_zone,
24
- "itype"=> instance.instance_type,
25
25
  "role"=> role,
26
26
  "environment"=> environment,
27
- "hostname"=> instance.public_dns_name,
28
- "apps" => layout[role].to_s,
27
+ "hostname" => instance.public_dns_name,
28
+ "launch_time" => instance.launch_time.to_s,
29
+ "apps" => roles[role].to_s,
29
30
  "instance"=> instance.instance_id
30
31
  }
31
- puts data
32
- addserver(data['instance'], data, nil)
32
+ Gaptool::Data::addserver(iid, data, nil)
33
33
  end
34
34
  end
35
35
  return {"action" => "complete"}
data/lib/routes.rb CHANGED
@@ -31,15 +31,16 @@ class GaptoolServer < Sinatra::Application
31
31
  sgid = Gaptool::EC2::get_or_create_securitygroup(data['role'], data['environment'], data['zone'], security_group)
32
32
  image_id = data['ami'] || Gaptool::Data::get_ami_for_role(data['role'], data['zone'].chop)
33
33
  data['terminable'] = data['terminable'].nil? ? true : !!data['terminable']
34
+ data['secret'] = secret
34
35
 
35
- id = Gaptool::EC2::create_ec2_instance(
36
+ instance = Gaptool::EC2::create_ec2_instance(
36
37
  {
37
38
  :image_id => image_id,
38
39
  :availability_zone => data['zone'],
39
40
  :instance_type => data['itype'],
40
41
  :key_name => "gaptool",
41
42
  :security_group_ids => sgid,
42
- :user_data => "#!/bin/bash\ncurl --silent -H 'X-GAPTOOL-USER: #{env['HTTP_X_GAPTOOL_USER']}' -H 'X-GAPTOOL-KEY: #{env['HTTP_X_GAPTOOL_KEY']}' #{$redis.hget('config', 'url')}/register -X PUT --data '#{data.to_json}' | bash"
43
+ :user_data => "#!/bin/bash\ncurl --silent -H 'X-GAPTOOL-USER: #{env['HTTP_X_GAPTOOL_USER']}' -H 'X-GAPTOOL-KEY: #{env['HTTP_X_GAPTOOL_KEY']}' #{Gaptool::Data.get_config('url')}/register -X PUT --data '#{data.to_json}' | bash"
43
44
  }, {
44
45
  role: data['role'],
45
46
  env: data['environment'],
@@ -47,10 +48,13 @@ class GaptoolServer < Sinatra::Application
47
48
  }
48
49
  )
49
50
  # Add host tag
50
- Gaptool::Data::addserver(id, data, secret)
51
- json({instance: id,
51
+ data.merge(instance.reject { |k, v| k == :id })
52
+ Gaptool::Data::addserver(instance[:id], data, secret)
53
+ json({instance: instance[:id],
52
54
  ami: image_id,
53
55
  role: data['role'],
56
+ hostname: instance[:hostname],
57
+ launch_time: instance[:launch_time],
54
58
  environment: data['environment'],
55
59
  secret: secret,
56
60
  terminable: data['terminable'],
@@ -77,13 +81,15 @@ class GaptoolServer < Sinatra::Application
77
81
  raise Forbidden, "Can't register instance: wrong secret or missing role/environment" unless instance_id
78
82
 
79
83
  hostname = Gaptool::EC2::get_ec2_instance_data(data['zone'].chop, instance_id)[:hostname]
84
+ Gaptool::Data.set_server_data_attr(instance_id, "hostname", hostname)
80
85
  host_data = Gaptool::Data::get_server_data instance_id, initkey: true, force_runlist: true
81
86
 
82
87
  chef_repo = host_data['chef_repo']
83
88
  chef_branch = host_data['chef_branch']
89
+ chef_environment = host_data['environment']
84
90
  # FIXME: remove init key from redis
85
- initkey = host_data['init_key']
86
- run_list = host_data['chef_runlist'].to_json
91
+ initkey = Gaptool::Data::get_config("initkey")
92
+ run_list = host_data['chef_runlist']
87
93
 
88
94
  jdata = {
89
95
  'hostname' => hostname,
@@ -104,6 +110,8 @@ class GaptoolServer < Sinatra::Application
104
110
  initkey: initkey,
105
111
  chef_branch: chef_branch,
106
112
  chef_repo: chef_repo,
113
+ chef_environment: chef_environment,
114
+ chef_version: Gaptool::Data::ensure_config("chef_version", "11.16.4"),
107
115
  json: jdata
108
116
  }
109
117
  end
@@ -111,14 +119,14 @@ class GaptoolServer < Sinatra::Application
111
119
  get '/hosts' do
112
120
  servers = Gaptool::Data::servers.map do |inst|
113
121
  Gaptool::Data::get_server_data inst
114
- end
122
+ end.select{ |s| !s['registered']}
115
123
  json servers
116
124
  end
117
125
 
118
126
  get '/apps' do
119
127
  out = {}
120
128
  Gaptool::Data.apps.each do |app|
121
- out[app] = Gaptool::Data::get_app_data(app)
129
+ out["app:#{app}"] = Gaptool::Data::get_app_data(app)
122
130
  end
123
131
  json out
124
132
  end
@@ -126,12 +134,12 @@ class GaptoolServer < Sinatra::Application
126
134
  get '/hosts/:role' do
127
135
  servers = Gaptool::Data::servers_in_role(params[:role]).map do |inst|
128
136
  Gaptool::Data::get_server_data inst
129
- end
137
+ end.select{ |s| !s['registered'] }
130
138
  json servers
131
139
  end
132
140
 
133
141
  get '/instance/:id' do
134
- json Gaptool::Data::get_server_data(params[:id])
142
+ json Gaptool::Data::stringify_apps(Gaptool::Data::get_server_data(params[:id]))
135
143
  end
136
144
 
137
145
  get '/hosts/:role/:environment' do
@@ -141,14 +149,14 @@ class GaptoolServer < Sinatra::Application
141
149
  list = Gaptool::Data::servers_in_role_env params[:role], params[:environment]
142
150
  end
143
151
  servers = list.map do |inst|
144
- Gaptool::Data::get_server_data inst
152
+ Gaptool::Data::stringify_apps(Gaptool::Data::get_server_data(inst))
145
153
  end
146
154
 
147
155
  json servers
148
156
  end
149
157
 
150
158
  get '/host/:role/:environment/:instance' do
151
- json Gaptool::Data::get_server_data params[:instance]
159
+ json Gaptool::Data::stringify_apps(Gaptool::Data::get_server_data(params[:instance]))
152
160
  end
153
161
 
154
162
  get '/ssh/:role/:environment/:instance' do
@@ -166,7 +174,7 @@ class GaptoolServer < Sinatra::Application
166
174
  end
167
175
 
168
176
  post '/rehash' do
169
- json Gaptool::Rehash::rehash()
177
+ json Gaptool::EC2::rehash()
170
178
  end
171
179
 
172
180
  end
data/lib/views/init.erb CHANGED
@@ -1,12 +1,18 @@
1
+ #!/bin/bash
2
+ set -e
3
+ cd /root
1
4
  apt-get update
2
5
  apt-get install -ymq zsh git libssl-dev ruby1.9.1-full build-essential
3
- gem install --bindir /usr/local/bin --no-ri --no-rdoc chef
6
+ curl -LO https://www.getchef.com/chef/install.sh
7
+ bash install.sh -v <%= chef_version %>
8
+
4
9
  cat << 'EOFKEY' > /root/.ssh/id_rsa
5
10
  <%= initkey %>
6
11
  EOFKEY
7
12
  chmod 600 /root/.ssh/id_rsa
8
13
  echo 'StrictHostKeyChecking no' > /root/.ssh/config
14
+
9
15
  git clone -b <%= chef_branch %> <%= chef_repo %> /root/ops
10
16
  echo '<%= json %>' > /root/init.json
11
- chef-solo -c /root/ops/cookbooks/init.rb -j /root/init.json && \
17
+ chef-solo -c /root/ops/cookbooks/init.rb -j /root/init.json -E <%= chef_environment %> && \
12
18
  (rm /root/.ssh/id_rsa; userdel -r ubuntu; rm -rf /root/.ssh; rm -rf /root/ops)
data/tasks/config.rb ADDED
@@ -0,0 +1,24 @@
1
+ namespace :config do
2
+ desc "Add or update a new config key"
3
+ task :set, [:key,:value] do |t, args|
4
+ DH.set_config(args[:key], args[:value])
5
+ end
6
+
7
+ desc "Delete a key if set"
8
+ task :del, [:key] do |t, args|
9
+ DH.del_config(args[:key])
10
+ end
11
+
12
+ desc "Get a config"
13
+ task :get, [:key] do |t,args|
14
+ DH.get_config(args[:key])
15
+ end
16
+ end
17
+
18
+ desc "List config"
19
+ task :config do
20
+ puts 'Config:'
21
+ DH.get_all_configs().keys.each do |k|
22
+ puts " - #{k}"
23
+ end
24
+ end
data/tasks/docker.rb CHANGED
@@ -43,6 +43,11 @@ unless File.exists?('/.dockerenv')
43
43
  sys(%w(fig run --rm gaptool rake test))
44
44
  end
45
45
 
46
+ desc "Rehash instances"
47
+ task :rehash => :build do
48
+ sys(%w(fig run --rm gaptool rake rehash))
49
+ end
50
+
46
51
  desc "Stop docker containers"
47
52
  task :stop do
48
53
  sys(%w(fig stop))
data/tasks/gem.rb CHANGED
@@ -1,27 +1,30 @@
1
- namespace :gem do
1
+ unless File.exists?('/.dockerenv')
2
+ namespace :gem do
2
3
 
3
- desc "Build the gem"
4
- task :build => :clean do
5
- sys(%w(gem build gaptool-server.gemspec))
6
- end
4
+ desc "Build the gem"
5
+ task :build => :clean do
6
+ sys(%w(gem build gaptool-server.gemspec))
7
+ end
7
8
 
8
- desc "Clean built file"
9
- task :clean do
10
- sys(%w(rm -vf *.gem))
11
- end
9
+ desc "Clean built file"
10
+ task :clean do
11
+ sys(%w(rm -vf *.gem))
12
+ end
12
13
 
13
- desc "Bump the version"
14
- task :bump do
15
- version = File.read('VERSION').strip
16
- nver = version.next
17
- f = File.open('VERSION', 'w')
18
- f.write(nver)
19
- f.close
20
- puts "Bumped #{version} => #{nver}"
21
- end
14
+ desc "Bump the version"
15
+ task :bump do
16
+ version = File.read('VERSION').strip
17
+ nver = version.next
18
+ f = File.open('VERSION', 'w')
19
+ f.write(nver)
20
+ f.close
21
+ puts "Bumped #{version} => #{nver}"
22
+ end
22
23
 
23
- desc "Push"
24
- task :push => :build do
25
- sys(%w(gem push gaptool-server*.gem))
24
+ desc "Push"
25
+ task :push => :build do
26
+ version = File.read('VERSION').strip
27
+ sys(%W(gem push gaptool-server-#{version}.gem))
28
+ end
26
29
  end
27
30
  end
data/test/api_test.rb CHANGED
@@ -44,7 +44,8 @@ describe "Test API" do
44
44
  'chef_runlist' => ['recipe[myrecipe]'],
45
45
  'terminable' => true,
46
46
  'zone' => 'my-zone-1a',
47
- 'itype' => 'm1.type'
47
+ 'itype' => 'm1.type',
48
+ "hostname" => 'fake.hostname.gild.com'
48
49
  }
49
50
  end
50
51
 
@@ -55,13 +56,18 @@ describe "Test API" do
55
56
  it "should return 200" do
56
57
  get '/'
57
58
  expect(last_response.status).to eq(200)
59
+ expect(last_response.content_type).to include('text/html')
60
+
61
+ header 'Accept', 'application/json'
62
+ get '/'
63
+ expect(last_response.status).to eq(200)
64
+ expect(last_response.content_type).to include('application/json')
58
65
  end
59
66
 
60
67
  it "should create a instance" do
61
68
  post '/init', host_data.to_json
62
69
  expect(last_response.status).to eq(200)
63
- expect(last_response.content_type).to eq('application/json')
64
- expect(JSON.parse(last_response.body).keys).to eq(["instance", "ami", "role", "environment", "secret", "terminable", "security_group"])
70
+ expect(JSON.parse(last_response.body).keys).to eq(["instance", "ami", "role", "hostname", "launch_time", "environment", "secret", "terminable", "security_group"])
65
71
  end
66
72
 
67
73
  it "should get the runlist from the role" do
@@ -162,6 +168,20 @@ describe "Test API" do
162
168
 
163
169
  it "should register the server" do
164
170
  add_and_register_server
171
+ expect(last_response.body).to include("-E #{host_data['environment']}")
172
+ end
173
+
174
+ it "should not find any hosts" do
175
+ post '/init', host_data.to_json
176
+ expect(last_response.status).to eq(200)
177
+
178
+ get '/hosts'
179
+ expect(last_response.status).to eq(200)
180
+ expect(JSON.parse(last_response.body)).to eq([])
181
+
182
+ get "/hosts/#{host_data['role']}"
183
+ expect(last_response.status).to eq(200)
184
+ expect(JSON.parse(last_response.body)).to eq([])
165
185
  end
166
186
 
167
187
  it "should find an host" do
@@ -190,7 +210,7 @@ describe "Test API" do
190
210
  it "should find an host by role" do
191
211
  other = host_data.merge({'role' => 'otherrole'})
192
212
  id1 = add_and_register_server(other)['instance']
193
- id2 = add_and_register_server()['instance']
213
+ add_and_register_server()['instance']
194
214
 
195
215
  get '/hosts/otherrole'
196
216
  expect(last_response.status).to eq(200)
@@ -214,7 +234,7 @@ describe "Test API" do
214
234
  it "should find all hosts by environment and role" do
215
235
  id1 = add_and_register_server()['instance']
216
236
  id2 = add_and_register_server()['instance']
217
- id3 = add_and_register_server(host_data.merge({'environment' => 'otherenv'}))['instance']
237
+ add_and_register_server(host_data.merge({'environment' => 'otherenv'}))['instance']
218
238
  id4 = add_and_register_server(host_data.merge({'role' => 'otherrole'}))['instance']
219
239
  get '/hosts/testrole/testenv'
220
240
  expect(last_response.status).to eq(200)
@@ -247,8 +267,8 @@ describe "Test API" do
247
267
  it "should return the list of apps" do
248
268
  DH.add_app("firstapp", "testrole")
249
269
  DH.add_app("secondapp", "testrole")
250
- apps_list = {"firstapp" => {"role" => "testrole"},
251
- "secondapp" =>{"role" => "testrole"}}
270
+ apps_list = {"app:firstapp" => {"role" => "testrole"},
271
+ "app:secondapp" =>{"role" => "testrole"}}
252
272
  get "/apps"
253
273
  expect(last_response.status).to eq(200)
254
274
  expect(JSON.parse(last_response.body)).to eq(apps_list)
data/test/data_test.rb CHANGED
@@ -9,6 +9,11 @@ describe "data helpers" do
9
9
  DH.set_config('chef_branch', 'master')
10
10
  end
11
11
 
12
+ after(:all) do
13
+ keys = $redis.redis.keys('*').select{|k| !k.start_with?('gt:')}
14
+ expect(keys).to eq([])
15
+ end
16
+
12
17
  def data
13
18
  {
14
19
  'role' => "role",
data/test/test_helper.rb CHANGED
@@ -11,6 +11,7 @@ libpath = File.realpath(File.join(File.dirname(__FILE__), "..", "lib"))
11
11
  require 'rspec'
12
12
  require 'rack/test'
13
13
  require 'fakeredis/rspec'
14
+ require 'redis-namespace'
14
15
  require "#{libpath}/app.rb"
15
16
 
16
17
  RSpec.configure do |conf|
@@ -22,4 +23,5 @@ end
22
23
 
23
24
  DH = Gaptool::Data
24
25
 
25
- $redis = Redis.new
26
+ conn = Redis.new
27
+ $redis = Redis::Namespace.new(:gt, redis:conn)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaptool-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.beta1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Bailey
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-10-14 00:00:00.000000000 Z
13
+ date: 2014-12-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -152,6 +152,20 @@ dependencies:
152
152
  - - "~>"
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0.10'
155
+ - !ruby/object:Gem::Dependency
156
+ name: redis-namespace
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '1.5'
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '1.5'
155
169
  - !ruby/object:Gem::Dependency
156
170
  name: rspec
157
171
  requirement: !ruby/object:Gem::Requirement
@@ -239,6 +253,7 @@ files:
239
253
  - lib/routes.rb
240
254
  - lib/views/init.erb
241
255
  - tasks/app.rb
256
+ - tasks/config.rb
242
257
  - tasks/docker.rb
243
258
  - tasks/gem.rb
244
259
  - tasks/user.rb
@@ -266,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
281
  version: '0'
267
282
  requirements: []
268
283
  rubyforge_project:
269
- rubygems_version: 2.2.2
284
+ rubygems_version: 2.4.3
270
285
  signing_key:
271
286
  specification_version: 4
272
287
  summary: gaptool-server for managing cloud resources