Wednesday, January 21, 2015

How to setup Eclipse Django for Open Stack Development ( Horizon as Example ) via VirtualBox

I was sharing Openstack Juno DevStack Setup and How to setup RDP to connect with your Ubuntu. The purpose of those efforts is trying to setup your own development box for OpenStack. Here, I would like to talk more about how to setup up your own IDE environment (Eclipse/PyDev/Django) on your test box for openstack. Regarding it, I'm appreciated my coworker Tone's help to put everything together to pilot this show case.

Here is general steps to setup a test box for OpenStack module. The post (http://chianingwang.blogspot.com/2014/11/how-to-install-openstack-juno-on.html) cover first No. 1~3 steps and No. 4 step is in my another post (http://chianingwang.blogspot.com/2015/01/how-to-use-windows-rdp-to-access-your.html). This post I will go through the Steps 5 to 7.
  1. Install VirtualBox.
  2. Install Ubuntu on VirtualBox
  3. Install DevStack on VirtualBox
  4. Setup RDP with your Ubuntu (Guest OS)
  5. Install Eclipse on Ubuntu (Guest OS)
  6. Install PyDev (Django) with Eclipse on Ubuntu (Guest OS)
  7. Download Code, Import into Eclipse, Configure and run the code on Eclipse. Here are the break down items.
    1. Download Horizon Source Code
    2. Import Code into Eclipse
    3. Configure PyDev Project
    4. Run(Debug) as PyDev for OpenStack (Horizon) Project in Eclipse
PS: The reason why we setup the IDE tool on VirtualBox is because the OpenStack Development is not working on windows box. Even you have cygwin for Simulate Linux but it's difficult to do the debugging. Thus, for those windows user, you can leverage virtualization tools such as VirtualBox or VMWare Workstation to setup your own IDE for OpenStack Development.

Install Eclipse ( Step 5 )

After setup Devstack and configure your RDP, now you are able to log in with RDP from your windows. For OpenStack development, we need IDE tool. Here are the steps how to install Eclipse Luna on your Ubuntu 14.04 client.
1.Open a terminal (Ctrl-Alt-T) or search terminal in Ubuntu :
2.Make sure Previous Version's Eclipse is NOT installed in your Ubuntu. You may need to remove both "eclipse" and "eclipse-platform" packages to get rid of it. If it still gets into way when trying to install Luna using this easy way, you may need to look at the "hard way" below.
# sudo apt-get remove eclipse eclipse-platform
3.Install a Java 1.7 JDK, however if you setup DevStack before you can skip this, since DevStack installed Java already:
# sudo apt-get install openjdk-7-jdk
4.Install Maven:
# sudo apt-get install maven
5.Download Eclipse. The "for Java EE Developers", "for Java Developers" and "for RCP and RAP Developers" versions all seem to work. Currently the file which was tested to work is (note that it is for 64 bit Ubuntu version) available at this page
6.Extract the Eclipse installation tarball into your home directory (I just unzip the Eclipse on my Ubuntu Desktop):
# tar -xzvf <path/to/your-tar-file> or (/home/Username/Desktop)
7.Increase the memory for the Eclipse installation by modifying the eclipse.ini under eclipse folder file. Since I put eclipse on desktop. I can try.
  # vim /home/username/Desktop/eclipse/eclipse.ini
· Change the -Xmx setting (line 20) to be AT least 1G(1024m), recommended 2GB. (i.e. -Xmx2048m).
· Change the -XX:MaxPermSize (line 18) to at most 512m. If you have the -Xmx setting set to 1G, then I suggest to use a lower value, for example 300m.
8.Run the Eclipse, or double click ( I suggest right click create a short cut on desktop, but be careful the name conflict )




9. If everything seems to work, return back to GettingStarted: Eclipse and continue from step 5 in the section "Installing Eclipse". The Maven Integration software packages as installed in the step 4 are already installed in the Luna so that step can be safely skipped.

Install PyDev ( Django ) ( Step 6 )

Install PyDev ( Django ) on Linux base Eclipse is much easier then Windows Eclipse. You just need to go to eclipse , check the help from menu. Help -> Marketplace. the search for PyDev and click install. The action will finish the PyDev (Django) module on your eclipse.

Find "pydev" and install Python IDE for Eclipse 3.9.1






Setup the Development Box and Connect with Code base. ( Step 7 )

This paragraph we would like to talk about how to download Code, import into Eclipse, Configure and run the code on Eclipse. I use Horizon module as example.

1. Download the Horizon source code.

If you install DevStack, I think you default install git already. since we follow the similar cli to download the horizon code. However, you might want to create a specific folder under your eclipse workspace. eg: when I lunched eclipse, I setup my workspace with LUNA subdirectory. I will do 

# cd /home/(username)/workspace/LUNA/

And to make sure I download the horizon code in my eclipse workspace.
# git clone -b stable/juno https://github.com/openstack/horizon.git

To avoiding the credential issue when you import the code into Eclipse, you might grant the access privilege to you code (horizon) folder.
# sudo chmod -R ugo+rw ./LUNA/horizon

2. Import code to Eclipse

Here, we are import the code into eclipse via creating a PyDev project ( PS: not Django project )


But when you do the first time, you might see the Finish button is disable since you haven't choose interpreter. You can click the "Please configure an interpreter before proceeding" blue link and choose "Quick Auto-Config".



If you have horizon folder with source code under your Eclipse workspace, when you create the PyDev project and check "Use default". The project will automatically base on your source code location to as a new PyDev project in you Eclipse.

3. Configure your horizon PyDev project in Eclipse

First of all, you need to prepare a local setting file. Here are the steps how to prepare it.
  • Copy / Paste horizon/openstack_dashboard/local/local_settings.py.example to the same directory.



  • Then it will prompt name conflicted then you can rename local_settings.py.example to local_settings.py



  • Check your ip address. If your virtual box has setup 3rd Network adapter as Bridged Adapter before, you should be able to find your available ip address to represent your box, eg: 192.168.1.XX)
    • # ip addr
    • # ifconfig
  • Modify OPENSTACK_HOST = "YOUR IP ADDRESS" in around line 134 in file local_settings.py that you just copy.
    • eg: OPENSTACK_HOST = "192.168.1.33"

  • Setup the environment for horizon, you can find the install_venv.py the setup script under the horizon/tools/ directory.
    • # sudo python install_venv.py



4. Run Horizon on Eclipse

Now, we would like to run our horizon code in different port to review what's we change on horizon UI as unit test. Run as --> Run Configuration --> choose the PyDev Django setting.







On the left hand sub view, you can choose the PyDev Django --> local_horizon (if you don't have any setting before, you can create a new one by yourself), and right hand sub view you can click "main" tab.

In "Project" section, browser and choose "horizon" project then "OK", the rest of the setting should be brought up automatically.


In "Main Module" section, browse and choose "manage.py"


In Main Tab, the configuration will look like this, then click "Apply"


Then click Argument Tab, and type "runserver (your ip):(ports)" eg: runserver 192.168.1.32:8989, then apply the setting once you finish.




Now we can run as / debug as the code and display with ports we assign to run the unit test.


You copy and paste the ip:port (eg:http://192.168.1.33:8989) from console to your browser. You can use your DevStack's username password to login. If you can't remember it, it's in localrc under devstack folder. In my localrc example, the login either "admin" or "demo" and password are all "devstack"






Again, enjoy the post and feel free to share with me whatever you thought. Hopefully you can enjoy your OpenStack Development Journey

Reference:

https://wiki.opendaylight.org/view/GettingStarted:_Eclipse

4 comments:

  1. dont think i can be done this easy way, now where the project mixed up with django and angular js https://docs.openstack.org/releasenotes/horizon/ocata.html

    ReplyDelete
  2. On ocata:
    Django version 1.8.14, using settings 'openstack_dashboard.settings'
    Starting development server at http://192.168.0.33:8989/
    Quit the server with CONTROL-C.
    [06/Apr/2017 13:26:39] "GET / HTTP/1.1" 302 0
    Not Found: /dashboard/auth/login/
    [06/Apr/2017 13:26:45] "GET /dashboard/auth/login/?next=/ HTTP/1.1" 404 6330
    Not Found: /dashboard/static/dashboard/css/34f8a8f8d5e5.css
    Not Found: /dashboard/static/dashboard/css/c804f054a81f.css
    Not Found: /dashboard/static/dashboard/js/5508d0ed7005.js
    Not Found: /dashboard/static/dashboard/js/886050f47505.js
    Not Found: /dashboard/static/dashboard/js/e4052a6ff48a.js
    [06/Apr/2017 13:26:45] "GET /i18n/js/horizon+openstack_dashboard/ HTTP/1.1" 200 2372
    Not Found: /dashboard/static/dashboard/img/favicon.ico
    [06/Apr/2017 13:26:46] "GET /dashboard/static/dashboard/js/886050f47505.js HTTP/1.1" 404 6330
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/js/5508d0ed7005.js HTTP/1.1" 404 6330
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/js/e4052a6ff48a.js HTTP/1.1" 404 6330
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/css/34f8a8f8d5e5.css HTTP/1.1" 404 6330
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/img/favicon.ico HTTP/1.1" 404 6330
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/css/c804f054a81f.css HTTP/1.1" 404 6330
    Not Found: /dashboard/static/dashboard/js/5508d0ed7005.js
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/js/5508d0ed7005.js HTTP/1.1" 404 6330
    Not Found: /dashboard/static/dashboard/js/886050f47505.js
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/js/886050f47505.js HTTP/1.1" 404 6330
    Not Found: /dashboard/static/dashboard/js/e4052a6ff48a.js
    [06/Apr/2017 13:26:47] "GET /dashboard/static/dashboard/js/e4052a6ff48a.js HTTP/1.1" 404 6330

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. but when you start it up in apache and authentitace earlier it works fine, ...until the end of the session

    ReplyDelete