[PATCH aeolus-conductor] BZ:867353 Fixed template XPath in Images Controller

mtaylor at redhat.com mtaylor at redhat.com
Mon Oct 22 15:08:25 UTC 2012


From: Martyn Taylor <mtaylor at redhat.com>

The strange XPath in the images controller can only have been there
to support this CDATA attribute that has appeared in our API for
wrapping templates.

The CDATA XML attribute is used to specify data with in a document
that is not to be parsed.  Is is true that our templates are stored
as XML strings in our template model, however, we do not need nor
want a user to know about this.  It is an implementation detail only.
---
 src/app/controllers/api/images_controller.rb       |    4 +-
 src/spec/controllers/api/images_controller_spec.rb |   47 +------------------
 2 files changed, 5 insertions(+), 46 deletions(-)

diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb
index dfe627b..49227b5 100644
--- a/src/app/controllers/api/images_controller.rb
+++ b/src/app/controllers/api/images_controller.rb
@@ -150,10 +150,10 @@ module Api
          !doc.xpath("/image/tdl").empty? &&
          !doc.xpath("/image/environment").empty?
 
-        template = Nokogiri::XML(doc.xpath("/image/tdl").text).xpath("/template")
+        template = doc.xpath("/image/tdl/template").to_xml
 
         { :type => :build,
-          :params => { :template => template.to_s,
+          :params => { :template => template,
                        :targets => doc.xpath("/image/targets").text,
                        :environment => doc.xpath("/image/environment").text}
         }
diff --git a/src/spec/controllers/api/images_controller_spec.rb b/src/spec/controllers/api/images_controller_spec.rb
index 85a5313..f2662a6 100644
--- a/src/spec/controllers/api/images_controller_spec.rb
+++ b/src/spec/controllers/api/images_controller_spec.rb
@@ -226,8 +226,7 @@ describe Api::ImagesController do
 
         context "when trying to build image" do
           before(:each) do
-            tpl =%q{<template>
-                      <name>Fedora 15 Template</name>
+            tpl =%q{<name>Fedora 15 Template</name>
                       <os>
                         <name>Fedora</name>
                         <version>15</version>
@@ -237,13 +236,12 @@ describe Api::ImagesController do
                         </install>
                         <rootpw>p at ssw0rd</rootpw>
                       </os>
-                      <description>A Fedora 15 Image Factory Template</description>
-                    </template>}
+                      <description>A Fedora 15 Image Factory Template</description>}
             xml = Nokogiri::XML::Builder.new do
               image {
                 targets "mock"
                 tdl {
-                  cdata(tpl)
+                  template tpl
                   target "mock"
                 }
                 environment "default"
@@ -312,45 +310,6 @@ describe Api::ImagesController do
           it { response.headers['Content-Type'].should include("application/xml") }
         end
 
-        context "when trying to build image with incorrect template XML without CDATA" do
-          before(:each) do
-            tpl =%q{template>
-                      <name>Fedora 15 Template</name>
-                      <os>
-                        <name>Fedora</name>
-                        <version>15</version>
-                        <arch>x86_64</arch>
-                        <install type='url'>
-                          <url>http://download.fedoraproject.org/pub/fedora/linux/releases/15/Fedora/x86_64/os/</url>
-                        </install>
-                        <rootpw>p at ssw0rd</rootpw>
-                      </os>
-                      <description>A Fedora 15 Image Factory Template</description>
-                    </template>}
-            xml = %{<image>
-                      <targets>mock</targets>
-                      <tdl>
-                        #{tpl}
-                        <target>mock</target>
-                      </tdl>
-                      <environment>default</environment>
-                    </image>}
-            Aeolus::Image::Factory::Image.stub(:new).and_return(@image)
-            Aeolus::Image::Warehouse::Image.stub(:create!).and_return(@image)
-            Aeolus::Image::Warehouse::Template.stub(:create!).and_return(@image)
-            @image.stub(:targets=).and_return(@image)
-            @image.stub(:template=).and_return(@image)
-            @image.stub(:save!)
-            Aeolus::Image::Factory::TargetImage.stub(:status).and_return(nil)
-
-            request.env['RAW_POST_DATA'] = xml
-            post :create
-          end
-
-          it { response.response_code.should == 400 }
-          it { response.headers['Content-Type'].should include("application/xml") }
-        end
-
         context "when trying to import image" do
           before(:each) do
             xml = Nokogiri::XML::Builder.new do
-- 
1.7.6.4




More information about the aeolus-devel mailing list