Statistics
| Branch: | Tag: | Revision:

root / README.develop @ 602d6541

History | View | Annotate | Download (5.7 kB)

1 bbd4f788 Georgios Gousios
DEVELOP.txt - Information on how to setup a development environment. 
2 bbd4f788 Georgios Gousios
3 bbd4f788 Georgios Gousios
Dependencies
4 bbd4f788 Georgios Gousios
------------
5 bbd4f788 Georgios Gousios
6 602d6541 Vangelis Koukis
Synnefo is written in Python 2.6 and depends on the following Python modules
7 602d6541 Vangelis Koukis
[package versions confirmed to be compatible are in braces]
8 bbd4f788 Georgios Gousios
9 602d6541 Vangelis Koukis
- django 1.2 [Django==1.2.4]
10 602d6541 Vangelis Koukis
- simplejson [simplejson==2.1.3]
11 602d6541 Vangelis Koukis
- selenium [?]
12 602d6541 Vangelis Koukis
- pyzmq-static [pyzmq==2.0.10.1]
13 602d6541 Vangelis Koukis
- pycurl [pycurl==7.19.0]
14 602d6541 Vangelis Koukis
- python-dateutil  [python-dateutil==1.4.1]
15 602d6541 Vangelis Koukis
  WARNING: version python-dateutil==2.0 downloaded by pip known *not* to work with Python 2.6
16 bbd4f788 Georgios Gousios
17 bbd4f788 Georgios Gousios
also, depending on the database engine of choice, on one of the following:
18 602d6541 Vangelis Koukis
- MySQL-python [MySQL-python==1.2.3]
19 602d6541 Vangelis Koukis
- psycopg2 [psycopg2==2.4]
20 f5e590e4 Georgios Gousios
21 f5e590e4 Georgios Gousios
22 bbd4f788 Georgios Gousios
Preparing the development environment
23 bbd4f788 Georgios Gousios
-------------------------------------
24 bbd4f788 Georgios Gousios
25 bbd4f788 Georgios Gousios
1. Prepare the system 
26 bbd4f788 Georgios Gousios
The easiest method is to setup a working environment through virtualenv. 
27 bbd4f788 Georgios Gousios
Alternatively, you can use your system's package manager to install
28 bbd4f788 Georgios Gousios
the dependencies (e.g. Macports has them all).
29 bbd4f788 Georgios Gousios
30 bbd4f788 Georgios Gousios
*On Snow Leopard, you have to set the following environment variable for
31 bbd4f788 Georgios Gousios
pip to compile the dependencies correctly. 
32 bbd4f788 Georgios Gousios
33 bbd4f788 Georgios Gousios
	$export ARCHFLAGS="-arch x86_64"
34 bbd4f788 Georgios Gousios
35 602d6541 Vangelis Koukis
*On Ubuntu, a few more packages must be installed before installing the
36 bbd4f788 Georgios Gousios
prerequisite Python libraries
37 bbd4f788 Georgios Gousios
38 bbd4f788 Georgios Gousios
	$sudo aptitude install libcurl3-gnutls libcurl3-gnutls-dev uuid-dev 
39 bbd4f788 Georgios Gousios
40 bbd4f788 Georgios Gousios
2. Checkout the code and install the Python prerequisites. This assumes
41 bbd4f788 Georgios Gousios
that python is already installed on the host.
42 bbd4f788 Georgios Gousios
43 bbd4f788 Georgios Gousios
    $ sudo easy_install virtualenv
44 bbd4f788 Georgios Gousios
    $ git clone https://user@code.grnet.gr/git/synnefo synnefo
45 bbd4f788 Georgios Gousios
    $ virtualenv --python=python2.6 synnefo --no-site-packages
46 bbd4f788 Georgios Gousios
    ...
47 bbd4f788 Georgios Gousios
    $ cd synnefo
48 602d6541 Vangelis Koukis
    $ ./bin/pip install <list_of_prerequisites>
49 bbd4f788 Georgios Gousios
50 83d51c7b Georgios Gousios
3. At this point you should have all required dependencies installed. Now you
51 bbd4f788 Georgios Gousios
have to select a database engine. The choices are: postgres, mysql and sqlite.
52 bbd4f788 Georgios Gousios
53 bbd4f788 Georgios Gousios
-SQLite
54 bbd4f788 Georgios Gousios
The python sqlite driver is available by default with Python so no additional 
55 bbd4f788 Georgios Gousios
configuration is required. Also, most self-respecting systems have the sqlite 
56 bbd4f788 Georgios Gousios
library installed by default.   
57 bbd4f788 Georgios Gousios
58 bbd4f788 Georgios Gousios
-MySQL
59 bbd4f788 Georgios Gousios
MySQL must be installed first
60 bbd4f788 Georgios Gousios
61 bbd4f788 Georgios Gousios
*Ubuntu - Debian
62 bbd4f788 Georgios Gousios
	$sudo apt-get install libmysqlclient-dev
63 bbd4f788 Georgios Gousios
64 bbd4f788 Georgios Gousios
*MacPorts
65 bbd4f788 Georgios Gousios
	$sudo port install mysql5
66 bbd4f788 Georgios Gousios
67 bbd4f788 Georgios Gousios
Install the MySQL python library
68 bbd4f788 Georgios Gousios
69 bbd4f788 Georgios Gousios
	$ bin/pip install MySQL-python
70 bbd4f788 Georgios Gousios
71 bbd4f788 Georgios Gousios
Note: On MacOSX with Mysql install from MacPorts the above command will fail
72 bbd4f788 Georgios Gousios
complaining that it cannot find the mysql_config command. Do the following and
73 bbd4f788 Georgios Gousios
restart the installation
74 bbd4f788 Georgios Gousios
75 bbd4f788 Georgios Gousios
	$ echo "mysql_config = /opt/local/bin/mysql_config5" >> ./build/MySQL-python/site.cfg
76 bbd4f788 Georgios Gousios
77 bbd4f788 Georgios Gousios
Configure a MySQL db/account for synnefo
78 bbd4f788 Georgios Gousios
79 bbd4f788 Georgios Gousios
	$ mysql -u root -p
80 bbd4f788 Georgios Gousios
81 bbd4f788 Georgios Gousios
	mysql> create database synnefo;
82 bbd4f788 Georgios Gousios
	mysql> show databases;
83 bbd4f788 Georgios Gousios
	mysql> GRANT ALL on synnefo.* TO username IDENTIFIED BY 'password';
84 bbd4f788 Georgios Gousios
 
85 bbd4f788 Georgios Gousios
-Postgres
86 bbd4f788 Georgios Gousios
87 bbd4f788 Georgios Gousios
#Ubuntu - Debian
88 bbd4f788 Georgios Gousios
	$ sudo apt-get install postgresql-8.4 libpq-dev
89 bbd4f788 Georgios Gousios
90 bbd4f788 Georgios Gousios
#MacPorts
91 bbd4f788 Georgios Gousios
	$ sudo port install postgresql84
92 bbd4f788 Georgios Gousios
93 bbd4f788 Georgios Gousios
Install the postgres Python library
94 bbd4f788 Georgios Gousios
95 bbd4f788 Georgios Gousios
	$ bin/pip install psycopg2
96 bbd4f788 Georgios Gousios
97 bbd4f788 Georgios Gousios
Configure a postgres db/account for synnefo
98 7fb0fc9f Vangelis Koukis
	Become the postgres user, connect to PostgreSQL:
99 7fb0fc9f Vangelis Koukis
	$ sudo su - postgres 
100 7fb0fc9f Vangelis Koukis
	$ psql
101 7fb0fc9f Vangelis Koukis
	
102 7fb0fc9f Vangelis Koukis
	Run the following commands:
103 7fb0fc9f Vangelis Koukis
	DROP DATABASE synnefo;
104 7fb0fc9f Vangelis Koukis
	DROP USER username;
105 7fb0fc9f Vangelis Koukis
	CREATE USER username WITH PASSWORD 'password';
106 7fb0fc9f Vangelis Koukis
	CREATE DATABASE synnefo;
107 7fb0fc9f Vangelis Koukis
	GRANT ALL PRIVILEGES ON DATABASE synnefo TO username;
108 7fb0fc9f Vangelis Koukis
	ALTER DATABASE synnefo OWNER TO username;
109 7fb0fc9f Vangelis Koukis
	ALTER USER username CREATEDB;
110 7fb0fc9f Vangelis Koukis
111 7fb0fc9f Vangelis Koukis
The last line enables the newly created user to create own databases. This is
112 7fb0fc9f Vangelis Koukis
needed for Django to create and drop the test_synnefo database for unit
113 7fb0fc9f Vangelis Koukis
testing.
114 bbd4f788 Georgios Gousios
	
115 83d51c7b Georgios Gousios
4. At this point you should have a working DB. Now configure Django to access it: 
116 bbd4f788 Georgios Gousios
Copy the default configuration file 
117 bbd4f788 Georgios Gousios
118 bbd4f788 Georgios Gousios
    $ cp settings.py.dist settings.py
119 bbd4f788 Georgios Gousios
    
120 83d51c7b Georgios Gousios
and then copy/edit according to the database used:  
121 bbd4f788 Georgios Gousios
    
122 bbd4f788 Georgios Gousios
-SQLite
123 bbd4f788 Georgios Gousios
124 bbd4f788 Georgios Gousios
	PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + '/'
125 bbd4f788 Georgios Gousios
126 bbd4f788 Georgios Gousios
	DATABASES = {
127 bbd4f788 Georgios Gousios
	    'default': {
128 83d51c7b Georgios Gousios
		'ENGINE': 'django.db.backends.sqlite3',
129 83d51c7b Georgios Gousios
		'NAME': PROJECT_PATH + 'synnefo.db' #WARN: This must be an absolute path
130 bbd4f788 Georgios Gousios
	    }
131 bbd4f788 Georgios Gousios
	}
132 bbd4f788 Georgios Gousios
133 bbd4f788 Georgios Gousios
-MySQL
134 bbd4f788 Georgios Gousios
	DATABASES = {
135 bbd4f788 Georgios Gousios
	    'default': {
136 83d51c7b Georgios Gousios
		'ENGINE': 'django.db.backends.mysql', 
137 bbd4f788 Georgios Gousios
		'NAME': 'synnefo',
138 bbd4f788 Georgios Gousios
		'USER': 'USERNAME'
139 bbd4f788 Georgios Gousios
		'PASSWORD': 'PASSWORD',
140 bbd4f788 Georgios Gousios
		'HOST': 'HOST',
141 bbd4f788 Georgios Gousios
		'PORT': 'PORT',
142 bbd4f788 Georgios Gousios
		'OPTIONS': {
143 bbd4f788 Georgios Gousios
		    'init_command': 'SET storage_engine=INNODB',
144 bbd4f788 Georgios Gousios
		}
145 bbd4f788 Georgios Gousios
	    }
146 bbd4f788 Georgios Gousios
	}
147 bbd4f788 Georgios Gousios
148 bbd4f788 Georgios Gousios
-Postgres    
149 bbd4f788 Georgios Gousios
150 bbd4f788 Georgios Gousios
    DATABASES = {
151 bbd4f788 Georgios Gousios
	    'default': {
152 83d51c7b Georgios Gousios
		'ENGINE': 'django.db.backends.postgresql_psycopg2',
153 bbd4f788 Georgios Gousios
		'NAME': 'DATABASE',
154 bbd4f788 Georgios Gousios
		'USER': 'USERNAME',
155 bbd4f788 Georgios Gousios
		'PASSWORD': 'PASSWORD',
156 bbd4f788 Georgios Gousios
		'HOST': 'HOST',
157 bbd4f788 Georgios Gousios
		'PORT': 'PORT',
158 bbd4f788 Georgios Gousios
	    }
159 bbd4f788 Georgios Gousios
	}
160 bbd4f788 Georgios Gousios
161 83d51c7b Georgios Gousios
5. Try it out. The following command will attempt to connect to the DB and 
162 bbd4f788 Georgios Gousios
print out DDL statements. It should not fail.
163 bbd4f788 Georgios Gousios
164 bbd4f788 Georgios Gousios
	$ ./bin/python manage.py sql db
165 bbd4f788 Georgios Gousios
	
166 83d51c7b Georgios Gousios
6. Create the DB and (optionally) load test data
167 bbd4f788 Georgios Gousios
    
168 bbd4f788 Georgios Gousios
    $ ./bin/python manage.py syncdb
169 bbd4f788 Georgios Gousios
	$ ./bin/python manage.py loaddata db/fixtures/flavors.json
170 bbd4f788 Georgios Gousios
	$ ./bin/python manage.py loaddata db/fixtures/images.json
171 f5e590e4 Georgios Gousios
172 f5e590e4 Georgios Gousios
The following fictures can be loaded optionally depending on
173 f5e590e4 Georgios Gousios
testing requirements:
174 f5e590e4 Georgios Gousios
175 bbd4f788 Georgios Gousios
	$ ./bin/python manage.py loaddata db/fixtures/vms.json
176 f5e590e4 Georgios Gousios
	$ ./bin/python manage.py loaddata db/fixtures/initial_data.json
177 f5e590e4 Georgios Gousios
	$ ./bin/python manage.py loaddata db/fixtures/disks.json
178 83d51c7b Georgios Gousios
179 83d51c7b Georgios Gousios
7. Set the BACKEND_PREFIX_ID variable to some unique prefix, e.g. your commit
180 83d51c7b Georgios Gousios
username 
181 83d51c7b Georgios Gousios
182 83d51c7b Georgios Gousios
8. Start the system
183 f5e590e4 Georgios Gousios
    $ ./bin/python db/db_controller.py  #DB synch daemon
184 b8feb4ce Georgios Gousios
    $ ./bin/python manage.py runserver  #Django
185 f5e590e4 Georgios Gousios
186 f5e590e4 Georgios Gousios
9. (Hopefully) Done
187 bbd4f788 Georgios Gousios
188 bbd4f788 Georgios Gousios
UI Testing
189 bbd4f788 Georgios Gousios
----------
190 83d51c7b Georgios Gousios
The functional ui tests require the Selenium server and the synnefo app to 
191 83d51c7b Georgios Gousios
be running.
192 bbd4f788 Georgios Gousios
193 bbd4f788 Georgios Gousios
    $ wget http://selenium.googlecode.com/files/selenium-server-standalone-2.0b2.jar
194 bbd4f788 Georgios Gousios
    $ java -jar selenium-server-standalone-2.0b2.jar &
195 bbd4f788 Georgios Gousios
    $ ./bin/python manage.py runserver &
196 bbd4f788 Georgios Gousios
    $ ./bin/python manage.py test ui
197 bbd4f788 Georgios Gousios
198 bbd4f788 Georgios Gousios
Test coverage
199 bbd4f788 Georgios Gousios
-------------
200 bbd4f788 Georgios Gousios
201 bbd4f788 Georgios Gousios
In order to get code coverage reports you need to install django-test-coverage
202 bbd4f788 Georgios Gousios
   
203 bbd4f788 Georgios Gousios
   $ ./bin/pip install django-test-coverage
204 bbd4f788 Georgios Gousios
205 bbd4f788 Georgios Gousios
Then edit your settings.py and configure the test runner:
206 bbd4f788 Georgios Gousios
207 bbd4f788 Georgios Gousios
   TEST_RUNNER = 'django-test-coverage.runner.run_tests'