This commit depends on the aeolus-image-rubygem commit:
Add provider_account-filtered 'provider images' method to build model
---
src/app/models/hardware_profile.rb | 2 +-
src/app/models/instance.rb | 10 ++-
src/app/models/provider_account.rb | 13 +---
src/spec/factories/provider_account.rb | 8 ++
src/spec/models/instance_spec.rb | 3 +-
src/spec/models/provider_account_spec.rb | 5 +-
src/spec/vcr/cassettes/iwhd_connection.yml | 143 ++++++++++++++++++++++++++++
src/spec/vcr_setup.rb | 2 +-
src/spec/vcr_setup_norec.rb | 2 +-
util/build-all | 2 +-
10 files changed, 167 insertions(+), 23 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index b1eea14..6b7041c 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -230,7 +230,7 @@ class HardwareProfile < ActiveRecord::Base
match = BigDecimal.new(back_end_property.range_last.to_s) >=
BigDecimal.new(front_end_property.value.to_s) ? true : false
when "enum"
create_array_from_property(back_end_property).each do |value|
- if front_end_property.value.nil? or BigDecimal.new(value) >=
BigDecimal.new(front_end_property.value)
+ if front_end_property.value.nil? or BigDecimal.new(value) >=
BigDecimal.new(front_end_property.value.to_s)
match = true
end
end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index b9605cc..86a1c0f 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -188,9 +188,13 @@ class Instance < ActiveRecord::Base
image_build || (image.nil? ? nil : image.latest_pushed_build)
end
- def provider_images_for_match(provider)
- the_build = build
- (the_build ? the_build.provider_images : []).select {|pi| pi.provider_name ==
provider.name}
+ def provider_images_for_match(provider_account)
+ if (the_build = build)
+ the_build.provider_images_by_provider_and_account(
+ provider_account.provider.name, provider_account.warehouse_id)
+ else
+ []
+ end
end
def assembly_xml
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index c44be65..a58f473 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -65,7 +65,6 @@ class ProviderAccount < ActiveRecord::Base
validate :validate_presence_of_credentials
validate :validate_credentials
validate :validate_unique_username
- before_create :no_account?
before_destroy :destroyable?
scope :enabled, lambda { where(:provider_id => Provider.enabled) }
@@ -93,16 +92,6 @@ class ProviderAccount < ActiveRecord::Base
return true
end
- def no_account?
- #if provider.provider_accounts.empty?
- if provider.provider_accounts.empty?
- return true
- else
- errors.add(:base, "Only one account is supported per provider")
- return false
- end
- end
-
def object_list
super << provider
end
@@ -349,7 +338,7 @@ class ProviderAccount < ActiveRecord::Base
# hardware_profile that can satisfy the input hardware_profile
elsif !(hwp = HardwareProfile.match_provider_hardware_profile(provider,
instance.hardware_profile))
errors << I18n.t('instances.errors.hw_profile_match_not_found',
:account_name => name)
- elsif (account_images = instance.provider_images_for_match(provider)).empty?
+ elsif (account_images = instance.provider_images_for_match(self)).empty?
errors << I18n.t('instances.errors.image_not_pushed_to_provider',
:account_name => name)
elsif instance.requires_config_server? and config_server.nil?
errors << I18n.t('instances.errors.no_config_server_available',
:account_name => name)
diff --git a/src/spec/factories/provider_account.rb
b/src/spec/factories/provider_account.rb
index b5d359a..93afc12 100644
--- a/src/spec/factories/provider_account.rb
+++ b/src/spec/factories/provider_account.rb
@@ -29,6 +29,14 @@ FactoryGirl.define do
end
end
+ factory :mock_provider_account2, :parent => :provider_account do
+ association :provider, :factory => :mock_provider2
+ after_build do |acc|
+ acc.credentials << Factory.build(:username_credential)
+ acc.credentials << Factory.build(:password_credential)
+ end
+ end
+
factory :ec2_provider_account, :parent => :provider_account do
association :provider, :factory => :ec2_provider
after_build do |acc|
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 279f3e5..792c9a7 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -193,7 +193,8 @@ describe Instance do
end
it "shouldn't match provider accounts where image is not pushed" do
- @pool.pool_family.provider_accounts = [FactoryGirl.create(:mock_provider_account,
:label => 'testaccount')]
+ account2 = FactoryGirl.create(:mock_provider_account2, :label =>
'testaccount')
+ @pool.pool_family.provider_accounts = [account2]
@instance.matches.last.should include('testaccount: image is not pushed to this
provider account')
end
diff --git a/src/spec/models/provider_account_spec.rb
b/src/spec/models/provider_account_spec.rb
index 8b6e569..158df1d 100644
--- a/src/spec/models/provider_account_spec.rb
+++ b/src/spec/models/provider_account_spec.rb
@@ -123,7 +123,7 @@ describe ProviderAccount do
provider_account2.should be_valid
end
- it "should fail to create more than one account per provider" do
+ it "should not fail to create more than one account per provider" do
provider = FactoryGirl.create :mock_provider
acc1 = FactoryGirl.create(:mock_provider_account, :provider => provider)
acc2 = Factory.build(:mock_provider_account, :provider => provider)
@@ -131,8 +131,7 @@ describe ProviderAccount do
acc2.stub!(:validate_unique_username).and_return(true)
provider.provider_accounts << acc1
provider.provider_accounts << acc2
- acc2.save.should == false
- acc2.errors[:base].should include('Only one account is supported per
provider')
+ acc2.save.should == true
end
it "should require quota to be set" do
diff --git a/src/spec/vcr/cassettes/iwhd_connection.yml
b/src/spec/vcr/cassettes/iwhd_connection.yml
index 9699b25..6de6e67 100644
--- a/src/spec/vcr/cassettes/iwhd_connection.yml
+++ b/src/spec/vcr/cassettes/iwhd_connection.yml
@@ -2163,6 +2163,96 @@
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :post
+ uri:
http://localhost:9090/target_images/_query
+ body: ($build == "63838705-8608-44c6-aded-7c243137172c")
+ headers:
+ accept:
+ - "*/*; q=0.5, application/xml"
+ accept-encoding:
+ - gzip, deflate
+ content-length:
+ - "50"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Wed, 14 Dec 2011 11:45:15 GMT
+ transfer-encoding:
+ - chunked
+ body: |
+ <objects>
+ <object>
+ <bucket>target_images</bucket>
+ <key>1a955a06-ca92-4546-9121-6c35e162f67b</key>
+ </object>
+ </objects>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://localhost:9090/provider_images/_query
+ body: ($target_image == "1a955a06-ca92-4546-9121-6c35e162f67b")
+ headers:
+ accept:
+ - "*/*; q=0.5, application/xml"
+ accept-encoding:
+ - gzip, deflate
+ content-length:
+ - "57"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Wed, 14 Dec 2011 11:45:28 GMT
+ transfer-encoding:
+ - chunked
+ body: |
+ <objects>
+ <object>
+ <bucket>provider_images</bucket>
+ <key>aa57b1ab-f565-4a7a-b054-58ef5af1a053</key>
+ </object>
+ </objects>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://localhost:9090/provider_images/_query
+ body: ($target_image == "1a955a06-ca92-4546-9121-6c35e162f67b" &&
$provider == "mock")
+ headers:
+ accept:
+ - "*/*; q=0.5, application/xml"
+ accept-encoding:
+ - gzip, deflate
+ content-length:
+ - "80"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Wed, 14 Dec 2011 11:45:28 GMT
+ transfer-encoding:
+ - chunked
+ body: |
+ <objects>
+ <object>
+ <bucket>provider_images</bucket>
+ <key>aa57b1ab-f565-4a7a-b054-58ef5af1a053</key>
+ </object>
+ </objects>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
uri:
http://localhost:9090/provider_images/_query
body: ($target_image == "ce1c6d32-5e26-4feb-9b86-83435a39b1f0")
headers:
@@ -2192,6 +2282,59 @@
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://localhost:9090/provider_images/_query
+ body: ($target_image == "ce1c6d32-5e26-4feb-9b86-83435a39b1f0" &&
$provider == "mock")
+ headers:
+ accept:
+ - "*/*; q=0.5, application/xml"
+ accept-encoding:
+ - gzip, deflate
+ content-length:
+ - "80"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Wed, 14 Dec 2011 11:45:28 GMT
+ transfer-encoding:
+ - chunked
+ body: |
+ <objects>
+ <object>
+ <bucket>provider_images</bucket>
+ <key>aa57b1ab-f565-4a7a-b054-58ef5af1a053</key>
+ </object>
+ </objects>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://localhost:9090/provider_images/_query
+ body: ($target_image == "ce1c6d32-5e26-4feb-9b86-83435a39b1f0" &&
$provider == "mock2")
+ headers:
+ accept:
+ - "*/*; q=0.5, application/xml"
+ accept-encoding:
+ - gzip, deflate
+ content-length:
+ - "81"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 404
+ message: Not Found
+ headers:
+ date:
+ - Wed, 14 Dec 2011 13:53:22 GMT
+ content-length:
+ - "0"
+ body:
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
method: :get
uri:
http://localhost:9090/images/53d2a281-448b-4872-b1b0-680edaad5922
body:
diff --git a/src/spec/vcr_setup.rb b/src/spec/vcr_setup.rb
index 49cbe64..bd38120 100644
--- a/src/spec/vcr_setup.rb
+++ b/src/spec/vcr_setup.rb
@@ -33,7 +33,7 @@ Aeolus::Image::Warehouse::Connection.class_eval do
opts[:plain] ||= false
opts[:headers] ||= {}
result=nil
- VCR.use_cassette('iwhd_connection', :record => :new_episodes) do
+ VCR.use_cassette('iwhd_connection', :record => :new_episodes,
:match_requests_on => [:method, :uri, :body]) do
result = RestClient::Request.execute :method => opts[:method], :url => @uri +
path, :payload => opts[:content], :headers => opts[:headers]
end
diff --git a/src/spec/vcr_setup_norec.rb b/src/spec/vcr_setup_norec.rb
index 6dcd2e9..506cf71 100644
--- a/src/spec/vcr_setup_norec.rb
+++ b/src/spec/vcr_setup_norec.rb
@@ -52,4 +52,4 @@ VCR.config do |c|
c.allow_http_connections_when_no_cassette = true
end
-VCR::Cassette.new(File.basename(file.path, '.yml'), :record => :none)
+VCR::Cassette.new(File.basename(file.path, '.yml'), :record => :none,
:match_requests_on => [:method, :uri, :body])
diff --git a/util/build-all b/util/build-all
index d230125..c0eaaf0 100755
--- a/util/build-all
+++ b/util/build-all
@@ -10,7 +10,7 @@ cd ../aeolus-configure
rake rpms
cd ../aeolus-image-rubygem
rake rpms
-cd ../aeolus-image
+cd ../aeolus-cli
rake rpms
sudo yum --nogpgcheck -y install ~/rpmbuild/RPMS/noarch/rubygem-* \
~/rpmbuild/RPMS/noarch/aeolus-* --enablerepo=fedora-aeolus-testing
--
1.7.6.4