When I run `rake cucumber` on this patch, I get this failure:
(::) failed steps (::)
undefined method `pem' for nil:NilClass (NoMethodError)
./app/models/cloud_account.rb:143:in `generate_clound_account_key'
/usr/lib/ruby/1.8/net/http.rb:543:in `start'
./app/models/cloud_account.rb:142:in `generate_clound_account_key'
./features/step_definitions/pool_steps.rb:27:in `/^the Pool has the
following Realms named "([^\"]*)"$/'
features/pool.feature:41:in `And the Pool has the following Realms named
"Europe, United States"'
Failing Scenarios:
cucumber features/pool.feature:39 # Scenario: View Pool's Realms
17 scenarios (1 failed, 16 passed)
156 steps (1 failed, 6 skipped, 149 passed)
On 09/06/2010 10:25 AM, Michal Fojtik wrote:
> ---
> src/app/controllers/cloud_accounts_controller.rb | 8 ++++++
> src/app/models/cloud_account.rb | 13 +++++++++
> src/app/models/instance_key.rb | 27
> ++++++++++++++++++++
> src/app/views/provider/accounts.html.erb | 2 +
> src/db/migrate/20090804142049_create_instances.rb | 1 +
> .../migrate/20100902081651_create_instance_keys.rb | 14 ++++++++++
> src/test/fixtures/instance_keys.yml | 11 ++++++++
> src/test/unit/instance_key_test.rb | 8 ++++++
> 8 files changed, 84 insertions(+), 0 deletions(-)
> create mode 100644 src/app/models/instance_key.rb
> create mode 100644 src/db/migrate/20100902081651_create_instance_keys.rb
> create mode 100644 src/test/fixtures/instance_keys.yml
> create mode 100644 src/test/unit/instance_key_test.rb
>
> diff --git a/src/app/controllers/cloud_accounts_controller.rb
> b/src/app/controllers/cloud_accounts_controller.rb
> index 9343f62..d2838ce 100644
> --- a/src/app/controllers/cloud_accounts_controller.rb
> +++ b/src/app/controllers/cloud_accounts_controller.rb
> @@ -65,6 +65,14 @@ class CloudAccountsController< ApplicationController
> end
> end
>
> + def key
> + @cloud_account = CloudAccount.find(params[:id])
> + require_privilege(Privilege::ACCOUNT_MODIFY,@cloud_account.provider)
> + unless @cloud_account.instance_key.nil?
> + render :text => @cloud_account.instance_key.pem
> + end
> + end
> +
> def destroy
> acct = CloudAccount.find(params[:id])
> provider = acct.provider
> diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
> index 69c8b87..bbd0740 100644
> --- a/src/app/models/cloud_account.rb
> +++ b/src/app/models/cloud_account.rb
> @@ -33,11 +33,13 @@ class CloudAccount< ActiveRecord::Base
> validates_uniqueness_of :username, :scope => :provider_id
> validates_presence_of :password
>
> + has_one :instance_key, :dependent => :destroy
> has_many :permissions, :as => :permission_object, :dependent =>
> :destroy,
> :include => [:role],
> :order => "permissions.id ASC"
>
>
> + after_create :generate_clound_account_key
> before_destroy {|entry| entry.destroyable? }
>
> def destroyable?
> @@ -133,6 +135,17 @@ class CloudAccount< ActiveRecord::Base
> end
>
> private
> +
> + def generate_clound_account_key
> + client = connect
> + if client.feature?(:instances, :authentication_key)
> + client.create_key(:name => "#{self.id}_#{self.name}") do |key|
> + InstanceKey.create(:cloud_account => self, :pem => key.pem,
> + :name => key.id)
> + end
> + end
> + end
> +
> def valid_credentials?
> begin
> deltacloud = DeltaCloud.new(username, password, provider.url)
> diff --git a/src/app/models/instance_key.rb b/src/app/models/instance_key.rb
> new file mode 100644
> index 0000000..b3b7513
> --- /dev/null
> +++ b/src/app/models/instance_key.rb
> @@ -0,0 +1,27 @@
> + #
> +# Copyright (C) 2009 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301, USA. A copy of the GNU General Public License is
> +# also available at http://www.gnu.org/copyleft/gpl.html.
> +
> +# Filters added to this controller apply to all controllers in the
> application.
> +# Likewise, all the methods added will be available for all controllers.
> +#
> +class InstanceKey< ActiveRecord::Base
> +
> + belongs_to :cloud_account
> + has_many :instances
> +
> +end
> diff --git a/src/app/views/provider/accounts.html.erb
> b/src/app/views/provider/accounts.html.erb
> index ca8d287..99b9f9c 100644
> --- a/src/app/views/provider/accounts.html.erb
> +++ b/src/app/views/provider/accounts.html.erb
> @@ -6,6 +6,7 @@
> <tr>
> <th scope="col">Label</th>
> <th scope="col">Username</th>
> +<th scope="col">Instance Key</th>
> <th scope="col"></th>
> <th scope="col"></th>
> </tr>
> @@ -15,6 +16,7 @@
> <tr>
> <td><%= acct.label %></td>
> <td><%= acct.username %></td>
> +<td><%= link_to acct.instance_key.name, {:controller => 'cloud_accounts',
> :action => 'key', :id => acct.id } if acct.instance_key%></td>
> <td><%= link_to "Edit", {:controller => 'cloud_accounts',
> :action => 'edit', :id => acct.id} if has_account_modify?(@provider)
> %></td>
> <td><%= link_to "Delete", {:controller => 'cloud_accounts',
> :action => 'destroy', :id => acct.id} if has_account_modify?(@provider)&&
> acct.destroyable? %></td>
> <td><%= link_to "Quota", {:controller => 'quota', :action =>
> 'show', :id => acct.id, :parent_type => "cloud_account"} %></td>
> diff --git a/src/db/migrate/20090804142049_create_instances.rb
> b/src/db/migrate/20090804142049_create_instances.rb
> index 42706e1..4222782 100644
> --- a/src/db/migrate/20090804142049_create_instances.rb
> +++ b/src/db/migrate/20090804142049_create_instances.rb
> @@ -33,6 +33,7 @@ class CreateInstances< ActiveRecord::Migration
> t.string :private_address
> t.string :state
> t.string :condor_job_id
> + t.integer :instance_key_id
> t.integer :lock_version, :default => 0
> t.integer :acc_pending_time, :default => 0
> t.integer :acc_running_time, :default => 0
> diff --git a/src/db/migrate/20100902081651_create_instance_keys.rb
> b/src/db/migrate/20100902081651_create_instance_keys.rb
> new file mode 100644
> index 0000000..841d7ff
> --- /dev/null
> +++ b/src/db/migrate/20100902081651_create_instance_keys.rb
> @@ -0,0 +1,14 @@
> +class CreateInstanceKeys< ActiveRecord::Migration
> + def self.up
> + create_table :instance_keys do |t|
> + t.integer :cloud_account_id, :null => false
> + t.string :name, :null => false
> + t.text :pem
> + t.timestamps
> + end
> + end
> +
> + def self.down
> + drop_table :instance_keys
> + end
> +end
> diff --git a/src/test/fixtures/instance_keys.yml
> b/src/test/fixtures/instance_keys.yml
> new file mode 100644
> index 0000000..2893341
> --- /dev/null
> +++ b/src/test/fixtures/instance_keys.yml
> @@ -0,0 +1,11 @@
> +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
> +
> +# This model initially had no columns defined. If you add columns to the
> +# model remove the '{}' from the fixture names and add the columns
> immediately
> +# below each fixture, per the syntax in the comments below
> +#
> +one: {}
> +# column: value
> +#
> +two: {}
> +# column: value
> diff --git a/src/test/unit/instance_key_test.rb
> b/src/test/unit/instance_key_test.rb
> new file mode 100644
> index 0000000..0f835a8
> --- /dev/null
> +++ b/src/test/unit/instance_key_test.rb
> @@ -0,0 +1,8 @@
> +require 'test_helper'
> +
> +class InstanceKeyTest< ActiveSupport::TestCase
> + # Replace this with your real tests.
> + test "the truth" do
> + assert true
> + end
> +end
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel