Pages

Tuesday, 23 May 2017

Git - find a specific version by stacktrace

So you have a stacktrace, something that tells you that on line XXX an exception has been raised. You want to find out what was the exact version of the code that was running at that time.

git log origin/neutron-ha-tool-maintenance --oneline -- files/default/neutron-ha-tool.py |
cut -d " " -f 1 |
while read revision; do echo $revision; git show $revision:files/default/neutron-ha-tool.py |
sed -n 576,577p ; done |
less

Friday, 19 May 2017

OpenStack - Launch your First VM

Some notes on how to get started with a freshly baked OpenStack (Liberty)


  • First, an image needs to be uploaded:


wget -qO - http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img | openstack image create cirros --public --container-format=bare --disk-format=qcow2


  • Then we need to create a network:


openstack network create testnetwork


  • Within the network, a subnet needs to be created:


neutron subnet-create --name testsubnet testnetwork 192.168.37.0/24


  • Please note that a more recent version of OpenStack might support the openstack subnet create command as well.



  • Let's create a router now:


neutron router-create testrouter


  • Now set the router's default gateway by connecting it to a network:


neutron router-gateway-set testrouter floating


  • And link the router to the subnet:


neutron router-interface-add testrouter testsubnet


  • Now launch your instance:


nova boot --flavor m1.tiny --image cirros --nic net-id=a6a6c271-a391-4bff-9eda-79a97a8e1154 i1


  • Create a floating IP:


neutron floatingip-create floating
nova floating-ip-associate i1 192.168.122.131


  • Add rules to security group for icmp and ssh


openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22:22 default

Saturday, 29 April 2017

Remove Already Merged Branches from Git

In case you need that, here is the draft:

git branch --merged master | sed -n 's,^ \+\(.*\)$,\1,p' | xargs git branch -d

Wednesday, 26 April 2017

Tmate cheatsheet

If you detached tmate, you might want to re-attach by:
tmate -S /tmp/tmate-0/DpfNjI attach

Tuesday, 25 April 2017

iptables - deny connecting to a host

I would like to test a scenario where server A cannot reach server B. To establish this, I will add iptables rules on server A so ssh connections fail. After some research (basically reading this article) I managed to come up with the rules I need. Before doing anything it is good to know the state of the system. Use
iptables -S
to find out existing rules on your system. To block connections to ssh, use:
iptables -A OUTPUT -p tcp --dport ssh -d 192.168.124.82 -j REJECT
removing the rule is simple, list the rules with iptables -S and replace -A with -D:
iptables -D OUTPUT -d 192.168.124.82/32 -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable

Friday, 10 March 2017

Running Cinder Migration Unit Tests

Cinder has some unit tests for migration. If you want to run them on your computer, you'll need to set up database administrator accounts for your backends, and export an environment variable before running the test:
One-liner:
for backend in \
    mysql+pymysql://root:secret@localhost/mysql \
    postgresql://postgres:secret@localhost/cinder \
    sqlite:///somefile.db \
; do
    OS_TEST_DBAPI_ADMIN_CONNECTION=$backend \
        python -m subunit.run cinder.tests.unit.test_migrations |
            subunit2pyunit
done


MySQL
OS_TEST_DBAPI_ADMIN_CONNECTION='mysql+pymysql://root:secret@localhost/mysql'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

PostgreSQL
OS_TEST_DBAPI_ADMIN_CONNECTION='postgresql://postgres:secret@localhost/cinder'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

SQLite
OS_TEST_DBAPI_ADMIN_CONNECTION='sqlite:///somefile.db'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

Friday, 24 February 2017

PostgreSQL Notes

Backup a Database

sudo -u postgres --format=custom --file=<file name> <database name>

Restore a Database

First, create an empty database:
create database <database name> with encoding='utf-8';
Then grant all permissions to your user:
grant all on database <database name> to <user name>;
Then restore the dump:
sudo -u postgres pg_restore \
    --schema=public \
    --dbname=<database name> \
    --no-owner \
    --no-privileges \
    --role=<user name> \
    <file name>