On 01/02/2012 03:26 PM, jprovazn@redhat.com wrote:
From: Jan Provaznikjprovazn@redhat.com
https://bugzilla.redhat.com/show_bug.cgi?id=723680
src/app/controllers/deployments_controller.rb | 2 +- src/app/models/instance.rb | 15 ++ src/config/locales/en.yml | 1 + src/spec/models/instance_spec.rb | 6 + src/spec/vcr/cassettes/iwhd_connection.yml | 176 +++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/deployments_controller.rb b/src/app/controllers/deployments_controller.rb index 8245dd1..35006d4 100644 --- a/src/app/controllers/deployments_controller.rb +++ b/src/app/controllers/deployments_controller.rb @@ -353,7 +353,7 @@ class DeploymentsController< ApplicationController
def set_errors_flash(errors) unless errors.empty?
flash[:error] = {
flash.now[:error] = { :summary => t("deployments.flash.error.not_launched"), :failures => errors }
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 111cbd9..b9605cc 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -344,6 +344,17 @@ class Instance< ActiveRecord::Base end end
- def image_arch
- # try to get architecture of the image associated with this instance
- # for imported images template is empty -> architecture is not set,
- # in this case we omit this check
- return Aeolus::Image::Warehouse::Image.find(build.image.uuid).os.arch
- rescue
- logger.warn "failed to get image architecture for instance '#{name}', skipping architecture check: #{$!}"
- logger.warn $!.backtrace.join("\n ")
- nil
- end
- def matches errors = [] if pool.pool_family.provider_accounts.empty?
@@ -353,6 +364,10 @@ class Instance< ActiveRecord::Base errors<< I18n.t('instances.errors.pool_family_quota_reached') if pool.pool_family.quota.reached? errors<< I18n.t('instances.errors.user_quota_reached') if owner.quota.reached? errors<< I18n.t('instances.errors.image_not_found', :b_uuid=> image_build_uuid, :i_uuid => image_uuid) if image_build.nil? and image.nil?
arch = image_arch
if arch.present? and hardware_profile.architecture and hardware_profile.architecture.value != arch
errors<< I18n.t('instances.errors.architecture_mismatch', :inst_arch => hardware_profile.architecture.value, :img_arch => arch)
end return [[], errors] unless errors.empty?
matched = []
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index 0275275..57fe873 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -359,6 +359,7 @@ en: stop_not_be_performed: "stop cannot be performed on this instance." must_be_enabled: "%{account_name}: provider must be enabled" cannot_destroy: "destroy cannot be performed on this instance."
architecture_mismatch: "Assembly hardware profile architecture (%{inst_arch}) doesn't match image hardware profile architecture (%{img_arch})." headers: vm_name: VM NAME status: STATUS
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb index a1fe525..279f3e5 100644 --- a/src/spec/models/instance_spec.rb +++ b/src/spec/models/instance_spec.rb @@ -204,6 +204,12 @@ describe Instance do @instance.matches.last.should include('testaccount: hardware profile match not found') end
- it "shouldn't return any matches if instance hwp architecture doesn't match image architecture" do
- @pool.pool_family.provider_accounts = [FactoryGirl.create(:mock_provider_account, :label => 'testaccount')]
- @instance.hardware_profile.architecture.value = 'i386'
- @instance.matches.last.should include("Assembly hardware profile architecture (i386) doesn't match image hardware profile architecture (x86_64).")
- end
- it "should return a match if all requirements are satisfied" do build = @instance.image_build || @instance.image.latest_pushed_build provider = FactoryGirl.create(:mock_provider, :name => build.provider_images.first.provider_name)
diff --git a/src/spec/vcr/cassettes/iwhd_connection.yml b/src/spec/vcr/cassettes/iwhd_connection.yml index b786856..9699b25 100644 --- a/src/spec/vcr/cassettes/iwhd_connection.yml +++ b/src/spec/vcr/cassettes/iwhd_connection.yml @@ -74,6 +74,7 @@ <object_attr name="latest_unpushed" path="http://localhost:9090/images/53d2a281-448b-4872-b1b0-680edaad5922/latest_unp... <object_attr name="object_type" path="http://localhost:9090/images/53d2a281-448b-4872-b1b0-680edaad5922/object_typ... <object_attr name="uuid" path="http://localhost:9090/images/53d2a281-448b-4872-b1b0-680edaad5922/uuid%22/%3...
<object_attr name="template" path="http://localhost:9090/images/53d2a281-448b-4872-b1b0-680edaad5922/template"/> </object> http_version: "1.1"
@@ -2235,3 +2236,178 @@ - "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/template
- body:
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "0"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 13 Jun 2011 14:11:46 GMT
content-length:
- "36"
- body: e4b99e0e-1cc9-11e1-812a-5254002aa03c
- http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
- method: :post
- uri: http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c
- body: op=parts
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "8"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 02 Jan 2012 12:42:43 GMT
transfer-encoding:
- chunked
- body: |
+<object>
<object_body path="http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c"/>
<object_attr_list path="http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c/_attrs"/>
<object_attr name="object_type" path="http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c/object_type"/>
<object_attr name="uuid" path="http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c/uuid"/>
+</object>
- http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
- method: :get
- uri: http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c/object_...
- body:
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "0"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 02 Jan 2012 12:42:45 GMT
content-length:
- "8"
- body: template
- http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
- method: :get
- uri: http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c/uuid
- body:
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "0"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 02 Jan 2012 12:42:47 GMT
content-length:
- "36"
- body: e4b99e0e-1cc9-11e1-812a-5254002aa03c
- http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
- method: :get
- uri: http://localhost:9090/templates/e4b99e0e-1cc9-11e1-812a-5254002aa03c
- body:
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "0"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 02 Jan 2012 12:42:48 GMT
transfer-encoding:
- chunked
- body: |-
+<?xml version="1.0"?> +<template> +<name>test1</name> +<description>Some text here</description> +<os> +<name>Fedora</name> +<arch>x86_64</arch> +<version>14</version> +<install type="url"> +<url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64...</url> +</install> +</os> +<repositories> +<repository name="custom"> +<url>http://repos.fedorapeople.org/repos/aeolus/demo/webapp/</url> +<signed>false</signed> +</repository> +</repositories> +</template>
- http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
- method: :get
- uri: http://localhost:9090/templates
- body:
- headers:
accept:
- "*/*; q=0.5, application/xml"
accept-encoding:
- gzip, deflate
content-length:
- "0"
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
date:
- Mon, 02 Jan 2012 13:23:37 GMT
transfer-encoding:
- chunked
- body: |
+<objects>
<object>
<bucket>templates</bucket>
<key>e4b99e0e-1cc9-11e1-812a-5254002aa03c</key>
</object>
<object>
<bucket>templates</bucket>
<key>013b1526-1cca-11e1-812a-5254002aa03c</key>
</object>
+</objects>
- http_version: "1.1"
ACK to both patches.