vmpooler 3.4.0 → 3.5.1

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
  SHA256:
3
- metadata.gz: 928e0c76962d0ebbc7c3944ab16a0c03597f26e49b8132f4243110eae3794102
4
- data.tar.gz: 89d63548f801b69578ad0c05333839e705efc848f97594af5e24e05ecff49f99
3
+ metadata.gz: abc6c0e799944bad6d5f766f21a5fd55038daf2741604a79dbf1dd409a4c6f54
4
+ data.tar.gz: 6977e9af54319329a9a526e0dfea5d39b453c57f391a24782f64fbf70f3cc300
5
5
  SHA512:
6
- metadata.gz: ffc00f6b5d6f034aff3be29d48e14087a7e19202bf25c14a434f428848d9386dcca4a12a3add327b33843c36761adefe462ffa5f3017328eaca7bf4adfa2f6ab
7
- data.tar.gz: 3d30c947ec9a3ce254435b4131bc7bf949740bf61aa30f297f35410a0297f3740e2fb8d5c2deb88bfaf4e6a662823afb66f51fa44e8547f54d76c72af34e48e7
6
+ metadata.gz: 33c3cea211a61f072498adbeff5c2ea8b9862e9dee8cac3a38b0f2757492a8df7ed7b8150b7213777b597804c235ea61c12eaeeed5a3c0907053d2f5111746a6
7
+ data.tar.gz: 28785ede40fdc245732195a6beeea9e4bced0c0d85fc54d12bfe6b6e931c50dc1d81942bd540201bcc33ff07ae876114b82524b47567314fbf1e1883e96252a6
@@ -68,7 +68,7 @@ module Vmpooler
68
68
  end
69
69
  end
70
70
 
71
- def authenticate_ldap(port, host, encryption_hash, user_object, base, username_str, password_str)
71
+ def authenticate_ldap(port, host, encryption_hash, user_object, base, username_str, password_str, service_account_hash = nil)
72
72
  tracer.in_span(
73
73
  "Vmpooler::API::Helpers.#{__method__}",
74
74
  attributes: {
@@ -79,6 +79,14 @@ module Vmpooler
79
79
  },
80
80
  kind: :client
81
81
  ) do
82
+ if service_account_hash
83
+ username = service_account_hash[:user_dn]
84
+ password = service_account_hash[:password]
85
+ else
86
+ username = "#{user_object}=#{username_str},#{base}"
87
+ password = password_str
88
+ end
89
+
82
90
  ldap = Net::LDAP.new(
83
91
  :host => host,
84
92
  :port => port,
@@ -86,12 +94,22 @@ module Vmpooler
86
94
  :base => base,
87
95
  :auth => {
88
96
  :method => :simple,
89
- :username => "#{user_object}=#{username_str},#{base}",
90
- :password => password_str
97
+ :username => username,
98
+ :password => password
91
99
  }
92
100
  )
93
101
 
94
- return true if ldap.bind
102
+ if service_account_hash
103
+ return true if ldap.bind_as(
104
+ :base => base,
105
+ :filter => "(#{user_object}=#{username_str})",
106
+ :password => password_str
107
+ )
108
+ elsif ldap.bind
109
+ return true
110
+ else
111
+ return false
112
+ end
95
113
 
96
114
  return false
97
115
  end
@@ -116,6 +134,7 @@ module Vmpooler
116
134
  :method => :start_tls,
117
135
  :tls_options => { :ssl_version => 'TLSv1' }
118
136
  }
137
+ service_account_hash = auth[:ldap]['service_account_hash']
119
138
 
120
139
  unless ldap_base.is_a? Array
121
140
  ldap_base = ldap_base.split
@@ -134,7 +153,8 @@ module Vmpooler
134
153
  search_user_obj,
135
154
  search_base,
136
155
  username_str,
137
- password_str
156
+ password_str,
157
+ service_account_hash
138
158
  )
139
159
  return true if result
140
160
  end
@@ -283,11 +283,9 @@ module Vmpooler
283
283
  def update_user_metrics(operation, vmname)
284
284
  tracer.in_span("Vmpooler::API::V3.#{__method__}") do |span|
285
285
  begin
286
- backend.multi
287
- backend.hget("vmpooler__vm__#{vmname}", 'tag:jenkins_build_url')
288
- backend.hget("vmpooler__vm__#{vmname}", 'token:user')
289
- backend.hget("vmpooler__vm__#{vmname}", 'template')
290
- jenkins_build_url, user, poolname = backend.exec
286
+ jenkins_build_url = backend.hget("vmpooler__vm__#{vmname}", 'tag:jenkins_build_url')
287
+ user = backend.hget("vmpooler__vm__#{vmname}", 'token:user')
288
+ poolname = backend.hget("vmpooler__vm__#{vmname}", 'template')
291
289
  poolname = poolname.gsub('.', '_')
292
290
 
293
291
  if user
@@ -82,21 +82,21 @@ module Vmpooler
82
82
  end
83
83
 
84
84
  # Check the state of a VM
85
- def check_pending_vm(vm, pool, timeout, provider)
85
+ def check_pending_vm(vm, pool, timeout, timeout_notification, provider)
86
86
  Thread.new do
87
87
  begin
88
- _check_pending_vm(vm, pool, timeout, provider)
88
+ _check_pending_vm(vm, pool, timeout, timeout_notification, provider)
89
89
  rescue StandardError => e
90
90
  $logger.log('s', "[!] [#{pool}] '#{vm}' #{timeout} #{provider} errored while checking a pending vm : #{e}")
91
91
  @redis.with_metrics do |redis|
92
- fail_pending_vm(vm, pool, timeout, redis)
92
+ fail_pending_vm(vm, pool, timeout, timeout_notification, redis)
93
93
  end
94
94
  raise
95
95
  end
96
96
  end
97
97
  end
98
98
 
99
- def _check_pending_vm(vm, pool, timeout, provider)
99
+ def _check_pending_vm(vm, pool, timeout, timeout_notification, provider)
100
100
  mutex = vm_mutex(vm)
101
101
  return if mutex.locked?
102
102
 
@@ -106,7 +106,7 @@ module Vmpooler
106
106
  if provider.vm_ready?(pool, vm, redis)
107
107
  move_pending_vm_to_ready(vm, pool, redis, request_id)
108
108
  else
109
- fail_pending_vm(vm, pool, timeout, redis)
109
+ fail_pending_vm(vm, pool, timeout, timeout_notification, redis)
110
110
  end
111
111
  end
112
112
  end
@@ -122,35 +122,55 @@ module Vmpooler
122
122
  $logger.log('d', "[!] [#{pool}] '#{vm}' no longer exists. Removing from pending.")
123
123
  end
124
124
 
125
- def fail_pending_vm(vm, pool, timeout, redis, exists: true)
125
+ def fail_pending_vm(vm, pool, timeout, timeout_notification, redis, exists: true)
126
126
  clone_stamp = redis.hget("vmpooler__vm__#{vm}", 'clone')
127
-
128
127
  time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60
129
- if time_since_clone > timeout
130
- if exists
131
- request_id = redis.hget("vmpooler__vm__#{vm}", 'request_id')
132
- pool_alias = redis.hget("vmpooler__vm__#{vm}", 'pool_alias') if request_id
133
- open_socket_error = redis.hget("vmpooler__vm__#{vm}", 'open_socket_error')
134
- redis.smove("vmpooler__pending__#{pool}", "vmpooler__completed__#{pool}", vm)
135
- if request_id
136
- ondemandrequest_hash = redis.hgetall("vmpooler__odrequest__#{request_id}")
137
- if ondemandrequest_hash && ondemandrequest_hash['status'] != 'failed' && ondemandrequest_hash['status'] != 'deleted'
138
- # will retry a VM that did not come up as vm_ready? only if it has not been market failed or deleted
139
- redis.zadd('vmpooler__odcreate__task', 1, "#{pool_alias}:#{pool}:1:#{request_id}")
140
- end
141
- end
142
- $metrics.increment("errors.markedasfailed.#{pool}")
143
- $logger.log('d', "[!] [#{pool}] '#{vm}' marked as 'failed' after #{timeout} minutes with error: #{open_socket_error}")
144
- else
128
+
129
+ already_timed_out = time_since_clone > timeout
130
+ timing_out_soon = time_since_clone > timeout_notification && !redis.hget("vmpooler__vm__#{vm}", 'timeout_notification')
131
+
132
+ return true if !already_timed_out && !timing_out_soon
133
+
134
+ if already_timed_out
135
+ unless exists
145
136
  remove_nonexistent_vm(vm, pool, redis)
137
+ return true
146
138
  end
139
+ open_socket_error = handle_timed_out_vm(vm, pool, redis)
147
140
  end
141
+
142
+ redis.hset("vmpooler__vm__#{vm}", 'timeout_notification', 1) if timing_out_soon
143
+
144
+ nonexist_warning = if already_timed_out
145
+ "[!] [#{pool}] '#{vm}' marked as 'failed' after #{timeout} minutes with error: #{open_socket_error}"
146
+ elsif timing_out_soon
147
+ "[!] [#{pool}] '#{vm}' no longer exists when attempting to send notification of impending failure"
148
+ else
149
+ "[!] [#{pool}] '#{vm}' This error is wholly unexpected"
150
+ end
151
+ $logger.log('d', nonexist_warning)
148
152
  true
149
153
  rescue StandardError => e
150
154
  $logger.log('d', "Fail pending VM failed with an error: #{e}")
151
155
  false
152
156
  end
153
157
 
158
+ def handle_timed_out_vm(vm, pool, redis)
159
+ request_id = redis.hget("vmpooler__vm__#{vm}", 'request_id')
160
+ pool_alias = redis.hget("vmpooler__vm__#{vm}", 'pool_alias') if request_id
161
+ open_socket_error = redis.hget("vmpooler__vm__#{vm}", 'open_socket_error')
162
+ redis.smove("vmpooler__pending__#{pool}", "vmpooler__completed__#{pool}", vm)
163
+ if request_id
164
+ ondemandrequest_hash = redis.hgetall("vmpooler__odrequest__#{request_id}")
165
+ if ondemandrequest_hash && ondemandrequest_hash['status'] != 'failed' && ondemandrequest_hash['status'] != 'deleted'
166
+ # will retry a VM that did not come up as vm_ready? only if it has not been market failed or deleted
167
+ redis.zadd('vmpooler__odcreate__task', 1, "#{pool_alias}:#{pool}:1:#{request_id}")
168
+ end
169
+ end
170
+ $metrics.increment("errors.markedasfailed.#{pool}")
171
+ open_socket_error
172
+ end
173
+
154
174
  def move_pending_vm_to_ready(vm, pool, redis, request_id = nil)
155
175
  clone_time = redis.hget("vmpooler__vm__#{vm}", 'clone')
156
176
  finish = format('%<time>.2f', time: Time.now - Time.parse(clone_time))
@@ -452,6 +472,9 @@ module Vmpooler
452
472
  ip_start = Time.now
453
473
  ip = provider.get_vm_ip_address(new_vmname, pool_name)
454
474
  ip_finish = format('%<time>.2f', time: Time.now - ip_start)
475
+
476
+ raise StandardError, "failed to obtain IP after #{ip_finish} seconds" if ip.nil?
477
+
455
478
  $logger.log('s', "[+] [#{pool_name}] Obtained IP for '#{new_vmname}' in #{ip_finish} seconds")
456
479
 
457
480
  @redis.with_metrics do |redis|
@@ -1250,19 +1273,20 @@ module Vmpooler
1250
1273
  end
1251
1274
  end
1252
1275
 
1253
- def check_pending_pool_vms(pool_name, provider, pool_check_response, inventory, pool_timeout)
1276
+ def check_pending_pool_vms(pool_name, provider, pool_check_response, inventory, pool_timeout, pool_timeout_notification)
1254
1277
  pool_timeout ||= $config[:config]['timeout'] || 15
1278
+ pool_timeout_notification ||= $config[:config]['timeout_notification'] || 5
1255
1279
  @redis.with_metrics do |redis|
1256
1280
  redis.smembers("vmpooler__pending__#{pool_name}").reverse.each do |vm|
1257
1281
  if inventory[vm]
1258
1282
  begin
1259
1283
  pool_check_response[:checked_pending_vms] += 1
1260
- check_pending_vm(vm, pool_name, pool_timeout, provider)
1284
+ check_pending_vm(vm, pool_name, pool_timeout, pool_timeout_notification, provider)
1261
1285
  rescue StandardError => e
1262
1286
  $logger.log('d', "[!] [#{pool_name}] _check_pool failed with an error while evaluating pending VMs: #{e}")
1263
1287
  end
1264
1288
  else
1265
- fail_pending_vm(vm, pool_name, pool_timeout, redis, exists: false)
1289
+ fail_pending_vm(vm, pool_name, pool_timeout, pool_timeout_notification, redis, exists: false)
1266
1290
  end
1267
1291
  end
1268
1292
  end
@@ -1389,7 +1413,7 @@ module Vmpooler
1389
1413
 
1390
1414
  check_ready_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['ready_ttl'] || $config[:config]['ready_ttl'])
1391
1415
 
1392
- check_pending_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['timeout'])
1416
+ check_pending_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['timeout'], pool['timeout_notification'])
1393
1417
 
1394
1418
  check_completed_pool_vms(pool['name'], provider, pool_check_response, inventory)
1395
1419
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vmpooler
4
- VERSION = '3.4.0'
4
+ VERSION = '3.5.1'
5
5
  end
data/lib/vmpooler.rb CHANGED
@@ -82,6 +82,7 @@ module Vmpooler
82
82
  end
83
83
  parsed_config[:config]['clone_target'] = ENV['CLONE_TARGET'] if ENV['CLONE_TARGET']
84
84
  parsed_config[:config]['timeout'] = string_to_int(ENV['TIMEOUT']) if ENV['TIMEOUT']
85
+ parsed_config[:config]['timeout_notification'] = string_to_int(ENV['TIMEOUT_NOTIFICATION']) if ENV['TIMEOUT_NOTIFICATION']
85
86
  parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
86
87
  parsed_config[:config]['max_tries'] = string_to_int(ENV['MAX_TRIES']) if ENV['MAX_TRIES']
87
88
  parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmpooler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-18 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement