How to make access to test machines easier using shell functions

On our daily work, we have to deal with a quite large number of test systems (usually spread across the world), and perform some operations on these test systems. Even though we automate the testcase execution, it’s useful to have ssh/console access to a machine when you need it nevertheless [1].

After some time having to look on wiki pages the access data for my systems (hostname, passwords, users), I figured I could speed up my work by defining shell aliases to the machines I commonly access at work. Reading a bit more about the subject, it became clear to me that the use of shell functions would be a better solution, since you can do way more stuff with them.

The approach I chose was to write a shell script kept under my source code folder, and then source it on your ~/.bashrc file as follows:

source /path/to/code/

So that when you start a new shell instance, the functions defined on this script get loaded.

Another aspect of software testing is that our test systems need to be constantly re-installed over and over, therefore generating a new ssh fingerprint every time you do the re-install (and making your ssh to complain loudly when you try to access those machines). In order to work around this, you can call ssh with appropriate options so that it doesn’t cache the fingerprints.

SSH_TEST='/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'

StrictHostKeyChecking=no means that ssh won’t ask you if you want to accept the new fingerprint, it will just accept it. Also, it will sent the fingerprint it just got from the machine re-installed and send it to the vast fields of /dev/null land 🙂 so you won’t get complaints from ssh every time your test system gets re-installed [2].

This way, we can create a base test_system() function that will be used by the actual machine access functions, like:

test_system() {
local host=$1
local profile=$2
local user='user'
local pass='password'
echo "Client partition information"
echo "HMC LPAR profile: $profile"
echo "Hostname: $host"
echo "User: $user"
echo "Password: .pasroot"
echo "ssh $user@$host"
$SSH_TEST $user@$host

Notice here that since I do test on power platforms, I put information about lpar profiles. You can customize this base class to better suit your needs, obviously. The idea is to show information about your test systems in a handy way (ie, you can cut and paste info directly from your terminal emulator, not having to look somewhere else), as well as executing the ssh access function at the same time. With a base class like that, you can choose a short name for your system, define some parameters and then just pass them to the base function:

foo() {
local host=''
local profile='foo'
test_system $host $profile

So when you type foo at a shell prompt, you’ll start an ssh connection to the test machine, as well as print handy information like:

lucas@freedom:~$ foo

Client partition information
HMC LPAR profile: foo
User: user
Password: password

This is good for bug reports where somebody needs access to your test systems, you can just copy and paste that info right away on the bug report. To summarize, you can assemble your list of test systems, and access those systems (with all the bells and whistles of shell completion) in a faster and more convenient way.

[1] I agree that there might be better ways to do test machine management, but this was a simple and surprisingly effective solution for my personal needs.

[2] That should go without saying, but keep in mind that this is approach is useful for test machines you have in your lab, not production systems. If the fingerprint of your server changed and you didn’t know about it, you definitely have a problem 🙂


Moving is over, at last

They finally delivered my oven this morning, and that officially marks the moving process as finished. Now the house is fully operational, and I’m looking forward the good time I’ll spend here. This is another milestone on this great project called life 😀

Hello to Planet LTC

For those reading this blog trough planet LTC, I’ll introduce myself:

My name is Lucas Meneghel Rodrigues, and I’m the lead of the Linux on Power test team. My team does testing of the enterprise distros of our partners, to ensure high quality of the final product.

As we’re software engineers, we’re allways searching for ways to streamline our work, and since we love open source, we want to share as much as we can of the work we’re producing.

We took the challenge of raising the bar of open source testing, helping the community to produce high quality open source test suites and test instrumentation frameworks. I’ll get more into that on the next posts. For now I just wanted to see if the syndication is already working 🙂

The moving saga is coming to an end

Slowly but surely things are falling into the proper places. I’ve spent way too much time to move, and resolve the little annoyances… Now the only things left are:

  • The oven (quite important part of a house :))
  • The washing machine
  • Fix for a broken glass on one of the new apartment’s window

As I usually say, this world is a vast exercise of patience :D. In other news, it seems that this blog will be syndicated on planet LTC. Let’s see 🙂