On 11/29/2011 02:06 PM, jzigmund(a)redhat.com wrote:
From: Jozef Zigmund<jzigmund(a)redhat.com>
---
src/app/controllers/catalog_entries_controller.rb | 6 +++-
src/app/models/deployable.rb | 33 +++++++++++++++++++++
src/app/views/catalog_entries/_form.html.haml | 2 +-
src/app/views/catalog_entries/show.html.haml | 21 ++++++++++++-
src/config/locales/en.yml | 8 +++++
5 files changed, 67 insertions(+), 3 deletions(-)
Some additional minor comments
inline, but more importantly, it's not
parsing my deployable. Instead of a list of assemblies (showing which
images are valid, etc), I just get the following:
"Something went wrong, check XML file!"
On further investigation (after reviewing below) it looks like what's
happening is it's hitting an invalid HWP and abandoning any further
parsing. We should parse and show the whole deployable metadata -- and
where an image UUID or HWP is invalid, the "pretty" parsed display
should indicate this, that way the user can go in and fix the image or
hwp in the xml by clicking 'edit'.
I added the HWP and now that shows up. I did not verify whether image
validation is being done here, but it's not obvious from the patch below
whether we're doing that yet.
diff --git a/src/app/controllers/catalog_entries_controller.rb
b/src/app/controllers/catalog_entries_controller.rb
index 7b6940f..f97235a 100644
--- a/src/app/controllers/catalog_entries_controller.rb
+++ b/src/app/controllers/catalog_entries_controller.rb
@@ -56,6 +56,11 @@ class CatalogEntriesController< ApplicationController
save_breadcrumb(catalog_catalog_entry_path((a)catalog_entry.catalog, @catalog_entry),
@catalog_entry.deployable.name)
@providers = Provider.all
@catalogs_options = Catalog.all.map {|c| [c.name, c.id]}
+ @image_details = @catalog_entry.deployable.get_image_details
+ if @image_details.detect { |assembly| assembly.keys.include? :error }
+ @error = true
+ flash[:error] = t('deployable.flash.error.attribute_not_exist')
This
should be "deployables.flash.error..." combined with the en.yml fix
below
+ end
end
def create
@@ -123,7 +128,6 @@ class CatalogEntriesController< ApplicationController
@catalog_entry = CatalogEntry.find(params[:id])
require_privilege(Privilege::MODIFY, @catalog_entry.deployable)
params[:catalog_entry][:deployable].delete(:owner_id) if params[:catalog_entry] and
params[:catalog_entry][:deployable]
-
if @catalog_entry.update_attributes(params[:catalog_entry])
flash[:notice] = t"catalog_entries.flash.notice.updated"
redirect_to catalog_catalog_entry_path((a)catalog_entry.catalog, @catalog_entry)
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
index 8f869a4..a0a7fbc 100644
--- a/src/app/models/deployable.rb
+++ b/src/app/models/deployable.rb
@@ -105,4 +105,37 @@ class Deployable< ActiveRecord::Base
self.xml_filename = image.name
self.name = image.name
end
+
+ #get details of image for catalog_entry#show
+ def get_image_details
+ stored_xml = Nokogiri::XML(xml)
+ result_array ||= []
+ stored_xml.xpath("//assembly").each do |assembly|
+ if assembly.attr('name')
+ assembly_hash ||= {:name => assembly.attr('name')}
+ error = false
+ else
+ assembly_hash ||= {:error =>
I18n.t('deployable.flash.error.attribute_not_exist')}
+ error = true
+ end
+ unless error
+ if assembly.attr('hwp')
+ hwp_name = stored_xml.xpath("//assembly").attr('hwp').value
+ assembly_hash[:hwp] = {:name => hwp_name}
+
+ hwp = HardwareProfile.find_by_name(hwp_name)
+ if hwp
+ assembly_hash[:hwp][:hdd] = hwp.storage.value
+ assembly_hash[:hwp][:ram] = hwp.memory.value
+ assembly_hash[:hwp][:arch] = hwp.architecture.value
+ else
+ assembly_hash = {:error =>
I18n.t('deployable.flash.error.attribute_not_exist')}
You're losing the
whole assembly hash here if the HWP is invalid. I
think we need to keep the assembly hash -- but flag the HWP in the
displayed table as invalid, similar to how we need to flag invalid images.
+ end
+ end
+ end
+ result_array<< assembly_hash
+ end
+ #returned value [{:name => 'assembly1',{:hwp => {...}}, {:error
=> "msg"}, {assembly3} ..]
+ result_array
+ end
end
diff --git a/src/app/views/catalog_entries/_form.html.haml
b/src/app/views/catalog_entries/_form.html.haml
index 5c8b2bb..e03865d 100644
--- a/src/app/views/catalog_entries/_form.html.haml
+++ b/src/app/views/catalog_entries/_form.html.haml
@@ -9,7 +9,7 @@
- else
%p
= form.label :catalog_id, t('catalog_entries.form.catalog')
- = @catalog.name
+ = @catalog ? @catalog.name : @catalog_entry.catalog.name
.clear
= form.fields_for :deployable, @catalog_entry.deployable do |deployable_fields|
%p
diff --git a/src/app/views/catalog_entries/show.html.haml
b/src/app/views/catalog_entries/show.html.haml
index 5162796..fac8e11 100644
--- a/src/app/views/catalog_entries/show.html.haml
+++ b/src/app/views/catalog_entries/show.html.haml
@@ -12,7 +12,26 @@
%section.image
%header
%h2= t('.image')
- %pre= @catalog_entry.deployable.xml
+ - if @error
+ Something went wrong, check XML file!
We should probably only do this if
the XML is completely invalid --
otherwise we need to show, for each assembly, image details (if valid,
and if not valid, show that it's invalid), and HWP (details if valid,
show the user that it's invalid otherwise)
+ - else
+ %table
+ %thead
+ %tr
+ %th=t'.name'
+ %th=t'.hwp_profile'
+ %th=t'.hdd'
+ %th=t'.ram'
+ %th=t'.arch'
+ %tbody
+ - @image_details.each do |assembly|
+ %tr
+ %td=assembly[:name]
+ %td=assembly[:hwp][:name]
+ %td=assembly[:hwp][:hdd]
+ %td=assembly[:hwp][:ram]
+ %td=assembly[:hwp][:arch]
+
%section.build
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index b6dc774..b08d7c9 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -631,6 +631,11 @@ en:
environment: Environment
choose_catalog: "Choose a catalog to enable access:"
add_catalog: "Add +"
+ name: Name
+ profile: Profile
+ hdd: HDD
+ ram: RAM
+ arch: ARCH
edit:
editing_catalog_entry: Editing Catalog Entry
list:
@@ -751,6 +756,9 @@ en:
not_deleted:
one: "Deployable %{list} was not deleted. There are deployments associated
with it."
other: "Deployables %{list} were not deleted. They have deployments
associated with them."
+ flash:
+ error:
+ attribute_not_exist: "Some attribute(s) is missing in XML, please check
the file!"
This should have one fewer indent levels. This is showing up as
deployables.index.flash.error, rather deployables.flash.error
name: Name
summary: Summary
settings: