Wednesday, February 27, 2013

Using a spare router to extend wifi coverage (and an upstart init script to control routing)

Or, "How i learned to route eth0 through wlan0 and script it".

First off, a disclaimer

This is not about using my spare router as a signal amplifier. I didn't find a way to do that with my Sweex LW150. Also note that, as the title unfortunately omits, this story also needs a spare laptop. Or something else that has wifi and an ethernet port, and can run iptables.

The house is not too big, the signal is too weak.

The use case: Wireless router is at one end of the house, near the stables. Large parts of the house, including the salon and the servants' quarters, are out of reach. And halfway, in the music room, there's this small laptop that's always on when i'm at home, and only runs Spotify and Guayadeque (on Lubuntu 12.10).

Iptables, and scripting it

So i hooked up the spare router to the laptop (which by now runs a dhcp server). To make traffic pass from the spare router (eth0) to the internet connection (wlan0), there's some iptables stuff to do. To make sure the routing restarts when the laptop has gone down, i created an upstart configuration. This also enables me to turn routing off and on quickly. Here's how:
  1. Create /etc/init/route-eth0-wlan0.conf:
    # route-eth0-wlan0 - Route traffic from eth0 to internet on wlan0
    # We have internet on our machine's wlan0 interface, an unrelated wireless
    # router in eth0, and want to route that router's traffic.
    # The router on eth0 will then be an extra access point for our internet,
    # extending its range.

    description "Route eth0 through wlan0"

    # Make sure we start before an interface receives traffic
    start on (starting network-interface
              or starting network-manager
              or starting networking)

    stop on runlevel [!023456]

    console output

    pre-start script
        # Set up IP FORWARDing and Masquerading (NAT)
        iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE
        iptables --append FORWARD --in-interface eth0 -j ACCEPT
        # enable IP forwarding
        echo 1 > /proc/sys/net/ipv4/ip_forward
    end script

    post-stop script
        # disable IP forwarding
        echo 0 > /proc/sys/net/ipv4/ip_forward
        # delete old configuration, if any
        # Flush all the rules in filter and nat tables
        iptables --flush               
        iptables --table nat --flush
        # delete all chains that are not in default filter and nat table, if any
        iptables --delete-chain    
        iptables --table nat --delete-chain
    end script
  2. Symlink /etc/init.d/route-eth0-wlan0 -> /lib/init/upstart-job
Now i can start and stop the routing by running sudo service route-eth0-wlan0 (start|stop).

Update 2013-03-27: The motto "because we can" applies to all of the above. After, i applied "use the right tool for the job" and bought a wireless repeater from Amazon (Anker Kompakt, 26 Euros, works great).

Monday, February 11, 2013

My Barcelona Testing Sprint

[edit 14-2: see bottom of article for information that came after the sprint]

The Barcelona Sprint was about Plone's testing. Most of Plone's code is covered by tests, and these tests are automatically run by a Jenkins server, so we know when stuff starts not working anymore.

One focus of the sprint was improving the Jenkins setup, so a commit or pull request that breaks the build triggers an email, irc notification or otherwise to the author. This code now goes by the name of mr.roboto [1].

Another focus area was to get more Robot Framework tests into Plone. RF fires up a real browser, where Javascript also works. This way we can test things like overlays and folder re-ordering.

To show everyone how to use this goodness, we wrote documentation and modified the template for creating new Plone products so the boilerplate is already there.

To go more into detail, the sprint went like this for me:

I spent the first day familiarizing myself with Robot Framework tests, using these links: [2-9]. I set up a basic add-on package that tested if an overlay popped up.

The second day i paired up with Carles Bruguera of UPC University (, and we started working on Products.CMFPlone. The great thing about RF is that you can write stuff like:
Scenario: Login overlay:
 Given I am not logged in
  When I click the login button
  Then I should get an overlay with login form

Statements like "I am not logged in" are called keywords, you define these somewhere else in your test. It makes for easy reading, you could (theoretically) even show it to your customer and ask "Is this what it is supposed to do?"


 The third day we continued this work. All the while, Laura Perez Mayos (of Iskra, and Víctor Fernández de Alba (also UPC) were working on the other tests in CMFPlone. By the end of the day we were done [10], and there was beer. Have a look and see what it looks like [11].

Some more information on the sprint will probably seep through coming week. The project page is [12], the twitter hashtag #bcnsprint. The last link you should definitely see is [13].

[6] Reference documentation:
[10] For a given value of done. As the testrunner will try out different browsers, we might find some failing tests. So far we only tried Firefox and a little of Chrome.

information that came after the sprint: