root / README.develop @ 9ad94f0a
History | View | Annotate | Download (7.6 kB)
1 |
DEVELOP.txt - Information on how to setup a development environment. |
---|---|
2 |
|
3 |
Dependencies |
4 |
------------ |
5 |
|
6 |
Synnefo is written in Python 2.6 and depends on the following Python modules |
7 |
[package versions confirmed to be compatible are in braces] |
8 |
|
9 |
- django 1.2 [Django==1.2.4] |
10 |
- simplejson [simplejson==2.1.3] |
11 |
- selenium [?] |
12 |
- pyzmq-static [pyzmq==2.0.10.1] |
13 |
- pycurl [pycurl==7.19.0] |
14 |
- python-dateutil [python-dateutil==1.4.1] |
15 |
WARNING: version python-dateutil==2.0 downloaded by pip known *not* to work with Python 2.6 |
16 |
- south [south==0.7.1] |
17 |
|
18 |
also, depending on the database engine of choice, on one of the following: |
19 |
- MySQL-python [MySQL-python==1.2.3] |
20 |
- psycopg2 [psycopg2==2.4] |
21 |
|
22 |
|
23 |
Preparing the development environment |
24 |
------------------------------------- |
25 |
|
26 |
1. Prepare the system |
27 |
The easiest method is to setup a working environment through virtualenv. |
28 |
Alternatively, you can use your system's package manager to install |
29 |
the dependencies (e.g. Macports has them all). |
30 |
|
31 |
*On Snow Leopard and linux (64-bit), you have to set the following environment variable for |
32 |
pip to compile the dependencies correctly. |
33 |
|
34 |
$export ARCHFLAGS="-arch x86_64" |
35 |
|
36 |
*On Ubuntu, a few more packages must be installed before installing the |
37 |
prerequisite Python libraries |
38 |
|
39 |
$sudo aptitude install libcurl3-gnutls libcurl3-gnutls-dev uuid-dev |
40 |
|
41 |
2. Checkout the code and install the Python prerequisites. This assumes |
42 |
that python is already installed on the host. |
43 |
|
44 |
$ sudo easy_install virtualenv |
45 |
$ git clone https://user@code.grnet.gr/git/synnefo synnefo |
46 |
$ virtualenv --python=python2.6 synnefo --no-site-packages |
47 |
... |
48 |
$ cd synnefo |
49 |
$ ./bin/pip install <list_of_prerequisites> |
50 |
|
51 |
3. At this point you should have all required dependencies installed. Now you |
52 |
have to select a database engine. The choices are: postgres, mysql and sqlite. |
53 |
|
54 |
-SQLite |
55 |
The python sqlite driver is available by default with Python so no additional |
56 |
configuration is required. Also, most self-respecting systems have the sqlite |
57 |
library installed by default. |
58 |
|
59 |
-MySQL |
60 |
MySQL must be installed first |
61 |
|
62 |
*Ubuntu - Debian |
63 |
$sudo apt-get install libmysqlclient-dev |
64 |
|
65 |
*MacPorts |
66 |
$sudo port install mysql5 |
67 |
|
68 |
Install the MySQL python library |
69 |
|
70 |
$ bin/pip install MySQL-python |
71 |
|
72 |
Note: On MacOSX with Mysql install from MacPorts the above command will fail |
73 |
complaining that it cannot find the mysql_config command. Do the following and |
74 |
restart the installation |
75 |
|
76 |
$ echo "mysql_config = /opt/local/bin/mysql_config5" >> ./build/MySQL-python/site.cfg |
77 |
|
78 |
Configure a MySQL db/account for synnefo |
79 |
|
80 |
$ mysql -u root -p |
81 |
|
82 |
mysql> create database synnefo; |
83 |
mysql> show databases; |
84 |
mysql> GRANT ALL on synnefo.* TO username IDENTIFIED BY 'password'; |
85 |
|
86 |
-Postgres |
87 |
|
88 |
#Ubuntu - Debian |
89 |
$ sudo apt-get install postgresql-8.4 libpq-dev |
90 |
|
91 |
#MacPorts |
92 |
$ sudo port install postgresql84 |
93 |
|
94 |
Install the postgres Python library |
95 |
|
96 |
$ bin/pip install psycopg2 |
97 |
|
98 |
Configure a postgres db/account for synnefo |
99 |
Become the postgres user, connect to PostgreSQL: |
100 |
$ sudo su - postgres |
101 |
$ psql |
102 |
|
103 |
Run the following commands: |
104 |
DROP DATABASE synnefo; |
105 |
DROP USER username; |
106 |
CREATE USER username WITH PASSWORD 'password'; |
107 |
CREATE DATABASE synnefo; |
108 |
GRANT ALL PRIVILEGES ON DATABASE synnefo TO username; |
109 |
ALTER DATABASE synnefo OWNER TO username; |
110 |
ALTER USER username CREATEDB; |
111 |
|
112 |
The last line enables the newly created user to create own databases. This is |
113 |
needed for Django to create and drop the test_synnefo database for unit |
114 |
testing. |
115 |
|
116 |
4. At this point you should have a working DB. Now configure Django to access it: |
117 |
Copy the default configuration file |
118 |
|
119 |
$ cp settings.py.dist settings.py |
120 |
|
121 |
and then copy/edit according to the database used: |
122 |
|
123 |
-SQLite |
124 |
|
125 |
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + '/' |
126 |
|
127 |
DATABASES = { |
128 |
'default': { |
129 |
'ENGINE': 'django.db.backends.sqlite3', |
130 |
'NAME': PROJECT_PATH + 'synnefo.db' #WARN: This must be an absolute path |
131 |
} |
132 |
} |
133 |
|
134 |
-MySQL |
135 |
DATABASES = { |
136 |
'default': { |
137 |
'ENGINE': 'django.db.backends.mysql', |
138 |
'NAME': 'synnefo', |
139 |
'USER': 'USERNAME' |
140 |
'PASSWORD': 'PASSWORD', |
141 |
'HOST': 'HOST', |
142 |
'PORT': 'PORT', |
143 |
'OPTIONS': { |
144 |
'init_command': 'SET storage_engine=INNODB', |
145 |
} |
146 |
} |
147 |
} |
148 |
|
149 |
-Postgres |
150 |
|
151 |
DATABASES = { |
152 |
'default': { |
153 |
'ENGINE': 'django.db.backends.postgresql_psycopg2', |
154 |
'NAME': 'DATABASE', |
155 |
'USER': 'USERNAME', |
156 |
'PASSWORD': 'PASSWORD', |
157 |
'HOST': 'HOST', |
158 |
'PORT': 'PORT', |
159 |
} |
160 |
} |
161 |
|
162 |
5. Try it out. The following command will attempt to connect to the DB and |
163 |
print out DDL statements. It should not fail. |
164 |
|
165 |
$ ./bin/python manage.py sql db |
166 |
|
167 |
6. Create the DB and (optionally) load test data |
168 |
|
169 |
$ ./bin/python manage.py syncdb |
170 |
$ ./bin/python manage.py loaddata db/fixtures/flavors.json |
171 |
$ ./bin/python manage.py loaddata db/fixtures/images.json |
172 |
|
173 |
The following fictures can be loaded optionally depending on |
174 |
testing requirements: |
175 |
|
176 |
$ ./bin/python manage.py loaddata db/fixtures/vms.json |
177 |
$ ./bin/python manage.py loaddata db/fixtures/initial_data.json |
178 |
$ ./bin/python manage.py loaddata db/fixtures/disks.json |
179 |
|
180 |
7. Set the BACKEND_PREFIX_ID variable to some unique prefix, e.g. your commit |
181 |
username |
182 |
|
183 |
8. Start the system |
184 |
$ ./bin/python db/db_controller.py #DB synch daemon |
185 |
$ ./bin/python manage.py runserver #Django |
186 |
|
187 |
9. (Hopefully) Done |
188 |
|
189 |
South Database Migration |
190 |
------------------------ |
191 |
|
192 |
First, remember to add the south app to settings.py (it is already included in the |
193 |
settings.py.dist). |
194 |
|
195 |
In addition, do not use the syncdb management command. Only the first time |
196 |
|
197 |
The first time (is not required, since when you read this documentation the migration |
198 |
is already active) the migration of the schema will initialised with the following |
199 |
command: |
200 |
|
201 |
$ ./bin/python schemamigration db --initial |
202 |
|
203 |
Each time you make changes to the database and data migration is not required (WARNING: always |
204 |
perform this with extreme care): |
205 |
|
206 |
$ ./bin/python schemamigration db --auto |
207 |
|
208 |
The above will create the migration script. Now this must be applied to the live database. |
209 |
|
210 |
$ ./bin/python migrate db |
211 |
|
212 |
Consider this example (adding a field to the SynnefoUser model): |
213 |
|
214 |
bkarak@nefarian:~/devel/synnefo$ ./bin/python manage.py schemamigration db --auto |
215 |
+ Added field new_south_test_field on db.SynnefoUser |
216 |
Created 0002_auto__add_field_synnefouser_new_south_test_field.py. You can now apply this migration with: ./manage.py migrate db |
217 |
bkarak@nefarian:~/devel/synnefo$ ./manage.py migrate db |
218 |
Running migrations for db: |
219 |
- Migrating forwards to 0002_auto__add_field_synnefouser_new_south_test_field. |
220 |
> db:0002_auto__add_field_synnefouser_new_south_test_field |
221 |
- Loading initial data for db. |
222 |
Installing json fixture 'initial_data' from '/home/bkarak/devel/synnefo/../synnefo/db/fixtures'. |
223 |
Installed 1 object(s) from 1 fixture(s) |
224 |
|
225 |
South needs some extra definitions to the model to preserve and migrate the existing data, for example, if we add a field |
226 |
in a model, we should declare its default value. If not, south management will propably fail, after indicating the error. |
227 |
|
228 |
If we need to do data migration as well, for example rename a field, we use tha 'datamigration' management command. |
229 |
|
230 |
UI Testing |
231 |
---------- |
232 |
The functional ui tests require the Selenium server and the synnefo app to |
233 |
be running. |
234 |
|
235 |
$ wget http://selenium.googlecode.com/files/selenium-server-standalone-2.0b2.jar |
236 |
$ java -jar selenium-server-standalone-2.0b2.jar & |
237 |
$ ./bin/python manage.py runserver & |
238 |
$ ./bin/python manage.py test ui |
239 |
|
240 |
Test coverage |
241 |
------------- |
242 |
|
243 |
In order to get code coverage reports you need to install django-test-coverage |
244 |
|
245 |
$ ./bin/pip install django-test-coverage |
246 |
|
247 |
Then edit your settings.py and configure the test runner: |
248 |
|
249 |
TEST_RUNNER = 'django-test-coverage.runner.run_tests' |