Tuesday, December 4, 2012

My first day with openstack---development environment setup

I want to add new extension to Openstack Quantum. Before I can do any coding, I need to have a decent development environment. The developer guide on the Openstack.org wiki does not really help much for me. With some googling, I came cross a github page:https://github.com/bcwaldon/vagrant_devstack
Here are what I did to create my first openstack development environment:
1. git clone https://github.com/bcwaldon/vagrant_devstack 

2. cd vagrant_devstack
    based on the README, I also added submodules 

    git submodule init
    git submodule update


3. vagrant up
In the Vagrantfile, it tries to download vagrant box from http://c479942.r42.cf2.rackcdn.com/precise64.box, but the file is not there anymore.  I googled again and found this one http://dl.dropbox.com/u/1537815/precise64.box. I changed Vagrantfile to use the new box and restarted "vagrant up".

After waiting for sometime, I see following error message

"Mounting NFS shared folders failed. This is most often caused by the NFS client software not being installed on the guest machine. Please verify that the NFS client software is properly installed, and consult any resources specific to the linux distro you're using for more information on how to do this."

Most likely, you have a dirty vagrant environment, try vagrant reload to see if the problem goes away.


After a good a mount of time waiting on devstack to be installed, I hit on following error:
"+ sudo rm -rf /home/vagrant/cache /home/vagrant/devstack /home/vagrant/postinstall.sh
rm: cannot remove `/home/vagrant/cache': Device or resource busy
++ failed
++ local r=1
+++ jobs -p
++ kill
++ set +o xtrace
---- End output of su -c 'set -e; cd /home/vagrant/devstack; RECLONE=yes bash stack.sh > devstack.log' vagrant ----
Ran su -c 'set -e; cd /home/vagrant/devstack; RECLONE=yes bash stack.sh > devstack.log' vagrant returned 1
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
"
To understand the problem, I did vagrant ssh and login to my VM. It seems that the original devstack directory has been removed. I did another git clone git://github.com/openstack-dev/devstack.git to get the devstack. Then I manually run stack.sh. It seems that at the end of lib/nova:cleanup_nova, the function tries to clean out the instances directory and the cache directory is among the deleting directories. But this directory is really mounted from my host machine by vagrant. The quick and dirty fix for this is to not to cleanup directory

agrant@precise64:~/devstack/lib$ git diff . 
diff --git a/lib/nova b/lib/nova index fbb5a01..ae4554d 100644 --- a/lib/nova +++ b/lib/nova @@ -102,7 +102,7 @@ function cleanup_nova() { sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true # Clean out the instances directory. - sudo rm -rf $NOVA_INSTANCES_PATH/* + #sudo rm -rf $NOVA_INSTANCES_PATH/* fi }

Since I have a changed devstack tree in my VM, I don't want cookbook script to re-clone the devstack tree. I have changed vagrant_devstack/cookbooks/devstack/recipes/default.rb to not clone devstack source code by disable following commands:

execute "git clone #{node[:devstack][:repository]}" do
 cwd node[:devstack][:dir]
 user node[:devstack][:user]
 group node[:devstack][:group]
 not_if { File.directory?("#{node[:devstack][:dir]}/devstack") }
end

execute "git checkout #{node[:devstack][:branch]}" do
 cwd "#{node[:devstack][:dir]}/devstack"
 user node[:devstack][:user]
 group node[:devstack][:group]
end

I'm not familiar with cookbook, I thought that "not_if { File.directory?("#{node[:devstack][:dir]}/devstack")" will avoid to overwrite my devstack directory on VM. But it seems that my devstack directory got wipe out everytime. Anyway, quickly disable lines above,solved my problem.

After changed script, I did vagrant reload in my host directory, the vagrant reload failed immediately while the cookbook tries to relink my host public key to the VM ~/.ssh/id_rsa. The quick fix for this is go to vagrant-openstack/recipes/cache.rb and fix following commands

execute "ln -s /home/#{u}/.host-ssh/id_rsa /home/#{u}/.ssh/id_rsa" 
do
    user u
    group u
not_if { File.exists?("/home/#{u}/.ssh/id_rsa") }
end
Again, I thought not_if statement should avoid the file relink is id_rsa is there already. But it seems that not_if does not work.

After all these changes, my vagrant up finished successfully. I have devstack up running. By default, the devstack does not enable quantum. But it is what I really need. To enable quantum + openvswitch, I did following changes:
diff --git a/stackrc b/stackrc index 01e9556..f47ad40 100644 --- a/stackrc +++ b/stackrc @@ -14,7 +14,9 @@ DATABASE_TYPE=mysql # ``disable_service`` functions in ``localrc``. # For example, to enable Swift add this to ``localrc``: # enable_service swift -ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE +ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE,quantum,q-svc,q-agt +Q_PLUGIN=openvswitch
+ENABLE_TENANT_TUNNELS=True

After restart devstack, the quantum is up running.

Now on my host directory, I have a cache/stack directory that has all the devstack source code. The /opt/stack on the VM has a running copy of the devstack. I did a git branch work; git checkout work on all the directories under cache/stack so that we can have a dev branch.

Next, I will need to find a IDE to do my developemnt. eclipse+pydev+egit seems a good choice for me. First. I installed eclipse, then from http://pydev.org/updates, I installed pydev. From http://download.eclipse.org/egit/updates, I installed egit.
I used egit to import all the git repos from cache/stack directory. And then convert each of repo into general project. Switching to pydev perspective, right click on project names that just imported, select PyDev and set the project as PyDev project.

That is it, next, I will need to find out what "not_if" means and how fix the cookbook script so that I can make a right patch.