Custom Search
Showing posts with label OpenStack Debug Tips. Show all posts
Showing posts with label OpenStack Debug Tips. Show all posts

Monday, December 8, 2014

Setting Up OpenStack Python Client Development Environment

1)
Clone the Project

#git clone https://github.com/openstack/python-keystoneclient.git

2)
Goto cloned directory

#cd python-keystoneclient



3)
Setup the Environment


3,a)
With run_tests.sh

#./run_tests.sh

OR

3,b)
With tox

#sudo pip install tox
#tox

4)
Run the client commands


4,a)
With run_tests.sh Environment


4,a,a)Goto cloned directory
#cd python-keystoneclient

4,a,b)
Create a script named "keystone" with following statements in cloned directory.
#vim keystone

#!/usr/bin/python
# PBR Generated from 'console_scripts'
import sys
from keystoneclient.shell import main
if __name__ == "__main__":
    sys.exit(main())


4,a,c)
Run the keystone client commands from run_tests.sh Environment
#source .venv/bin/activate
#.venv/bin/python keystone tenant-list
#.venv/bin/python keystone user-list


OR

4,b)
With Tox Environment

4,b,a)
Goto cloned directory
#cd python-keystoneclient

4,b,b)
Create a script named "keystone" with following statements in cloned directory.
#vim keystone

#!/usr/bin/python
# PBR Generated from 'console_scripts'
import sys
from keystoneclient.shell import main
if __name__ == "__main__":
    sys.exit(main())


4,b,c)
Run the keystone client commands from Tox Environment
#source .tox/py27/bin/activate
#.tox/py27/bin/python keystone tenant-list
#.tox/py27/bin/python keystone user-list


5)
Run the Tests


5,a)
With run_tests.sh
#./run_tests.sh --debug keystoneclient.tests.v2_0.test_tenants.TenantTests.test_list

##Only pep8 test
#./run_tests.sh --debug --pep8 keystoneclient.tests.v2_0.test_tenants

##manual pep8 test with the wrapper flake8
#source .venv/bin/activate
#flake8 keystoneclient/tests/v2_0/test_tenants.py


OR

5,b)
With tox


* Deactivate virtualenv (Important), then run tox command , otherwise tox command will try to recreate the virtualenv from scratch
#deactivate

*UnitTest
#tox -e py27 -- keystoneclient.tests.v2_0.test_tenants.TenantTests.test_list
#tox -e py27 -- keystoneclient.tests.v2_0.test_tenants
#tox -e py27

*pep8 test
#tox -e pep8 -- keystoneclient.tests.v2_0.test_tenants
#tox -e pep8

http://fosshelp.blogspot.in/2014/11/openstack-unit-testing-tox-runtestssh.html







Thursday, December 4, 2014

OpenStack Debug Python Unit Test using pdb

1)
Add following statements in Unit Test Code where you want to debug

import pdb
pdb.set_trace()




2)
Run "run_tests.sh" with "--debug" option

#./run_tests.sh --debug neutron.tests.unit.opencontrail.test_extension_ipam.IpamExtensionTestCase.test_create_ipam

OR

Run the test with "testtools" instead of "testr"

a)
If you are using "run_tests.sh" environment
#source .venv/bin/activate
#.venv/bin/python -m testtools.run neutron.tests.unit.opencontrail.test_extension_ipam.IpamExtensionTestCase.test_create_ipam

b)
If you are using "Tox" environment
#source .tox/py27/bin/activate
#.tox/py27/bin/python -m testtools.run neutron.tests.unit.opencontrail.test_extension_ipam.IpamExtensionTestCase.test_create_ipam


Saturday, November 22, 2014

OpenStack API Examples using curl

1)
*Export keystone credentials

export OS_USERNAME=admin
export OS_PASSWORD=secret123
export OS_TENANT_NAME=demo
export OS_AUTH_URL=http://127.0.0.1:35357/v2.0


Run CLI commands with "--debug" option and copy the curl command from the output and execute it without using python client.





2)
Get Token


a)
*CLI command
#keystone --debug token-get

b)

*curl command
#curl -i -X POST http://127.0.0.1:35357/v2.0/tokens -H "Content-Type: application/json" -H "User-Agent: python-keystoneclient" -d '{"auth": {"tenantName": "demo", "passwordCredentials": {"username": "admin", "password": "secret123"}}}'

3)
Save token into a shell script variable like

TOKEN=blablabla

4)
List all images


a)
CLI command
#glance --debug image-list

b)
*curl command
*Note: Use double quotes for -H "X-Auth-Token:$TOKEN"

#curl -i -X GET -H "X-Auth-Token:$TOKEN" -H 'Content-Type: application/json' -H 'User-Agent: python-glanceclient' http://127.0.0.1:9292/v1/images/detail?sort_key=name&sort_dir=asc&limit=20

*Replace the option "-i" with "-s" and filter with "python -mjson.tool" to get readable formatted json output
#curl -s -X GET -H "X-Auth-Token:$TOKEN" -H 'Content-Type: application/json' -H 'User-Agent: python-glanceclient' http://127.0.0.1:9292/v1/images/detail?sort_key=name&sort_dir=asc&limit=20 | python -mjson.tool

5)
List all Virtual Machines


a)
CLI command
#nova --debug list

b)
*curl command
#curl -i 'http://127.0.0.1:8774/v1.1/02ef892087a640bcb66bd42a3ceccc79/servers/detail' -X GET -H "X-Auth-Project-Id: demo" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token:$TOKEN"

*Replace the option "-i" with "-s" and filter with "python -mjson.tool" to get readable formatted json output
#curl -s 'http://127.0.0.1:8774/v1.1/02ef892087a640bcb66bd42a3ceccc79/servers/detail' -X GET -H "X-Auth-Project-Id: demo" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token:$TOKEN" | python -mjson.tool

6)
List all networks


a)
CLI command
#neutron --debug net-list

b)

*curl command
#curl -i http://127.0.0.1:9696/v2.0/networks.json -X GET -H "X-Auth-Token:$TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -H "User-Agent: python-neutronclient"

*Replace the option "-i" with "-s" and filter with "python -mjson.tool" to get readable formatted json output
#curl -s http://127.0.0.1:9696/v2.0/networks.json -X GET -H "X-Auth-Token:$TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -H "User-Agent: python-neutronclient" | python -mjson.tool

7)
List all volumes


a)
CLI command
#cinder --debug list

b)
*curl command
#curl -i http://127.0.0.1:8776/v1/02ef892087a640bcb66bd42a3ceccc79/volumes/detail -X GET -H "X-Auth-Project-Id: demo" -H "User-Agent: python-cinderclient" -H "Accept: application/json" -H "X-Auth-Token:$TOKEN"

*Replace the option "-i" with "-s" and filter with "python -mjson.tool" to get readable formatted json output
#curl -s http://127.0.0.1:8776/v1/02ef892087a640bcb66bd42a3ceccc79/volumes/detail -X GET -H "X-Auth-Project-Id: demo" -H "User-Agent: python-cinderclient" -H "Accept: application/json" -H "X-Auth-Token:$TOKEN" | python -mjson.tool



Wednesday, November 12, 2014

OpenStack How to debug neutron contrail plugin

1)
Add log

#sudo vim /usr/lib/python2.7/dist-packages/neutron_plugin_contrail/plugins/opencontrail/contrail_plugin.py
LOG.warn(_('your debug message here'))

2)
Restart server

#sudo service neutron-server restart

3)
Run the CLI command

#neutron net-list --debug

4)
Check the logs

#sudo tail -f /var/log/neutron/server.log