From 3f6ead8134bfab2451a0143c4bf4533f99f365e2 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Fri, 31 Mar 2017 14:23:56 -0700 Subject: [PATCH] (POOLER-70) Update migrate_vm_and_record_timing for VM Provider Previously the Pool Manager would use vSphere objects directly. This commit - Modifies the migrate_vm_and_record_timing method to use VM and Pool names instead of VM and Pool objects. --- lib/vmpooler/pool_manager.rb | 6 +++--- spec/unit/pool_manager_spec.rb | 20 ++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 747f760..d8426f5 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -506,11 +506,11 @@ module Vmpooler end end - def migrate_vm_and_record_timing(vm_object, vm_name, pool, host, source_host_name, dest_host_name, provider) + def migrate_vm_and_record_timing(vm_name, pool_name, source_host_name, dest_host_name, provider) start = Time.now - provider.migrate_vm_host(vm_object, host) + provider.migrate_vm_to_host(pool_name, vm_name, dest_host_name) finish = '%.2f' % (Time.now - start) - $metrics.timing("migrate.#{pool}", finish) + $metrics.timing("migrate.#{pool_name}", finish) $metrics.increment("migrate_from.#{source_host_name}") $metrics.increment("migrate_to.#{dest_host_name}") checkout_to_migration = '%.2f' % (Time.now - Time.parse($redis.hget("vmpooler__vm__#{vm_name}", 'checkout'))) diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index 78ad85e..df5e317 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -1981,45 +1981,41 @@ EOT end describe '#migrate_vm_and_record_timing' do - let(:provider) { double('provider') } - let(:vm_object) { double('vm_object') } let(:source_host_name) { 'source_host' } let(:dest_host_name) { 'dest_host' } - before do - expect(subject).not_to be_nil - end - before(:each) do create_vm(vm,token) - expect(provider).to receive(:migrate_vm_host).with(vm_object, host) + expect(subject).not_to be_nil + + expect(provider).to receive(:migrate_vm_to_host).with(pool, vm, dest_host_name) end it 'should return the elapsed time for the migration' do - result = subject.migrate_vm_and_record_timing(vm_object, vm, pool, host, source_host_name, dest_host_name, provider) + result = subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) expect(result).to match(/0\.[\d]+/) end it 'should add timing metric' do expect(metrics).to receive(:timing).with("migrate.#{pool}",String) - subject.migrate_vm_and_record_timing(vm_object, vm, pool, host, source_host_name, dest_host_name, provider) + subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) end it 'should increment from_host and to_host metric' do expect(metrics).to receive(:increment).with("migrate_from.#{source_host_name}") expect(metrics).to receive(:increment).with("migrate_to.#{dest_host_name}") - subject.migrate_vm_and_record_timing(vm_object, vm, pool, host, source_host_name, dest_host_name, provider) + subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) end it 'should set migration_time metric in redis' do expect(redis.hget("vmpooler__vm__#{vm}", 'migration_time')).to be_nil - subject.migrate_vm_and_record_timing(vm_object, vm, pool, host, source_host_name, dest_host_name, provider) + subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) expect(redis.hget("vmpooler__vm__#{vm}", 'migration_time')).to match(/0\.[\d]+/) end it 'should set checkout_to_migration metric in redis' do expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to be_nil - subject.migrate_vm_and_record_timing(vm_object, vm, pool, host, source_host_name, dest_host_name, provider) + subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to match(/0\.[\d]+/) end end