You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(3) |
Feb
(15) |
Mar
|
Apr
(9) |
May
|
Jun
(6) |
Jul
|
Aug
|
Sep
(23) |
Oct
(25) |
Nov
(44) |
Dec
(9) |
2010 |
Jan
(14) |
Feb
|
Mar
(4) |
Apr
(1) |
May
|
Jun
(3) |
Jul
|
Aug
(4) |
Sep
|
Oct
(10) |
Nov
(4) |
Dec
(22) |
2011 |
Jan
(14) |
Feb
|
Mar
(3) |
Apr
(7) |
May
(16) |
Jun
(4) |
Jul
(6) |
Aug
(3) |
Sep
|
Oct
(4) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
(10) |
Apr
(24) |
May
|
Jun
|
Jul
(2) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <jh...@us...> - 2011-04-12 06:08:39
|
Revision: 268 http://etch.svn.sourceforge.net/etch/?rev=268&view=rev Author: jheiss Date: 2011-04-12 06:08:33 +0000 (Tue, 12 Apr 2011) Log Message: ----------- Add xmlattrvalue method to XML abstraction layer Modified Paths: -------------- trunk/server/lib/etch.rb trunk/test/unit/test_xml_abstraction.rb Modified: trunk/server/lib/etch.rb =================================================================== --- trunk/server/lib/etch.rb 2011-04-12 01:23:53 UTC (rev 267) +++ trunk/server/lib/etch.rb 2011-04-12 06:08:33 UTC (rev 268) @@ -1414,6 +1414,19 @@ end end + def self.xmlattrvalue(elem, attrname) + case Etch.xmllib + when :libxml + elem.attributes[attrname] + when :nokogiri + elem[attrname] + when :rexml + elem.attributes[attrname] + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def self.xmlattrremove(elem, attribute) case Etch.xmllib when :libxml Modified: trunk/test/unit/test_xml_abstraction.rb =================================================================== --- trunk/test/unit/test_xml_abstraction.rb 2011-04-12 01:23:53 UTC (rev 267) +++ trunk/test/unit/test_xml_abstraction.rb 2011-04-12 06:08:33 UTC (rev 268) @@ -434,6 +434,17 @@ raise "Unknown XML library #{Etch.xmllib}" end end + def test_xmlattrvalue + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element attrname="attrvalue"><child/></element><element attrname="othervalue"/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + first = Etch.xmlarray(doc, '/root/element').first + second = Etch.xmlarray(doc, '/root/element').last + assert_equal('attrvalue', Etch.xmlattrvalue(first, 'attrname')) + assert_equal('othervalue', Etch.xmlattrvalue(second, 'attrname')) + end def test_xmlattrremove file = Tempfile.new('etch_xml_abstraction') file.puts '<root><element attrname="attrvalue"><child/></element><element attrname="othervalue"/><other/></root>' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-04-12 01:23:59
|
Revision: 267 http://etch.svn.sourceforge.net/etch/?rev=267&view=rev Author: jheiss Date: 2011-04-12 01:23:53 +0000 (Tue, 12 Apr 2011) Log Message: ----------- Add support for nokogiri as a choice of XML libraries in addition to the existing support for libxml and rexml. Modified Paths: -------------- trunk/server/lib/etch.rb trunk/server/lib/etchserver.rb trunk/test/README Modified: trunk/server/lib/etch.rb =================================================================== --- trunk/server/lib/etch.rb 2011-04-12 01:21:17 UTC (rev 266) +++ trunk/server/lib/etch.rb 2011-04-12 01:23:53 UTC (rev 267) @@ -3,6 +3,19 @@ require 'digest/sha1' # hexdigest require 'base64' # decode64, encode64 require 'fileutils' # mkdir_p +require 'erb' +require 'versiontype' # Version +require 'logger' + +class Etch + def self.xmllib + @@xmllib + end + def self.xmllib=(lib) + @@xmllib=lib + end +end + # By default we try to use libxml, falling back to rexml if it is not # available. The xmllib environment variable can be used to force one library # or the other, mostly for testing purposes. @@ -10,24 +23,24 @@ if !ENV['xmllib'] || ENV['xmllib'] == 'libxml' require 'rubygems' # libxml is a gem require 'libxml' - @@xmllib = :libxml + Etch.xmllib = :libxml + elsif ENV['xmllib'] == 'nokogiri' + require 'rubygems' # nokogiri is a gem + require 'nokogiri' + Etch.xmllib = :nokogiri else raise LoadError end rescue LoadError if !ENV['xmllib'] || ENV['xmllib'] == 'rexml' require 'rexml/document' - @@xmllib = :rexml + Etch.xmllib = :rexml else raise end end -require 'erb' -require 'versiontype' # Version -require 'logger' class Etch - # FIXME: I'm not really proud of this, it seems like there ought to be a way # to just use one logger. The problem is that on the server we'd like to # use RAILS_DEFAULT_LOGGER for general logging (which is logging to @@ -270,8 +283,10 @@ end # Validate the filtered file against config.dtd - if !Etch.xmlvalidate(config_xml, @config_dtd) - raise "Filtered config.xml for #{file} fails validation" + begin + Etch.xmlvalidate(config_xml, @config_dtd) + rescue Exception => e + raise Etch.wrap_exception(e, "Filtered config.xml for #{file} fails validation:\n" + e.message) end generation_status = :unknown @@ -846,8 +861,10 @@ end # Validate the filtered file against commands.dtd - if !Etch.xmlvalidate(commands_xml, @commands_dtd) - raise "Filtered commands.xml for #{command} fails validation" + begin + Etch.xmlvalidate(commands_xml, @commands_dtd) + rescue Exception => e + raise Etch.wrap_exception(e, "Filtered commands.xml for #{command} fails validation:\n" + e.message) end generation_status = :unknown @@ -1076,102 +1093,154 @@ end end + # These methods provide an abstraction from the underlying XML library in + # use, allowing us to use whatever the user has available and switch between + # libraries easily. + def self.xmlnewdoc - case @@xmllib + case Etch.xmllib when :libxml LibXML::XML::Document.new + when :nokogiri + Nokogiri::XML::Document.new when :rexml REXML::Document.new else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlroot(doc) - case @@xmllib + case Etch.xmllib when :libxml doc.root + when :nokogiri + doc.root when :rexml doc.root else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlsetroot(doc, root) - case @@xmllib + case Etch.xmllib when :libxml doc.root = root + when :nokogiri + doc.root = root when :rexml doc << root else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlload(file) - case @@xmllib + case Etch.xmllib when :libxml LibXML::XML::Document.file(file) + when :nokogiri + Nokogiri::XML(File.open(file)) do |config| + # Nokogiri is tolerant of malformed documents by default. Good when + # parsing HTML, but there's no reason for us to tolerate errors. We + # want to ensure that the user's instructions to us are clear. + config.options = Nokogiri::XML::ParseOptions::STRICT + end when :rexml REXML::Document.new(File.open(file)) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlloaddtd(dtdfile) - case @@xmllib + case Etch.xmllib when :libxml LibXML::XML::Dtd.new(IO.read(dtdfile)) + when :nokogiri + # For some reason there isn't a straightforward way to load a standalone + # DTD in Nokogiri + dtddoctext = '<!DOCTYPE dtd [' + File.read(dtdfile) + ']' + dtddoc = Nokogiri::XML(dtddoctext) + dtddoc.children.first when :rexml nil else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end + # Returns true if validation is successful, or if validation is not + # supported by the XML library in use. Raises an exception if validation + # fails. def self.xmlvalidate(xmldoc, dtd) - case @@xmllib + case Etch.xmllib when :libxml - xmldoc.validate(dtd) + result = xmldoc.validate(dtd) + # LibXML::XML::Document#validate is documented to return false if + # validation fails. However, as currently implemented it raises an + # exception instead. Just in case that behavior ever changes raise an + # exception if a false value is returned. + if result + true + else + raise "Validation failed" + end + when :nokogiri + errors = dtd.validate(xmldoc) + if errors.empty? + true + else + raise errors.join('|') + end when :rexml true else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end - def self.xmlnewelem(name) - case @@xmllib + def self.xmlnewelem(name, doc) + case Etch.xmllib when :libxml LibXML::XML::Node.new(name) + when :nokogiri + Nokogiri::XML::Element.new(name, doc) when :rexml REXML::Element.new(name) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmleach(xmldoc, xpath, &block) - case @@xmllib + case Etch.xmllib when :libxml xmldoc.find(xpath).each(&block) + when :nokogiri + xmldoc.xpath(xpath).each(&block) when :rexml xmldoc.elements.each(xpath, &block) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmleachall(xmldoc, &block) - case @@xmllib + case Etch.xmllib when :libxml if xmldoc.kind_of?(LibXML::XML::Document) xmldoc.root.each_element(&block) else xmldoc.each_element(&block) end + when :nokogiri + if xmldoc.kind_of?(Nokogiri::XML::Document) + xmldoc.root.element_children.each(&block) + else + xmldoc.element_children.each(&block) + end when :rexml if xmldoc.node_type == :document xmldoc.root.elements.each(&block) @@ -1179,23 +1248,25 @@ xmldoc.elements.each(&block) end else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmleachattrall(elem, &block) - case @@xmllib + case Etch.xmllib when :libxml elem.attributes.each(&block) + when :nokogiri + elem.attribute_nodes.each(&block) when :rexml elem.attributes.each_attribute(&block) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlarray(xmldoc, xpath) - case @@xmllib + case Etch.xmllib when :libxml elements = xmldoc.find(xpath) if elements @@ -1203,28 +1274,34 @@ else [] end + when :nokogiri + xmldoc.xpath(xpath).to_a when :rexml xmldoc.elements.to_a(xpath) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlfindfirst(xmldoc, xpath) - case @@xmllib + case Etch.xmllib when :libxml xmldoc.find_first(xpath) + when :nokogiri + xmldoc.at_xpath(xpath) when :rexml xmldoc.elements[xpath] else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmltext(elem) - case @@xmllib + case Etch.xmllib when :libxml elem.content + when :nokogiri + elem.content when :rexml text = elem.text # REXML returns nil rather than '' if there is no text @@ -1234,57 +1311,67 @@ '' end else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlsettext(elem, text) - case @@xmllib + case Etch.xmllib when :libxml elem.content = text + when :nokogiri + elem.content = text when :rexml elem.text = text else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmladd(xmldoc, xpath, name, contents=nil) - case @@xmllib + case Etch.xmllib when :libxml elem = LibXML::XML::Node.new(name) if contents elem.content = contents end xmldoc.find_first(xpath) << elem - elem + when :nokogiri + elem = Nokogiri::XML::Node.new(name, xmldoc) + if contents + elem.content = contents + end + xmldoc.at_xpath(xpath) << elem when :rexml elem = REXML::Element.new(name) if contents elem.text = contents end xmldoc.elements[xpath].add_element(elem) - elem else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlcopyelem(elem, destelem) - case @@xmllib + case Etch.xmllib when :libxml destelem << elem.copy(true) + when :nokogiri + destelem << elem.dup when :rexml - destelem.add_element(elem.dup) + destelem.add_element(elem.clone) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlremove(xmldoc, element) - case @@xmllib + case Etch.xmllib when :libxml element.remove! + when :nokogiri + element.remove when :rexml if xmldoc.node_type == :document xmldoc.root.elements.delete(element) @@ -1292,40 +1379,51 @@ xmldoc.elements.delete(element) end else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlremovepath(xmldoc, xpath) - case @@xmllib + case Etch.xmllib when :libxml xmldoc.find(xpath).each { |elem| elem.remove! } + when :nokogiri + xmldoc.xpath(xpath).each { |elem| elem.remove } when :rexml - xmldoc.delete_element(xpath) + elem = nil + # delete_element only removes the first match, so call it in a loop + # until it returns nil to indicate no matching element remain + begin + elem = xmldoc.delete_element(xpath) + end while elem != nil else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlattradd(elem, attrname, attrvalue) - case @@xmllib + case Etch.xmllib when :libxml elem.attributes[attrname] = attrvalue + when :nokogiri + elem[attrname] = attrvalue when :rexml elem.add_attribute(attrname, attrvalue) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end def self.xmlattrremove(elem, attribute) - case @@xmllib + case Etch.xmllib when :libxml attribute.remove! + when :nokogiri + attribute.remove when :rexml elem.attributes.delete(attribute) else - raise "Unknown @xmllib #{@xmllib}" + raise "Unknown XML library #{Etch.xmllib}" end end Modified: trunk/server/lib/etchserver.rb =================================================================== --- trunk/server/lib/etchserver.rb 2011-04-12 01:21:17 UTC (rev 266) +++ trunk/server/lib/etchserver.rb 2011-04-12 01:23:53 UTC (rev 267) @@ -3,25 +3,6 @@ require 'openssl' require 'time' # Time.parse require 'fileutils' # mkdir_p -# By default we try to use libxml, falling back to rexml if it is not -# available. The xmllib environment variable can be used to force one library -# or the other, mostly for testing purposes. -begin - if !ENV['xmllib'] || ENV['xmllib'] == 'libxml' - require 'rubygems' # libxml is a gem - require 'libxml' - @@xmllib = :libxml - else - raise LoadError - end -rescue LoadError - if !ENV['xmllib'] || ENV['xmllib'] == 'rexml' - require 'rexml/document' - @@xmllib = :rexml - else - raise - end -end require 'logger' require 'etch' @@ -372,11 +353,11 @@ # Generate the XML document to return to the client response_xml = Etch.xmlnewdoc - responseroot = Etch.xmlnewelem('files') + responseroot = Etch.xmlnewelem('files', response_xml) Etch.xmlsetroot(response_xml, responseroot) # Add configs for files we generated if response[:configs] - configs_xml = Etch.xmlnewelem('configs') + configs_xml = Etch.xmlnewelem('configs', response_xml) response[:configs].each do |file, config_xml| # Update the stored record of the config # Exclude configs which correspond to files for which we're requesting @@ -408,18 +389,18 @@ end end if !need_sum.empty? - need_sums_xml = Etch.xmlnewelem('need_sums') + need_sums_xml = Etch.xmlnewelem('need_sums', response_xml) need_sum.each do |need| - need_xml = Etch.xmlnewelem('need_sum') + need_xml = Etch.xmlnewelem('need_sum', response_xml) Etch.xmlsettext(need_xml, need) need_sums_xml << need_xml end responseroot << need_sums_xml end if !need_orig.empty? - need_origs_xml = Etch.xmlnewelem('need_origs') + need_origs_xml = Etch.xmlnewelem('need_origs', response_xml) need_orig.each do |need| - need_xml = Etch.xmlnewelem('need_orig') + need_xml = Etch.xmlnewelem('need_orig', response_xml) Etch.xmlsettext(need_xml, need) need_origs_xml << need_xml end @@ -431,7 +412,7 @@ # "commands", so we have to use something different here as the XML # element we insert all of those into as part of the response. if response[:allcommands] - commands_xml = Etch.xmlnewelem('allcommands') + commands_xml = Etch.xmlnewelem('allcommands', response_xml) response[:allcommands].each do |commandname, command_xml| # Update the stored record of the command config = EtchConfig.find_or_create_by_client_id_and_file(:client_id => @client.id, :file => commandname, :config => command_xml.to_s) @@ -444,19 +425,19 @@ responseroot << commands_xml end if response[:retrycommands] - retrycommands_xml = Etch.xmlnewelem('retrycommands') + retrycommands_xml = Etch.xmlnewelem('retrycommands', response_xml) response[:retrycommands].each_key do |commandname| - retry_xml = Etch.xmlnewelem('retrycommand') + retry_xml = Etch.xmlnewelem('retrycommand', response_xml) Etch.xmlsettext(retry_xml, commandname) retrycommands_xml << retry_xml end responseroot << retrycommands_xml end - # FIXME: clean up XML formatting + # Clean up XML formatting # But only if we're in debug mode, in regular mode nobody but the # machines will see the XML and they don't care if it is pretty. - # Tidy's formatting breaks things, it inserts leading/trailing whitespace into text nodes + # FIXME: Tidy's formatting breaks things, it inserts leading/trailing whitespace into text nodes if @debug && false require 'tidy' Tidy.path = '/sw/lib/libtidy.dylib' Modified: trunk/test/README =================================================================== --- trunk/test/README 2011-04-12 01:21:17 UTC (rev 266) +++ trunk/test/README 2011-04-12 01:23:53 UTC (rev 267) @@ -3,8 +3,8 @@ To execute a specific test method run "rake test TEST=test/file.rb TESTOPTS='--name=test_files'" -To force a particular XML library set xmllib=libxml or xmllib=rexml in -your environment before running the tests. +To force a particular XML library set xmllib=libxml or xmllib=nokogiri or +xmllib=rexml in your environment before running the tests. Some of the older files here have all of their tests in one method. Over time I'm breaking those up into multiple methods so that it is easier to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-04-12 01:21:23
|
Revision: 266 http://etch.svn.sourceforge.net/etch/?rev=266&view=rev Author: jheiss Date: 2011-04-12 01:21:17 +0000 (Tue, 12 Apr 2011) Log Message: ----------- Add unit tests of XML abstraction functions Added Paths: ----------- trunk/test/unit/ trunk/test/unit/test_xml_abstraction.rb Added: trunk/test/unit/test_xml_abstraction.rb =================================================================== --- trunk/test/unit/test_xml_abstraction.rb (rev 0) +++ trunk/test/unit/test_xml_abstraction.rb 2011-04-12 01:21:17 UTC (rev 266) @@ -0,0 +1,465 @@ +require 'test/unit' +require 'tempfile' +$: << "#{File.dirname(File.expand_path(__FILE__))}/../../server/lib" +require 'etch' + +# Test the XML abstraction methods in etch.rb + +class TestXMLAbstraction < Test::Unit::TestCase + def test_xmlnewdoc + puts "Etch is using XML library: " + Etch.xmllib.to_s + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Document, Etch.xmlnewdoc) + when :nokogiri + assert_kind_of(Nokogiri::XML::Document, Etch.xmlnewdoc) + when :rexml + assert_kind_of(REXML::Document, Etch.xmlnewdoc) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlroot_and_xmlsetroot + doc = Etch.xmlnewdoc + Etch.xmlsetroot(doc, Etch.xmlnewelem('root', doc)) + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + when :nokogiri + assert_kind_of(Nokogiri::XML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + when :rexml + assert_kind_of(REXML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlload + goodfile = Tempfile.new('etch_xml_abstraction') + goodfile.puts '<root><element/></root>' + goodfile.close + doc = Etch.xmlload(goodfile.path) + badfile = Tempfile.new('etch_xml_abstraction') + badfile.puts '<badroot>' + badfile.close + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + assert_raises(LibXML::XML::Error) { Etch.xmlload(badfile.path) } + when :nokogiri + assert_kind_of(Nokogiri::XML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + assert_raises(Nokogiri::XML::SyntaxError) { Etch.xmlload(badfile.path) } + when :rexml + assert_kind_of(REXML::Node, Etch.xmlroot(doc)) + assert_equal('root', Etch.xmlroot(doc).name) + assert_raises(REXML::ParseException) { Etch.xmlload(badfile.path) } + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlloaddtd + dtdfile = Tempfile.new('etch_xml_abstraction') + dtdfile.puts '<!ELEMENT root (element)>' + dtdfile.puts '<!ELEMENT element EMPTY>' + dtdfile.close + dtd = Etch.xmlloaddtd(dtdfile.path) + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Dtd, dtd) + when :nokogiri + assert_kind_of(Nokogiri::XML::DTD, dtd) + when :rexml + assert_nil(dtd) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlvalidate + goodfile = Tempfile.new('etch_xml_abstraction') + goodfile.puts '<root><element/></root>' + goodfile.close + gooddoc = Etch.xmlload(goodfile.path) + + badfile = Tempfile.new('etch_xml_abstraction') + badfile.puts '<root/>' + badfile.close + baddoc = Etch.xmlload(badfile.path) + + dtdfile = Tempfile.new('etch_xml_abstraction') + dtdfile.puts '<!ELEMENT root (element)>' + dtdfile.puts '<!ELEMENT element EMPTY>' + dtdfile.close + dtd = Etch.xmlloaddtd(dtdfile.path) + + case Etch.xmllib + when :libxml + assert(Etch.xmlvalidate(gooddoc, dtd)) + assert_raises(LibXML::XML::Error) { Etch.xmlvalidate(baddoc, dtd) } + when :nokogiri + assert(Etch.xmlvalidate(gooddoc, dtd)) + assert_raises(RuntimeError) { Etch.xmlvalidate(baddoc, dtd) } + when :rexml + # REXML doesn't support validation, xmlvalidate will always return true + assert(Etch.xmlvalidate(gooddoc, dtd)) + assert(Etch.xmlvalidate(baddoc, dtd)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlnewelem + doc = Etch.xmlnewdoc + elem = Etch.xmlnewelem('element', doc) + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert_equal('element', elem.name) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert_equal('element', elem.name) + when :rexml + assert_kind_of(REXML::Element, elem) + assert_equal('element', elem.name) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmleach + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element/><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + counter = 0 + Etch.xmleach(doc, '/root/element') do |elem| + counter += 1 + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert_equal('element', elem.name) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert_equal('element', elem.name) + when :rexml + assert_kind_of(REXML::Element, elem) + assert_equal('element', elem.name) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + assert_equal(2, counter) + end + def test_xmleachall + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/><otherchild/></element><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + counter = 0 + Etch.xmleachall(doc) do |elem| + counter += 1 + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert(['element', 'other'].include?(elem.name)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert(['element', 'other'].include?(elem.name)) + when :rexml + assert_kind_of(REXML::Element, elem) + assert(['element', 'other'].include?(elem.name)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + assert_equal(3, counter) + + counter = 0 + Etch.xmleachall(Etch.xmlfindfirst(doc, '/root/element')) do |elem| + counter += 1 + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert(['child', 'otherchild'].include?(elem.name)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert(['child', 'otherchild'].include?(elem.name)) + when :rexml + assert_kind_of(REXML::Element, elem) + assert(['child', 'otherchild'].include?(elem.name)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + assert_equal(2, counter) + + end + def test_xmleachattrall + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root attrone="foo" attrtwo="bar"/>' + file.close + doc = Etch.xmlload(file.path) + + counter = 0 + Etch.xmleachattrall(doc.root) do |attr| + counter += 1 + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Attr, attr) + assert(['attrone', 'attrtwo'].include?(attr.name)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Attr, attr) + assert(['attrone', 'attrtwo'].include?(attr.name)) + when :rexml + assert_kind_of(REXML::Attribute, attr) + assert(['attrone', 'attrtwo'].include?(attr.name)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + assert_equal(2, counter) + end + def test_xmlarray + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element/><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + assert_kind_of(Array, Etch.xmlarray(doc, '/root/*')) + assert_equal(3, Etch.xmlarray(doc, '/root/*').length) + + assert_kind_of(Array, Etch.xmlarray(doc, '/root/element')) + assert_equal(2, Etch.xmlarray(doc, '/root/element').length) + + assert_kind_of(Array, Etch.xmlarray(doc, '/root/bogus')) + assert_equal(0, Etch.xmlarray(doc, '/root/bogus').length) + + Etch.xmlarray(doc, '/root/*').each do |elem| + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert(['element', 'other'].include?(elem.name)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert(['element', 'other'].include?(elem.name)) + when :rexml + assert_kind_of(REXML::Element, elem) + assert(['element', 'other'].include?(elem.name)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + end + def test_xmlfindfirst + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/><otherchild/></element><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + elem = Etch.xmlfindfirst(doc, '/root/element') + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, elem) + assert_equal('element', elem.name) + # This ensures we got the first <element> and not the second + assert_equal(2, elem.children.length) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, elem) + assert_equal('element', elem.name) + # This ensures we got the first <element> and not the second + assert_equal(2, elem.children.length) + when :rexml + assert_kind_of(REXML::Element, elem) + assert_equal('element', elem.name) + # This ensures we got the first <element> and not the second + assert_equal(2, elem.children.length) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmltext + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element>some text</element><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + assert_equal('some text', Etch.xmltext(Etch.xmlfindfirst(doc, '/root/element'))) + assert_equal('', Etch.xmltext(Etch.xmlfindfirst(doc, '/root/other'))) + end + def test_xmlsettext + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element>some text</element><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + Etch.xmlsettext(Etch.xmlfindfirst(doc, '/root/element'), 'new text') + assert_equal('new text', Etch.xmltext(Etch.xmlfindfirst(doc, '/root/element'))) + Etch.xmlsettext(Etch.xmlfindfirst(doc, '/root/other'), 'other text') + assert_equal('other text', Etch.xmltext(Etch.xmlfindfirst(doc, '/root/other'))) + end + def test_xmladd + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element/></root>' + file.close + doc = Etch.xmlload(file.path) + + Etch.xmladd(doc, '/root/element', 'childone') + Etch.xmladd(doc, '/root/element', 'childtwo', 'some text') + childone = Etch.xmlfindfirst(doc, '/root/element/childone') + childtwo = Etch.xmlfindfirst(doc, '/root/element/childtwo') + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, childone) + assert_equal('childone', childone.name) + assert_equal('', Etch.xmltext(childone)) + assert_kind_of(LibXML::XML::Node, childtwo) + assert_equal('childtwo', childtwo.name) + assert_equal('some text', Etch.xmltext(childtwo)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, childone) + assert_equal('childone', childone.name) + assert_equal('', Etch.xmltext(childone)) + assert_kind_of(Nokogiri::XML::Element, childtwo) + assert_equal('childtwo', childtwo.name) + assert_equal('some text', Etch.xmltext(childtwo)) + when :rexml + assert_kind_of(REXML::Element, childone) + assert_equal('childone', childone.name) + assert_equal('', Etch.xmltext(childone)) + assert_kind_of(REXML::Element, childtwo) + assert_equal('childtwo', childtwo.name) + assert_equal('some text', Etch.xmltext(childtwo)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlcopyelem + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/></element><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + original = Etch.xmlfindfirst(doc, '/root/element/child') + Etch.xmlcopyelem(original, Etch.xmlfindfirst(doc, '/root/other')) + copy = Etch.xmlfindfirst(doc, '/root/other/child') + # Change the child so that we can test that it is separate from the orignal + Etch.xmlsettext(copy, 'some text') + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, original) + assert_kind_of(LibXML::XML::Node, copy) + assert_equal('child', original.name) + assert_equal('', Etch.xmltext(original)) + assert_equal('child', copy.name) + assert_equal('some text', Etch.xmltext(copy)) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, original) + assert_kind_of(Nokogiri::XML::Element, copy) + assert_equal('child', original.name) + assert_equal('', Etch.xmltext(original)) + assert_equal('child', copy.name) + assert_equal('some text', Etch.xmltext(copy)) + when :rexml + assert_kind_of(REXML::Element, original) + assert_kind_of(REXML::Element, copy) + assert_equal('child', original.name) + assert_equal('', Etch.xmltext(original)) + assert_equal('child', copy.name) + assert_equal('some text', Etch.xmltext(copy)) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlremove + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/></element><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + Etch.xmlremove(doc, Etch.xmlfindfirst(doc, '/root/element')) + assert_nil(Etch.xmlfindfirst(doc, '/root/element')) + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, Etch.xmlfindfirst(doc, '/root/other')) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, Etch.xmlfindfirst(doc, '/root/other')) + when :rexml + assert_kind_of(REXML::Element, Etch.xmlfindfirst(doc, '/root/other')) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlremovepath + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/></element><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + Etch.xmlremovepath(doc, '/root/element') + assert_nil(Etch.xmlfindfirst(doc, '/root/element')) + case Etch.xmllib + when :libxml + assert_kind_of(LibXML::XML::Node, Etch.xmlfindfirst(doc, '/root/other')) + when :nokogiri + assert_kind_of(Nokogiri::XML::Element, Etch.xmlfindfirst(doc, '/root/other')) + when :rexml + assert_kind_of(REXML::Element, Etch.xmlfindfirst(doc, '/root/other')) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlattradd + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element><child/></element><element/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + first = Etch.xmlarray(doc, '/root/element').first + second = Etch.xmlarray(doc, '/root/element').last + Etch.xmlattradd(first, 'attrname', 'attrvalue') + case Etch.xmllib + when :libxml + assert_equal('attrvalue', first.attributes['attrname']) + assert_nil(second.attributes['attrname']) + when :nokogiri + assert_equal('attrvalue', first['attrname']) + assert_nil(second['attrname']) + when :rexml + assert_equal('attrvalue', first.attributes['attrname']) + assert_nil(second.attributes['attrname']) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end + def test_xmlattrremove + file = Tempfile.new('etch_xml_abstraction') + file.puts '<root><element attrname="attrvalue"><child/></element><element attrname="othervalue"/><other/></root>' + file.close + doc = Etch.xmlload(file.path) + + first = Etch.xmlarray(doc, '/root/element').first + second = Etch.xmlarray(doc, '/root/element').last + + Etch.xmleachattrall(first) do |attr| + Etch.xmlattrremove(first, attr) + end + + case Etch.xmllib + when :libxml + assert_nil(first.attributes['attrname']) + assert_equal('othervalue', second.attributes['attrname']) + when :nokogiri + assert_nil(first['attrname']) + assert_equal('othervalue', second['attrname']) + when :rexml + assert_nil(first.attributes['attrname']) + assert_equal('othervalue', second.attributes['attrname']) + else + raise "Unknown XML library #{Etch.xmllib}" + end + end +end + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-03-11 21:27:07
|
Revision: 265 http://etch.svn.sourceforge.net/etch/?rev=265&view=rev Author: jheiss Date: 2011-03-11 21:27:00 +0000 (Fri, 11 Mar 2011) Log Message: ----------- Add my rc.static-routes and rc.virtfs scripts and associated infrastructure for managing static routes and virtual interfaces on various platforms. Added Paths: ----------- trunk/etchserver-samples/source/etc/network/ trunk/etchserver-samples/source/etc/network/if-up.d/ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local trunk/etchserver-samples/source/etc/rc.static-routes/ trunk/etchserver-samples/source/etc/rc.static-routes/config.xml trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes trunk/etchserver-samples/source/etc/rc.virtifs/ trunk/etchserver-samples/source/etc/rc.virtifs/config.xml trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml trunk/etchserver-samples/source/etc/static-routes/ trunk/etchserver-samples/source/etc/static-routes/config.xml trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 trunk/etchserver-samples/source/etc/static-routes/static-routes.script trunk/etchserver-samples/source/etc/virtifs/ trunk/etchserver-samples/source/etc/virtifs/config.xml trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf trunk/etchserver-samples/source/etc/virtifs/virtifs.script trunk/etchserver-samples/source/sbin/ trunk/etchserver-samples/source/sbin/ifup-local/ trunk/etchserver-samples/source/sbin/ifup-local/config.xml trunk/etchserver-samples/source/sbin/ifup-local/ifup-local Added: trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,11 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="/Debian|Ubuntu/">ifup-local</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local =================================================================== --- trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local (rev 0) +++ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,7 @@ +#!/bin/sh + +# Setup any virtual interfaces needed on this system +/etc/rc.virtifs +# Setup any custom routing needed on this system +/etc/rc.static-routes + Added: trunk/etchserver-samples/source/etc/rc.static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc.static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc.static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,16 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain>rc.static-routes</plain> + </source> + </file> + <test> + <exec kernel="Linux">ping -c1 -W20 -q etch</exec> + <exec operatingsystem="Solaris">ping etch 20</exec> + <exec operatingsystem="FreeBSD">ping -c1 -t20 -q etch</exec> + </test> +</config> + Added: trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes =================================================================== --- trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes (rev 0) +++ trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,445 @@ +#!/usr/bin/perl -w +############################################################################## +# This script controls routing on systems which need some form of static +# routing configuration. +############################################################################## + +$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin'; + +my $OS = `uname -s`; +chomp $OS; + +my $ROUTE_CONFIG = "/etc/static-routes"; + +# Silently exit if the route config file doesn't exist, that's an +# indication that this machine doesn't need any special routing. +exit if (! -f $ROUTE_CONFIG); + +# First clean out any existing static routes +clean_routing_table(); + +# Then add the desired static routes +open(RC, "<$ROUTE_CONFIG") || die; +while(<RC>) +{ + next if (/^\s*#/); # Skip comments + next if (/^\s*$/); # And blank lines + + # Lines in the file contain two fields, seperated by whitespace. + # The first field is a destination (network and netmask) in + # nnn.nnn.nnn.nnn/xx format. + # The second field is either a gateway IP, or a network + # interface name. + # Examples: + # 10.0.0.0/4 10.8.90.1 + # 224.0.0.0/4 eth0 + + my ($dest, $via) = split; + if ($dest && $via) + { + if (($dest =~ /\//) || ($dest eq "default")) + { + if ($via =~ /^\d+\.\d+\.\d+\.\d+$/) + { + add_route_via_gateway($dest, $via); + } + else + { + add_route_via_interface($dest, $via); + } + } + else + { + if ($via =~ /^\d+\.\d+\.\d+\.\d+$/) + { + add_host_route_via_gateway($dest, $via); + } + else + { + add_host_route_via_interface($dest, $via); + } + } + } +} +close(RC); + +# +# Subroutines +# + +sub clean_routing_table +{ + # Look through the routing table for things that look like + # static routes and remove them. + open(NETSTAT, 'netstat -rn |') || die; + while(<NETSTAT>) + { + if ($OS eq 'Linux') + { + my ($dest, $gw, $mask, + $flags, $mss, $window, $irtt, $if) = split; + # On Linux it seems that if the Gateway field + # is an IP address but isn't 0.0.0.0 then the + # route is static. + # Except for routes specified by interface + # instead of gateway. It seems impossible to + # distinguish those in a general sense, so we + # cheat and make an exception for our multicast + # route. + if ($gw && + $gw =~ /^\d+\.\d+\.\d+\.\d+$/ && + $gw ne '0.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + delete_route_via_gateway($dest, $gw, $mask); + } + } + elsif ($dest && $dest eq '224.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if, $mask); + } + else + { + delete_route_via_interface($dest, $if, $mask); + } + } + + } + elsif ($OS eq 'SunOS') + { + my ($dest, $gw, $flags, $ref, $use, $if) = split; + # On Solaris it seems that if the Interface + # field is empty then the route is static. + # Except for routes specified by interface + # instead of gateway. It seems impossible to + # distinguish those in a general sense, so we + # cheat and make an exception for our multicast + # route. + if ($gw && $gw =~ /^\d+\.\d+\.\d+\.\d+$/ && ! $if) + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + # There doesn't appear to be a way to + # get Solaris to show you the netmask + # associated with existing routes, but + # you need the netmask to remove the + # routes. So guess at the netmask for + # standard routes in our environment and + # hope for the best. + if ($dest =~ /^10.0/) + { + $dest .= "/8"; + } + elsif ($dest =~ /^10./) + { + $dest .= "/16"; + } + elsif ($dest =~ /^172.16/) + { + $dest .= "/12"; + } + elsif ($dest =~ /^192.168/) + { + $dest .= "/16"; + } + elsif ($dest =~ /^224/) + { + $dest .= "/4"; + } + + delete_route_via_gateway($dest, $gw); + } + } + elsif ($dest && $dest eq '224.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if); + } + else + { + # Guess at the netmask here too + $dest .= "/4"; + + delete_route_via_interface($dest, $if); + } + } + } + elsif ($OS eq 'FreeBSD') + { + my ($dest, $gw, $flags, $ref, $use, $if) = split; + # On FreeBSD if the 'Flags' field contains a 'S' + # then the route is static. How civilized. + if ($flags && $flags =~ /S/) + { + if ($gw =~ /^\d+\.\d+\.\d+\.\d+$/) + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + delete_route_via_gateway($dest, $gw); + } + } + else + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if); + } + else + { + delete_route_via_interface($dest, $if); + } + } + } + } + } + close(NETSTAT); +} + +sub add_route_via_gateway +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route add -net $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route add -net $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route add -net $dest $gw"); + } +} + +sub add_host_route_via_gateway +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route add -host $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route add -host $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route add -host $dest $gw"); + } +} + +sub add_route_via_interface +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route add -net $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route add -net $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route add -net $dest -interface $if"); + } +} + +sub add_host_route_via_interface +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route add -host $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route add -host $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route add -host $dest -interface $if"); + } +} + +sub delete_route_via_gateway +{ + # The mask is only supplied for Linux systems, on Solaris and + # FreeBSD the mask is attached in /xx format to the destination + # This is because netstat -rn on Linux reports the netmask + # associated with each route in a seperate column, rather than + # attaching it to the network number with the /xx format. + # And I'm too lazy to convert it. + my ($dest, $gw, $mask) = @_; + + if ($OS eq 'Linux') + { + system("route del -net $dest netmask $mask gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route delete -net $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -net $dest $gw"); + } +} + +sub delete_host_route_via_gateway +{ + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route del -host $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route delete -host $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -host $dest $gw"); + } +} + +sub delete_route_via_interface +{ + # The mask is only supplied for Linux systems, on Solaris and + # FreeBSD the mask is attached in /xx format to the destination. + # This is because netstat -rn on Linux reports the netmask + # associated with each route in a seperate column, rather than + # attaching it to the network number with the /xx format. + # And I'm too lazy to convert it. + my ($dest, $if, $mask) = @_; + + if ($OS eq 'Linux') + { + system("route del -net $dest netmask $mask dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route delete -net $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -net $dest -interface $if"); + } +} + +sub delete_host_route_via_interface +{ + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route del -host $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route delete -host $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -host $dest -interface $if"); + } +} + Added: trunk/etchserver-samples/source/etc/rc.virtifs/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc.virtifs/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc.virtifs/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +<config> + <file> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain>rc.virtifs</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs =================================================================== --- trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs (rev 0) +++ trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,80 @@ +#!/usr/bin/ruby -w + +require 'facter' +require 'resolv' +require 'ipaddr' + +ENV['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' + +VIRTIFS_CONFIG = '/etc/virtifs' + +# Silently exit if the config file doesn't exist, that's an indication +# that this machine doesn't need any virtual interfaces configured. +exit if !File.exist?(VIRTIFS_CONFIG) + +# Tell facter to load everything, otherwise it tries to dynamically +# load the individual fact libraries using a very broken mechanism +Facter.loadfacts + +# Prepare the configuration of our virtual interfaces +virtcounters = {} +virtifs = {} +IO.foreach(VIRTIFS_CONFIG) do |line| + line.chomp! + next if line =~ /^\s*#/ # Skip comments + next if line =~ /^\s*$/ # And blank lines + hostname, cachedip = line.split + + # Try to look up the IP for that hostname + res = Resolv::DNS::new() + ip = nil + begin + addr = res.getaddress(hostname) + ip = addr.to_s + rescue Resolv::ResolvError + ip = cachedip + end + ipaddr = IPAddr.new(ip) + + # Find the physical interface to which this virtual interface should + # belong + Facter['interfaces'].value.split(',').each do |nic| + if nic !~ /:/ && nic !~ /__tmp/ + ifip = Facter["ipaddress_#{nic}"].value + next if ifip.nil? + mask = Facter["netmask_#{nic}"].value + subnetaddr = IPAddr.new("#{ifip}/#{mask}") + if subnetaddr.include?(ipaddr) + # Calculate the virtual interface name + virtif = nic + ':' + if virtcounters.has_key?(nic) + virtcounters[nic] += 1 + else + virtcounters[nic] = 0 + end + virtif << virtcounters[nic].to_s + # Store the interface data + virtifs[virtif] = { 'ip' => ip, 'mask' => mask } + break + end + end + end +end + +# Clean up any existing virtual interfaces +Facter['interfaces'].value.split(',').each do |nic| + if nic =~ /:/ + puts "ifconfig #{nic} down" + system "ifconfig #{nic} down" + end +end + +# Activate our virtual interface configuration +virtifs.each do |virtif, virtifdata| + ip = virtifdata['ip'] + mask = virtifdata['mask'] + + puts "ifconfig #{virtif} #{ip} netmask #{mask}" + system "ifconfig #{virtif} #{ip} netmask #{mask}" +end + Added: trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes =================================================================== --- trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes (rev 0) +++ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,9 @@ +#!/bin/sh + +# Solaris assumes init scripts are shell scripts and explicity calls +# them via /sbin/sh rather than just executing them. rc.static-routes +# is a Perl script, so this is a simple wrapper around it to make things +# work properly. + +/etc/rc.static-routes "$@" + Added: trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +<config> + <file> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="Solaris">S70static-routes</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,20 @@ +<config> + <depend>/etc/rc.static-routes</depend> + + <file> + <source> + <script>static-routes.script</script> + </source> + </file> + + <post> + <exec>/etc/rc.static-routes</exec> + </post> + + <test> + <exec kernel="Linux">ping -c3 -W20 -q etch</exec> + <exec operatingsystem="Solaris">sleep 3 ; ping etch 20</exec> + <exec operatingsystem="FreeBSD">ping -c3 -t20 -q etch</exec> + </test> +</config> + Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,4 @@ +# nodegroup # filename +nodegroup1 static-routes.group1 +nodegroup2 static-routes.group2 + Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,9 @@ +# You might have multiple clients that need a similar set of routes, but +# those clients are on multiple subnets and they need to use the correct +# gateway for their subnet. No worries, just list them all here and +# static-routes.script will only add the routes that are reachable by +# any given client. +default 10.1.8.10 +10.0.0.0/8 10.1.8.1 +default 10.1.10.10 +10.0.0.0/8 10.1.10.1 Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +# You might have multiple clients that need a similar set of routes, but +# those clients are on multiple subnets and they need to use the correct +# gateway for their subnet. No worries, just list them all here and +# static-routes.script will only add the routes that are reachable by +# any given client. +default 10.1.10.1 +default 10.1.12.1 +default 10.3.12.1 +default 10.3.14.1 +224.0.0.0/4 eth1 Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.script =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.script (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.script 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,76 @@ +#!/usr/bin/ruby + +require 'ipaddr' + +# Given an IP return true if the IP is in the same subnet as any of the +# interfaces on this machine +def directly_reachable(target) + number_of_interfaces_checked = 0 + @facts['interfaces'].split(',').each do |inf| + if @facts["ipaddress_#{inf}"] && @facts["netmask_#{inf}"] + number_of_interfaces_checked += 1 + infaddr = IPAddr.new(@facts["ipaddress_#{inf}"] + '/' + @facts["netmask_#{inf}"]) + return true if infaddr.include?(IPAddr.new(target)) + end + end + if number_of_interfaces_checked > 0 + return false + else + # If Facter failed for some reason and didn't send us any interface + # data we don't want to have etch unconfigure/misconfigure the + # networking on the client + abort "No interface addresses/netmasks received" + end +end + +# Filters the supplied routing config file, leaving only routes which have +# a destination directly reachable via one of the client's interfaces. This +# allows us to put the routes for all subnets in one file, rather than +# maintaining a seperate route file for each subnet. This isn't strictly +# necessary on some platforms, as on those platforms attempting to add a +# route to an unreachable destination will fail. However, there are +# platforms that will let you add routes to unreachable destinations, and +# packets taking that route silently disappear. +def filter(file) + output = '' + IO.foreach(file) do |line| + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + dest, via = line.split + if via =~ /^\d+\.\d+\.\d+\.\d+$/ && directly_reachable(via) + output << line + else + @facts['interfaces'].split(',').each do |inf| + if via == inf + output << line + end + end + end + end + + if !output.empty? + output.insert(0, "# Entries from #{file}\n") + end + output +end + +test_contents = [] +IO.foreach('static-routes.etchconf') do |line| + line.chomp! + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + group, file = line.split(' ', 2) + if @groups.include?(group) + test_contents << filter(file) + end +end + +if !test_contents.empty? + testpass = '' + test_contents.each { |lines| lines.each { |line| dest, via = line.split ; (testpass = true) if dest == 'default' }} + if testpass == true + test_contents.each { |addme| @contents << addme } + end +end Added: trunk/etchserver-samples/source/etc/virtifs/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,14 @@ +<config> + <depend>/etc/rc.virtifs</depend> + + <file> + <source> + <script>virtifs.script</script> + </source> + </file> + + <post> + <exec>/etc/rc.virtifs</exec> + </post> +</config> + Added: trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,4 @@ +# Node group Virtual IP or hostname +nodegroup1 10.1.2.3 +nodegroup2 virtual1.example.com + Added: trunk/etchserver-samples/source/etc/virtifs/virtifs.script =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/virtifs.script (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/virtifs.script 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,21 @@ +#!/usr/bin/ruby + +require 'resolv' + +IO.foreach('virtifs.etchconf') do |line| + line.chomp! + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + group, hostname = line.split + if @groups.include?(group) + res = Resolv::DNS::new() + addr = res.getaddress(hostname) + if !addr + abort "DNS lookup of virtual interface #{hostname} failed" + end + ip = addr.to_s + @contents << hostname << ' ' << ip << "\n" + end +end + Added: trunk/etchserver-samples/source/sbin/ifup-local/config.xml =================================================================== --- trunk/etchserver-samples/source/sbin/ifup-local/config.xml (rev 0) +++ trunk/etchserver-samples/source/sbin/ifup-local/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,11 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="/RedHat|CentOS/">ifup-local</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/sbin/ifup-local/ifup-local =================================================================== --- trunk/etchserver-samples/source/sbin/ifup-local/ifup-local (rev 0) +++ trunk/etchserver-samples/source/sbin/ifup-local/ifup-local 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,8 @@ +#!/bin/sh + +# Setup any virtual interfaces needed on this system +/etc/rc.virtifs +# Setup any custom routing needed on this system +/etc/rc.static-routes + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-03-11 01:11:21
|
Revision: 264 http://etch.svn.sourceforge.net/etch/?rev=264&view=rev Author: jheiss Date: 2011-03-11 01:11:15 +0000 (Fri, 11 Mar 2011) Log Message: ----------- Add tests for scripts that call return or exit. Fix handling of scripts that call return. Slightly modify the test of a script with a syntax error to use "syntax_error" rather than "syntax error". It makes it more obvious in the error messages that something unnatural is going on. Modified Paths: -------------- trunk/server/lib/etch.rb trunk/test/test_scripts.rb Modified: trunk/server/lib/etch.rb =================================================================== --- trunk/server/lib/etch.rb 2011-03-10 00:41:10 UTC (rev 263) +++ trunk/server/lib/etch.rb 2011-03-11 01:11:15 UTC (rev 264) @@ -1384,7 +1384,7 @@ @dlogger.debug "Processing script #{script} for file #{@file}" @contents = '' begin - eval(IO.read(script)) + run_script_stage2(script) rescue Exception => e if e.kind_of?(SystemExit) # The user might call exit within a script. We want the scripts @@ -1397,5 +1397,13 @@ end @contents end + # The user might call return within a script. We want the scripts to act as + # much like a real script as possible. Wrapping the eval in an extra method + # allows us to handle a return within the script seamlessly. If the user + # calls return it triggers a return from this method. Otherwise this method + # returns naturally. Either works for us. + def run_script_stage2(script) + eval(IO.read(script)) + end end Modified: trunk/test/test_scripts.rb =================================================================== --- trunk/test/test_scripts.rb 2011-03-10 00:41:10 UTC (rev 263) +++ trunk/test/test_scripts.rb 2011-03-11 01:11:15 UTC (rev 264) @@ -52,7 +52,7 @@ end File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| - file.write('syntax error') + file.write('syntax_error') end # Gather some stats about the file before we run etch @@ -64,8 +64,73 @@ # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'script with syntax error size comparison') assert_equal(before_ctime, File.stat(@targetfile).ctime, 'script with syntax error ctime comparison') - + # + # Script that calls return, make sure nothing blows up + # + testname = 'script calls return' + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <script>source.script</script> + </source> + </file> + </config> + EOF + end + + File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| + file.write('return') + end + + # Gather some stats about the file before we run etch + before_size = File.stat(@targetfile).size + before_ctime = File.stat(@targetfile).ctime + + #run_etch(@server, @testroot, :errors_expected => false, :testname => testname) + run_etch(@server, @testroot, :testname => testname) + + # Verify that etch didn't do anything to the file + assert_equal(before_size, File.stat(@targetfile).size, testname + ' size comparison') + assert_equal(before_ctime, File.stat(@targetfile).ctime, testname + ' ctime comparison') + + # + # Script that calls exit, make sure nothing blows up + # + testname = 'script calls exit' + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <script>source.script</script> + </source> + </file> + </config> + EOF + end + + File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| + file.write('exit') + end + + # Gather some stats about the file before we run etch + before_size = File.stat(@targetfile).size + before_ctime = File.stat(@targetfile).ctime + + run_etch(@server, @testroot, :testname => testname) + + # Verify that etch didn't do anything to the file + assert_equal(before_size, File.stat(@targetfile).size, testname + ' size comparison') + assert_equal(before_ctime, File.stat(@targetfile).ctime, testname + ' ctime comparison') + + # # Run a test where the script doesn't output anything # testname = 'script with no output' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-03-10 00:41:16
|
Revision: 263 http://etch.svn.sourceforge.net/etch/?rev=263&view=rev Author: jheiss Date: 2011-03-10 00:41:10 +0000 (Thu, 10 Mar 2011) Log Message: ----------- Update comment associated with tempdir method Modified Paths: -------------- trunk/client/etchclient.rb Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-26 00:09:22 UTC (rev 262) +++ trunk/client/etchclient.rb 2011-03-10 00:41:10 UTC (rev 263) @@ -1981,8 +1981,9 @@ requests end - # Haven't found a Ruby method for creating temporary directories, - # so create a temporary file and replace it with a directory. + # Ruby 1.8.7 and later have Dir.mktmpdir, but we support ruby 1.8.5 for + # RHEL/CentOS 5. So this is a basic substitute. + # FIXME: consider "backport" for Dir.mktmpdir def tempdir(file) filebase = File.basename(file) filedir = File.dirname(file) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2011-01-26 00:09:28
|
Revision: 262 http://etch.svn.sourceforge.net/etch/?rev=262&view=rev Author: thepob Date: 2011-01-26 00:09:22 +0000 (Wed, 26 Jan 2011) Log Message: ----------- I am glad my first few commits to etch have already reverted others changes. /facepalm Modified Paths: -------------- trunk/client/etchclient.rb Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-25 22:33:52 UTC (rev 261) +++ trunk/client/etchclient.rb 2011-01-26 00:09:22 UTC (rev 262) @@ -35,7 +35,7 @@ require 'etch' class Etch::Client - VERSION = '3.17.0' + VERSION = 'unset' CONFIRM_PROCEED = 1 CONFIRM_SKIP = 2 @@ -43,6 +43,7 @@ PRIVATE_KEY_PATHS = ["/etc/ssh/ssh_host_rsa_key", "/etc/ssh_host_rsa_key"] DEFAULT_CONFIGDIR = '/etc' DEFAULT_VARBASE = '/var/etch' + DEFAULT_DETAILED_RESULTS = ['SERVER'] # We need these in relation to the output capturing ORIG_STDOUT = STDOUT.dup @@ -56,17 +57,18 @@ @local = options[:local] ? File.expand_path(options[:local]) : nil @debug = options[:debug] @dryrun = options[:dryrun] + @listfiles = options[:listfiles] @interactive = options[:interactive] @filenameonly = options[:filenameonly] @fullfile = options[:fullfile] @key = options[:key] ? options[:key] : get_private_key_path @disableforce = options[:disableforce] @lockforce = options[:lockforce] + + @last_response = "" @configdir = DEFAULT_CONFIGDIR @varbase = DEFAULT_VARBASE - - @last_response = "" @file_system_root = '/' # Not sure if this needs to be more portable # This option is only intended for use by the test suite @@ -77,6 +79,7 @@ end @configfile = File.join(@configdir, 'etch.conf') + @detailed_results = [] if File.exist?(@configfile) IO.foreach(@configfile) do |line| @@ -121,6 +124,9 @@ end elsif key == 'path' ENV['PATH'] = value + elsif key == 'detailed_results' + warn "Adding detailed results destination '#{value}'" if @debug + @detailed_results << value end end end @@ -132,6 +138,10 @@ warn "No readable private key found, messages to server will not be signed and may be rejected depending on server configuration" end + if @detailed_results.empty? + @detailed_results = DEFAULT_DETAILED_RESULTS + end + @origbase = File.join(@varbase, 'orig') @historybase = File.join(@varbase, 'history') @lockbase = File.join(@varbase, 'locks') @@ -199,6 +209,9 @@ status = 0 message = '' + # A variable to collect filenames if operating in @listfiles mode + files_to_list = {} + # Prep http instance http = nil if !@local @@ -291,6 +304,11 @@ unlock_all_files end + # It usually takes a few back and forth exchanges with the server to + # exchange all needed data and get a complete set of configuration. + # The number of iterations is capped at 10 to prevent any unplanned + # infinite loops. The limit of 10 was chosen somewhat arbitrarily but + # seems fine in practice. 10.times do # # Send request to server @@ -391,9 +409,13 @@ # needed to create the original files. responsedata[:configs].each_key do |file| puts "Processing config for #{file}" if (@debug) - continue_processing = process_file(file, responsedata) - if !continue_processing - throw :stop_processing + if !@listfiles + continue_processing = process_file(file, responsedata) + if !continue_processing + throw :stop_processing + end + else + files_to_list[file] = true end end responsedata[:need_sums].each_key do |need_sum| @@ -473,6 +495,11 @@ end # begin/rescue end # catch + if @listfiles + puts "Files under management:" + files_to_list.keys.sort.each {|file| puts file} + end + # Send results to server if !@dryrun && !@local rails_results = [] @@ -482,13 +509,15 @@ rails_results << "fqdn=#{CGI.escape(@facts['fqdn'])}" rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" - @results.each do |result| - # Strangely enough this works. Even though the key is not unique to - # each result the Rails parameter parsing code keeps track of keys it - # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" - rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" - rails_results << "results[][message]=#{CGI.escape(result['message'])}" + if @detailed_results.include?('SERVER') + @results.each do |result| + # Strangely enough this works. Even though the key is not unique to + # each result the Rails parameter parsing code keeps track of keys it + # has seen, and if it sees a duplicate it starts a new hash. + rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" + rails_results << "results[][message]=#{CGI.escape(result['message'])}" + end end puts "Sending results to server #{@resultsuri}" if (@debug) resultspost = Net::HTTP::Post.new(@resultsuri.path) @@ -509,6 +538,29 @@ end end + if !@dryrun + @detailed_results.each do |detail_dest| + # If any of the destinations look like a file (start with a /) then we + # log to that file + if detail_dest =~ %r{^/} + FileUtils.mkpath(File.dirname(detail_dest)) + File.open(detail_dest, 'a') do |file| + # Add a header for the overall status of the run + file.puts "Etch run at #{Time.now}" + file.puts "Status: #{status}" + if !message.empty? + file.puts "Message:\n#{message}\n" + end + # Then the detailed results + @results.each do |result| + file.puts "File #{result['file']}, result #{result['success']}:\n" + file.puts result['message'] + end + end + end + end + end + status end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2011-01-25 22:33:59
|
Revision: 261 http://etch.svn.sourceforge.net/etch/?rev=261&view=rev Author: thepob Date: 2011-01-25 22:33:52 +0000 (Tue, 25 Jan 2011) Log Message: ----------- this is cleaner than the previous commit. Modified Paths: -------------- trunk/client/etchclient.rb Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-25 22:16:34 UTC (rev 260) +++ trunk/client/etchclient.rb 2011-01-25 22:33:52 UTC (rev 261) @@ -35,7 +35,7 @@ require 'etch' class Etch::Client - VERSION = 'unset' + VERSION = '3.17.0' CONFIRM_PROCEED = 1 CONFIRM_SKIP = 2 @@ -43,7 +43,6 @@ PRIVATE_KEY_PATHS = ["/etc/ssh/ssh_host_rsa_key", "/etc/ssh_host_rsa_key"] DEFAULT_CONFIGDIR = '/etc' DEFAULT_VARBASE = '/var/etch' - DEFAULT_DETAILED_RESULTS = ['SERVER'] # We need these in relation to the output capturing ORIG_STDOUT = STDOUT.dup @@ -57,7 +56,6 @@ @local = options[:local] ? File.expand_path(options[:local]) : nil @debug = options[:debug] @dryrun = options[:dryrun] - @listfiles = options[:listfiles] @interactive = options[:interactive] @filenameonly = options[:filenameonly] @fullfile = options[:fullfile] @@ -67,6 +65,8 @@ @configdir = DEFAULT_CONFIGDIR @varbase = DEFAULT_VARBASE + + @last_response = "" @file_system_root = '/' # Not sure if this needs to be more portable # This option is only intended for use by the test suite @@ -77,7 +77,6 @@ end @configfile = File.join(@configdir, 'etch.conf') - @detailed_results = [] if File.exist?(@configfile) IO.foreach(@configfile) do |line| @@ -122,9 +121,6 @@ end elsif key == 'path' ENV['PATH'] = value - elsif key == 'detailed_results' - warn "Adding detailed results destination '#{value}'" if @debug - @detailed_results << value end end end @@ -136,10 +132,6 @@ warn "No readable private key found, messages to server will not be signed and may be rejected depending on server configuration" end - if @detailed_results.empty? - @detailed_results = DEFAULT_DETAILED_RESULTS - end - @origbase = File.join(@varbase, 'orig') @historybase = File.join(@varbase, 'history') @lockbase = File.join(@varbase, 'locks') @@ -207,9 +199,6 @@ status = 0 message = '' - # A variable to collect filenames if operating in @listfiles mode - files_to_list = {} - # Prep http instance http = nil if !@local @@ -302,11 +291,6 @@ unlock_all_files end - # It usually takes a few back and forth exchanges with the server to - # exchange all needed data and get a complete set of configuration. - # The number of iterations is capped at 10 to prevent any unplanned - # infinite loops. The limit of 10 was chosen somewhat arbitrarily but - # seems fine in practice. 10.times do # # Send request to server @@ -407,13 +391,9 @@ # needed to create the original files. responsedata[:configs].each_key do |file| puts "Processing config for #{file}" if (@debug) - if !@listfiles - continue_processing = process_file(file, responsedata) - if !continue_processing - throw :stop_processing - end - else - files_to_list[file] = true + continue_processing = process_file(file, responsedata) + if !continue_processing + throw :stop_processing end end responsedata[:need_sums].each_key do |need_sum| @@ -493,11 +473,6 @@ end # begin/rescue end # catch - if @listfiles - puts "Files under management:" - files_to_list.keys.sort.each {|file| puts file} - end - # Send results to server if !@dryrun && !@local rails_results = [] @@ -507,15 +482,13 @@ rails_results << "fqdn=#{CGI.escape(@facts['fqdn'])}" rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" - if @detailed_results.include?('SERVER') - @results.each do |result| - # Strangely enough this works. Even though the key is not unique to - # each result the Rails parameter parsing code keeps track of keys it - # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" - rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" - rails_results << "results[][message]=#{CGI.escape(result['message'])}" - end + @results.each do |result| + # Strangely enough this works. Even though the key is not unique to + # each result the Rails parameter parsing code keeps track of keys it + # has seen, and if it sees a duplicate it starts a new hash. + rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" + rails_results << "results[][message]=#{CGI.escape(result['message'])}" end puts "Sending results to server #{@resultsuri}" if (@debug) resultspost = Net::HTTP::Post.new(@resultsuri.path) @@ -536,29 +509,6 @@ end end - if !@dryrun - @detailed_results.each do |detail_dest| - # If any of the destinations look like a file (start with a /) then we - # log to that file - if detail_dest =~ %r{^/} - FileUtils.mkpath(File.dirname(detail_dest)) - File.open(detail_dest, 'a') do |file| - # Add a header for the overall status of the run - file.puts "Etch run at #{Time.now}" - file.puts "Status: #{status}" - if !message.empty? - file.puts "Message:\n#{message}\n" - end - # Then the detailed results - @results.each do |result| - file.puts "File #{result['file']}, result #{result['success']}:\n" - file.puts result['message'] - end - end - end - end - end - status end @@ -2293,24 +2243,21 @@ def get_user_confirmation while true print "Proceed/Skip/Quit? " - if instance_variable_defined?("@response") - case @response - when /p|P/ then print "[P|s|q] " - when /s|S/ then print "[p|S|q] " - when /q|Q/ then print "[p|s|Q] " - end - else - print "[p|s|q] " + case @last_response + when /p|P/ then print "[P|s|q] " + when /s|S/ then print "[p|S|q] " + when /q|Q/ then print "[p|s|Q] " + else print "[p|s|q] " end - response = $stdin.gets.chomp - if response =~ /p/i || (instance_variable_defined?("@response") && @response =~ /p/i) - @response = response if !response.strip.empty? + response = $stdin.gets.chomp + if response =~ /p/i || @last_response =~ /p/i + @last_response = response if !response.strip.empty? return CONFIRM_PROCEED - elsif response =~ /s/i || (instance_variable_defined?("@response") && @response =~ /s/i) - @response = response if !response.strip.empty? + elsif response =~ /s/i || @last_response =~ /s/i + @last_response = response if !response.strip.empty? return CONFIRM_SKIP - elsif response =~ /q/i || (instance_variable_defined?("@response") && @response =~ /q/i) - @response = response if !response.strip.empty? + elsif response =~ /q/i || @last_response =~ /q/i + @last_response = response if !response.strip.empty? return CONFIRM_QUIT end end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2011-01-25 22:16:40
|
Revision: 260 http://etch.svn.sourceforge.net/etch/?rev=260&view=rev Author: thepob Date: 2011-01-25 22:16:34 +0000 (Tue, 25 Jan 2011) Log Message: ----------- completing ticket #12 - allowing interactive mode to default to the previously used selection Modified Paths: -------------- trunk/client/etchclient.rb Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-20 19:42:05 UTC (rev 259) +++ trunk/client/etchclient.rb 2011-01-25 22:16:34 UTC (rev 260) @@ -2292,13 +2292,25 @@ def get_user_confirmation while true - print "Proceed/Skip/Quit? [p|s|q] " - response = $stdin.gets.chomp - if response == 'p' + print "Proceed/Skip/Quit? " + if instance_variable_defined?("@response") + case @response + when /p|P/ then print "[P|s|q] " + when /s|S/ then print "[p|S|q] " + when /q|Q/ then print "[p|s|Q] " + end + else + print "[p|s|q] " + end + response = $stdin.gets.chomp + if response =~ /p/i || (instance_variable_defined?("@response") && @response =~ /p/i) + @response = response if !response.strip.empty? return CONFIRM_PROCEED - elsif response == 's' + elsif response =~ /s/i || (instance_variable_defined?("@response") && @response =~ /s/i) + @response = response if !response.strip.empty? return CONFIRM_SKIP - elsif response == 'q' + elsif response =~ /q/i || (instance_variable_defined?("@response") && @response =~ /q/i) + @response = response if !response.strip.empty? return CONFIRM_QUIT end end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2011-01-20 19:42:12
|
Revision: 259 http://etch.svn.sourceforge.net/etch/?rev=259&view=rev Author: darrendao Date: 2011-01-20 19:42:05 +0000 (Thu, 20 Jan 2011) Log Message: ----------- Update etch_to_trunk so that user can specify where the nventory server is running Modified Paths: -------------- trunk/client/etch_to_trunk Modified: trunk/client/etch_to_trunk =================================================================== --- trunk/client/etch_to_trunk 2011-01-19 23:16:00 UTC (rev 258) +++ trunk/client/etch_to_trunk 2011-01-20 19:42:05 UTC (rev 259) @@ -15,6 +15,9 @@ opts.on('-t', '--timezone TIMEZONE', 'Time zone of etch server.') do |opt| options[:timezone] = opt end +opts.on('--nv SERVER', 'Where nVentory server is running.') do |opt| + options[:nv_server] = opt +end opts.on_tail('-h', '--help', 'Show this message.') do puts opts exit @@ -37,7 +40,12 @@ end # Find the requested clients -nvclient = NVentory::Client.new +nv_server = options[:nv_server] +if nv_server + nvclient = NVentory::Client.new(:server=>"http://#{nv_server}") +else + nvclient = NVentory::Client.new +end results = nvclient.get_objects('nodes', {}, { 'name' => nodes }, {}, {}) nodes.each do |name| if results.empty? && results[name].nil? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-19 23:16:06
|
Revision: 258 http://etch.svn.sourceforge.net/etch/?rev=258&view=rev Author: jheiss Date: 2011-01-19 23:16:00 +0000 (Wed, 19 Jan 2011) Log Message: ----------- Add documentation of detailed_results setting in etch.conf Modified Paths: -------------- trunk/client/etch.8 Modified: trunk/client/etch.8 =================================================================== --- trunk/client/etch.8 2011-01-19 23:15:32 UTC (rev 257) +++ trunk/client/etch.8 2011-01-19 23:16:00 UTC (rev 258) @@ -158,6 +158,12 @@ .IP .B key = SSH host key to use for authentication rather than standard system key. +.IP +.B detailed_results = +Etch can send detailed results back to the server for viewing in the web UI +and/or to a local log file. Value should be SERVER or the full path to a log +file. Setting may be specified multiple times to send logs to multiple +destinations. .TP .B /etc/etch/ca.pem SSL certificate(s) needed to verify the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-19 23:15:42
|
Revision: 257 http://etch.svn.sourceforge.net/etch/?rev=257&view=rev Author: jheiss Date: 2011-01-19 23:15:32 +0000 (Wed, 19 Jan 2011) Log Message: ----------- Exclude logs and sqlite database from distributions. Modified Paths: -------------- Rakefile Modified: Rakefile =================================================================== --- Rakefile 2011-01-18 00:19:56 UTC (rev 256) +++ Rakefile 2011-01-19 23:15:32 UTC (rev 257) @@ -18,7 +18,7 @@ task :dist do rm_rf(DIST) mkdir(DIST) - system("(cd #{TAGDIR} && find client server test etchserver-* LICENSE README VERSION | grep -v '\.svn' | cpio -pdum ../../#{DIST})") + system("(cd #{TAGDIR} && find client server test etchserver-* LICENSE README VERSION | grep -v '\.svn' | grep -v server/log/*.log | grep -v server/db/*.sqlite3 | cpio -pdum ../../#{DIST})") system("tar czf #{DIST}.tar.gz #{DIST}") rm_rf(DIST) system("openssl md5 #{DIST}.tar.gz > #{DIST}.tar.gz.md5") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-18 00:20:03
|
Revision: 256 http://etch.svn.sourceforge.net/etch/?rev=256&view=rev Author: jheiss Date: 2011-01-18 00:19:56 +0000 (Tue, 18 Jan 2011) Log Message: ----------- Tag 3.18.0 release Modified Paths: -------------- Rakefile tags/release-3.18.0/VERSION Added Paths: ----------- tags/release-3.18.0/ Modified: Rakefile =================================================================== --- Rakefile 2011-01-17 05:31:39 UTC (rev 255) +++ Rakefile 2011-01-18 00:19:56 UTC (rev 256) @@ -1,4 +1,4 @@ -ETCHVER = '3.17.0' +ETCHVER = '3.18.0' TAGNAME = "release-#{ETCHVER}" TAGDIR = "tags/#{TAGNAME}" DIST = "etch-#{ETCHVER}" Modified: tags/release-3.18.0/VERSION =================================================================== --- trunk/VERSION 2011-01-17 05:31:39 UTC (rev 255) +++ tags/release-3.18.0/VERSION 2011-01-18 00:19:56 UTC (rev 256) @@ -1 +1 @@ -trunk +3.18.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-17 05:31:45
|
Revision: 255 http://etch.svn.sourceforge.net/etch/?rev=255&view=rev Author: jheiss Date: 2011-01-17 05:31:39 +0000 (Mon, 17 Jan 2011) Log Message: ----------- ticket:9 Add --list-files option. Don't log to local file in dry run mode. Logging to the server has always operated that way, I forgot to make local file logging operate the same way initially. Modified Paths: -------------- trunk/client/etch trunk/client/etchclient.rb trunk/test/test_options.rb Modified: trunk/client/etch =================================================================== --- trunk/client/etch 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/client/etch 2011-01-17 05:31:39 UTC (rev 255) @@ -35,6 +35,13 @@ # entries. options[:dryrun] = 'damp' end +opts.on('--list-files', 'Just list the files that would be configured') do |opt| + options[:listfiles] = opt + # generate all is implied + @generateall = true + # Set :dryrun as a extra measure to make sure we don't change anything + options[:dryrun] = 'listfiles' +end opts.on('--interactive', 'Prompt for confirmation before each change.') do |opt| options[:interactive] = opt end Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/client/etchclient.rb 2011-01-17 05:31:39 UTC (rev 255) @@ -57,6 +57,7 @@ @local = options[:local] ? File.expand_path(options[:local]) : nil @debug = options[:debug] @dryrun = options[:dryrun] + @listfiles = options[:listfiles] @interactive = options[:interactive] @filenameonly = options[:filenameonly] @fullfile = options[:fullfile] @@ -206,6 +207,9 @@ status = 0 message = '' + # A variable to collect filenames if operating in @listfiles mode + files_to_list = {} + # Prep http instance http = nil if !@local @@ -298,6 +302,11 @@ unlock_all_files end + # It usually takes a few back and forth exchanges with the server to + # exchange all needed data and get a complete set of configuration. + # The number of iterations is capped at 10 to prevent any unplanned + # infinite loops. The limit of 10 was chosen somewhat arbitrarily but + # seems fine in practice. 10.times do # # Send request to server @@ -398,9 +407,13 @@ # needed to create the original files. responsedata[:configs].each_key do |file| puts "Processing config for #{file}" if (@debug) - continue_processing = process_file(file, responsedata) - if !continue_processing - throw :stop_processing + if !@listfiles + continue_processing = process_file(file, responsedata) + if !continue_processing + throw :stop_processing + end + else + files_to_list[file] = true end end responsedata[:need_sums].each_key do |need_sum| @@ -480,6 +493,11 @@ end # begin/rescue end # catch + if @listfiles + puts "Files under management:" + files_to_list.keys.sort.each {|file| puts file} + end + # Send results to server if !@dryrun && !@local rails_results = [] @@ -518,23 +536,25 @@ end end - @detailed_results.each do |detail_dest| - # If any of the destinations look like a file (start with a /) then we - # log to that file - if detail_dest =~ %r{^/} - FileUtils.mkpath(File.dirname(detail_dest)) - File.open(detail_dest, 'a') do |file| - # Add a header for the overall status of the run - file.puts "Etch run at #{Time.now}" - file.puts "Status: #{status}" - if !message.empty? - file.puts "Message:\n#{message}\n" + if !@dryrun + @detailed_results.each do |detail_dest| + # If any of the destinations look like a file (start with a /) then we + # log to that file + if detail_dest =~ %r{^/} + FileUtils.mkpath(File.dirname(detail_dest)) + File.open(detail_dest, 'a') do |file| + # Add a header for the overall status of the run + file.puts "Etch run at #{Time.now}" + file.puts "Status: #{status}" + if !message.empty? + file.puts "Message:\n#{message}\n" + end + # Then the detailed results + @results.each do |result| + file.puts "File #{result['file']}, result #{result['success']}:\n" + file.puts result['message'] + end end - # Then the detailed results - @results.each do |result| - file.puts "File #{result['file']}, result #{result['success']}:\n" - file.puts result['message'] - end end end end Modified: trunk/test/test_options.rb =================================================================== --- trunk/test/test_options.rb 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/test/test_options.rb 2011-01-17 05:31:39 UTC (rev 255) @@ -495,6 +495,47 @@ t.kill end + def test_list_files + # + # Test --list-files + # + testname = '--list-files' + + # Put some text into the original file so that we can make sure it is + # not touched. + origcontents = "This is the original text\n" + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file/> + <source> + <plain>source</plain> + </source> + </file> + </config> + EOF + end + + sourcecontents = "This is a test\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + + # Test that output from etch is appropriate + #run_etch(@server, @testroot, :extra_args => '--list-files', :testname => testname) + output = `ruby #{CLIENTDIR}/etch --generate-all --test-root=#{@testroot} --key=#{File.dirname(__FILE__)}/keys/testkey --server=http://localhost:#{@server[:port]} --list-files` + assert(output.include?("Files under management:\n#{@targetfile}\n")) + + # Ensure that the target file wasn't touched + assert_equal(origcontents, get_file_contents(@targetfile), testname) + end + def teardown remove_repository(@repodir) FileUtils.rm_rf(@testroot) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-17 05:28:23
|
Revision: 254 http://etch.svn.sourceforge.net/etch/?rev=254&view=rev Author: jheiss Date: 2011-01-17 05:28:16 +0000 (Mon, 17 Jan 2011) Log Message: ----------- Add FIXME comment for small issue I noticed Modified Paths: -------------- trunk/test/test_conf.rb Modified: trunk/test/test_conf.rb =================================================================== --- trunk/test/test_conf.rb 2011-01-14 23:56:52 UTC (rev 253) +++ trunk/test/test_conf.rb 2011-01-17 05:28:16 UTC (rev 254) @@ -402,6 +402,8 @@ # Check that details weren't sent to server # Odd that assert_no_match requires a Regexp when assert_match accepts a String assert_no_match(Regexp.new(Regexp.escape(sourcecontents)), latest_result_message, testname) + + # FIXME: verify no logging in dry run mode end def teardown This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-14 23:56:59
|
Revision: 253 http://etch.svn.sourceforge.net/etch/?rev=253&view=rev Author: jheiss Date: 2011-01-14 23:56:52 +0000 (Fri, 14 Jan 2011) Log Message: ----------- Add support for a detailed_results setting in the client config file, allowing users to log detailed results to a local file in addition to or instead of sending them to the server. Modified Paths: -------------- trunk/client/etch.conf trunk/client/etchclient.rb trunk/test/test_conf.rb Modified: trunk/client/etch.conf =================================================================== --- trunk/client/etch.conf 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/client/etch.conf 2011-01-14 23:56:52 UTC (rev 253) @@ -11,8 +11,15 @@ #local = /var/etch/configs # Etch will try to find an SSH host key and use it to sign all requests to the -# etch server. Several standard locations for SSH keys are searched by -# default, if your key is not in a standard location you can point etch to it. -# See https://sourceforge.net/apps/trac/etch/wiki/ClientAuthentication +# etch server. Several standard locations for host keys are searched by +# default. If your host key is not in a standard location then you can point +# etch to it. +# See http://sourceforge.net/apps/trac/etch/wiki/ClientAuthentication #key = /etc/ssh/ssh_host_rsa_key +# Etch can send detailed results back to the server for viewing in the web UI +# and/or to a local log file. They are sent to the server by default. +# Note that SERVER is ignored when etch is running in local mode. +#detailed_results = SERVER +#detailed_results = /var/etch/results.log + Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/client/etchclient.rb 2011-01-14 23:56:52 UTC (rev 253) @@ -43,6 +43,7 @@ PRIVATE_KEY_PATHS = ["/etc/ssh/ssh_host_rsa_key", "/etc/ssh_host_rsa_key"] DEFAULT_CONFIGDIR = '/etc' DEFAULT_VARBASE = '/var/etch' + DEFAULT_DETAILED_RESULTS = ['SERVER'] # We need these in relation to the output capturing ORIG_STDOUT = STDOUT.dup @@ -75,6 +76,7 @@ end @configfile = File.join(@configdir, 'etch.conf') + @detailed_results = [] if File.exist?(@configfile) IO.foreach(@configfile) do |line| @@ -119,6 +121,9 @@ end elsif key == 'path' ENV['PATH'] = value + elsif key == 'detailed_results' + warn "Adding detailed results destination '#{value}'" if @debug + @detailed_results << value end end end @@ -130,6 +135,10 @@ warn "No readable private key found, messages to server will not be signed and may be rejected depending on server configuration" end + if @detailed_results.empty? + @detailed_results = DEFAULT_DETAILED_RESULTS + end + @origbase = File.join(@varbase, 'orig') @historybase = File.join(@varbase, 'history') @lockbase = File.join(@varbase, 'locks') @@ -480,13 +489,15 @@ rails_results << "fqdn=#{CGI.escape(@facts['fqdn'])}" rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" - @results.each do |result| - # Strangely enough this works. Even though the key is not unique to - # each result the Rails parameter parsing code keeps track of keys it - # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" - rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" - rails_results << "results[][message]=#{CGI.escape(result['message'])}" + if @detailed_results.include?('SERVER') + @results.each do |result| + # Strangely enough this works. Even though the key is not unique to + # each result the Rails parameter parsing code keeps track of keys it + # has seen, and if it sees a duplicate it starts a new hash. + rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" + rails_results << "results[][message]=#{CGI.escape(result['message'])}" + end end puts "Sending results to server #{@resultsuri}" if (@debug) resultspost = Net::HTTP::Post.new(@resultsuri.path) @@ -507,6 +518,27 @@ end end + @detailed_results.each do |detail_dest| + # If any of the destinations look like a file (start with a /) then we + # log to that file + if detail_dest =~ %r{^/} + FileUtils.mkpath(File.dirname(detail_dest)) + File.open(detail_dest, 'a') do |file| + # Add a header for the overall status of the run + file.puts "Etch run at #{Time.now}" + file.puts "Status: #{status}" + if !message.empty? + file.puts "Message:\n#{message}\n" + end + # Then the detailed results + @results.each do |result| + file.puts "File #{result['file']}, result #{result['success']}:\n" + file.puts result['message'] + end + end + end + end + status end Modified: trunk/test/test_conf.rb =================================================================== --- trunk/test/test_conf.rb 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/test/test_conf.rb 2011-01-14 23:56:52 UTC (rev 253) @@ -308,6 +308,102 @@ assert(File.exist?("#{@repodir}/pathtest/testpost.output")) end + def test_conf_detailed_results + # + # Test the detailed_results setting in etch.conf + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file></warning_file> + <source> + <plain>source</plain> + </source> + </file> + </config> + EOF + end + + # No setting, should log to server by default + testname = 'etch.conf detailed_results setting, not set' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + + # Configure logging to server + testname = 'etch.conf detailed_results setting, log to server' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = SERVER" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + + # Configure logging to file + logfile = Tempfile.new('etchlog') + testname = 'etch.conf detailed_results setting, log to file' + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = #{logfile.path}" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, File.read(logfile.path), testname) + # Check that details weren't sent to server + # Odd that assert_no_match requires a Regexp when assert_match accepts a String + assert_no_match(Regexp.new(Regexp.escape(sourcecontents)), latest_result_message, testname) + + # Configure logging to server and file + logfile = Tempfile.new('etchlog') + testname = 'etch.conf detailed_results setting, log to server and file' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = SERVER" + file.puts "detailed_results = #{logfile.path}" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + assert_match(sourcecontents, File.read(logfile.path), testname) + + # Configure no logging + testname = 'etch.conf detailed_results setting, log nowhere' + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results =" + end + run_etch(@server, @testroot, :testname => testname) + # Check that details weren't sent to server + # Odd that assert_no_match requires a Regexp when assert_match accepts a String + assert_no_match(Regexp.new(Regexp.escape(sourcecontents)), latest_result_message, testname) + end + def teardown remove_repository(@repodir) FileUtils.rm_rf(@testroot) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-14 23:54:22
|
Revision: 252 http://etch.svn.sourceforge.net/etch/?rev=252&view=rev Author: jheiss Date: 2011-01-14 23:54:16 +0000 (Fri, 14 Jan 2011) Log Message: ----------- Pull some code for fetching the latest result from the server out into a method so that we can reuse it in other tests. Modified Paths: -------------- trunk/test/etchtest.rb trunk/test/test_outputcapture.rb Modified: trunk/test/etchtest.rb =================================================================== --- trunk/test/etchtest.rb 2011-01-13 17:47:20 UTC (rev 251) +++ trunk/test/etchtest.rb 2011-01-14 23:54:16 UTC (rev 252) @@ -192,5 +192,23 @@ end end end + + # Fetch the latest result for this client from the server. Useful for + # verifying that results were logged to the server as expected. + def latest_result_message + hostname = Facter['fqdn'].value + lrm = '' + Net::HTTP.start('localhost', @server[:port]) do |http| + response = http.get("/results.xml?clients.name=#{hostname}&sort=created_at_reverse") + if !response.kind_of?(Net::HTTPSuccess) + response.error! + end + response_xml = REXML::Document.new(response.body) + if response_xml.elements['/results/result/message'] + lrm = response_xml.elements['/results/result/message'].text + end + end + lrm + end end Modified: trunk/test/test_outputcapture.rb =================================================================== --- trunk/test/test_outputcapture.rb 2011-01-13 17:47:20 UTC (rev 251) +++ trunk/test/test_outputcapture.rb 2011-01-14 23:54:16 UTC (rev 252) @@ -66,21 +66,6 @@ run_etch(@server, @testroot, :testname => testname) - # Fetch the latest result for this client from the server and verify that - # it contains the output from the post command. - hostname = Facter['fqdn'].value - latest_result_message = '' - Net::HTTP.start('localhost', @server[:port]) do |http| - response = http.get("/results.xml?clients.name=#{hostname}&sort=created_at_reverse") - if !response.kind_of?(Net::HTTPSuccess) - response.error! - end - response_xml = REXML::Document.new(response.body) - latest_result_message = nil - if response_xml.elements['/results/result/message'] - latest_result_message = response_xml.elements['/results/result/message'].text - end - end assert_match(postoutput, latest_result_message, testname) end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-13 17:47:27
|
Revision: 251 http://etch.svn.sourceforge.net/etch/?rev=251&view=rev Author: jheiss Date: 2011-01-13 17:47:20 +0000 (Thu, 13 Jan 2011) Log Message: ----------- Don't throw an exception if session is not defined. I'm not really sure why it wouldn't be defined, but it seems to happen occasionally, particularly with the "GET /" healthcheck requests from the load balancers. Modified Paths: -------------- trunk/server/app/views/layouts/application.html.erb Modified: trunk/server/app/views/layouts/application.html.erb =================================================================== --- trunk/server/app/views/layouts/application.html.erb 2011-01-13 17:37:04 UTC (rev 250) +++ trunk/server/app/views/layouts/application.html.erb 2011-01-13 17:47:20 UTC (rev 251) @@ -17,7 +17,7 @@ <div id="header"> <p id="account_links"> -<%- if session[:account_id] -%> +<%- if session && session[:account_id] -%> Welcome back, <%= link_to logged_in_account.name, account_path(logged_in_account) %>! | <%= link_to "Help", "http://etch.sourceforge.net/" %> | <%= link_to "Logout", :controller => 'login', :action => 'logout' %> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-13 17:37:10
|
Revision: 250 http://etch.svn.sourceforge.net/etch/?rev=250&view=rev Author: jheiss Date: 2011-01-13 17:37:04 +0000 (Thu, 13 Jan 2011) Log Message: ----------- Replace internal URL with URL of sourceforge wiki site Modified Paths: -------------- trunk/server/app/views/layouts/application.html.erb Modified: trunk/server/app/views/layouts/application.html.erb =================================================================== --- trunk/server/app/views/layouts/application.html.erb 2011-01-07 03:32:19 UTC (rev 249) +++ trunk/server/app/views/layouts/application.html.erb 2011-01-13 17:37:04 UTC (rev 250) @@ -19,7 +19,7 @@ <p id="account_links"> <%- if session[:account_id] -%> Welcome back, <%= link_to logged_in_account.name, account_path(logged_in_account) %>! - | <%= link_to "Help", "http://onewiki.yellowpages.com/display/ACH/UsingEtch" %> + | <%= link_to "Help", "http://etch.sourceforge.net/" %> | <%= link_to "Logout", :controller => 'login', :action => 'logout' %> <%- else -%> <%= link_to "Login", :controller => 'login', :action => 'login' %> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2011-01-07 03:32:27
|
Revision: 249 http://etch.svn.sourceforge.net/etch/?rev=249&view=rev Author: jheiss Date: 2011-01-07 03:32:19 +0000 (Fri, 07 Jan 2011) Log Message: ----------- Add :testname option to all remaining run_etch calls. Modified Paths: -------------- trunk/test/test_actions.rb trunk/test/test_auth.rb trunk/test/test_commands.rb trunk/test/test_delete.rb trunk/test/test_depend.rb trunk/test/test_file.rb trunk/test/test_history.rb trunk/test/test_link.rb trunk/test/test_local_requests.rb trunk/test/test_nodegroups.rb trunk/test/test_options.rb trunk/test/test_outputcapture.rb trunk/test/test_scripts.rb trunk/test/test_transitions.rb Modified: trunk/test/test_actions.rb =================================================================== --- trunk/test/test_actions.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_actions.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -33,6 +33,7 @@ # Basic tests to ensure that actions are performed under normal # circumstances # + testname = 'basic action test' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -74,9 +75,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running initial action test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the actions were executed # The setup actions will get run several times as we loop @@ -100,7 +99,7 @@ # Run etch again and make sure that the exec_once command wasn't run # again - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => 'action test, exec_once') assert_equal("exec_once\n", get_file_contents("#{@repodir}/exec_once"), 'exec_once_2nd_check') end @@ -109,6 +108,7 @@ # # Test a failed setup command to ensure etch aborts # + testname = 'failed setup' # Put some text into the original file so that we can make sure it # is not touched. @@ -140,9 +140,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running initial action test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file was not touched assert_equal(origcontents, get_file_contents(@targetfile), 'failed setup') @@ -152,6 +150,7 @@ # # Test a failed pre command to ensure etch aborts # + testname = 'failed pre' # Put some text into the original file so that we can make sure it # is not touched. @@ -183,9 +182,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running failed pre test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file was not touched assert_equal(origcontents, get_file_contents(@targetfile), 'failed pre') @@ -196,6 +193,7 @@ # Run a test where the test action fails, ensure that the original # target file is restored and any post actions re-run afterwards # + testname = 'failed test' # Put some text into the original file so that we can make sure it # is restored. @@ -232,9 +230,7 @@ file.write("Testing a failed test\n") end - # Run etch - #puts "Running failed test test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the original was restored, and that post was run twice assert_equal(origcontents, get_file_contents(@targetfile), 'failed test target') @@ -246,6 +242,7 @@ # Run a test where the test_before_post action fails, ensure that # post is not run # + testname = 'failed test_before_post' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -268,9 +265,7 @@ EOF end - # Run etch - #puts "Running failed test_before_post test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that post was not run assert(!File.exist?("#{@repodir}/post"), 'failed test_before_post post') @@ -279,14 +274,13 @@ # Run a test where the test action fails, and the original target file # is a symlink. Ensure that the symlink is restored. # + testname = 'failed test_before_post symlink' # Prepare the target File.delete(@targetfile) if File.exist?(@targetfile) File.symlink(@destfile, @targetfile) - # Run etch - #puts "Running failed test symlink test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the original symlink was restored assert_equal(@destfile, File.readlink(@targetfile), 'failed test symlink') @@ -295,15 +289,14 @@ # Run a test where the test action fails, and the original target file # is a directory. Ensure that the directory is restored. # + testname = 'failed test_before_post directory' # Prepare the target File.delete(@targetfile) if File.exist?(@targetfile) Dir.mkdir(@targetfile) File.open("#{@targetfile}/testfile", 'w') { |file| } - # Run etch - #puts "Running failed test directory test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the original directory was restored assert(File.directory?(@targetfile), 'failed test directory') @@ -314,6 +307,7 @@ # target file. Ensure that the end result is that there is no file left # behind. # + testname = 'failed test_before_post no original' # We can reuse the config.xml from the previous test @@ -323,9 +317,7 @@ end File.delete("#{@repodir}/post") if File.exist?("#{@repodir}/post") - # Run etch - #puts "Running failed test no original file test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the lack of an original file was restored assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), 'failed test no original file') @@ -344,6 +336,7 @@ # back if the test fails) is made as /etc/foo/bar.XXXXX, which requires # that /etc/foo exist first. # + testname = 'test action with nested target' nestedtargetdir = deleted_tempfile nestedtargetfile = File.join(nestedtargetdir, 'etchnestedtest') @@ -370,9 +363,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running nested target with test test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(nestedtargetfile), 'nested target with test') @@ -390,6 +381,7 @@ # So if the user wants to use something like && in an action they must # escape the & with & # + testname = 'XML escape' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -413,9 +405,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running XML escape test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the action was executed assert_equal("post\n", get_file_contents("#{@repodir}/post_with_escape"), 'post with escape') @@ -425,6 +415,7 @@ # # Test an action involving passing an environment variable # + testname = 'action with environment variable' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -456,9 +447,7 @@ end File.chmod(0755, "#{@repodir}/post_with_env") - # Run etch - #puts "Running environment variable test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the action was executed assert_equal("testvalue\n", get_file_contents("#{@repodir}/post_with_env_output"), 'post with environment variable') Modified: trunk/test/test_auth.rb =================================================================== --- trunk/test/test_auth.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_auth.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -89,9 +89,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -120,9 +118,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -159,9 +155,7 @@ file.write(origcontents) end - # Run etch with the wrong key to force a bad signature - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true, :key => "--key=#{File.join(File.dirname(__FILE__), 'keys', 'testkey2')}") + run_etch(@server, @testroot, :errors_expected => true, :key => "--key=#{File.join(File.dirname(__FILE__), 'keys', 'testkey2')}", :testname => testname) # Verify that the file was not touched assert_equal(origcontents, get_file_contents(@targetfile), testname) @@ -204,9 +198,7 @@ file.write(origcontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file was not touched assert_equal(origcontents, get_file_contents(@targetfile), testname) @@ -219,7 +211,7 @@ sleep 3 repodir2 = initialize_repository server2 = start_server(repodir2) - run_etch(server2, @testroot) + run_etch(server2, @testroot, :testname => 'adding client to database') stop_server(server2) remove_repository(repodir2) @@ -247,9 +239,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) Modified: trunk/test/test_commands.rb =================================================================== --- trunk/test/test_commands.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_commands.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -45,9 +45,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(testname, get_file_contents(@targetfile), testname) @@ -75,9 +73,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) end def test_commands_guard_succeeds @@ -104,9 +100,7 @@ File.open(@targetfile, 'w') { |file| file.print(testname) } - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was not touched assert_equal(testname, get_file_contents(@targetfile), testname) @@ -142,9 +136,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that both steps ran and in the proper order assert_equal("firststep\nsecondstep\n", get_file_contents(@targetfile), testname) @@ -189,7 +181,7 @@ # Run etch #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that both commands ran, ordering doesn't matter assert_equal(['firstcmd', 'secondcmd'], get_file_contents(@targetfile).split("\n").sort, testname) @@ -233,9 +225,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that both commands ran and in the proper order assert_equal("firstcmd\nsecondcmd\n", get_file_contents(@targetfile), testname) @@ -287,9 +277,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the command-generated file and the regular file were created # properly @@ -332,9 +320,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that only the desired step executed assert_equal("notingroup\n", get_file_contents(@targetfile), testname) @@ -357,9 +343,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) end def teardown Modified: trunk/test/test_delete.rb =================================================================== --- trunk/test/test_delete.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_delete.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -45,9 +45,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was deleted assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) @@ -71,9 +69,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link was deleted assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) @@ -99,9 +95,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the directory was not deleted assert(File.directory?(@targetfile), testname) @@ -128,9 +122,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the directory was deleted assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) @@ -151,9 +143,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that we still don't have a file. That's rather unlikely, # this is really more a test that etch doesn't throw an error if @@ -164,6 +154,7 @@ # # Test duplicate script instructions # + testname = 'duplicate script' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -185,15 +176,14 @@ file.puts("@contents << 'true'") end - # Run etch - #puts "Running duplicate script instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert(!File.exist?(@targetfile), 'duplicate script instructions') # # Test contradictory script instructions # + testname = 'contradictory script' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -218,9 +208,7 @@ file.puts("@contents << 'true'") end - # Run etch - #puts "Running contradictory script instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file wasn't removed assert(File.exist?(@targetfile), 'contradictory script instructions') Modified: trunk/test/test_depend.rb =================================================================== --- trunk/test/test_depend.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_depend.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -29,6 +29,7 @@ # # Run a basic dependency test # + testname = 'initial dependency test' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -74,9 +75,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running initial dependency test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the files were created properly assert_equal(sourcecontents, get_file_contents(@targetfile), 'dependency file 1') @@ -136,9 +135,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :extra_args => @targetfile) + run_etch(@server, @testroot, :extra_args => @targetfile, :testname => testname) # Verify that the files were created properly assert_equal(sourcecontents, get_file_contents(@targetfile), 'single request dependency file 1') @@ -200,9 +197,7 @@ end end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true, :extra_args => @targetfile) + run_etch(@server, @testroot, :errors_expected => true, :extra_args => @targetfile, :testname => testname) # Verify that the files weren't modified assert_equal(origcontents, get_file_contents(@targetfile), 'circular dependency file 1') @@ -254,9 +249,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the regular file and the command-generated file were created # properly Modified: trunk/test/test_file.rb =================================================================== --- trunk/test/test_file.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_file.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -28,6 +28,7 @@ # # Run a test of basic file creation # + testname = 'initial file test' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -47,9 +48,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running initial file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -64,6 +63,7 @@ # # Test with a template # + testname = 'file with template' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -84,9 +84,7 @@ file.write(templatecontents) end - # Run etch - #puts "Running initial file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -101,6 +99,7 @@ # # Test using a different warning file # + testname = 'different warning file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -125,9 +124,7 @@ file.write(warningcontents) end - # Run etch - #puts "Running different warning file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -142,6 +139,7 @@ # # Test using no warning file # + testname = 'no warning file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -162,9 +160,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running no warning file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), 'no warning file') @@ -172,6 +168,7 @@ # # Test using a different line comment string # + testname = 'different line comment string' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -192,9 +189,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running different line comment test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -209,6 +204,7 @@ # # Test using comment open/close # + testname = 'comment open/close' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -231,9 +227,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running comment open/close test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = "/*\n" @@ -249,6 +243,7 @@ # # Test warning on second line # + testname = 'warning on second line' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -271,9 +266,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running warning on second line test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = sourcecontents_firstline @@ -289,6 +282,7 @@ # # Test no space around warning # + testname = 'no space around warning' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -309,9 +303,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running no space around warning test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -325,6 +317,7 @@ # # Test ownership and permissions # + testname = 'ownership and permissions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -342,9 +335,7 @@ EOF end - # Run etch - #puts "Running file ownership and permissions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file ownership got set correctly # Most systems don't support give-away chown, so this test won't work @@ -362,6 +353,7 @@ # # Test ownership w/ bogus owner/group names # + testname = 'file ownership w/ bogus owner/group names' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -378,9 +370,7 @@ EOF end - # Run etch - #puts "Running file ownership w/ bogus owner/group names" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the ownership defaulted to UID/GID 0 # Most systems don't support give-away chown, so this test won't work @@ -395,6 +385,7 @@ # # Run a test of always_manage_metadata # + testname = 'always_manage_metadata' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -414,9 +405,7 @@ file.write(testcontents) end - # Run etch - #puts "Running always_manage_metadata test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file permissions got set correctly perms = File.stat(@targetfile).mode & 07777 @@ -428,6 +417,7 @@ # # Test duplicate plain instructions # + testname = 'duplicate plain instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -454,9 +444,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running duplicate plain instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file contents were updated assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate plain instructions') @@ -464,6 +452,7 @@ # # Test contradictory plain instructions # + testname = 'contradictory plain instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -493,9 +482,7 @@ file.write(source2contents) end - # Run etch - #puts "Running contradictory plain instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file contents didn't change assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory plain instructions') @@ -503,6 +490,7 @@ # # Test duplicate template instructions # + testname = 'duplicate template instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -529,9 +517,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running duplicate template instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file contents were updated assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate template instructions') @@ -539,6 +525,7 @@ # # Test contradictory template instructions # + testname = 'contradictory template instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -568,9 +555,7 @@ file.write(source2contents) end - # Run etch - #puts "Running contradictory template instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file contents didn't change assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory template instructions') @@ -578,6 +563,7 @@ # # Test duplicate script instructions # + testname = 'duplicate script instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -604,9 +590,7 @@ file.puts("@contents << '#{sourcecontents}'") end - # Run etch - #puts "Running duplicate script instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file contents were updated assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate script instructions') @@ -614,6 +598,7 @@ # # Test contradictory script instructions # + testname = 'contradictory script instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -643,9 +628,7 @@ file.write(source2contents) end - # Run etch - #puts "Running contradictory script instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file contents didn't change assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory script instructions') @@ -682,9 +665,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(specialtargetfile), testname) Modified: trunk/test/test_history.rb =================================================================== --- trunk/test/test_history.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_history.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -31,6 +31,7 @@ # # Ensure original file is backed up and history log started # + testname = 'initial history test' # Put some text into the original file so that we can make sure it was # properly backed up. @@ -58,9 +59,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running initial history test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(origcontents, get_file_contents(@origfile), 'original backup of file') assert_equal(origcontents, get_file_contents(File.join(@historydir, '0000')), '0000 history file') @@ -69,15 +68,14 @@ # # Ensure history log is updated and original file does not change # + testname = 'history update' updatedsourcecontents = "This is a second test\n" File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| file.write(updatedsourcecontents) end - # Run etch - #puts "Running update test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(origcontents, get_file_contents(@origfile), 'original backup of file unchanged') assert_equal(origcontents, get_file_contents(File.join(@historydir, '0000')), '0000 history file') @@ -87,6 +85,7 @@ # # Test revert feature # + testname = 'revert' # Intentionally mix revert with other instructions to make sure the file # is reverted and nothing else happens. @@ -105,9 +104,7 @@ EOF end - # Run etch - #puts "Running revert test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(origcontents, get_file_contents(@targetfile), 'original contents reverted') assert(!File.exist?(@origfile), 'reverted original file') @@ -120,15 +117,14 @@ # Update the contents of a reverted file and make sure etch doesn't # overwrite them, as it should no longer be managing the file. # + testname = 'no update to reverted file' updatedorigcontents = "This is new original text\n" File.open(@targetfile, 'w') do |file| file.write(updatedorigcontents) end - # Run etch - #puts "Running revert test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(updatedorigcontents, get_file_contents(@targetfile), 'Updated original contents unchanged') assert(!File.exist?(@origfile), 'reverted original file') @@ -149,6 +145,7 @@ # tries before we achieved convergence and the client sent the correct # original contents. # + testname = 'history setup' origcontents = "This is the original text" @@ -175,9 +172,7 @@ file.puts("@contents << IO.read(@original_file)") end - # Run etch - #puts "Running history setup test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(origcontents + "\n", get_file_contents(@origfile), 'original backup of file via setup') assert_equal(sourcecontents + origcontents + "\n", get_file_contents(@targetfile), 'contents using original backup of file via setup') @@ -215,9 +210,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => 'delayed history setup, first run') origcontents = "This is the original text for #{testname}" @@ -243,9 +236,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(origcontents + "\n", get_file_contents(@origfile), testname) end @@ -254,6 +245,7 @@ # # Ensure original file is backed up when it is a link # + testname = 'history link' # Generate another file to use as our link target @destfile = released_tempfile @@ -281,9 +273,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running history link test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@origfile), 'original backup of link') assert_match("#{@targetfile} -> #{@destfile}", get_file_contents(File.join(@historydir, '0000')), '0000 history file of link') @@ -293,6 +283,7 @@ # # Ensure original file is backed up when it is a directory # + testname = 'history directory' # Make the original target a directory File.delete(@targetfile) @@ -326,9 +317,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running history directory test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert(File.directory?(@origfile), 'original backup of directory') # Verify that etch backed up the original directory properly @@ -346,6 +335,7 @@ # being converted to something else, as the original backup is handled # differently in that case # + testname = 'history directory' origtarfile = File.join(@testroot, 'var', 'etch', 'orig', "#{@targetfile}.TAR") @@ -374,9 +364,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running history directory contents test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # In this case, because we converted a directory to something else the # original will be a tarball of the directory @@ -390,6 +378,7 @@ # # Test the conversion of old RCS history logs to the new format # + testname = 'history conversion' # Mock up an original file and RCS history log mockorigcontents = "This is the original text\n" @@ -443,9 +432,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running history conversion test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(mockorigcontents, get_file_contents(File.join(@historydir, '0000')), 'RCS conv 0000 history file') assert_equal(mocksourcecontents, get_file_contents(File.join(@historydir, '0001')), 'RCS conv 0001 history file') Modified: trunk/test/test_link.rb =================================================================== --- trunk/test/test_link.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_link.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -37,6 +37,7 @@ # # Run a test of creating a link # + testname = 'initial link' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -49,15 +50,14 @@ EOF end - # Run etch - #puts "Running initial link test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@targetfile), 'link create') # # Run a test of updating the link to point to a different destination # + testname = 'link update' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -70,9 +70,7 @@ EOF end - # Run etch - #puts "Running link update test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile2, File.readlink(@targetfile), 'link update') @@ -83,6 +81,7 @@ # we write out the updated link, in case it has problems with links to # files that don't exist (we had such a bug once). # + testname = 'link update from non-existent file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -99,9 +98,7 @@ # previous test) File.delete(@destfile2) - # Run etch - #puts "Running link update from non-existent file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@targetfile), 'link update from non-existent file') end @@ -111,6 +108,7 @@ # Run a test where we ask etch to create a link to a non-existent # destination. It should fail by design. # + testname = 'link to non-existent destination' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -125,9 +123,7 @@ File.delete(@destfile) - # Run etch - #puts "Running link to non-existent destination test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link was not created assert(!File.symlink?(@targetfile), 'link to non-existent destination') @@ -136,6 +132,7 @@ # Then run the same test (link to non-existent destination) with the # override flag turned on to make sure etch does create the link. # + testname = 'link to non-existent destination with override' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -149,9 +146,7 @@ EOF end - # Run etch - #puts "Running link to non-existent destination with override test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link was updated properly assert_equal(@destfile, File.readlink(@targetfile), 'link to non-existent destination with override') @@ -161,6 +156,7 @@ # # Test creating a relative link # + testname = 'relative link' # We'll use @destfile as the target, but need a relative path to it. # Conveniently Pathname has a function to figure that out for us. @@ -178,9 +174,7 @@ EOF end - # Run etch - #puts "Running relative link test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link was updated properly assert_equal(reldestfile, File.readlink(@targetfile), 'relative link') @@ -190,6 +184,7 @@ # # Test ownership and permissions # + testname = 'link ownership and permissions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -205,9 +200,7 @@ EOF end - # Run etch - #puts "Running link ownership and permissions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link ownership got set correctly # Most systems don't support give-away chown, so this test won't work @@ -227,6 +220,7 @@ # # Test duplicate dest instructions # + testname = 'duplicate dest instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -240,9 +234,7 @@ EOF end - # Run etch - #puts "Running duplicate dest instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@targetfile), 'duplicate dest instructions') end @@ -251,6 +243,7 @@ # # Test contradictory dest instructions # + testname = 'contradictory dest instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -264,9 +257,7 @@ EOF end - # Run etch - #puts "Running contradictory dest instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the link wasn't created assert(!File.symlink?(@targetfile) && !File.exist?(@targetfile), 'contradictory dest instructions') @@ -276,6 +267,7 @@ # # Test duplicate script instructions # + testname = 'duplicate script instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -293,9 +285,7 @@ file.puts("@contents << '#{@destfile}'") end - # Run etch - #puts "Running duplicate script instructions test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@targetfile), 'duplicate script instructions') end @@ -304,6 +294,7 @@ # # Test contradictory script instructions # + testname = 'contradictory script instructions' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -324,9 +315,7 @@ file.puts("@contents << '#{@destfile2}'") end - # Run etch - #puts "Running contradictory script instructions test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the link wasn't created assert(!File.symlink?(@targetfile) && !File.exist?(@targetfile), 'contradictory script instructions') Modified: trunk/test/test_local_requests.rb =================================================================== --- trunk/test/test_local_requests.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_local_requests.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -66,9 +66,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -118,9 +116,7 @@ EOF end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly # Our whitespace in the heredoc above gets added to the generated file, so Modified: trunk/test/test_nodegroups.rb =================================================================== --- trunk/test/test_nodegroups.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_nodegroups.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -49,9 +49,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -90,9 +88,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -131,9 +127,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), testname) @@ -175,9 +169,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that the file wasn't modified assert_equal(oldsourcecontents, get_file_contents(@targetfile), testname) Modified: trunk/test/test_options.rb =================================================================== --- trunk/test/test_options.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_options.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -29,6 +29,7 @@ # Test killswitch (not really a command-line option, but seems to # fit best in this file) # + testname = 'killswitch' # Put some text into the original file so that we can make sure it is # not touched. @@ -60,9 +61,7 @@ file.write('killswitch test') end - # Run etch - #puts "Running killswitch test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) assert_equal(origcontents, get_file_contents(@targetfile), 'killswitch') end @@ -71,6 +70,7 @@ # # Test --dry-run # + testname = '--dry-run' # Put some text into the original file so that we can make sure it is # not touched. @@ -98,9 +98,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running --dry-run test" - run_etch(@server, @testroot, :extra_args => '--dry-run') + run_etch(@server, @testroot, :extra_args => '--dry-run', :testname => testname) assert_equal(origcontents, get_file_contents(@targetfile), '--dry-run') end @@ -231,9 +229,7 @@ end end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :extra_args => "#{@targetfile} #{targetfile2} etchtest1 etchtest2") + run_etch(@server, @testroot, :extra_args => "#{@targetfile} #{targetfile2} etchtest1 etchtest2", :testname => testname) # Verify that only the requested files were created assert_equal(sourcecontents, get_file_contents(@targetfile), testname + ' file 1') @@ -318,9 +314,7 @@ end end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :extra_args => "#{@targetfile} #{targetfile2}") + run_etch(@server, @testroot, :extra_args => "#{@targetfile} #{targetfile2}", :testname => testname) # Verify that all were created assert_equal(sourcecontents, get_file_contents(@targetfile), testname + ' filesonly file 1') @@ -412,9 +406,7 @@ end end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot, :extra_args => "etchtest1 #{targetfile2}") + run_etch(@server, @testroot, :extra_args => "etchtest1 #{targetfile2}", :testname => testname) # Verify that all were created assert_equal(origcontents + testname, get_file_contents(cmdtargetfile1), testname + ' cmdandfile cmd 1') @@ -473,7 +465,7 @@ sleep(5) # Test that we don't follow redirects by default - run_etch(@server, @testroot, :errors_expected => true, :extra_args => '', :port => redirect_port) + run_etch(@server, @testroot, :errors_expected => true, :extra_args => '', :port => redirect_port, :testname => testname) assert_equal(origcontents, get_file_contents(@targetfile), testname) # Check that we do follow redirects with the appropriate option @@ -497,7 +489,7 @@ response.set_redirect( WEBrick::HTTPStatus::Found, "http://localhost:#{redirect_port}/") end - run_etch(@server, @testroot, :errors_expected => true, :port => redirect_port) + run_etch(@server, @testroot, :errors_expected => true, :port => redirect_port, :testname => testname) server.shutdown t.kill Modified: trunk/test/test_outputcapture.rb =================================================================== --- trunk/test/test_outputcapture.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_outputcapture.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -64,9 +64,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Fetch the latest result for this client from the server and verify that # it contains the output from the post command. @@ -116,13 +114,10 @@ begin Timeout.timeout(Etch::Client::OUTPUT_CAPTURE_TIMEOUT + 15) do - # Run etch - #puts "Running '#{testname}' test" - # # NOTE: This test is not normally run because the timeout is so long. # Uncomment this run_etch line to run this test. # - #run_etch(@server, @testroot) + #run_etch(@server, @testroot, :testname => testname) end rescue Timeout::Error flunk('output capturing did not time out as expected') Modified: trunk/test/test_scripts.rb =================================================================== --- trunk/test/test_scripts.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_scripts.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -36,6 +36,7 @@ # # Start with a test of a script with a syntax error # + testname = 'script with syntax error' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -58,9 +59,7 @@ before_size = File.stat(@targetfile).size before_ctime = File.stat(@targetfile).ctime - # Run etch - #puts "Running script with syntax error test" - run_etch(@server, @testroot, :errors_expected => true) + run_etch(@server, @testroot, :errors_expected => true, :testname => testname) # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'script with syntax error size comparison') @@ -69,6 +68,7 @@ # # Run a test where the script doesn't output anything # + testname = 'script with no output' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -91,9 +91,7 @@ before_size = File.stat(@targetfile).size before_ctime = File.stat(@targetfile).ctime - # Run etch - #puts "Running script with no output" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'script with no output size comparison') @@ -102,6 +100,7 @@ # # Run a test using a script to generate the contents of a file # + testname = 'script to generate the contents of a file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -121,9 +120,7 @@ file.puts("@contents << '#{sourcecontents}'") end - # Run etch - #puts "Running file script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -138,6 +135,7 @@ # # Run a test where the script reads the contents from another file # + testname = 'script reads the contents from another file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -162,9 +160,7 @@ file.puts("@contents << IO.read('source')") end - # Run etch - #puts "Running file source script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -179,6 +175,7 @@ # # Run a test where the script appends to the original file # + testname = 'script appends to the original file' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -202,9 +199,7 @@ file.puts("@contents << IO.read('source')") end - # Run etch - #puts "Running file source script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly correctcontents = '' @@ -220,6 +215,7 @@ # # Run a test of using a script to generate a link # + testname = 'script to generate a link' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -238,9 +234,7 @@ file.puts("@contents << '#{@destfile}'") end - # Run etch - #puts "Running link script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the link was created properly assert_equal(@destfile, File.readlink(@targetfile), 'link script') @@ -249,6 +243,7 @@ # Run a test where the script doesn't output anything in link # context # + testname = 'link script with no output' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -269,9 +264,7 @@ before_readlink = File.readlink(@targetfile) before_ctime = File.stat(@targetfile).ctime - # Run etch - #puts "Running link script with no output" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that etch didn't do anything to the file assert_equal(before_readlink, File.readlink(@targetfile), 'link script with no output readlink comparison') @@ -280,6 +273,7 @@ # # Run a test of using a script to generate a directory # + testname = 'script to generate a directory' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -296,9 +290,7 @@ file.puts("@contents << 'true'") end - # Run etch - #puts "Running directory script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the directory was created assert(File.directory?(@targetfile), 'directory script') @@ -307,6 +299,7 @@ # Run a test where the script doesn't output anything in directory # context # + testname = 'directory script with no output' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -331,9 +324,7 @@ before_size = File.stat(@targetfile).size before_ctime = File.stat(@targetfile).ctime - # Run etch - #puts "Running directory script with no output" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'directory script with no output size comparison') @@ -342,6 +333,7 @@ # # Run a test of using a script to delete # + testname = 'script to delete' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -359,9 +351,7 @@ file.puts("@contents << 'true'") end - # Run etch - #puts "Running delete script test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was removed assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), 'delete script') @@ -370,6 +360,7 @@ # Run a test where the script doesn't output anything in delete # context # + testname = 'delete script with no output' # Recreate the target file origcontents = "This is the original text\n" @@ -396,9 +387,7 @@ before_size = File.stat(@targetfile).size before_ctime = File.stat(@targetfile).ctime - # Run etch - #puts "Running delete script with no output" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'delete script with no output size comparison') Modified: trunk/test/test_transitions.rb =================================================================== --- trunk/test/test_transitions.rb 2010-12-24 00:50:24 UTC (rev 248) +++ trunk/test/test_transitions.rb 2011-01-07 03:32:19 UTC (rev 249) @@ -44,6 +44,7 @@ # # File to link transition # + testname = 'file to link transition' FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| @@ -56,15 +57,14 @@ EOF end - # Run etch - #puts "Running file to link test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert_equal(@destfile, File.readlink(@targetfile), 'file to link') # # File to directory transition # + testname = 'file to directory transition' # Reset target FileUtils.rm_rf(@targetfile) @@ -81,9 +81,7 @@ EOF end - # Run etch - #puts "Running file to directory test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) assert(File.directory?(@targetfile), 'file to directory') end @@ -92,6 +90,7 @@ # # Link to file transition # + testname = 'link to file transition' # Reset target FileUtils.rm_rf(@targetfile) @@ -116,9 +115,7 @@ file.write(sourcecontents) end - # Run etch - #puts "Running link to file test" - run_etch(@server, @testroot) + run_etch(@server, @testroot, :testname => testname) # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(@targetfile), 'link to file') @@ -128,6 +125,7 @@ # identical contents to the file contents we should be writing out # (to test that the comparison method doesn't follow symlinks) # + 'link w/ same contents to file transition' # Reset target FileUtils.rm_rf(@targetfile) @@ -... [truncated message content] |
From: <jh...@us...> - 2010-12-24 00:50:30
|
Revision: 248 http://etch.svn.sourceforge.net/etch/?rev=248&view=rev Author: jheiss Date: 2010-12-24 00:50:24 +0000 (Fri, 24 Dec 2010) Log Message: ----------- Document etch.conf in the man page Modified Paths: -------------- trunk/client/etch.8 Modified: trunk/client/etch.8 =================================================================== --- trunk/client/etch.8 2010-12-23 02:06:14 UTC (rev 247) +++ trunk/client/etch.8 2010-12-24 00:50:24 UTC (rev 248) @@ -140,6 +140,25 @@ .SH FILES .TP +.B /etc/etch.conf +Optional configuration file for the etch client. The distribution ships with +an example file showing the available settings and their defaults. The file +syntax consists of "name = value" parameters. Lines starting with '#' and +empty lines are interpreted as comments. +.IP +.B server = +The URL for connecting to the server. http:// and https:// are supported. +.IP +.B path = +PATH environment etch should use when executing external commands. +.IP +.B local = +Etch can read configuration from a local directory rather than from a server. +If set this will override the server setting. +.IP +.B key = +SSH host key to use for authentication rather than standard system key. +.TP .B /etc/etch/ca.pem SSL certificate(s) needed to verify the .B etch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2010-12-23 02:06:20
|
Revision: 247 http://etch.svn.sourceforge.net/etch/?rev=247&view=rev Author: jheiss Date: 2010-12-23 02:06:14 +0000 (Thu, 23 Dec 2010) Log Message: ----------- Add /etc/etch.conf to files list Modified Paths: -------------- trunk/client/etch-client.spec Modified: trunk/client/etch-client.spec =================================================================== --- trunk/client/etch-client.spec 2010-12-23 02:05:05 UTC (rev 246) +++ trunk/client/etch-client.spec 2010-12-23 02:06:14 UTC (rev 247) @@ -18,6 +18,7 @@ /usr/lib/ruby/site_ruby/1.8/etch.rb /usr/lib/ruby/site_ruby/1.8/versiontype.rb /usr/share/man/man8/etch.8 +/etc/etch.conf /etc/etch /usr/sbin/etch_cron_wrapper /etc/cron.d/etch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2010-12-23 02:05:11
|
Revision: 246 http://etch.svn.sourceforge.net/etch/?rev=246&view=rev Author: jheiss Date: 2010-12-23 02:05:05 +0000 (Thu, 23 Dec 2010) Log Message: ----------- This file has been deprecated for a while and is now woefully out of date. Remove it. Removed Paths: ------------- trunk/client/Makefile Deleted: trunk/client/Makefile =================================================================== --- trunk/client/Makefile 2010-12-22 21:51:50 UTC (rev 245) +++ trunk/client/Makefile 2010-12-23 02:05:05 UTC (rev 246) @@ -1,206 +0,0 @@ -# Deprecated, see Rakefile - -BUILDROOT=/var/tmp/etch-client-buildroot -# Grab the current version from the library -VER=$(shell ruby -e "$$:.unshift('.'); require 'etchclient'; puts Etch::Client::VERSION") - -all: - -redhat: redhatprep rpm -redhatprep: - # Install everything needed for the command which sets VER above - rpm --quiet -q ruby || sudo yum install ruby - # And the package which contains the rpmbuild command - rpm --quiet -q rpm-build || sudo yum install rpm-build -rpm: etch-client.spec - # - # Create package file structure in build root - # - rm -rf $(BUILDROOT) - mkdir -p $(BUILDROOT)/usr/sbin - cp -p etch $(BUILDROOT)/usr/sbin - chmod 555 $(BUILDROOT)/usr/sbin/etch - cp -p etch_to_trunk $(BUILDROOT)/usr/sbin - chmod 555 $(BUILDROOT)/usr/sbin/etch_to_trunk - mkdir -p $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8 - cp -p etchclient.rb $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8/etchclient.rb - cp -p ../server/lib/etch.rb $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8/etch.rb - cp -p ../server/lib/versiontype.rb $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/lib/ruby/site_ruby/1.8/versiontype.rb - mkdir -p $(BUILDROOT)/usr/share/man/man8 - cp -p etch.8 $(BUILDROOT)/usr/share/man/man8 - mkdir -p $(BUILDROOT)/etc/etch - cp -p ca.pem $(BUILDROOT)/etc/etch - cp -p dhparams $(BUILDROOT)/etc/etch - # Cron job - mkdir -p $(BUILDROOT)/etc/cron.d - cp etch_cron $(BUILDROOT)/etc/cron.d/etch - cp etch_cron_wrapper $(BUILDROOT)/usr/sbin - chmod 555 $(BUILDROOT)/usr/sbin/etch_cron_wrapper - # - # Now build the package - # - sed 's/VER/$(VER)/' etch-client.spec > etch-client.spec_withversion - rpmbuild -bb --buildroot $(BUILDROOT) etch-client.spec_withversion - rm -rf $(BUILDROOT) - -debian: debianprep deb -debianprep: - # Install everything needed for the command which sets VER above - sudo apt-get --no-upgrade --quiet install ruby libopenssl-ruby rubygems facter -deb: control - rm -rf $(BUILDROOT) - mkdir -p $(BUILDROOT)/DEBIAN - grep -v '^#' control | sed 's/VER/$(VER)/' > $(BUILDROOT)/DEBIAN/control - mkdir -p $(BUILDROOT)/usr/sbin - cp -p etch $(BUILDROOT)/usr/sbin - chmod 555 $(BUILDROOT)/usr/sbin/etch - cp -p etch_to_trunk $(BUILDROOT)/usr/sbin - chmod 555 $(BUILDROOT)/usr/sbin/etch_to_trunk - mkdir -p $(BUILDROOT)/usr/local/lib/site_ruby/1.8 - cp -p etchclient.rb $(BUILDROOT)/usr/local/lib/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/local/lib/site_ruby/1.8/etchclient.rb - cp -p ../server/lib/etch.rb $(BUILDROOT)/usr/local/lib/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/local/lib/site_ruby/1.8/etch.rb - cp -p ../server/lib/versiontype.rb $(BUILDROOT)/usr/local/lib/site_ruby/1.8 - chmod 444 $(BUILDROOT)/usr/local/lib/site_ruby/1.8/versiontype.rb - mkdir -p $(BUILDROOT)/usr/share/man/man8 - cp -p etch.8 $(BUILDROOT)/usr/share/man/man8 - mkdir -p $(BUILDROOT)/etc/etch - cp -p ca.pem $(BUILDROOT)/etc/etch - cp -p dhparams $(BUILDROOT)/etc/etch - sudo chown -R 0:0 $(BUILDROOT) - dpkg --build $(BUILDROOT) etch-client-$(VER).deb - rm -rf $(BUILDROOT) - -solaris: solarisprep sysvpkg sysvpkg-sparc -solarisprep: - # Install everything needed for the command which sets VER above - pkginfo -q CSWruby || sudo pkg-get -i ruby - pkginfo -q CSWrubygems || sudo pkg-get -i rubygems - pkginfo -q CSWfacter || sudo pkg-get -i facter -sysvpkg: pkginfo depend - # - # Create package file structure in build root - # - rm -rf $(BUILDROOT) - mkdir -p $(BUILDROOT)/usr/sbin - cp -p etch $(BUILDROOT)/usr/sbin - mv $(BUILDROOT)/usr/sbin/etch $(BUILDROOT)/usr/sbin/etch.tmp - cat $(BUILDROOT)/usr/sbin/etch.tmp | sed 's,/usr/bin/ruby,/opt/csw/bin/ruby,' > $(BUILDROOT)/usr/sbin/etch - rm $(BUILDROOT)/usr/sbin/etch.tmp - chmod 555 $(BUILDROOT)/usr/sbin/etch - cp -p etch_to_trunk $(BUILDROOT)/usr/sbin - mv $(BUILDROOT)/usr/sbin/etch_to_trunk $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp - cat $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp | sed 's,/usr/bin/ruby,/opt/csw/bin/ruby,' > $(BUILDROOT)/usr/sbin/etch_to_trunk - rm $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp - chmod 555 $(BUILDROOT)/usr/sbin/etch_to_trunk - mkdir -p $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - cp -p etchclient.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/etchclient.rb - cp -p ../server/lib/etch.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/etch.rb - cp -p ../server/lib/versiontype.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/versiontype.rb - mkdir -p $(BUILDROOT)/usr/share/man/man8 - cp -p etch.8 $(BUILDROOT)/usr/share/man/man8 - mkdir -p $(BUILDROOT)/etc/etch - cp -p ca.pem $(BUILDROOT)/etc/etch - cp -p dhparams $(BUILDROOT)/etc/etch - # Cron job for registration - cat etch_cron_wrapper | sed 's,/usr/bin/perl,/opt/csw/bin/perl,' > $(BUILDROOT)/usr/sbin/etch_cron_wrapper - chmod 555 $(BUILDROOT)/usr/sbin/etch_cron_wrapper - # - # Now build the package - # - rm -rf solbuild - mkdir solbuild - sed 's/%VER%/$(VER)/' pkginfo > solbuild/pkginfo - echo "i pkginfo=./pkginfo" > solbuild/prototype - cp depend solbuild/depend - echo "i depend=./depend" >> solbuild/prototype - cp postinstall solbuild/postinstall - echo "i postinstall=./postinstall" >> solbuild/prototype - cp postremove solbuild/postremove - echo "i postremove=./postremove" >> solbuild/prototype - # The tail +2 removes the first line, which is the base directory - # and doesn't need to be included in the package. - # The first sed just cleans up the directory names - # The second sed tell pkgadd to not force our permissions on directories - # The $$ in that sed escapes the $ from make - find $(BUILDROOT) | pkgproto | tail +2 | sed "s,$(BUILDROOT),," | sed '/^d/s/[^ ]* [^ ]* [^ ]*$$/? ? ?/' >> solbuild/prototype - cd solbuild && pkgmk -r $(BUILDROOT) -d $(PWD)/solbuild - pkgtrans solbuild ../YPCetch-$(VER).pkg YPCetch - rm -rf solbuild - rm -rf $(BUILDROOT) - -# On Sparc systems we're having problems with the CSW/Blastwave ruby -# core dumping when running etch. The Sunfreeware ruby seems to work. -# Sunfreeware doesn't play well with pkg-get, so we create a bit of a -# hybrid. We still express all the dependencies against CSW, and put -# our library file (etchclient.rb) into /opt/csw. We modify etch to use -# the Sunfreeware ruby in /usr/local/bin, but then tell it to also look -# in the /opt/csw directory for libraries. -# I'm going to guess that the smaller utilities like etch_to_trunk won't have -# problems, so I'm leaving them set to /opt/csw/bin/ruby. -sysvpkg-sparc: pkginfo depend - # - # Create package file structure in build root - # - rm -rf $(BUILDROOT) - mkdir -p $(BUILDROOT)/usr/sbin - cp -p etch $(BUILDROOT)/usr/sbin - mv $(BUILDROOT)/usr/sbin/etch $(BUILDROOT)/usr/sbin/etch.tmp - cat $(BUILDROOT)/usr/sbin/etch.tmp | sed 's,/usr/bin/ruby,/usr/local/bin/ruby,' > $(BUILDROOT)/usr/sbin/etch - rm $(BUILDROOT)/usr/sbin/etch.tmp - mv $(BUILDROOT)/usr/sbin/etch $(BUILDROOT)/usr/sbin/etch.tmp - # The $$ in that awk escapes the $ from make - cat $(BUILDROOT)/usr/sbin/etch.tmp | awk '/unshift.*__FILE__/ {print "$$:.unshift \"/opt/csw/lib/ruby/site_ruby/1.8\"\n" $$0; next}; {print}' > $(BUILDROOT)/usr/sbin/etch - rm $(BUILDROOT)/usr/sbin/etch.tmp - chmod 555 $(BUILDROOT)/usr/sbin/etch - cp -p etch_to_trunk $(BUILDROOT)/usr/sbin - mv $(BUILDROOT)/usr/sbin/etch_to_trunk $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp - cat $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp | sed 's,/usr/bin/ruby,/opt/csw/bin/ruby,' > $(BUILDROOT)/usr/sbin/etch_to_trunk - rm $(BUILDROOT)/usr/sbin/etch_to_trunk.tmp - chmod 555 $(BUILDROOT)/usr/sbin/etch_to_trunk - mkdir -p $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - cp -p etchclient.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/etchclient.rb - cp -p ../server/lib/etch.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/etch.rb - cp -p ../server/lib/versiontype.rb $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8 - chmod 444 $(BUILDROOT)/opt/csw/lib/ruby/site_ruby/1.8/versiontype.rb - mkdir -p $(BUILDROOT)/usr/share/man/man8 - cp -p etch.8 $(BUILDROOT)/usr/share/man/man8 - mkdir -p $(BUILDROOT)/etc/etch - cp -p ca.pem $(BUILDROOT)/etc/etch - cp -p dhparams $(BUILDROOT)/etc/etch - # Cron job for registration - cat etch_cron_wrapper | sed 's,/usr/bin/perl,/opt/csw/bin/perl,' > $(BUILDROOT)/usr/sbin/etch_cron_wrapper - chmod 555 $(BUILDROOT)/usr/sbin/etch_cron_wrapper - # - # Now build the package - # - rm -rf solbuild - mkdir solbuild - sed 's/%VER%/$(VER)/' pkginfo > solbuild/pkginfo - echo "i pkginfo=./pkginfo" > solbuild/prototype - cp depend solbuild/depend - echo "i depend=./depend" >> solbuild/prototype - cp postinstall solbuild/postinstall - echo "i postinstall=./postinstall" >> solbuild/prototype - cp postremove solbuild/postremove - echo "i postremove=./postremove" >> solbuild/prototype - # The tail +2 removes the first line, which is the base directory - # and doesn't need to be included in the package. - # The first sed just cleans up the directory names - # The second sed tell pkgadd to not force our permissions on directories - # The $$ in that sed escapes the $ from make - find $(BUILDROOT) | pkgproto | tail +2 | sed "s,$(BUILDROOT),," | sed '/^d/s/[^ ]* [^ ]* [^ ]*$$/? ? ?/' >> solbuild/prototype - cd solbuild && pkgmk -r $(BUILDROOT) -d $(PWD)/solbuild - pkgtrans solbuild ../YPCetch-$(VER)-sparc.pkg YPCetch - rm -rf solbuild - rm -rf $(BUILDROOT) - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2010-12-22 21:51:56
|
Revision: 245 http://etch.svn.sourceforge.net/etch/?rev=245&view=rev Author: jheiss Date: 2010-12-22 21:51:50 +0000 (Wed, 22 Dec 2010) Log Message: ----------- Add desc to the gem task so that it shows up in the rake -T list Modified Paths: -------------- trunk/client/Rakefile Modified: trunk/client/Rakefile =================================================================== --- trunk/client/Rakefile 2010-12-22 21:09:27 UTC (rev 244) +++ trunk/client/Rakefile 2010-12-22 21:51:50 UTC (rev 245) @@ -406,6 +406,7 @@ puts "Portfile is #{portfile}" end +desc 'Build rubygem package' task :gem do # # Create package file structure in build root This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jh...@us...> - 2010-12-22 21:09:33
|
Revision: 244 http://etch.svn.sourceforge.net/etch/?rev=244&view=rev Author: jheiss Date: 2010-12-22 21:09:27 +0000 (Wed, 22 Dec 2010) Log Message: ----------- Update to 3.17.0 version Modified Paths: -------------- trunk/client/Portfile Modified: trunk/client/Portfile =================================================================== --- trunk/client/Portfile 2010-12-22 21:07:20 UTC (rev 243) +++ trunk/client/Portfile 2010-12-22 21:09:27 UTC (rev 244) @@ -5,7 +5,7 @@ PortGroup ruby 1.0 name etch -version 3.16.0 +version 3.17.0 categories sysutils maintainers aput.net:jheiss openmaintainer @@ -25,9 +25,9 @@ master_sites sourceforge -checksums md5 5ee5d5aad12f4d5271ae8b676419948f \ - sha1 c1e4d4496e8edd9adf85d9893a5fc56935703946 \ - rmd160 5fd7d9e84e966a2031a30d4da49ab822bfca746c +checksums md5 9b5216f62d4add225f50984cc07f630b \ + sha1 a4bc1c61f349464ca793d858abeca08760bde6e5 \ + rmd160 f827b360c69cceab1a864b11c7cf434b7c7a4a39 depends_build port:rb-rake depends_run port:facter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |