Merge pull request #469 from puppetlabs/tag_vm_user

(maint) Adding a provider method tag_vm_user
This commit is contained in:
Gene Liverman 2021-12-09 13:41:30 -05:00 committed by GitHub
commit 7872bfe8fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View file

@ -294,6 +294,12 @@ module Vmpooler
move_vm_queue(pool, vm, 'running', 'completed', redis, 'is listed as running, but has no checkouttime data. Removing from running') move_vm_queue(pool, vm, 'running', 'completed', redis, 'is listed as running, but has no checkouttime data. Removing from running')
end end
# tag VM if not tagged yet, this ensures the method is only called once
unless redis.hget("vmpooler__vm__#{vm}", 'user_tagged')
success = provider.tag_vm_user(pool, vm)
redis.hset("vmpooler__vm__#{vm}", 'user_tagged', 'true') if success
end
throw :stop_checking if provider.vm_ready?(pool, vm) throw :stop_checking if provider.vm_ready?(pool, vm)
throw :stop_checking if provider.get_vm(pool, vm) throw :stop_checking if provider.get_vm(pool, vm)

View file

@ -212,6 +212,22 @@ module Vmpooler
raise("#{self.class.name} does not implement vm_ready?") raise("#{self.class.name} does not implement vm_ready?")
end end
# tag_vm_user This method is called once we know who is using the VM (it is running). This method enables seeing
# who is using what in the provider pools.
# This method should be implemented in the providers, if it is not implemented, this base method will be called
# and should be a noop. The implementation should check if the vm has a user (as per redis) and add a new tag
# with the information.
# inputs
# [String] pool_name : Name of the pool
# [String] vm_name : Name of the VM to check if ready
# returns
# [Boolean] : true if successful, false if an error occurred and it should retry
def tag_vm_user(_pool_name, _vm_name)
# noop by design. If the provider does not implement this method, this base method is called (because inherited)
# and should basically do nothing.
true
end
# inputs # inputs
# [String] pool_name : Name of the pool # [String] pool_name : Name of the pool
# [String] vm_name : Name of the VM to check if it exists # [String] vm_name : Name of the VM to check if it exists

View file

@ -683,6 +683,25 @@ EOT
expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(true) expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(true)
end end
end end
it 'should try to tag if it has not been done' do
redis_connection_pool.with do |redis|
expect(provider).to receive(:vm_ready?).and_return(true)
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
expect(provider).to receive(:tag_vm_user)
subject._check_running_vm(vm, pool, 0, provider)
end
end
it 'should not try to tag if it has been done' do
redis_connection_pool.with do |redis|
expect(provider).to receive(:vm_ready?).and_return(true)
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
redis.hset("vmpooler__vm__#{vm}", 'user_tagged', 'true')
expect(provider).not_to receive(:tag_vm_user)
subject._check_running_vm(vm, pool, 0, provider)
end
end
end end
context 'with a locked vm mutex' do context 'with a locked vm mutex' do