Ignore this patch, there will be some other changes related to this.

Dne 5.10.2010 11:02, [email protected] napsal(a):
> From: Jan Provaznik<[email protected]>
>
> - even if downloading of repomd file failed, empty groups.xml or packages.xml
> files were cached.
> - also fixed repository_manager's rspec filename
> ---
>   .../util/repository_manager/comps_repository.rb    |   22 +++++---
>   src/spec/utils/repository_manager.rb               |   45 ----------------
>   src/spec/utils/repository_manager_spec.rb          |   55 
> ++++++++++++++++++++
>   3 files changed, 68 insertions(+), 54 deletions(-)
>   delete mode 100644 src/spec/utils/repository_manager.rb
>   create mode 100644 src/spec/utils/repository_manager_spec.rb
>
> diff --git a/src/app/util/repository_manager/comps_repository.rb 
> b/src/app/util/repository_manager/comps_repository.rb
> index 4454e5a..2da48b9 100644
> --- a/src/app/util/repository_manager/comps_repository.rb
> +++ b/src/app/util/repository_manager/comps_repository.rb
> @@ -1,6 +1,9 @@
>   require 'util/repository_manager/abstract_repository'
>   require 'open-uri'
>
> +class MissingRepoPart<  StandardError
> +end
> +
>   class CompsRepository<  AbstractRepository
>     def initialize(conf)
>       super
> @@ -42,15 +45,19 @@ class CompsRepository<  AbstractRepository
>     def download_xml(type)
>       begin
>         url = get_url(type)
> -    rescue
> +    rescue MissingRepoPart
>         return ''
>       end
>
> -    xml_data = open(url)
> +    resp = Typhoeus::Request.get(url, :timeout =>  30000, :follow_location 
> =>  true, :max_redirects =>  3)
> +    unless resp.code == 200
> +      raise "failed to fetch #{url}: #{resp.body}"
> +    end
> +
>       if url =~ /\.gz$/
> -      return Zlib::GzipReader.new(xml_data).read
> +      return Zlib::GzipReader.new(resp.body).read
>       else
> -      return xml_data.read
> +      return resp.body
>       end
>     end
>
> @@ -103,15 +110,12 @@ class CompsRepository<  AbstractRepository
>         return File.join(@baseurl, 'repodata', 'repomd.xml')
>       else
>         location = 
> repomd.xpath("/xmlns:repomd/xmlns:da...@type=\"#{type}\"]/xmlns:location").first
> -      raise "location for #{type} data not found" unless location
> +      raise MissingRepoPart, "location for #{type} data not found" unless 
> location
>         return File.join(@baseurl, location['href'])
>       end
>     end
>
>     def repomd
> -    unless @repomd
> -      @repomd = Nokogiri::XML(get_xml('repomd'))
> -    end
> -    return @repomd
> +    @repomd ||= Nokogiri::XML(get_xml('repomd'))
>     end
>   end
> diff --git a/src/spec/utils/repository_manager.rb 
> b/src/spec/utils/repository_manager.rb
> deleted file mode 100644
> index cac151c..0000000
> --- a/src/spec/utils/repository_manager.rb
> +++ /dev/null
> @@ -1,45 +0,0 @@
> -require 'spec_helper'
> -
> -describe RepositoryManager do
> -  before(:all) do
> -    @repositories_json = File.read(File.join(File.dirname(__FILE__),
> -                                             
> '../fixtures/repositories.json'))
> -    @packagegroups_json = File.read(File.join(File.dirname(__FILE__),
> -                                              
> '../fixtures/packagegroups.json'))
> -    @packages_json = File.read(File.join(File.dirname(__FILE__),
> -                                         '../fixtures/packages.json'))
> -  end
> -
> -  before(:each) do
> -    hydra = Typhoeus::Hydra.hydra
> -    hydra.stub(:get, "http://pulptest/repositories/";).and_return(
> -      Typhoeus::Response.new(:code =>  200, :body =>  @repositories_json))
> -    hydra.stub(:get, 
> "http://pulptest/repositories/jboss/packagegroups/";).and_return(
> -      Typhoeus::Response.new(:code =>  200, :body =>  @packagegroups_json))
> -    hydra.stub(:get, 
> "http://pulptest/repositories/jboss/packages/";).and_return(
> -      Typhoeus::Response.new(:code =>  200, :body =>  @packages_json))
> -
> -    @rmanager = RepositoryManager.new(:config =>  [{
> -      'baseurl' =>  'http://pulptest',
> -      'yumurl' =>  'http://pulptest',
> -      'type'    =>  'pulp',
> -    }])
> -  end
> -
> -  it "should return a list of repositories" do
> -    @rmanager.repositories.should have(1).items
> -    @rmanager.repositories.first.id.should eql('jboss')
> -  end
> -
> -  it "should return a list of packagegroups" do
> -    rep = @rmanager.repositories.first
> -    rep.groups.keys.sort.should == ["JBoss Core Packages", "JBoss Drools",
> -      "JBoss Social Networking Web Application"]
> -  end
> -
> -  it "should return a list of packages" do
> -    rep = @rmanager.repositories.first
> -    rep.packages.map {|p| p[:name]}.sort.should == ["J-SocialNet", "JSDoc",
> -      "drools-guvnor", "jboss-as5", "jboss-jgroups", "jboss-rails"]
> -  end
> -end
> diff --git a/src/spec/utils/repository_manager_spec.rb 
> b/src/spec/utils/repository_manager_spec.rb
> new file mode 100644
> index 0000000..f38c507
> --- /dev/null
> +++ b/src/spec/utils/repository_manager_spec.rb
> @@ -0,0 +1,55 @@
> +require 'spec_helper'
> +
> +describe RepositoryManager do
> +  before(:all) do
> +    @repositories_json = File.read(File.join(File.dirname(__FILE__),
> +                                             
> '../fixtures/repositories.json'))
> +    @packagegroups_json = File.read(File.join(File.dirname(__FILE__),
> +                                              
> '../fixtures/packagegroups.json'))
> +    @packages_json = File.read(File.join(File.dirname(__FILE__),
> +                                         '../fixtures/packages.json'))
> +  end
> +
> +  before(:each) do
> +    hydra = Typhoeus::Hydra.hydra
> +    hydra.stub(:get, "http://pulptest/repositories/";).and_return(
> +      Typhoeus::Response.new(:code =>  200, :body =>  @repositories_json))
> +    hydra.stub(:get, 
> "http://pulptest/repositories/jboss/packagegroups/";).and_return(
> +      Typhoeus::Response.new(:code =>  200, :body =>  @packagegroups_json))
> +    hydra.stub(:get, 
> "http://pulptest/repositories/jboss/packages/";).and_return(
> +      Typhoeus::Response.new(:code =>  200, :body =>  @packages_json))
> +    hydra.stub(:get, "http://nonexisting.repo/";).and_return(
> +      Typhoeus::Response.new(:code =>  404))
> +
> +    @rmanager = RepositoryManager.new(:config =>  [{
> +      'baseurl' =>  'http://pulptest',
> +      'yumurl' =>  'http://pulptest',
> +      'type'    =>  'pulp',
> +    }])
> +  end
> +
> +  it "should return a list of repositories" do
> +    @rmanager.repositories.should have(1).items
> +    @rmanager.repositories.first.id.should eql('jboss')
> +  end
> +
> +  it "should return a list of packagegroups" do
> +    rep = @rmanager.repositories.first
> +    rep.groups.keys.sort.should == ["JBoss Core Packages", "JBoss Drools",
> +      "JBoss Social Networking Web Application"]
> +  end
> +
> +  it "should return a list of packages" do
> +    rep = @rmanager.repositories.first
> +    rep.packages.map {|p| p[:name]}.sort.should == ["J-SocialNet", "JSDoc",
> +      "drools-guvnor", "jboss-as5", "jboss-jgroups", "jboss-rails"]
> +  end
> +
> +  it "should raise exception when downloading of repomd fails" do
> +    @rmanager = RepositoryManager.new(:config =>  [{
> +      'baseurl' =>  'http://nonexisting.repo/',
> +      'type'    =>  'xml',
> +    }])
> +    lambda { @rmanager.all_groups}.should raise_error
> +  end
> +end

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to