Bugzilla – Attachment 71781 Details for
Bug 155701
installation source doesn't provide patches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
IDP Log In
|
Forgot Password
test script
zmd-test.rb (text/plain), 6.10 KB, created by
Jiří Suchomel
on 2006-03-08 15:17:12 UTC
(
hide
)
Description:
test script
Filename:
MIME Type:
Creator:
Jiří Suchomel
Created:
2006-03-08 15:17:12 UTC
Size:
6.10 KB
patch
obsolete
>require 'net/http' >require 'xmlrpc/client' >require 'digest_auth' >require 'pp' > >class XMLRPC::Client > def set_auth > if @user.nil? > @auth = nil > else > # determine the realm and other digest parameters doing a non authorized request. > uri = URI.parse"http://#{@user}:#{@password}@#{@host}:#{@port}#{@path}" > req = Net::HTTP::Get.new(uri.path) > res = Net::HTTP.start(uri.host, uri.port) do |http| > begin > http.request(req) > rescue > end > end > header = res['WWW-Authenticate'] > digest_auth = DigestAuth.gen_auth_header("POST", uri, header, true) > @auth = digest_auth > end > end > > > def do_rpc(request, async=false) > header = { > "User-Agent" => USER_AGENT, > "Content-Type" => "text/xml; charset=utf-8", > "Content-Length" => request.size.to_s, > "Connection" => (async ? "close" : "keep-alive") > } > > header["Cookie"] = @cookie if @cookie > header.update(@http_header_extra) if @http_header_extra > > if @auth != nil > # add authorization header > set_auth > header["Authorization"] = @auth > end > > resp = nil > @http_last_response = nil > > if async > # use a new HTTP object for each call > Net::HTTP.version_1_2 > http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) > http.use_ssl = @use_ssl if @use_ssl > http.read_timeout = @timeout > http.open_timeout = @timeout > > # post request > http.start { > resp = http.post2(@path, request, header) > } > else > # reuse the HTTP object for each call => connection alive is possible > > # post request > resp = @http.post2(@path, request, header) > end > > @http_last_response = resp > > data = resp.body > > if resp.code == "401" > # Authorization Required > raise "Authorization failed.\nHTTP-Error: #{resp.code} #{resp.message}" > elsif resp.code[0,1] != "2" > raise "HTTP-Error: #{resp.code} #{resp.message}" > end > > ct = parse_content_type(resp["Content-Type"]).first > if ct != "text/xml" > if ct == "text/html" > raise "Wrong content-type: \n#{data}" > else > raise "Wrong content-type" > end > end > > expected = resp["Content-Length"] || "<unknown>" > if data.nil? or data.size == 0 > raise "Wrong size. Was #{data.size}, should be #{expected}" > elsif expected.to_i != data.size and resp["Transfer-Encoding"].nil? > raise "Wrong size. Was #{data.size}, should be #{expected}" > end > > c = resp["Set-Cookie"] > @cookie = c if c > > return data > end > >end > >PREFIX="/usr/local" > >deviceid_file = File.new(PREFIX + '/etc/zmd/deviceid') >$deviceid = deviceid_file.read >$secret = "acd67553c7a94beb90e48f9f35fcdf42" > > ># this class is a prxy via XML-RPC to the local Zenworks ># daemon (via its XML-RPC module) >class ZmdProxy > > # constructs the XML-RPC proxy > def initialize( deviceid, secret ) > uri = "http://#{deviceid}:#{secret}@localhost:2544/zmd/RPC2" > @server = XMLRPC::Client.new2(uri) > end > > def get_error > ret = @error > @error = "" > return ret > end > > # get the list of patches by for catalog > def get_patches(catalog_id="") > begin > return @server.call("zmd.packsys.get_patches",catalog_id) > rescue(XMLRPC::FaultException) > puts "error : #{$!.faultString}" > return [] #InvalidCatalog > end > end > > # get the list of all available catalogs > def catalog_list > begin > result = @server.call("zmd.system.catalog_list") > return result > rescue(XMLRPC::FaultException) > puts "error : #{$!.faultString}" > # what to do here? > return [] > end > end > > # add new service [providing new catalogs] (hash) > def service_add(service) > begin > result = @server.call("zmd.system.service_add", service) > return result > rescue(XMLRPC::FaultException) > puts "error : #{$!.faultString}" > @error = $!.faultString > return nil > end > end > > # lists available services > def services_list > begin > return @server.call("zmd.system.service_list") > rescue(XMLRPC::FaultException) > puts "error : #{$!.faultString}" > return {} > end > end > > > # poll the progress of current action > def poll(id) > begin > result = @server.call("zmd.system.poll",id) > return result > rescue(XMLRPC::FaultException) > puts "poll error: $!.faultString" > return { > "status" => 4, > "messages" => [], > "percent" => 100, > "error" => $!.faultString > } > end > end >end > >class Hash > def method_missing(methodname, *args) > # hash to methodname conversion > return self[methodname.to_s] > end >end > ># original name eh? >class ActiveUpdate > @@proxy = ZmdProxy.new($deviceid, $secret) > def initialize > end >end > ># the class for handling patches >class Patch < ActiveUpdate > def self.find(kind=:installed) > case kind > when :installed > result = [] > when :available > result = [] > @@proxy.get_patches("").each do |p| > pp p > result.push p > end > end > return result > end >end > > ># class for handling catalogs >class Catalog < ActiveUpdate > def self.find(kind=:all) > return @@proxy.catalog_list > end >end > ># class for handling services >class Service < ActiveUpdate > def self.find(kind=:all) > return @@proxy.services_list > end > # parameter is hash, returns possible error message > def self.add(service) > res = @@proxy.service_add(service) > if res.nil? > return @@proxy.get_error > end > > done = false > # first, check the download progress > while not done > poll = @@proxy.poll(res) >pp poll > done = true if poll.status > 1 > end > if poll.status == 4 && !poll.messages.nil? > return poll.messages.join("\n") > end > return [res] > end >end > ># if we are being executed from this file itself, do some testing >if __FILE__ == $0 > > proxy = ZmdProxy.new($deviceid, $secret) > >#puts "------ sa: " >#Service.add({:type=>"YUM", :uri=>"https://armstrong.suse.de/download/Code/10/update/i386", :name=>"armstrong"}) > >puts "------ services: " >Service.find(:all).each do |s| > pp s >end > >puts "------ catalogs: " >Catalog.find(:all).each do |s| > pp s >end > >puts "------ patches: " >Patch.find(:available).each do |p| > pp p >end > >end >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
Attachments on
bug 155701
:
71518
|
71545
|
71546
|
71699
| 71781 |
71792