A beginning Test::More suite, VIM discoveries, and FuseFS musings

by mjt in tech

A Perl Test::More suite for small networks

I’ve been wanting to implement some simple tests for my home network to make sure everything is running the way I expect it to on an ad-hoc basis. I’ve got a Nagios setup monitoring my Apache, MySQL, and Zimbra services, but I wanted a bit more granularity to my tests, a command-line interface, and the ability to separate out the “business logic” a la MVC.

Since I had documented my server installation routine in chronological order (eg, “first, unpack the box,”) I immediately noticed I had roughly determined a five-step overview of the process. Since most tests I’ve seen run numerically, I decided on:

  • 00prereqs.t - do I have everything I need to run the other tests?
  • 01dns.t - can I resolve host names, so I can find hosts and services?
  • 02time.t - is my clock correct (so later time dependencies would work?)
  • 03hosts.t - can I find all hosts I expect to find?
  • 04services.t - can I contact all services (SMTP, HTTP, etc) I expect to find?

UPDATE: I forgot that I moved the DNS test earlier in the sequence - my NTP test relies on DNS to find external time masters to get the current time.

Note: I discovered via 02time.t that Net::Time doesn’t work for me; Net::NTP does. I don’t know what the difference is, but “working” is always a plus in my book. Basically, using it, I test whether localtime is the same as NTP time (see Net::NTP time for details.)

I am not sure whether 04services.t will grow into multiple files for various services, but this works well enough for now. I won’t go into each individual test in each file for this post, but suffice it to say this is how I now test for sanity from my SVN tree:

    ~/src/mijit
    [204]meatbag$ prove -l t/
    t/00prereqs.....ok
    t/01time........ok
    t/02dns.........ok
    t/03hosts.......ok
    t/04services....ok
    All tests successful.
    Files=5, Tests=11,  2 wallclock secs ( 0.97 cusr +  0.26 csys =  1.23 CPU)
    

VIM discoveries

  • When using the gq command, the autoindent option can be your friend! This allows indented text to be left-aligned correctly (a necessity for my notes.txt file.)
  • some matchparen plugin that is installed on some of my machines and not others adds annoying cyan brace-matching highlighting. This drags my eye away completely away from the cursor - bad plugin! The quick fix: :NoMatchParen disables the plugin, and :DoMatchParen enables it again. Do as you like to your plugin/ directory.

FuseFS musings:

Much seems to have been made of FuseFS lately, which I think is a really neat (but not necessarily great,) idea - and I mean that in a it works in theory, but not reality. At least, that’s been my limited experience. Given the state of these tools and the tech know-how needed to deploy them, I find myself asking why not just set an expectation that WebDAV can do it for you (yes, I know it has its own problems with various clients requiring certain server headers. Maybe that means we should pressure people more to follow open standards.) That said, I have been finding the following quite useful to mount a remote directory to a local directory over SSH:

    sshfs -p $REMOTE_PORT $REMOTE_HOST:$REMOTE_DIR $LOCAL_DIR
    

i love paris in the T:flw.quid55328.com/aaakk/ch@ung

by mjt in art, tech

paris, las vegas, running windows

WordPress 2.2 now available

by mjt in tech

On behalf of the entire WordPress team, I’m proud and excited to announce the immediate availability of version 2.2 “Getz” for download. This version includes a number of new features, most notably Widgets integration, and over two hundred bug fixes. It’s named in honor of tenor saxophonist Stan Getz.
–Matt, from WordPress

Here’s my “short list” of observations:

  • Widgets (ie, AJAX-y sidebar thingies)
  • Full Atom support (plus new XML-RPC APIs)
  • Blogger.com integration
  • jQuery used for internal functions on admin page
  • Optionally set “home” and “siteurl” options in wp-config.php instead of the database (useful when supporting a dev/prod setup)
  • Tenor players (eg, Getz) rule

if you followed my previous post regarding subversion access to WP code, I can attest that the upgrade is now as easy as:

svn switch http://svn.automattic.com/wordpress/trunk/

…and hitting the database upgrade link. I needed to svn switch since, as you may have noticed, I had checked out the 2.1.3 tag, not the trunk. Switching to trunk should mean that all future upgrades are as easy as svn upgrade. Whee, etc!

Complexifiers v. Simplifiers Redux

by mjt in tech

Last year, Murali, from his Thought Garage, expanded on some perspectives I offered in the comments of a Berkun Blog comparing those who “complexify” and those who “simplify.” For simplifiers familiar with the often-debilitating effects of complexifiers (at least, in the world of software development, where “real world” issues like deadlines and deliverables reign,) the problem is what do we do with redundancy when we can’t take it out back and shoot it in the head?

The irony of adding to a lengthy discussion on the topic is hopefully not lost on us, but I feel compelled to add that this is precisely the problem Zen addresses. That is, there is a way to directly experience the truth of our situation without expending excess energy on processes that do not serve us. During walking meditation yesterday, it occurred to me that Yeats said this very thing to me in The Coming of Wisdom with Time:

THOUGH leaves are many, the root is one;
Through all the lying days of my youth
I swayed my leaves and flowers in the sun;
Now I may wither into the truth.
–Yeats, William Butler

So, the solution? Read. Read more. Read even yet still more.

Then, go ask a tree.

Selectively disabling TT wrapper in Catalyst

by mjt in tech

The following is a method for Catalyst sites using Template Toolkit with a site-wide WRAPPER directive to selectively return partial HTML for the purpose of serving Asynchronous HTML and HTTP (ie, “AHAH’).

Catalyst is a powerful and versatile web development framework that aims to be Perl’s counterpart to Ruby on Rails, fusing a Model-View-Controller (MVC) environment with the depth, breadth, and power of CPAN. If you build web sites with Perl, you should check it out.

The problem: you want to use TT’s WRAPPER directive to supply a site-wide wrapper template, but you also want to be able to selectively turn the wrapper off so that you can serve some pages as partial HTML. At first glance, Catalyst’s config() method might suggest that one could reconfigure your view in your action’s end(), but that proves fruitless and it clucks in the following manner:

[warn] Setting config after setup has been run is not a good idea.

My solution: create an end() in your controller that emits “partial” HTML fragments by creating a new Template Toolkit object with a locally-defined configuration. (Note that since we override the root controller’s end(), we must call forward/detach to it if we do not specify the “partial” parameter.)

sub end : Private {
my ($self, $c, $file) = @_;
my $params = $c->request->parameters;
if (exists $params->{'partial'}) {
my $html;
my $tt = Template->new({
%{ $c->config->{'View::TT'} },
INCLUDE_PATH => $c->path_to('root'),
WRAPPER => undef,
});
$tt->process($file, $c->stash, \$html) or $c->log->warn($tt->error);
$c->response->content_type('text/html');
$c->response->body($html);
}
else {
$c->detach(qw/CE::Controller::Root end/);
}
}

A more robust solution better-suited for larger projects might be a new view with an alternate configuration (eg, a custom View::TTpartial,) but I wanted to show the logic directly in my controller, allowing full control of the configuration and direct access to the $html.

Coming soon: the “data island” solution I ultimately opted for to obviate AHAH for serving map marker data to a Google map.