the first of these patches can be run either of the following two ways: [src/]$ rake cucumber (I currently have 5 failures from next running this) [src/]$ cucumber features/instance.feature
This is expected to fail without the follow-on patch applied.
[PATCH aggregator 1/2] BZ #642432 - test 'determine the key in use for an instance'. [PATCH aggregator 2/2] BZ #642432 - no way to determine the key for an instance.
https://bugzilla.redhat.com/show_bug.cgi?id=642432
If the instance has a key you should see a download link, if not, there should be no link. --- src/features/instance.feature | 21 +++++++++++++++++ src/features/step_definitions/instance.rb | 34 +++++++++++++++++++++++++++++ src/spec/factories/instance.rb | 12 +++++++++- src/spec/factories/instance_key.rb | 16 ++++++++----- 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/features/instance.feature create mode 100644 src/features/step_definitions/instance.rb
diff --git a/src/features/instance.feature b/src/features/instance.feature new file mode 100644 index 0000000..e98da69 --- /dev/null +++ b/src/features/instance.feature @@ -0,0 +1,21 @@ +# language: en +Feature: Mange Instances + In order to manage my cloud infrastructure + As a user + I want to manage instances + + Background: + Given I am an authorised user + And I am logged in + + Scenario: Download an Instance Key + Given a mock running instance exists + And I am viewing the mock instance detail + And I see "SSH key" + When I follow "Download" + Then I should see the Save dialog for a .pem file + + Scenario: Don't see' an Instance Key + Given a mock pending instance exists + When I am viewing the pending instance detail + Then I should not see "SSH key" \ No newline at end of file diff --git a/src/features/step_definitions/instance.rb b/src/features/step_definitions/instance.rb new file mode 100644 index 0000000..672f443 --- /dev/null +++ b/src/features/step_definitions/instance.rb @@ -0,0 +1,34 @@ +def mock_instance + @mock_instance ||= Factory :mock_running_instance +end + +def pending_instance + @pending_instance ||= Factory :mock_pending_instance +end + +Given /^a mock running instance exists$/ do + mock_instance +end + +Given /^a mock pending instance exists$/ do + pending_instance +end + +Given /^I am viewing the mock instance detail$/ do + visit url_for :action => 'show', :controller => 'instance', + :id => mock_instance +end + +When /^I am viewing the pending instance detail$/ do + visit url_for :action => 'show', :controller => 'instance', + :id => pending_instance +end + +Given /^I see "([^"]*)"$/ do |text| + response.should contain(text) +end + +Then /^I should see the Save dialog for a (.+) file$/ do |filetype| + response.headers["Content-Disposition"].should + match(/^attachment;\sfilename=.*#{filetype}$/) +end \ No newline at end of file diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb index 6bb83b2..7533ba9 100644 --- a/src/spec/factories/instance.rb +++ b/src/spec/factories/instance.rb @@ -9,10 +9,20 @@ Factory.define :instance do |i| i.state "running" end
-Factory.define :pending_instance, :parent => :instance do |i| +Factory.define :mock_running_instance, :parent => :instance do |i| + i.instance_key { |k| k.association(:mock_instance_key)} +end + +Factory.define :mock_pending_instance, :parent => :instance do |i| i.state Instance::STATE_PENDING end
Factory.define :new_instance, :parent => :instance do |i| i.state Instance::STATE_NEW end + +Factory.define :ec2_instance, :parent => :instance do |i| + i.association :hardware_profile, :factory => :ec2_hwp1 + i.association :cloud_account, :factory => :ec2_cloud_account + i.association :instance_key, :factory => :ec2_instance_key1 +end diff --git a/src/spec/factories/instance_key.rb b/src/spec/factories/instance_key.rb index f4bcaed..d5bc69a 100644 --- a/src/spec/factories/instance_key.rb +++ b/src/spec/factories/instance_key.rb @@ -1,11 +1,6 @@ Factory.define :instance_key do |p| p.sequence(:name) { |n| "instance_key#{n}" } -end - -Factory.define :ec2_instance_key1, :parent => :instance_key do |p| - p.cloud_account { |p| p.association(:ec2_cloud_account) } - p.name "1_user" - p.text " + p.pem " -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAm+Ri7uZz7iVTLLxtPiV2gLD37OOvovZ0VpWR3T7HK5NgxjlJssIjc8uKqPqY EdXssF+ZKKypiQzFkMhowthkw1sGN5R3NBrIiRKR1mcVuE7iiRBFikBoF/CaaXP2LSNtMv4xkUXO @@ -31,3 +26,12 @@ uH9ebPTGZc5cTpOEV9SupUez4cAedBGeHVDHy06sATrgIwKBgQCdqFhrse+uhRacK1LAymvBsou5 -----END RSA PRIVATE KEY----- " end + +Factory.define :ec2_instance_key1, :parent => :instance_key do |p| + p.cloud_account { |p| p.association(:ec2_cloud_account) } + p.name "1_user" +end + +Factory.define :mock_instance_key, :parent => :instance_key do |m| + m.cloud_account { |c| c.association(:mock_cloud_account) } +end \ No newline at end of file
https://bugzilla.redhat.com/show_bug.cgi?id=642432
This adds a link to download the private key, so the user can ssh into their instance. As a side effect, also fixes the model relationship between instance and instance_key. --- src/app/controllers/instance_controller.rb | 21 +++++++++++++++++++-- src/app/models/instance.rb | 1 + src/app/views/instance/show.haml | 4 ++++ src/app/views/layouts/_notification.rhtml | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb index 3bef6f0..2073937 100644 --- a/src/app/controllers/instance_controller.rb +++ b/src/app/controllers/instance_controller.rb @@ -23,6 +23,7 @@ require 'util/condormatic'
class InstanceController < ApplicationController before_filter :require_user, :get_nav_items + before_filter :instance, :only => [:show, :key] layout :layout
def section_id @@ -53,8 +54,17 @@ class InstanceController < ApplicationController end
def show - @instance = Instance.find(params[:id]) - require_privilege(Privilege::INSTANCE_VIEW, @instance.pool) + end + + def key + unless @instance.instance_key.nil? + send_data @instance.instance_key.pem, + :filename => "#{@instance.instance_key.name}.pem", + :type => "text/plain" + end + rescue + flash[:warning] = "SSH Key not found for this Instance." + redirect_to :action => "show", :id => @instance end
def new @@ -171,4 +181,11 @@ class InstanceController < ApplicationController action end
+ private + + def instance + @instance = Instance.find(params[:id]) + require_privilege(Privilege::INSTANCE_VIEW, @instance.pool) + end + end diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 5ede90e..22069e2 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -33,6 +33,7 @@ class Instance < ActiveRecord::Base belongs_to :template belongs_to :realm belongs_to :owner, :class_name => "User", :foreign_key => "owner_id" + belongs_to :instance_key
validates_presence_of :pool_id validates_presence_of :hardware_profile_id diff --git a/src/app/views/instance/show.haml b/src/app/views/instance/show.haml index 42236c8..071ec7c 100644 --- a/src/app/views/instance/show.haml +++ b/src/app/views/instance/show.haml @@ -40,6 +40,10 @@ %li = label_tag :console_connection, 'Console Connection' %span= 'via SSH' + - unless @instance.instance_key_id.nil? + %li + = label_tag :owner, 'SSH key' + %span= link_to("Download", { :controller => "instance", :action => "key", :id => @instance }) %li = label_tag :owner, 'Owner' %span= "#{@instance.owner.first_name} #{@instance.owner.last_name}" diff --git a/src/app/views/layouts/_notification.rhtml b/src/app/views/layouts/_notification.rhtml index 44793a5..02a65de 100644 --- a/src/app/views/layouts/_notification.rhtml +++ b/src/app/views/layouts/_notification.rhtml @@ -23,7 +23,7 @@ <% end %> <% end %> <% if flash[:warning] %> - <div class="warning"><h4><%= flash[:warning] %></h4></div> + <div class="error"><ul><li><%= flash[:warning] %></li></ul></div> <% end %> <% if flash[:notice] %> <div class="success"><ul><li><%= flash[:notice] %></li></ul></div>
deltacloud-devel@lists.fedorahosted.org