Small Mosaic


Categories:

books
career
codinghorrors
comics
events
geekstuff
justdont
languages
languages/bash
linkshot
magazines
meta
misctech
movies
nottech
operatingsystems
operatingsystems/linux
operatingsystems/linux/debian
operatingsystems/solaris
paranoidadmin
perl
presentations
programming
python
ruby
security
security/apache
security/tools
serversmells
services
services/dns
sites
specifications
sysadmin
tools
tools/commandline
tools/firefox
tools/gui
tools/network
tools/online
tools/online/greasemonkey
tools/puppet
unixdaemon

Archives:

February 20101
January 20102
October 20092
September 200910
August 200910
July 20094
June 20091
April 20093
March 20097
February 20094
January 200917
December 20081
November 20084
October 20085
September 20084
August 200812
July 20089
April 20084
March 20081
February 20081
January 200815
August 20072
June 20079
May 20076
April 20078
March 200731
February 20073
January 200721
December 20061
November 20064
October 20066
September 200632
August 200617
July 200614
June 20069
May 200613
March 200611
February 200616
January 200611
December 20051
November 20056
October 200519
September 200525
August 200516
July 200516
June 200513
May 20052
April 200519
March 200531
February 200520
January 200531
December 200421
November 200430
October 200432
September 200418
August 20047
July 200414
June 20045

Mon, 06 Apr 2009

Ruby DNS Testing - First Glance
DNS is one of those 'small config change here, errors a long way over there later' technologies that always leaves me a little worried about the knock on effect of my changes. As a simple, coarse, safeguard at work we use Nagios to check that a canary record in each zone can be resolved from each DNS server. It's far from a perfect solution but it does catch some of the bigger errors and typos.

In order to beef up this safety net (and encourage me to spend time using a language other than Perl) I've been investigating some of the testing options available in ruby, namely RSpec and Cucumber. I have to say the testing libraries themselves are actually nice to use and easy to pick up even for a non-rubyists like me. On the other hand I quickly developed a strong dislike of the ruby resolv library that actually does the DNS queries. The lack of decent tutorials or documentation for anything beyond the very basic uses and the (to me) very awkward API nearly had me running back to the safety of Net::DNS , a mature and widely used perl module. There is a ruby port that I'll have a look at in the future

For the testing itself I started writing RSpec stories against my own DNS and found the API easy to use. Testing existing configs against local policies is simple - for example all our domains should list at least three name servers -


it "should have at least 3 NS records" do
  @resolver = Resolv::DNS.new
  @nameservers = @resolver.getresources( domain, Resolv::DNS::Resource::IN::NS)
  @nameservers.should have_at_least(3).items
end

After doing some more scut work and testing other record types I moved onwards and upwards to Cucumber. I'm not sure I'd be able to gift someone else with writing the scenarios but they'll be easier to show business people than raw rspec stories. They'll also be very handy in migration meetings (an executable todo list), if it's not on the page it's not getting done.


Feature: Mass DNS Resolution
  In order to present a consistent brand image
  As a System Administrator
  I want to ensure no domains point away from our main IP

  Scenario Outline: Resolve a name to a number
    Given a hostname of <hostname>
    Then I should see the IP address 266.266.266.266

    Examples:
     | hostname        |
     | example.org     |
     | www.example.org |

Next time I work somewhere with ISO 27xxx compliance requirements I'll see if the controls can be written like this and have automatic verification run from them. Cucumber is a little wordy for my tastes but I can see where that could be a strength when presenting to the right audience (such as compliance auditors).

Next time we have a set of DNS migrations I'll be using at least one of these tools to write before and after test cases to ensure nothing gets missed or slips through the cracks. Once I've been through a couple I'll write up in more detail what we end up with.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2009/04/06 15:46 | /ruby | Permanent link to this entry | This entry + same date


Fri, 11 Jul 2008

Randexp - Generating test data with Ruby regexs
While paging through reddit programming recently (seems only fair since they linked to me ;)) I stumbled on to the very nifty Randexp gem, a library that uses regular expression patterns to generate data that would satisfy the pattern. Or in less tech terms - a really good test data generator.

  
# install randexp

$ irb

require "rubygems"
require "randexp"

# simple fake phone number -
/020(7|8) \d{3} \d{4}/.gen

# build a reusable class.
class Randgen
  def self.version()
   /\d{1,3}\.\d{1,4}/.gen
  end
end

# and use it.
/[:version:]/.gen

  

I especially like the ability to make your own character classes. I'm not a ruby guy but I can see this being very useful in lots of little data generation scripts and test harnesses.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2008/07/11 18:29 | /ruby | Permanent link to this entry | This entry + same date


Wed, 14 Mar 2007

Playing with Facter
I'm on-call tonight so I invested some time in facter, "A cross-platform Ruby library for retrieving facts from operating systems." While facter is an interesting command line program (its extension mechanism is quite nice) its main claim to fame is that it's used by puppet (which I'm slowly evaluating as a CFEngine replacement) to determine facts about a machine.

While the docs are a little light on the ground the tgz contains a couple of examples and after some playing around I think I've got a basic Linux Bonding fact ready. For your viewing pleasure, the Facter Linux Network Bonding custom fact. It's not amazingly powerful or complex but it does seem to do what I want and it gave me a reason to look around the Ruby Dir class so it's not all bad. I've mostly put it up to show how easy it is for someone with very little ruby knowledge to extend facter.

Note: I also discovered that you can't do a confine :bonding => :true, facter works on literal string values, not on true or false.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2007/03/14 23:20 | /ruby | Permanent link to this entry | This entry + same date


Mon, 12 Mar 2007

daemon_percentages.rb and Ruby Autovivification
Both Jim Weirich and Ben Summers were kind enough to email me about my Daemon Logging Percentages and Playing with Ruby Idioms post. They sent me an explanation on how to do the hash assignment in a way I find much nicer, so with no more delays I present - Option 4:

  
  tally = Hash.new(0)
  tally[daemon] += 1
  

It really is that simple - and I still missed it by a mile. I've updated the script to use this and I wanted to say thank you for the pointer, so thank you both.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2007/03/12 21:06 | /ruby | Permanent link to this entry | This entry + same date


books career codinghorrors events geekstuff justdont languages/bash magazines meta misctech movies nottech operatingsystems/linux operatingsystems/linux/debian operatingsystems/solaris perl presentations programming python ruby security security/apache security/tools serversmells services/dns sites sysadmin tools/commandline tools/firefox tools/gui tools/network tools/online tools/online/greasemonkey tools/puppet unixdaemon

Copyright © 2000-2005 Dean Wilson XML feed logo