Wednesday, August 12, 2015

Get public IP address of your computer

Open up the Terminal Application and run the command below to get the public IP address of your computer
dig +short myip.opendns.com @resolver1.opendns.com

Reference:
How to find my public IP address from command line on linux

Monday, August 3, 2015

Getting backtrace from qemu-kvm crash

When I'm running automated tests, qemu-kvm sometimes crashes and this needs to be debugged ASAP. To file a bug, I need a backtrace. As part of the test, the core which is dumped is saved.


  1. SSH into the machine where qemu-kvm crashed
  2. debuginfo-install qemu-kvm => This should install a bunch of packages to get a lot of symbol info. 
  3. gdb /usr/libexec/qemu-kvm <path to core file>
  4. Pass "thread apply all bt" to get the backtrace at the gdb prompt

Thursday, July 30, 2015

./configure options

When building packages, often we need to run ./configure with a bunch of options to build the package. To find out what the last options were used for configure, use this command:
./config.status --config

How to remember ./configure script arguments a year later

Monday, July 13, 2015

Execute a command, display output and get it's return code in Python

Often in my tests, I need to display the output and use the return code of the command I want to run. But I can't use check_output because my tests need to support RHEL6 and RHEL7 and RHEL6 is still on python 2.6.x and check_output is only available in Python 2.7

The following code snippet is modified from another website:

from subprocess import Popen, PIPE
 
cmd = "blah blah"
process = Popen(cmd.split(), stdout=PIPE)
process.communicate()    # execute it, the output goes to the stdout
exit_code = process.wait() # when finished, get the exit code


Thursday, July 2, 2015

Access Environment Vars in Python

To access environment variables in Python, import os module and run the following command
import os
print os.environ['ENV_VAR_YOU_WANT']

Monday, June 29, 2015

Combine 2 commits into one and update pull request

Finally, I was able to combine 2 commits into 1 commit and update the pull request. This will save me lots of time instead of creating a new pull request everytime and re-do work.

First time:
git clone <my-clone-of-upstream-repo>
cd <upstream-repo>
git remote add upstream <upstream-repo>
git config --global push.default simple
When starting a new pull request:
git checkout -b <new-branch>
Make changes, commit and send pull request. 

When combining n commits:
git fetch upstream
git merge-base new-branch master => This will generate a commit hash
git rebase --interactive <commit hash>
Your text editor will open with a file that lists all the commits in new-branch, and in front of each commit is the word "pick". For every line except the first, you want to replace the word "pick" with the word "squash" or "fixup". Save this file. 
git rebase upstream/master
git push -f

Thursday, June 11, 2015

Start vim without .vim settings

In my .vim settings, I have audo indent and smart indent enabled. Sometimes when I'm copying code, this causes the code to completely go wonky.

So, to avoid this and just copy the code, I disable the vim settings and open the file using
vim -u NONE filename