2014년 3월 29일 토요일

Keystone server debugging with Eclipse (pydev, egit)

Keystone running with Eclipse

Keystone is the component for authentication on openstack platform. In most cases, keystone means keystone server.

I`m going to take keystone server as a default sample for setting up python project with eclipse.

This post is inspired by the wiki post ( https://wiki.openstack.org/wiki/Setup_keystone_in_Eclipse ), but I've added more screenshots and some trouble shootings.

Prerequisites :
To run keystone server, you should have a mysql database for keystone ready on your mysql server.
Installing keystone with yum will be a quick and dirty solution for you, since you can run command like "keystone-manage db_sync". After that delete keystone and use it for debugging. ("openstack-db --init --service keystone --password KEYSTONE_DBPASS" is another option if you have installed openstack-utils)
But, if you don't have a luxury of knowing everything about installing openstack, try to install Packstack on your CentOS, and stop keystone service only and use the packstack resources to your keystone. All-In-One might be good choice for fast approach to build up keystone development environment.

1. Installing Eclipse + Pydev (On CentOS 6.5)

There are a lot of solutions for developing python on Linux, but I have selected Eclipse. (If you want use other IDE, you can google it. )

Flow the link below and download eclipse. As of eclipse version, I have downloaded eclipse Kepler. you can search for faster download mirror on Google like with "Eclipse download mirror", since eclipse is a big program :D
  http://www.eclipse.org/

To install Pydev on ecilpse, go to "Help" -> "Install New Software" like below. After that, insert pydev update link ( http://pydev.org/updates ), which may change for future reference, so you`d better check Pydev home page for update link. You should hit enter key after inserting update URL, and if you have installed pydev already, then next button will not be clickable.



Follow the next steps with positive mind with hitting OK or Next buttons.
After the installing finished, you must restart eclipse for changes to apply.

2. Let Eclipse know Python Environment of your OS.

To use Pydev properly, you need more steps for settings because Eclipse doesn't know where python compile environment is on your OS. Most of Linux system including CentOS has python, so no need to fear installing python on your computer.

For eclipse to understand where python directory is, you should do "auto-config" like the image below. you can make this window show up with "WIndow" -> "Preference" -> "PyDev" -> "Interperters" -> "Python interpreter". Don't forget to click OK button after auto-config.


3. Egit install and settings.

Like Pydev, you can install Egit with new install menu. Follow the same way with egit update URL ( http://download.eclipse.org/egit/updates ).

After Egit installed on eclipse, make the "git repo" window shows on your eclipse like image below. you can do that with "Window" -> "Show View" -> "Other" -> "Git" -> "Git repositories"

4. Cloning the Keystone project with egit

To get keystone project from public git website, copy the URL below.
   https://github.com/openstack/keystone.git

And click the button circled on the image below. (It`s a button with an green arrow)


A window will pop up like below with the URL filled with (if not, paste url manually). click next. On the next phase, select the branch you like (if you don't know what to do, just leave all being checked). and repeat clicking next till the end. :D

You may find that a new project is added to your git repositories and the directory where the file are downloaded.


5. Import Project to Eclipse

To make git files to be your eclipse project, you must import project. First click "Import" on working directory of keystone, and select "Import as general project". This means you are going to import these files with no options.




6. Set it as a Python project, and expose the project to Python runtime. 

Because you have imported the files as general project, you need to set it as Python project. And that is not all. You must make that project exposed to python environment which means python directory. If this is not done well, you will be faced with error like "can not find some python library" on eclipse.

To do so, click keystone project with left mouse, then context menu will pop up. Click on "Pydev" -> "set as PyDev project". Naturally context menu will go away and that project will be set as python one.

And one more time left click the project and "Pydev" -> "Set as source folder(add to PYTHONPATH)". This means that your project file will be exposed to all the python libraries installed on your operation system, so that your project can load those libs on compile time. This step can be done very easily but if you don't manage to do this, you won't be able to run keystone on your system.


7. Make keystone's debug Configuration. 

Caution :: This part was tough for me because none of other guide has it. Most of eclipse project like Android, Java, etc, you can make configuration before you run your app with clicking "Debug Configuration". But it seems that you should run keystone-all with no configuration to make a descent configuration with Pydev, if not you can't make it. So don't try to make configuration before run it or you will be faced with error like "pydev path for project must have only one segment"

First run keystone-all on bin folder like below. (run as -> python run)


Stop the app, and make Debug Configuration window shows up with the way like image below. (debug as -> debug configurations ...)



you will see window like below.



On Arguments tap, set the Program arguments like below. You must make some configuration and log file that can be referred to your keystone, and provide it as program arguments, otherwise it will use default directory, which can lead to the file authority error.

And change working directory like below. ( ${workspace_loc:keystone} )


On Environment tap, you should set some Environments for authentication. This is a keystone server, so there's no need to set environments like OS_USERNAME, etc.


You might notice standard_threads on the images above, which is a compulsive option to suppress "error: cannot switch to a different thread" on eclipse console.

8. Server running on eclipse 

This is the normal state of keystone server running on eclipse(it might vary on your keystone configuration)



As you can see all those blur images above(it's my account name), all of the file's owner will be on your account. I seems that this is not a good situation for further use like committing and pushing source to openstack git server. I recommend you to make a keystone user on your CentOS, and build environment on it. :)

x. End

If you have done well all of the things above, you may have a keystone server running on your eclipse like above. You can trigger your keystone server with web protocol(http or https) and tag some debug point, follow the code flow.

But you need more steps to debug keystone easily, it is about keystone-client. you can find it on my blog. Refer to the link below.

http://codingopenstack.blogspot.kr/2014/03/to-be-openstack-developer.html



댓글 없음:

댓글 쓰기