<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Nikolay Sturm's Blog]]></title>
  <link href="http://blog.nistu.de/atom.xml" rel="self"/>
  <link href="http://blog.nistu.de/"/>
  <updated>2012-02-15T08:37:37+01:00</updated>
  <id>http://blog.nistu.de/</id>
  <author>
    <name><![CDATA[Nikolay Sturm]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Setting up tddium for a Rails project]]></title>
    <link href="http://blog.nistu.de/2012/02/08/setting-up-tddium-for-a-rails-project/"/>
    <updated>2012-02-08T06:55:00+01:00</updated>
    <id>http://blog.nistu.de/2012/02/08/setting-up-tddium-for-a-rails-project</id>
    <content type="html"><![CDATA[<p>Lots has been written about the merits of continuous integration and I am a
firm believer in it. However, while our team at work uses test-driven
development, we still don&#8217;t have a CI server. This week I went on a quest to
change that.</p>

<p>In order to minimize maintenance, we decided to give
<a href="http://www.tddium.com/">tddium</a> a try. It is a hosted CI service for Ruby
(on Rails) projects.</p>

<h3>Setup</h3>

<p>Initial setup was quite painless and works as described on their
<a href="https://www.tddium.com/support/">webpage</a>:</p>

<ul>
<li>sign up on the webpage</li>
<li>install the <em>tddium</em> gem</li>
<li>guided setup with the <em>tddium</em> tool, including github integration and
email/campfire notification</li>
</ul>


<p>For a regular rails app, this should have been it. In our case however, the
tests wouldn&#8217;t even start as our sample app uses multiple databases. While
initial install was a matter of minutes, at this point I began a multi-hour
debug session, trying to figure out how to bend tddium to my will.</p>

<h3>Debugging</h3>

<p>The first problem was the Rails logger. Tddium seems to overwrite the standard
logger with their own implementation that is not fully compatible with the
standard Rails logger. In our case it doesn&#8217;t provide <em>auto_flushing=</em>. This,
however, was easy to fix:</p>

<pre><code>Rails.logger.auto_flushing = true if Rails.logger.respond_to?(:auto_flushing)
</code></pre>

<p>The next problem was a much bigger beast, multi database support. While the
documentation roughly explains database setup and the use of hooks to add
custom configuration, it took me quite some time to figure out how everything
really works and how I could change the setup to suite my needs.</p>

<p>At this point I have to mention the slow feedback cycle tddium has, from
running <code>tddium spec</code> to push code changes, to running the suite and seeing an
error, it took 2 to 3 minutes. On the plus side I am happy <code>tddium spec</code> exists
at all, this way you can easily run the suite on locally commited changes and
don&#8217;t have to push to github all the time. Great for testing stuff.</p>

<p>So, after many failures I was finally able to come up with this solution:</p>

<div><script src='https://gist.github.com/1766173.js?file='></script>
<noscript><pre><code>foo: &amp;foo
adapter: &lt;%= ENV['TDDIUM_DB_ADAPTER'] %&gt;
database: &lt;%= ENV['TDDIUM_DB_NAME'] %&gt;
username: &lt;%= ENV['TDDIUM_DB_USER'] %&gt;
password: &lt;%= ENV['TDDIUM_DB_PASSWORD'] %&gt;
&lt;%= &quot;socket: #{ENV['TDDIUM_DB_SOCKET']}&quot; if ENV['TDDIUM_DB_SOCKET'] %&gt;

development: &amp;development
adapter: &lt;%= ENV['TDDIUM_DB_ADAPTER'] %&gt;
database: &lt;%= ENV['TDDIUM_DB_NAME'] %&gt;
username: &lt;%= ENV['TDDIUM_DB_USER'] %&gt;
password: &lt;%= ENV['TDDIUM_DB_PASSWORD'] %&gt;
&lt;%= &quot;socket: #{ENV['TDDIUM_DB_SOCKET']}&quot; if ENV['TDDIUM_DB_SOCKET'] %&gt;

test: &amp;test
adapter: &lt;%= ENV['TDDIUM_DB_ADAPTER'] %&gt;
database: &lt;%= ENV['TDDIUM_DB_NAME'] %&gt;
username: &lt;%= ENV['TDDIUM_DB_USER'] %&gt;
password: &lt;%= ENV['TDDIUM_DB_PASSWORD'] %&gt;
&lt;%= &quot;socket: #{ENV['TDDIUM_DB_SOCKET']}&quot; if ENV['TDDIUM_DB_SOCKET'] %&gt;</code></pre></noscript></div>


<p>There are two things to notice:</p>

<ul>
<li>I was only able to setup a 2nd database <em>connection</em>. Unfortunately the user
is not permitted to create arbitray databases. In our case this was enough to
get the code to load and the test suite to run.</li>
<li>The <em>socket</em> entry is necessary for us but is not mentioned in the
documentation. I extracted it from tddium&#8217;s database.yml.</li>
</ul>


<p>At this point our test suite would run with two failing specs. In one case we
actually executed code accessing the 2nd database. This was easy to fix in our
specific case by rewriting the spec. The other problem was completely unrelated
und not reproducable locally, some text saved to the database was not retrieved
identically. We disabled this spec for now.</p>

<h3>Conclusion</h3>

<p>So far I am happy with tddium, it is a very lightweight CI service and in the
general case, much easier to setup than a custom CI server. If we hadn&#8217;t have
this multi-database setup, tddium would have been up and running within
minutes. Pricing seems fair, although it lacks many features if compared to
<a href="http://jenkins-ci.org/">Jenkins CI</a>. I am looking forward to its evolution and
hope integration of our other apps will be smoother. :-)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Thoughts about Security and Agile Development]]></title>
    <link href="http://blog.nistu.de/2012/01/21/thoughts-about-security-and-agile-development/"/>
    <updated>2012-01-21T08:57:00+01:00</updated>
    <id>http://blog.nistu.de/2012/01/21/thoughts-about-security-and-agile-development</id>
    <content type="html"><![CDATA[<p>When attending a security training for developers last week, I was astonished
to find a security professional without programming background as our trainer.
He mostly talked in waterfallish terms, just as I had done a decade ago when
I was more interested in IT security than the physics I studied at university.
So I began wondering about the role of security in agile development.</p>

<h2>Security on the product level</h2>

<p>As agile developers, we optimize our code for flexibility, so we can change it
easily at any point in time. In this world, security at the product level is
nothing more than a feature to add whenever it makes sense. It becomes a matter
of continuous risk management, which feature prioritisation is anyways.</p>

<p>We might start a new product without any security whatsoever, because who needs
security when we have no clue how to solve our business logic problems in the
first place? However, with each feature our risk profile changes and we have
to reassess our situation. We better implement that login functionality before
we go into public beta, but maybe it&#8217;s still ok to run without any encryption.
Once we launch the product, we better protect our servers with TLS and encrypt
sensitive data in the database.</p>

<h2>Security on the code level</h2>

<p>The story changes, however, when it comes to our daily coding practice. I
consider security another code quality like good design or freedom from
defects. Just as we use practices like TDD or Continuous Integration, we should
use secure coding practices like input validation and output encoding. These
practices need to be embedded in our daily practice. We have to make ourselves
aware of the trust boundaries where we need to apply them.</p>

<p>What secure coding practices do you use? Let us know in the comments!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stand-up desk migration for little money, an IKEA hack]]></title>
    <link href="http://blog.nistu.de/2011/12/18/stand-up-desk-migration-for-little-money/"/>
    <updated>2011-12-18T13:17:00+01:00</updated>
    <id>http://blog.nistu.de/2011/12/18/stand-up-desk-migration-for-little-money</id>
    <content type="html"><![CDATA[<p>When I remodeled my flat 1 year ago, I chose to downsize my desk and put the PC
in an underused corner of the living room. The problem there was, that the
corner isn&#8217;t too wide, just 114cm. As most desks have a minimal width of 120cm,
I was happy to find IKEA&#8217;s Vika line with the Vika Amon tabletop just 1m wide.
Together with two Vika Lage legs and a Vika Annefors table leg with storage
space to hold my PC it cost me just 43 Eur. As the Annefors is quite wide, I
moved it a couple of cm to the side and gained some space to put small stuff
like my mobile and wallet.</p>

<p>Every now and then I came across someone mentioning their move to a stand-up
desk to counter the ill side-effects of sitting all day. One day I figured I&#8217;d
give it a try, borrowed my girl friend&#8217;s ironing board, put some books on top
and my laptop on top of those.</p>

<p>It didn&#8217;t take me much getting used to and I was quickly oscillating between
ironing board and couch with my laptop. Happy as I was, at some point my girl
friend needed her ironing board back, so I decided to upgrade to some kind of
IKEA hack solution.</p>

<p>After discussing several options with my girlfriend, we settled on buying a
second tabletop with some wooden legs to cut to proper length. While searching
for the items, we came across the Lack side table for just 5 Eur. We quickly
realised, that this was the perfect solution and bought two.</p>

<p>These side tables mix perfectly with my Vika table, but together they are 10cm
wider than the Amon tabletop. As described above, this wasn&#8217;t much of a problem
for me, as I had positioned the Annefors a little to the side. This gave me an
effective width of about 114cm to work with. So we cut the side table&#8217;s legs,
left 2 of them a little longer to compensate for the missing tabletop on the
side and there was my new stand-up desk. This is how it looks:</p>

<p><img src="http://blog.nistu.de/images/stand-up_desk.jpg" title="my stand-up desk" ></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An example project using cucumber-puppet]]></title>
    <link href="http://blog.nistu.de/2011/12/11/an-example-project-using-cucumber-puppet/"/>
    <updated>2011-12-11T18:57:00+01:00</updated>
    <id>http://blog.nistu.de/2011/12/11/an-example-project-using-cucumber-puppet</id>
    <content type="html"><![CDATA[<p>Patrick Debois, the godfather of DevOps, recently posted an article called
<a href="http://www.jedi.be/blog/2011/12/05/puppet-unit-testing-like-a-pro/">Puppet unit testing like a pro</a>.
This article spawned some discussion about
<a href="http://projects.puppetlabs.com/projects/cucumber-puppet">cucumber-puppet</a>
usage and how to get started. As I wanted to develop some ideas about this
anyways, I setup an
<a href="https://github.com/nistude/cucumber-puppet.example">example project</a> on
github. You can follow the commit history to see how the project evolved and
how I currently think cucumber-puppet should be used:</p>

<ul>
<li>On a global scale, use a catalog policy to ensure all your node catalogs
obey the same basic rules.</li>
<li>Use module specific features to specify behaviour in manifests, templates,
custom functions, etc.</li>
<li>Don&#8217;t repeat your manifests in your features, however. There&#8217;s no value in
it.</li>
</ul>


<p>This exercise verified my thoughts on some technical aspects of
cucumber-puppet. The goal of this project should not be to provide step
definitions for all kinds of scenarios, but instead provide basic helper
methods that empower people to implement the steps they actually need. I want
you to implement step definitions on your own, however, you shouldn&#8217;t have to
dig through the puppet source to do so.</p>

<p>This was a great learning experience for me.</p>

<p>What do you think, is this going in a sensible direction? Are there any
specific things you would like to see in the example project? Let me know in
the comments!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An Epiphany in Test-Driven Development]]></title>
    <link href="http://blog.nistu.de/2011/12/02/an-epiphany-in-test-driven-development/"/>
    <updated>2011-12-02T14:21:00+01:00</updated>
    <id>http://blog.nistu.de/2011/12/02/an-epiphany-in-test-driven-development</id>
    <content type="html"><![CDATA[<p>The other day I started programming a new feature which quickly turned into a
major rewrite of some legacy code. As I am pretty new to programming, it took
me several attempts writing tests and code to consolidate my ideas. The
process was quite laborious as I only ever detected design flaws when I saw
the code written in front of me. With each iteration I also adapted my unit
tests, renaming methods and objects etc.</p>

<p>While doing all this, I wondered about the merits of test-driven development.
Weren&#8217;t my tests supposed to drive the design of my code?  How come I only
ever figured out something was wrong, when I saw the final code and its usage
pattern? At that time I shrugged these thoughts off and attributed my problems
to poor design skills.</p>

<p>A couple of iterations and days later I had <em>again</em> read lots of stuff about
object oriented design, the
<a href="http://en.wikipedia.org/wiki/SOLID_&amp;#40;object-oriented_design&amp;#41;">SOLID principles</a>,
<a href="http://pragprog.com/articles/tell-dont-ask">Tell, don&#8217;t ask</a>,
Test-Driven Development, you name it. At that point I suddenly noticed a
correlation between some idiom in my tests and a breakage of the
<a href="http://en.wikipedia.org/wiki/Law_of_Demeter">Law of Demeter</a> in my code. I
didn&#8217;t really believe in a connection between the two, but still I tweeted it.</p>

<p>Luckily <a href="http://blog.davidchelimsky.net/">David Chelimsky</a>, the author of
<a href="https://github.com/rspec">RSpec</a>, noticed my tweet and inquired about my
code. When <a href="https://gist.github.com/1397967">discussing</a> the issue, he pointed
out that my Demeter violation was actually hinted at by some other
characteristic of my tests, I was using <em>and_return()</em> in combination with a
message expectation.  This conversation primed my interest in test smells and
off I went for more reading and watching conference presentations.</p>

<p>Slowly it dawned on me, what these people meant, when they say <em>&#8220;Listen to
the tests&#8221;</em>. Tests have a form of elegancy of their own. When they lose this
property, they are telling you about some broken design principle. Combining
a message expectation with a stub, like I did in my code, hints at a violation
of the <em>Law of Demeter</em> and the <em>Tell, don&#8217;t ask</em> principle. The problem with
elegancy, however, is that you have to learn to detect it.</p>

<h2>What have I learned from all this?</h2>

<p>It looks as if test elegancy is not just a matter of taste, but there seem to
be certain patterns to it:</p>

<ul>
<li>having a message expectation return a value hints at a violation of the <em>Law
of Demeter</em> and the <em>Tell, don&#8217;t ask</em> principle (<em>&#8220;mock actions, stub
queries&#8221;</em>)</li>
<li>the more collaborators an object has, the higher the chance it does too many
different things</li>
<li>test setup should be simple, too many test doubles hint at a method that
does too many different things</li>
<li>write tests with only minimal requirements

<ul>
<li>explicitly require necessary modules, the list should be short (don&#8217;t just
include all Rails, for example)</li>
<li>use strings as identifiers for test doubles, not constants, to keep
collaborators out of the list of modules to load</li>
</ul>
</li>
<li>when using external libraries

<ul>
<li>put an interface in front and test it with focussed, state-based
integration tests</li>
<li>now you can mock this interface in your unit tests, don&#8217;t mock the
external library itself</li>
</ul>
</li>
</ul>


<h2>Where do I go from here?</h2>

<p>For me, it&#8217;s time to go through
<a href="http://growing-object-oriented-software.com/">Growing Object-Oriented Software, guided by tests</a>
again. This time I won&#8217;t just read it superficially, however, but instead work
through the text and examples more intensely.</p>

<p>What do you think of this?
Does it make sense?
Do you have any test smells to share?
Let me know in the comments!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Testing Exported Resources with cucumber-puppet]]></title>
    <link href="http://blog.nistu.de/2011/09/04/testing-exported-resources-with-cucumber-puppet/"/>
    <updated>2011-09-04T13:42:00+02:00</updated>
    <id>http://blog.nistu.de/2011/09/04/testing-exported-resources-with-cucumber-puppet</id>
    <content type="html"><![CDATA[<p>When I began testing puppet catalogs with
<a href="http://projects.puppetlabs.com/projects/cucumber-puppet">cucumber-puppet</a>, I
soon stumbled upon the problem of
<a href="http://docs.puppetlabs.com/guides/exported_resources.html">exported resources</a>.
As cucumber-puppet does not deal with database connections out of the box, it
was at first glance impossible to test, e.g. if your nagios server was
configured properly from a service module. This weekend I finally took the time
to look at the way puppet uses exported resources and realized an easy way to
make them work with cucumber-puppet.</p>

<p>The main trick is to use an sqlite3 in-memory database so that cucumber-puppet
won&#8217;t have to connect to any external database or mess with the filesystem
too much. With the database in place, you can access exported resources through
their model class <em>Puppet::Rails::Resource</em>. I used <em>database_cleaner</em> to ensure
empty databases between scenarios. The only nuisance so far is, that puppet will
want to create several directories with <em>storeconfigs</em> activated, so we have to
manage a temporary directory.</p>

<p>Here is a sample usage of exported resources with cucumber-puppet:</p>

<div><script src='https://gist.github.com/1192764.js?file='></script>
<noscript><pre><code>Feature: storeconfigs

  Scenario: export resource
    Given a node of class &quot;exporting&quot;
    When I compile its catalog
    Then it should export a resource &quot;File[foo]&quot;

  Scenario: collect resource
    Given a node of class &quot;collecting&quot;
    And an exported resource &quot;File[bar]&quot;
    When I compile its catalog
    Then there should be a resource &quot;File[bar]&quot;</code></pre></noscript></div>


<p>I plan to add proper support for exported resources to cucumber-puppet in the
future, but this blog post should be enough to get you started.</p>

<p>Was this blog post helpful to you? Do you have any ideas on improving
cucumber-puppet? Let me know in the comments!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Pomodoro Timer for the Awesome Window Manager]]></title>
    <link href="http://blog.nistu.de/2011/08/19/a-pomodoro-timer-for-the-awesome-window-manager/"/>
    <updated>2011-08-19T16:31:00+02:00</updated>
    <id>http://blog.nistu.de/2011/08/19/a-pomodoro-timer-for-the-awesome-window-manager</id>
    <content type="html"><![CDATA[<p>I like the
<a href="http://blog.nistu.de/2011/06/23/first-experiences-with-the-pomodoro-technique/">pomodoro technique</a>
and usually use <a href="http://www.pomodroido.com/">pomodroido</a> on my android phone.
The app notifies me acoustically, which is nice at home but would probably get
on my colleagues nerves at work pretty soon. So I figured I needed to integrate
a timer with visual notification into my work setup.</p>

<p>Unfortunately there is no good pomodoro timer availabe for my environment of
choice (Linux and the <a href="http://awesome.naquadah.org/">awesome window manager</a>),
so I build one myself. The timer is based on a tea timer from
<a href="http://comments.gmane.org/gmane.comp.window-managers.awesome/7182">Jörg Thalheim</a>
that you put into your <em>rc.lua</em> and add it to the widget list.</p>

<div><script src='https://gist.github.com/1156933.js?file='></script>
<noscript><pre><code>-- pomodoro timer widget
pomodoro = {}
-- tweak these values in seconds to your liking
pomodoro.pause_duration = 300
pomodoro.work_duration = 1200

pomodoro.pause_title = &quot;Pause finished.&quot;
pomodoro.pause_text = &quot;Get back to work!&quot;
pomodoro.work_title = &quot;Pomodoro finished.&quot;
pomodoro.work_text = &quot;Time for a pause!&quot;
pomodoro.working = true
pomodoro.left = pomodoro.work_duration
pomodoro.widget = widget({ type = &quot;textbox&quot; })
pomodoro.timer = timer { timeout = 1 }

function pomodoro:settime(t)
  if t &gt;= 3600 then -- more than one hour!
    t = os.date(&quot;%X&quot;, t-3600)
  else
    t = os.date(&quot;%M:%S&quot;, t)
  end
  self.widget.text = string.format(&quot;Pomodoro: &lt;b&gt;%s&lt;/b&gt;&quot;, t)
end

function pomodoro:notify(title, text, duration, working)
  naughty.notify {
    bg = &quot;#ff0000&quot;,
    fg = &quot;#aaaaaa&quot;,
    title = title,
    text  = text,
    timeout = 10
  }

  pomodoro.left = duration
  pomodoro:settime(duration)
  pomodoro.working = working
end

pomodoro:settime(pomodoro.work_duration)

pomodoro.widget:buttons(
  awful.util.table.join(
    awful.button({ }, 1, function()
      pomodoro.last_time = os.time()
      pomodoro.timer:start()
    end),
    awful.button({ }, 2, function()
      pomodoro.timer:stop()
    end),
    awful.button({ }, 3, function()
      pomodoro.timer:stop()
      pomodoro.left = pomodoro.work_duration
      pomodoro:settime(pomodoro.work_duration)
    end)
))

pomodoro.timer:add_signal(&quot;timeout&quot;, function()
  local now = os.time()
  pomodoro.left = pomodoro.left - (now - pomodoro.last_time)
  pomodoro.last_time = now

  if pomodoro.left &gt; 0 then
    pomodoro:settime(pomodoro.left)
  else
    if pomodoro.working then
      pomodoro:notify(pomodoro.work_title, pomodoro.work_text,
        pomodoro.pause_duration, false)
    else
      pomodoro:notify(pomodoro.pause_title, pomodoro.pause_text,
        pomodoro.work_duration, true)
    end
    pomodoro.timer:stop()
  end
end)

</code></pre></noscript></div>


<p>By default it lets you work for 20 minutes and then gives you a 5 minute pause.
You can change these values in the code. The widget uses mouse button one to
start the timer, mouse button 2 to stop the timer and mouse button 3 to reset
the timer. It should be simple to add keyboard shortcuts as well.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Upgrading a Rails Application]]></title>
    <link href="http://blog.nistu.de/2011/08/19/upgrading-a-rails-application/"/>
    <updated>2011-08-19T08:16:00+02:00</updated>
    <id>http://blog.nistu.de/2011/08/19/upgrading-a-rails-application</id>
    <content type="html"><![CDATA[<p>Yesterday I started my first upgrade of a rails application from 2.3 to 3.0.
Technically, it is not even a rails application, as we mostly just use the
ActiveRecord layer. Nevertheless it was a huge learning experience so far. In
this post I want to concenrate on the obstacles I had to overcome and the
lessons I learned from them.</p>

<p>The fun began, when I updated our gems and ran our specs for the first time.
Well, actually I couldn&#8217;t because the RSpec rake tasks where missing. Google to
the rescue, it turned out we had to add our test gems, like rspec-rails, to the
bundler development group or rake wouldn&#8217;t load the corresponding targets.  I
had known about bundler groups, but never bothered to figure out, what they
actually where intended for or how they worked.</p>

<p>With RSpec targets visible, I could finally run the test suite. Unfortunately
it didn&#8217;t get very far before the first error struck. Some of the garb gem&#8217;s
symbols where unresolvable. It turned out garb had gone through some major
restructurings deprecating the way we use it. Not sure about those, I
downgraded it to the old version we where using before, but the error
prevailed. After some googling I finally found the reason, garb contains the
file <em>lib/support.rb</em> which defines the missing symbols. Another gem,
right_http_connection, also contains a file <em>lib/support.rb</em>. As it turned out,
right&#8217;s file was loaded while garb&#8217;s wasn&#8217;t. The proposed solution was to
downgrade to a previous version of right_http_connection that didn&#8217;t contain
that file. Alternatively, it was proposed to load garb before
right_http_connection. I played with my Gemfile, changing the order of entries
and not requiring some gems, but I couldn&#8217;t get it working. So, with both gems
downgraded, the test suite actually ran.</p>

<p>The lesson I learned in this case was, that a gem can be thought of as a
namespace. There is absolutely no reason to leave this namespace and create a
potential for collisions by providing files like <em>lib/support.rb</em>. Put your
files into a subdirectory and be happy. If however, you feel there&#8217;s no way
around providing a generic file like this, at least use a require statement with
absolute pathname to not accidentaly refer to another, already loaded file.</p>

<p>The issue wasn&#8217;t over though. The test suite was running, but it showed strange
<em>ArgumentError: wrong number of arguments (1 for 0)</em> on some of my own methods.
A friend suggested a backtrace and so I learned about <em>rspec -b</em>. This showed
the real problem deep in the garb gem. garb uses ActiveRecord&#8217;s <em>camelize()</em>
method that seemingly was replaced by something different. This time the
culprit turned out to be right_aws, which also defines a camelize method but
with a different method signature. With the downgrade of
right_http_connection, I had to downgrade right_aws as well. The older
right_aws version however, was not rails 3 compatible and overwrote
ActiveRecord&#8217;s <em>camelize()</em>. In this dilemma I decided to make
right_http_connection a vendor gem and fix it locally so as to not collide
with garb. I already had two other gems in <em>vendor/gems</em> as those needed
trivial fixes as well.</p>

<p>At this point my gems where in a decent state, so I could run the test suite
and fix a couple of minor issues, except for one. Again I got an argument
error, but this time on one of my own methods called <em>load()</em>. On a mocked null
object. How was that possible? Using <em>Object#method</em> it turned out my mock was
somehow linked to <em>ActiveSupport::Dependencies::Loadable</em> which contains a
<em>load()</em> method that was invoked. Explicitly stubbing <em>load()</em> on the mock
object solved the issue, but I have yet to understand what is going on here.</p>

<p>The final problem was a deprecation notice from RSpec, that I was setting
configuration values after defining examples. This was really strange, as all I
was doing in <em>spec_helper.rb</em> was loading files from <em>spec/support</em> and setting
configuration values afterwards. Just as it was supposed to work. I
experimented a lot and finally came to the conclusion, that my <em>support</em>
directory was fine and so I resorted to Google again. After a couple of pages I
finally found the issue. RSpec doesn&#8217;t like it, when you mix <em>require
&#8216;spec_helper&#8217;</em> with <em>require File.dirname(__FILE__) + &#8216;/../spec_helper&#8217;</em> as
this leads to <em>spec_helper.rb</em> being loaded twice. Apparently this is the way
<em>require</em> works. Once understood, I changed all <em>require</em> to be of the same
form and had all my specs pass without further warnings.</p>

<p>The upgrade isn&#8217;t finished yet, I have to write more specs for some older code
and actually test the running application. But for a first day the outcome
wasn&#8217;t bad. I learned a lot and hope to have removed all major obstacles.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Book Review: The Clean Coder]]></title>
    <link href="http://blog.nistu.de/2011/08/14/book-review-the-clean-coder/"/>
    <updated>2011-08-14T13:53:00+02:00</updated>
    <id>http://blog.nistu.de/2011/08/14/book-review-the-clean-coder</id>
    <content type="html"><![CDATA[<p>The other day I finished reading
<a href="http://www.informit.com/store/product.aspx?isbn=0132696177">The Clean Coder &#8211; A Code of Conduct for Professional Programmers</a>
from Robert <a href="http://twitter.com/unclebobmartin">unclebob</a> Martin.</p>

<p>The book was an easy read, as it mostly contains anecdotes from Robert Martin&#8217;s
life as a corporate programmer in the 70&#8217;s and 80&#8217;s, that are used to make a
point about certain behaviours Robert Martin deems professional. As a
consequence the book does not go into detail about actually becomming a
professional programmer and overcomming the obstacles that thwart us. Instead I
take the book as a collection of ideas the reader should think about and how to
apply them in their daily work.</p>

<p>I found those chapters most intriguing, where Robert Martin talks about values
and attitudes. He deems it unprofessional to compromise on quality or accepting
unreasonable time frames. Instead it is the duty of a professional programmer
to enter a discussion with the business, making sure it understands (the
programmer&#8217;s) reality. Professionals actively seek compromises that are in the
best interest of <em>all</em> parties involved.</p>

<p>Other chapters deal more with practices around coding and testing that don&#8217;t
provide many new ideas for people with a background in agile methodologies and
practices.</p>

<p>Overall I like this book and will probably come back to it every now and then.
If I consider the value it provides, though it is much too expensive and I am
happy I waited for a daily deal on it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Category List Generator for Jekyll]]></title>
    <link href="http://blog.nistu.de/2011/08/14/a-category-list-generator-for-jekyll/"/>
    <updated>2011-08-14T10:42:00+02:00</updated>
    <id>http://blog.nistu.de/2011/08/14/a-category-list-generator-for-jekyll</id>
    <content type="html"><![CDATA[<p>The other day I moved my blog from
<a href="http://www.steve.org.uk/Software/chronicle/">chronicle</a> to
<a href="http://octopress.org/">Octopress</a>.</p>

<p>I used chronicle for about two years and finally got sick with a couple of
things. Most importantly, I didn&#8217;t like the site&#8217;s design anymore so I needed
<em>something</em> new. Chronicle is a static blog compiler, which didn&#8217;t quite
fulfill my needs of building a complete site with a couple of static pages.
Finally it is written in Perl, while I prefer coding (and patching tools
written) in Ruby these days.</p>

<p>While the switch to Octopress was rather painless (sorry for fucking up the RSS
transition), I missed an overview of all my categories.</p>

<p>Octopress is based on <a href="http://jekyllrb.com/">Jekyll</a> which uses
<a href="http://www.liquidmarkup.org/">Liquid</a> for templating. It took some time to
get my head twisted around its parts, but I finally managed to write a plugin
that lists all my categories with counts in the sidebar.</p>

<div><script src='https://gist.github.com/1144723.js?file=category_list.rb'></script>
<noscript><pre><code># place this file in your plugins directory and add the tag to your sidebar
#$ cat source/_includes/custom/asides/categories.html 
#&lt;section&gt;
#  &lt;h1&gt;Categories&lt;/h1&gt;
#  &lt;ul id=&quot;categories&quot;&gt;
#    {% category_list %}
#  &lt;/ul&gt;
#&lt;/section&gt;

module Jekyll
  class CategoryListTag &lt; Liquid::Tag
    def render(context)
      html = &quot;&quot;
      categories = context.registers[:site].categories.keys
      categories.sort.each do |category|
        posts_in_category = context.registers[:site].categories[category].size
        html &lt;&lt; &quot;&lt;li class='category'&gt;&lt;a href='http://blog.nistu.de/categories/#{category}/'&gt;#{category} (#{posts_in_category})&lt;/a&gt;&lt;/li&gt;\n&quot;
      end
      html
    end
  end
end

Liquid::Template.register_tag('category_list', Jekyll::CategoryListTag)</code></pre></noscript></div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Feature Branches and Friends]]></title>
    <link href="http://blog.nistu.de/2011/08/04/feature-branches-and-friends/"/>
    <updated>2011-08-04T09:08:00+02:00</updated>
    <id>http://blog.nistu.de/2011/08/04/feature-branches-and-friends</id>
    <content type="html"><![CDATA[<p>Last month I started a new job as web applications engineer, meaning I am
finally getting into programming and web operations. I am learning a lot and
trying out new stuff virtually every day. This gives me the opportunity to
actually experience lots of situations I had formerly only read about.</p>

<p>One of the first questions that came up was branching. We use
<a href="http://git-scm.com/">git</a>
for version control of our source code, so branches are cheap and easy to use.
Having played with
<a href="http://martinfowler.com/articles/continuousIntegration.html">Continuous Integration</a>
before however, I am aware that
<a href="http://martinfowler.com/bliki/FeatureBranch.html">feature branches</a>
are disliked in the CI community. So when do branches make sense?</p>

<p>Let me start with a little background. We are a small distributed team, so
pair programming is currently unfeasible. In order to maintain high quality
standards (and as I am new to the team), my code is being reviewed before going
live.</p>

<p>In order to encapsulate my work, I use private feature branches. These only
exist on my local checkout and facilitate code reviews. While waiting for
review, they give me the opportunity to add a quick bug fix or start working on
a new feature in a separate branch. I see counter-arguments to feature branches
as mostly concerning themselves with bigger teams, where conflict happens more
easily.</p>

<p>When developing a new feature, I also use spike branches. These are private
branches to quickly test an idea without any quality concerns. Once I see a
sensible solution to my problem, I throw away the spike branch and reimplement
the solution
<a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">test-driven</a>
in my feature branch.</p>

<p>As we don&#8217;t have releases but deploy HEAD directly, we don&#8217;t use public release
branches.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[First Experiences With the Pomodoro Technique]]></title>
    <link href="http://blog.nistu.de/2011/06/23/first-experiences-with-the-pomodoro-technique/"/>
    <updated>2011-06-23T11:35:00+02:00</updated>
    <id>http://blog.nistu.de/2011/06/23/first-experiences-with-the-pomodoro-technique</id>
    <content type="html"><![CDATA[<p>A long time problem of mine is getting started with creative tasks and
<a href="http://en.wikipedia.org/wiki/Procrastination">keep working</a>
on them. When I set out to learn some Ruby on Rails, I chose to try
a technique I had heard about a couple of times called the
<a href="http://en.wikipedia.org/wiki/Pomodoro_Technique">Pomodoro Technique</a>.</p>

<p>The idea is basically to work short bursts of time, usually 25 minutes and then
rest for a couple of minutes, reading email, getting coffee&#8230;</p>

<p>I started using it at home for programming and learning some new tools. In the
beginning I chose shorter intervals and longer breaks, slowly advancing to
regular intervals. The Pomodoro Technique helped me focusing immensely. I
stayed with my task and only checked Twitter or email in the breaks. When I was
in <a href="http://en.wikipedia.org/wiki/Flow_(psychology)">flow</a> I just skipped
breaks and worked through two or three pomodoros.</p>

<p>When I applied the Pomodoro Technique at work, I soon found some limits of
applicability, though.</p>

<p>I work as a sysadmin, where I have to deal with all kinds of task lengths from
minutes to days. Working on small user requests and being interrupted all the
time by users or colleagues doesn&#8217;t play well with Pomodoro. It works great
however, when requests get slow and I am able to work on some bigger tasks.
There, Pomodoro again helps me to focus on the task and keep distractions out
of my mind.</p>

<p>A second scenario that didn&#8217;t play well with Pomodoro was Pairing. Working
with a colleague on some bigger task, being interrupted by the Pomodoro timer
felt counterproductive. There was enough energy between the two of us, that
staying focused was no problem.</p>

<p>From my (limited) experiences I believe Pomodoro to be an effective technique
for improving focus if working alone on a bigger task. It helps me get
started and keep going. If working in different conditions, I still like to
schedule regular breaks to limit exhaustion.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Writing Cucumber Features for Configuration Management]]></title>
    <link href="http://blog.nistu.de/2011/06/09/writing-cucumber-features-for-configuration-management/"/>
    <updated>2011-06-09T11:08:00+02:00</updated>
    <id>http://blog.nistu.de/2011/06/09/writing-cucumber-features-for-configuration-management</id>
    <content type="html"><![CDATA[<p>I am test-infected, so when I played around with
<a href="http://vagrantup.com/">Vagrant</a> and
<a href="http://wiki.opscode.com/display/chef/Home">Chef</a> the other day, I was
wondering how a test-driven approach to writing cookbooks might look like.</p>

<p>I started with plain <a href="http://cukes.info/">Cucumber</a> and wrote a scenario like
this one:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Scenario:</span><span class="nf"> Uninstall ntpd on VM</span>
</span><span class='line'><span class="k">  Given </span><span class="nf">recipe &quot;</span><span class="s">ntp</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">  </span><span class="k">When </span><span class="nf">I provision a new virtual machine</span>
</span><span class='line'><span class="nf">  </span><span class="k">Then </span><span class="nf">package &quot;</span><span class="s">ntp</span><span class="nf">&quot; should be purged</span>
</span></code></pre></td></tr></table></div></figure>


<p>Having played with Cucumber and
<a href="http://www.puppetlabs.com/puppet/introduction/">Puppet</a> for a long time, I
realised, that I was entering the old road of 1-to-1 map between test and
implementation. My Chef recipe looked liked this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">package</span> <span class="s2">&quot;ntp&quot;</span> <span class="k">do</span>
</span><span class='line'>  <span class="n">action</span> <span class="ss">:purge</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>In this situation I remembered a blog post from
<a href="http://antonymarcano.com/blog/2011/03/goals-tasks-action/">Antony Marcano</a>
where he argues for a Goal -> Task -> Action approach to writing scenarios.
This way it should be simpler to find an adequate level of abstraction by
hiding concrete actions in step implementations.</p>

<p>In my case purging the package is even below the action level. I want to
specify that the ntp daemon should not be running and leave it to the
implementation, i.e. the chef recipe, how to get there. This is an improved
scenario:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Scenario:</span><span class="nf"> don&#39;t run ntpd on a virtual machine</span>
</span><span class='line'><span class="k">  Given </span><span class="nf">recipe &quot;</span><span class="s">ntp</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">  </span><span class="k">When </span><span class="nf">I provision a new virtual machine</span>
</span><span class='line'><span class="nf">  </span><span class="k">Then </span><span class="nf">&quot;</span><span class="s">ntpd</span><span class="nf">&quot; should not be running</span>
</span></code></pre></td></tr></table></div></figure>


<p>This is much better, as it decouples the Cucumber feature from the
configuration management details. If I ever need the ntp package installed for
whatever reason, but ensure the service being disabled, the scenario won&#8217;t
break as it would have in the first case. I could probably even switch from
Chef to Puppet with minimal efforts.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Support for Parameterised Classes in Cucumber-puppet 0.2.0]]></title>
    <link href="http://blog.nistu.de/2011/03/06/support-for-parameterised-classes-in-cucumber-puppet-0-2-0/"/>
    <updated>2011-03-06T11:24:00+01:00</updated>
    <id>http://blog.nistu.de/2011/03/06/support-for-parameterised-classes-in-cucumber-puppet-0-2-0</id>
    <content type="html"><![CDATA[<p>I just released version <a href="http://rubygems.org/gems/cucumber-puppet">0.2.0</a> of
<a href="http://projects.puppetlabs.com/projects/cucumber-puppet/wiki">cucumber-puppet</a>.
This version adds support for parameterised classes (requires puppet version
2.6.5 or newer).</p>

<p>Let&#8217;s assume we have a class with two parameters:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="n">dns</span> <span class="p">(</span><span class="vg">$nameserver1</span><span class="p">,</span> <span class="vg">$nameserver2</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="o">.</span><span class="n">.</span><span class="o">.</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>cucumber-puppet provides a sample <em>Given</em> step to specify the behaviour of this
class in <em>steps/puppet.rb</em> (<em>NOT</em> updated automatically):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Given </span><span class="nf">a node of class &quot;</span><span class="s">dns</span><span class="nf">&quot; with parameters:</span>
</span><span class='line'><span class="k">  |</span><span class="s"> name</span><span class="k">        |</span><span class="s"> value</span><span class="k">      |</span><span class="nf"></span>
</span><span class='line'><span class="k">  |</span><span class="s"> nameserver1</span><span class="k"> |</span><span class="s"> ns.foo.com</span><span class="k"> |</span><span class="nf"></span>
</span><span class='line'><span class="k">  |</span><span class="s"> nameserver2</span><span class="k"> |</span><span class="s"> ns.bar.com</span><span class="k"> |</span><span class="nf"></span>
</span><span class='line'><span class="k">When </span><span class="nf">I compile the catalog</span>
</span><span class='line'><span class="nf">...</span>
</span></code></pre></td></tr></table></div></figure>


<p>This will create a node with just the <em>dns</em> class and both parameters set
according to the table.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Ignite Talk on Cucumber-puppet]]></title>
    <link href="http://blog.nistu.de/2010/10/25/ignite-talk-on-cucumber-puppet/"/>
    <updated>2010-10-25T11:27:00+02:00</updated>
    <id>http://blog.nistu.de/2010/10/25/ignite-talk-on-cucumber-puppet</id>
    <content type="html"><![CDATA[<p>I gave an Ignite talk on
<a href="http://projects.puppetlabs.com/projects/cucumber-puppet/">cucumber-puppet</a> at
this years <a href="http://www.devopsdays.org/">DevOpsDays</a> Europe 2010 in Hamburg.
The <a href="http://www.slideshare.net/nistude/cucumberpuppet">slides</a> are available on
Slideshare.</p>

<p>For those not following <a href="http://twitter.com/nistude">me</a> on Twitter, I have
since <a href="http://projects.puppetlabs.com/projects/cucumber-puppet/news">released</a>
version 0.1.0 of cucumber-puppet, which supports all features mentioned in my
presentation.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Kanban in Operations - 10 Months Later]]></title>
    <link href="http://blog.nistu.de/2010/09/18/kanban-in-operations---10-months-later/"/>
    <updated>2010-09-18T11:33:00+02:00</updated>
    <id>http://blog.nistu.de/2010/09/18/kanban-in-operations&#8212;10-months-later</id>
    <content type="html"><![CDATA[<p>10 months ago we
<a href="http://blog.nistu.de/2009/11/15/kanban-in-operations---the-idea">introduced</a> Kanban
at work. This is a short status update on our journey.</p>

<p>The most important change we see, is a vastly improved focus on finishing work.
Unfortunately we don&#8217;t have numbers to back this up, but everyone on my team
agrees that the kanban board with its WIP limits and visualization of work
helps immensely. There is a downside however, some people see this as
additional pressure. Work is no longer hidden, but always clearly visible on
the board, so people <em>see</em> what needs to be done next and cannot just slack
as easily as in the old days.</p>

<p>Our board changed almost every month, as we optimized the design in our monthly
retro meetings. I spare you the details, but we still use a pretty basic design
with columns <em>Backlog</em> (MMF or Milestone), <em>Planning</em> (MMF -> Tasks), <em>WIP</em> and
<em>Done</em>.</p>

<p>Being a sysadmin team, we often have people come to us, asking for
implementation of some small project that still takes time to do properly. In
the old days, we would just take the project and try to implement it on the
side. These days, we have a prioritized project backlog and ask people to join
in a discussion on our kanban board about where their request fits in.
Interestingly, most people don&#8217;t take this opportunity! I consider this a good
thing, as it helps us focus on important projects instead of nice-to-have ones.
When people do come to our board, they see what else we have in our pipeline
and usually agree to some sensible prioritization.</p>

<p>Historically we never did much project planning, so when we introduced Kanban,
we started with ad-hoc planning. We ran into several issues with this approach:</p>

<ul>
<li>At our company, people can work from home some time of the week. With only a
physical kanban board, they had a hard time figuring out what to do next.</li>
<li>We had no place to store project artifacts.</li>
<li>There was not enough information on our post-its for people to actually
having an idea what the card was about.</li>
<li>Management began asking questions about project performance.</li>
</ul>


<p>Most of these problems where addressed by amending our physical kanban board
with an issue tracker called <a href="http://www.redmine.org/">redmine</a>. This allowed
us to store much more information with an issue and finally led to a point
where we even were able to estimate t-shirt sizes for our tasks and delight
management with some kind of sensible reporting (keeping it as minimal as
possible). We are still looking for the sweetspot of electronic issue tracking,
however. How much information can and should we collect in the issue upfront
and how much information should be pulled by the worker on demand?</p>

<p>Besides redmine we have a legacy ticketing system for user requests. Infected
with the pull virus, we applied some minor changes that allowed a quasi-pull
workflow when dealing with requests. Before, each new ticket was assigned to
one person and then pushed elsewhere if necessary. Now we can easily see which
tickets are not being worked on and pull them in case of a bottleneck.</p>

<p>A side effect of all this was my introduction to systems thinking. I only
started exploring this field recently, so there are not many results yet. It
was reassuring to see, though, that our failure demand is usually around 10%.</p>

<p>Despite all the positive effects, we are still struggling with commitment to
the Kanban way of working. Practice still heavily depends on a champion being
around.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Thoughts on Testing Puppet Manifests]]></title>
    <link href="http://blog.nistu.de/2010/08/23/thoughts-on-testing-puppet-manifests/"/>
    <updated>2010-08-23T11:29:00+02:00</updated>
    <id>http://blog.nistu.de/2010/08/23/thoughts-on-testing-puppet-manifests</id>
    <content type="html"><![CDATA[<p>When I started writing Puppet manifests, I soon figured out, that there are
many possibilities for mistakes, which I usually found when test-applying
(<code>--noop</code>) changes to a machine. This manual process was quite cumbersome, only
to find a missing comma. So I wondered how I could test manifests more easily
and on my development machine.</p>

<p>After playing with existing tools like Ohad Levy&#8217;s
<a href="http://github.com/ohadlevy/manitest">Manitest</a>, I stumbled upon
<a href="http://www.cukes.info/">Cucumber</a> and wrote some
<a href="http://github.com/nistude/cucumber-puppet">glue code</a>, so that I could write
cucumber features for my manifests.</p>

<p>In my first round of testing, I wrote features like this one:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Feature:</span><span class="nf"> Setup Amanda client</span>
</span><span class='line'><span class="nf">  In order to backup my servers</span>
</span><span class='line'><span class="nf">  As an admin</span>
</span><span class='line'><span class="nf">  I want my servers to be setup as amanda clients</span>
</span><span class='line'>
</span><span class='line'><span class="nf">  </span><span class="k">Scenario:</span><span class="nf"> Setup remote access</span>
</span><span class='line'><span class="k">    Given </span><span class="nf">a node of class &quot;</span><span class="s">amanda::client</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">When </span><span class="nf">I compile the catalog</span>
</span><span class='line'><span class="nf">    </span><span class="k">Then </span><span class="nf">there should be a resource &quot;</span><span class="s">File[/operator/.amandahosts]</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the file should contain &quot;</span><span class="s">amanda.no.domain operator</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the file should have a &quot;</span><span class="s">group</span><span class="nf">&quot; of &quot;</span><span class="s">operator</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the file should have a &quot;</span><span class="s">mode</span><span class="nf">&quot; of &quot;</span><span class="s">0400</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the file should have an &quot;</span><span class="s">owner</span><span class="nf">&quot; of &quot;</span><span class="s">operator</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the file should require &quot;</span><span class="s">Package[amanda-client]</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">the state should be &quot;</span><span class="s">present</span><span class="nf">&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="nf">  ...</span>
</span></code></pre></td></tr></table></div></figure>


<p>If you compare this to the puppet code being tested</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">file</span> <span class="p">{</span> <span class="s2">&quot;/operator/.amandahosts&quot;</span><span class="p">:</span>
</span><span class='line'>  <span class="n">content</span> <span class="o">=&gt;</span> <span class="s2">&quot;amanda.no.domain operator&quot;</span><span class="p">,</span>
</span><span class='line'>  <span class="k">ensure</span> <span class="o">=&gt;</span> <span class="n">present</span><span class="p">,</span>
</span><span class='line'>  <span class="n">group</span> <span class="o">=&gt;</span> <span class="s2">&quot;operator&quot;</span><span class="p">,</span>
</span><span class='line'>  <span class="n">mode</span> <span class="o">=&gt;</span> <span class="mo">0400</span><span class="p">,</span>
</span><span class='line'>  <span class="n">owner</span> <span class="o">=&gt;</span> <span class="s2">&quot;operator&quot;</span><span class="p">,</span>
</span><span class='line'>  <span class="nb">require</span> <span class="o">=&gt;</span> <span class="no">Package</span><span class="o">[</span><span class="s2">&quot;amanda-client&quot;</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>you will notice, that the scenario is basically a reimplementation of the
puppet code. This doesn&#8217;t make much sense.</p>

<p>To start over, I collected my actual problems when developing manifests in
order to think of a more sensible approach to writing Cucumber features.</p>

<ol>
<li><p>catalog does not compile</p>

<ul>
<li>syntax errors</li>
<li>missing template files (locally or in repository)</li>
</ul>
</li>
<li><p>catalog compiles, but cannot be applied</p>

<ul>
<li>unreachable or non-existent resources are referenced (<code>before</code>,
<code>notify</code>, &#8230;)</li>
<li>missing file sources in repository</li>
</ul>
</li>
<li><p>catalog applies but is faulty</p>

<ul>
<li>faulty files due to empty manifest variables or wrong values</li>
<li>missing dependencies between resources (wrong order, missing service
restarts after config file changes, &#8230;)</li>
<li>files are installed without ensuring directory creation beforehand</li>
</ul>
</li>
</ol>


<p>In order to deal with these issues, I first expanded
<a href="http://github.com/nistude/cucumber-puppet">cucumber-puppet</a> to permit defining
a host by its YAML node file. This way local (on my development machine)
catalog compilation can be verified easily. For remote catalog compilation, I
added a step ensuring files and templates are checked into git. Finally I
added a step to ensure resolvability of all referenced resources. Looks like
issues 1 and 2 are solved. :-)</p>

<p>Catalogs can now be verified like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Feature:</span><span class="nf"> General catalog policy</span>
</span><span class='line'><span class="nf">  In order to ensure applicability of a host&#39;s catalog</span>
</span><span class='line'><span class="nf">  As a manifest developer</span>
</span><span class='line'><span class="nf">  I want all catalogs to obey some general rules</span>
</span><span class='line'>
</span><span class='line'><span class="nf">  </span><span class="k">Scenario:</span><span class="nf"> Compile and verify catalog for host test</span>
</span><span class='line'><span class="k">    Given </span><span class="nf">a node specified by &quot;</span><span class="s">features/yaml/test.no.domain.yaml</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">When </span><span class="nf">I compile its catalog</span>
</span><span class='line'><span class="nf">    </span><span class="k">Then </span><span class="nf">compilation should succeed</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">all resource dependencies should resolve</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">all file sources should exist in git repository</span>
</span><span class='line'><span class="nf">    </span><span class="k">And </span><span class="nf">all file templates should exist in git repository</span>
</span></code></pre></td></tr></table></div></figure>


<p>My new way of writing cucumber features thus is to move away from single
resources and instead concentrate on the <a href="http://behaviour-driven.org/">BDD</a>
principle of <em>Outside-In</em> specification. Above feature specifies a generic
policy regarding catalog compilation. This specification could be augmented
with rules like <em>each file should have group, mode and owner set explicitly</em> or
<em>each file written to directory &#8220;/etc/apache2&#8221; should require
&#8220;Package[apache2]&#8221;</em>.</p>

<p>This new approach does not solve all issues mentioned above, there is still
more than enough room for manually verifying catalogs on real target hosts, but
it is in my opinion much more useful than my first attempt.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Cucumber-puppet 0.0.3 Released]]></title>
    <link href="http://blog.nistu.de/2010/04/17/cucumber-puppet-0-0-3-released/"/>
    <updated>2010-04-17T11:17:00+02:00</updated>
    <id>http://blog.nistu.de/2010/04/17/cucumber-puppet-0-0-3-released</id>
    <content type="html"><![CDATA[<p>I am happy to announce the release of cucumber-puppet 0.0.3. cucumber-puppet
is the glue between <a href="http://cukes.info/">cucumber</a> and
<a href="http://www.puppetlabs.com/puppet/">Puppet</a>, allowing you to write
<a href="http://en.wikipedia.org/wiki/Behaviour_driven_development">behavioural</a>
tests, or features as cucumber calls it, for your Puppet manifest. You can
find introductiary material to cucumber
<a href="http://wiki.github.com/aslakhellesoy/cucumber/tutorials-and-related-blog-posts">here</a>.</p>

<p>cucumber-puppet is currently in alpha-testing.</p>

<h3>Installation</h3>

<p>cucumber-puppet comes packaged as a gem</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>gem install cucumber-puppet
</span></code></pre></td></tr></table></div></figure>


<p>or can be cloned from <a href="http://github.com/">github</a></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git clone http://github.com/nistude/cucumber-puppet.git
</span></code></pre></td></tr></table></div></figure>


<h3>Usage</h3>

<h4>Initial setup</h4>

<p>Before writing your first feature, you have to setup the infrastructure in
your Puppet directory.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>puppet
</span><span class='line'><span class="nv">$ </span>cucumber-puppet-gen world
</span></code></pre></td></tr></table></div></figure>


<p>This installs some example step definitions for cucumber to <em>./features/steps/</em>
and ensures the cucumber-puppet glue code is available. You can adapt
cucumber-puppet to your needs in <em>./features/support/hooks.rb</em>.</p>

<h4>Writing features</h4>

<p>cucumber-puppet assumes you have your Puppet manifest organized in modules and
does the same with your feature files.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>cucumber-puppet-gen feature foo bar
</span></code></pre></td></tr></table></div></figure>


<p>generates <em>./features/modules/foo/bar.feature</em> from the standard template. Use
this file to write your feature and add missing step definitions to files in
<em>./features/steps/</em>.</p>

<p>A feature might look like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='cucumber'><span class='line'><span class="k">Feature:</span><span class="nf"> cucumber-puppet</span>
</span><span class='line'><span class="nf">  In order to run my puppet manifest&#39;s test suite</span>
</span><span class='line'><span class="nf">  As an admin</span>
</span><span class='line'><span class="nf">  I want the cucumber-puppet gem installed</span>
</span><span class='line'>
</span><span class='line'><span class="nf">  </span><span class="k">Scenario:</span><span class="nf"> Install cucumber-puppet</span>
</span><span class='line'><span class="k">    Given </span><span class="nf">a node of class &quot;</span><span class="s">cucumber-puppet</span><span class="nf">&quot;</span>
</span><span class='line'><span class="nf">    </span><span class="k">When </span><span class="nf">I compile the catalog</span>
</span><span class='line'><span class="nf">    </span><span class="k">Then </span><span class="nf">gem &quot;</span><span class="s">cucumber-puppet</span><span class="nf">&quot; should be &quot;</span><span class="s">installed</span><span class="nf">&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<h4>Running features</h4>

<p>To run above feature, execute</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>cucumber-puppet features/modules/foo/bar.feature
</span></code></pre></td></tr></table></div></figure>


<p>and see it complain about missing step definitions. Add these to <em>.rb</em> files in
<em>./features/steps/</em>.</p>

<p>If you have any questions or feedback, feel free to leave a comment or email me
at <em>cucumber-puppet</em> <em>at</em> <em>erisiandiscord.de</em>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Pragmatic Scalability for Puppet -- How a Cronjob Saved My Puppetmaster]]></title>
    <link href="http://blog.nistu.de/2010/04/14/pragmatic-scalability-for-puppet----how-a-cronjob-saved-my-puppetmaster/"/>
    <updated>2010-04-14T11:38:00+02:00</updated>
    <id>http://blog.nistu.de/2010/04/14/pragmatic-scalability-for-puppet&#8212;-how-a-cronjob-saved-my-puppetmaster</id>
    <content type="html"><![CDATA[<p>We are currently in the process of migrating to a different Linux distribution
at work and with that introduce
<a href="http://www.puppetlabs.com/puppet/introduction/">Puppet</a>
to manage these machines (about 130 desktop PCs and 20 Servers).</p>

<p>Recently we started noticing failed puppetd runs from time to time. Cause of
the problem was, that our puppet clients turned out to be running in batches,
so every 30 minutes our puppetmaster suffered a huge load spike.</p>

<p>Having read R.I.Pienaar&#8217;s
<a href="http://www.devco.net/archives/2010/03/17/scheduling_puppet_with_mcollective.php">Scheduling Puppet with MCollective</a>
blog post, I figured I needed a similar solution. Installing
<a href="http://code.google.com/p/mcollective/">MCollective</a>
crossed my mind for a moment, but it seemed overkill. Instead I came up with
the following simple, pragmatic solution.</p>

<p>I restart each puppetd process at a host specific time, thus spreading them
reasonably well across puppet&#8217;s run interval.</p>

<p>The crucial component is my external node classifier, which I use to calculate
the host specific time. It&#8217;s a ruby script that knows about all our machines
and is easily able to compute a nodes rank, in our case based on the hostname,
modulo 30, puppet&#8217;s run interval. This rank is used to terminate a cronjob
restarting puppetd daily.</p>

<p>Lets look at an example. Say you have hosts a.foo.com, b.foo.com and c.foo.com,
then their rank would be 0, 1 and 2 respectively. On host a.foo.com, the
cronjob would run at 11:00, on b.foo.com at 11:01 and on c.foo.com at 11:02. (I
chose the window between 11:00 and 11:30, as I figured most people would be at
work at that time and thus their desktop PCs switched on.)</p>

<p>As you can see, the result is far from perfect, but still quite impressive:</p>

<p><img src="http://blog.nistu.de/images/puppetmaster_load.png" title="puppetmaster load graph" ></p>

<p>I know, load graphs are mostly useless, but it&#8217;s all the data I have ATM. ;)</p>

<p>Where 4 cores couldn&#8217;t handle load spikes, 2 cores are evenly used and I might
even get by with just 1.</p>

<p>I would very much like to see some kind of scheduling support in the
puppetmaster, organizing clients for maximal spread.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Kiosk Setup With Nxclient]]></title>
    <link href="http://blog.nistu.de/2010/01/24/a-kiosk-setup-with-nxclient/"/>
    <updated>2010-01-24T11:34:00+01:00</updated>
    <id>http://blog.nistu.de/2010/01/24/a-kiosk-setup-with-nxclient</id>
    <content type="html"><![CDATA[<p><a href="http://www.nomachine.com/">NoMachine&#8217;s</a>
<a href="http://en.wikipedia.org/wiki/NX_technology">NX</a> client is a great tool for
running desktop applications on a remote machine. You can either attach to the
remote machine&#8217;s desktop session (<em>session shadowing</em>) or start an independent
NX session solely for remote usage.</p>

<p>As session shadowing unlocks a potentially running screensaver, it is only
suited for accessing PCs in locked offices or at home. In an open office
environment, only an independen NX session makes sense. This, however, has a
drawback as well. Many desktop applications like Firefox or OpenOffice do not
easily permit running multiple instances concurrently. Thus you have to close
these programs before starting them in the other session (local desktop session
or remote NX session). This gets quite annoying.</p>

<p>For people working in an open office environment, a combined solution is
needed, that uses the same session locally and remotely, while not opening it
to passersby. This means all programs are running inside an NX session and the
user starts nxclient even when locally logging in to the machine. The rest of
this blog post will deal with the peculiarities of this local setup.</p>

<p>Nxclient has two technical drawbacks preventing it from running stand-alone:</p>

<ol>
<li>At least in my setup (Ubuntu 9.10 with GDM), it doesn&#8217;t grab keyboard focus.</li>
<li>Nxclient forks nxssh for the actual session handling and ends itself, thus
closing the local desktop session.</li>
</ol>


<p>To work around the first issue, a window manager is needed. This should be as
minimal and lightweight as possible so as not to interfere with whatever is
running inside the NX session (think keyboard shortcuts or mouse gestures). I
chose fvwm2 with a minimal configuration, stripping it of virtually all its
functionality. I even chose to not lock the screen from fvwm2 but instead lock
the session from within NX. This way NX users and regular users, with only a
local desktop session, share the same screensaver configuration.</p>

<p>A natural workaround for the second issue would be to start fvwm2 after
nxclient and keeping it in the foreground. This way, a user would have to
explicitly exit fvwm2 to logout. To make the window manager as transparent as
possible, it would be much nicer, to terminate the session once nxssh is
terminated. This can be accomplished with fvwm2 running in the background and a
loop, waiting for nxssh to finish.</p>

<p>Putting it all together, this is how to setup an nxclient-only session with
GDM on Ubuntu 9.10:</p>

<ul>
<li>install fvwm2</li>
<li>install <a href="http://www.nomachine.com/select-package.php?os=linux&amp;id=1">nxclient</a></li>
<li>install <a href="http://blog.nistu.de/assets/nxclient_kiosk.tar.gz">support files</a></li>
</ul>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>sudo install -o root -g root -m 644 nxclient.desktop /usr/share/xsessions
</span><span class='line'><span class="nv">$ </span>sudo install -o root -g root -m 755 nxsession /usr/local/bin
</span><span class='line'><span class="nv">$ </span>sudo install -o root -g root -m 644 nx.fvwm2 /etc
</span></code></pre></td></tr></table></div></figure>


<ul>
<li>login with GDM, choosing <em>NX Client</em> as session (you might have to restart
gdm first)</li>
<li>configure nxclient for fullscreen mode</li>
<li>use <em>CTRL-ALT-T</em> to disconnect from the NX session, terminating nxclient</li>
</ul>

]]></content>
  </entry>
  
</feed>

