Linux tips for Automation

1. How to Keep Your SSH Sessions Alive

Login as root and change two settings below:

$vi /etc/ssh/sshd_config
ClientAliveInterval 0
#ClientAliveCountMax 3

ClientAliveInterval:
number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive). This is the limit of how long a client are allowed to stay unresponsive before being disconnected. Setting a value of 0 (the default) will disable these features so your connection could not be dropped if it is idle too long.

ServerAliveCountMax
Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session.
you can run $man sshd_config to read more details about these settings.

Another example:
/etc/ssh/sshd_config:
ClientAliveInterval 300
ClientAliveCountMax 2

These settings will make the SSH client or server send a null packet to the other side every 300 seconds (5 minutes), and give up if it doesn’t receive any response after 2 tries, at which point the connection is likely to have been discarded anyway.

 

2. Running  a command with sudo without entering password.

[admin@Thachsystem ]$ sudo /usr/share/hnthach/install_build.sh

for example, i want to run the script above in admin user. There are some commands in that script required sudo. So to run it , I need to do the following steps:

– Create the file installation in  /etc/sudoers.d/ directory.

–  Add one line to installation file:

[admin@Thachsystem ]$ sudo visudo -f /etc/sudoers.d/installation
%admingrp ALL=(ALL) NOPASSWD:/usr/share/hnthach/install_build.sh

the syntax is:  %groupname host = (user privileges ) NOPASSWD: /sbin/shutdown

admingrp is group name, this means that all member of the admingrp group will run this command using sudo without a password.

You can also use /etc/sudoers  instead of modifying /etc/sudoers.d. But i would prefer sudoers.d.  This is good way to separate customized changes to sudo rights and leaves the original sudoers file untouched.

 


 

 

Jmeter – Share cookie across thread groups

Objectives:  Get cookie data from the request in first thread group, store it to csv file. so requests in other thread groups can use that cookie.

Requirement:

  • Create new csv file. It needs to be clean up before running test suite.
  • Extract cookie data from thread group , save it as variables and store them to csv file.
  • In other thread group, fetch data from csv file and save them as variables. Then Insert cookie to the request.

Solutions:

  1. create new csv file:

Manually create a new csv file. Eg : D:\DailyRun\Jmeter\cookievar.csv

  1. Clean up csv file before getting and writing cookie into it. Otherwise, multiple values will append to csv file and it causes wrong cookie inserted to requests in other groups.

Use BSF Sampler to execute the command: 

exec(“cmd.exe /C D:\\thachhoangngoc\\deleteCSV.bat”);

This bat file contains commands to copy fresh file and overwrite the old one.

echo Delete cookievar.csv

copy /Y D:\thachhoangngoc\cookievar.csv D:\DailyRun\Jmeter\cookievar.csv

(Actually, this is a work around. I couldn’t find a solution to clean up csv file directly in Jmeter. I tried method  file.clear() in Beanshell script but it didn’t work.)BSF Sampler

  1. extract cookie data from first request. cookie will be generated in first request. You can find cookie data in response header.

Use Regular Expression Extractor to extract cookie data and save it to variables. In this example, cookie data contains JSESSIONID and JSESSIONIDSSO. So I added two regular expression Extractor.Regular Expression Extractor1Regular Expression Extractor2

  1. write two cookie variables to csv file.

Use BeanShell PostProcessor. File path here is D:\DailyRun\Jmeter\cookievar.csv.beanshellPostProcessor

  1. fetch cookie data from csv file in other thread groups:CSV data set config

Insert cookie into request using  BeanShell PreProcessor.

 InsertCookieusing BeanshellPreProcessorTestPlanJMX

 

 

 

 

 

 

 

 

 

 

 

 

Software QA Quotes

Below are my favorite quotes related to Software Quality Assurance. some of them are funny 🙂

  • “In God we trust, and for everything else we test.— this is my favorite one.

  • “Trust, But Verify”

  • “The only certainties in life are death, taxes and bugs in code”

  • “All code is guilty, until proven innocent”

  • “Life is too short for manual testing”

  • “No amount of testing can prove a software right, a single test can prove a software wrong.”— Amir Ghahrai

  • “To an optimist, the glass is half full. To a pessimist, the glass is half empty. To a good tester, the glass is twice as big as it needs to be.”

  • “The bitterness of poor quality remains long after the sweetness of meeting the schedule has been forgotten.”

  • “You can be a great tester if you have programming skills. You can also be a great tester if you have no programming skills at all. And, you can be a lousy tester with or without programming skills. A great tester will learn what skills she needs to continue to be great, in her own style.”— Jerry Weinberg

  • “More than the act of testing, the act of designing tests is one of the best bug preventers known. The thinking that must be done to create a useful test can discover and eliminate bugs before they are coded – indeed, test-design thinking can discover and eliminate bugs at every stage in the creation of software, from conception to specification, to design, coding and the rest.” – Boris Beizer

  • “You must be a constructive schizophrenic. Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer’s software. The tester in you is your Mr. Hyde – your Incredible Hulk. He must exercise what Gruenberger calls ‘low cunning.” – Boris Beizer

  • “The Definition of an Upgrade: Take old bugs out, put new ones in”

  • “Blame doesn’t fix bugs.”

  • “Fast, good, cheap: pick any two.”

  • “Lots of methodologies have come and gone, paradigms have changed but the requirements are always the same; Make it good and make it fast.”

  • “Discovering the unexpected is more important than confirming the known.“— George E. P. Box

  • “I do believe it’s important for testers to know the market that their client or their employer is in and the reason for that is if you understand what risks your client is facing and you understand what the competing products are and where the challenges lie in the market, you can plan your testing accordingly.”— Karen N. Johnson

  • “It’s not at all important to get it right the first time. It’s vitally important to get it right the last time.”— Andrew Hunt and David Thomas

  • “Walking on water and developing software from a specification are easy if both are frozen.”— Edward V. Berard

  • “Software and cathedrals are much the same: first we build them, then we pray.”

  • “Just like with everything else, tools won’t give you good results unless you know how, when, and why to apply them. If you go out and you buy the most expensive frying pan on the market it’s still not going to make you a good chef.”— Christin Wiedemann

  • “I remember the days when QA testers were treated almost as second-class citizens and developers ruled the software world. But as it recently occurred to me: we’re all testers now.” —Joe Colantonio

  • “Only conducting performance testing at the conclusion of system or functional testing is like conducting a diagnostic blood test on a patient who is already dead.”— Scott Barber