Skip to content

Commit

Permalink
Use task queue for CRUD operations on auth key pair
Browse files Browse the repository at this point in the history
  • Loading branch information
sseago committed Jan 26, 2017
1 parent 7fbb998 commit 49a0097
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
37 changes: 36 additions & 1 deletion app/models/manageiq/providers/cloud_manager/auth_key_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@ def self.class_by_ems(ext_management_system)
ext_management_system.class::AuthKeyPair
end

def self.create_key_pair(ext_management_system, options)
def self.create_key_pair_queue(userid, ext_management_system, options = {})
task_opts = {
:action => "creating Auth Key Pair for user #{userid}",
:userid => userid
}
queue_opts = {
:class_name => "ManageIQ::Providers::CloudManager::AuthKeyPair",
:method_name => 'create_key_pair',
:role => 'ems_operations',
:zone => ext_management_system.my_zone,
:args => [ext_management_system.id, options]
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def self.create_key_pair(ems_id, options)
raise ArgumentError, _("ems cannot be nil") if ems_id.nil?
ext_management_system = ExtManagementSystem.find(ems_id)
raise ArgumentError, _("ems cannot be found") if ext_management_system.nil?

klass = class_by_ems(ext_management_system)
# TODO(maufart): add cloud_tenant to database table?
created_key_pair = klass.raw_create_key_pair(ext_management_system, options)
Expand All @@ -21,6 +40,22 @@ def self.create_key_pair(ext_management_system, options)
)
end

def delete_key_pair_queue(userid)
task_opts = {
:action => "deleting Auth Key Pair for user #{userid}",
:userid => userid
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'delete_key_pair',
:instance_id => id,
:role => 'ems_operations',
:zone => resource.my_zone,
:args => []
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def delete_key_pair
raw_delete_key_pair
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe ManageIQ::Providers::CloudManager::AuthKeyPair do
let(:ems) { FactoryGirl.build(:ems_cloud) }
let(:ems) { FactoryGirl.create(:ems_cloud) }

context 'create and delete actions' do
it "has methods" do
Expand All @@ -9,7 +9,7 @@

# TODO(maufart): do we have any special approach to test module methods separately?
it 'forces implement methods' do
expect { subject.class.create_key_pair ems, {} }.to raise_error NotImplementedError
expect { subject.class.create_key_pair ems.id, {} }.to raise_error NotImplementedError
expect { subject.delete_key_pair }.to raise_error NotImplementedError
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
it 'creates new key pair in nova' do
service = double
key_pairs = double
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems)
allow(ems).to receive(:connect).with(:service => 'Compute').and_return(service)
allow(service).to receive(:key_pairs).and_return(key_pairs)
allow(key_pairs).to receive(:create).with(key_pair_attributes).and_return(
FactoryGirl.create :auth_key_pair_openstack)
subject.class.create_key_pair(ems, key_pair_attributes)
subject.class.create_key_pair(ems.id, key_pair_attributes)
end

it 'deletes existing key pair from nova' do
Expand Down

0 comments on commit 49a0097

Please sign in to comment.