Statistics
| Branch: | Tag: | Revision:

root / README.develop @ 432fc8c3

History | View | Annotate | Download (5.7 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

    
17
also, depending on the database engine of choice, on one of the following:
18
- MySQL-python [MySQL-python==1.2.3]
19
- psycopg2 [psycopg2==2.4]
20

    
21

    
22
Preparing the development environment
23
-------------------------------------
24

    
25
1. Prepare the system 
26
The easiest method is to setup a working environment through virtualenv. 
27
Alternatively, you can use your system's package manager to install
28
the dependencies (e.g. Macports has them all).
29

    
30
*On Snow Leopard, you have to set the following environment variable for
31
pip to compile the dependencies correctly. 
32

    
33
	$export ARCHFLAGS="-arch x86_64"
34

    
35
*On Ubuntu, a few more packages must be installed before installing the
36
prerequisite Python libraries
37

    
38
	$sudo aptitude install libcurl3-gnutls libcurl3-gnutls-dev uuid-dev 
39

    
40
2. Checkout the code and install the Python prerequisites. This assumes
41
that python is already installed on the host.
42

    
43
    $ sudo easy_install virtualenv
44
    $ git clone https://user@code.grnet.gr/git/synnefo synnefo
45
    $ virtualenv --python=python2.6 synnefo --no-site-packages
46
    ...
47
    $ cd synnefo
48
    $ ./bin/pip install <list_of_prerequisites>
49

    
50
3. At this point you should have all required dependencies installed. Now you
51
have to select a database engine. The choices are: postgres, mysql and sqlite.
52

    
53
-SQLite
54
The python sqlite driver is available by default with Python so no additional 
55
configuration is required. Also, most self-respecting systems have the sqlite 
56
library installed by default.   
57

    
58
-MySQL
59
MySQL must be installed first
60

    
61
*Ubuntu - Debian
62
	$sudo apt-get install libmysqlclient-dev
63

    
64
*MacPorts
65
	$sudo port install mysql5
66

    
67
Install the MySQL python library
68

    
69
	$ bin/pip install MySQL-python
70

    
71
Note: On MacOSX with Mysql install from MacPorts the above command will fail
72
complaining that it cannot find the mysql_config command. Do the following and
73
restart the installation
74

    
75
	$ echo "mysql_config = /opt/local/bin/mysql_config5" >> ./build/MySQL-python/site.cfg
76

    
77
Configure a MySQL db/account for synnefo
78

    
79
	$ mysql -u root -p
80

    
81
	mysql> create database synnefo;
82
	mysql> show databases;
83
	mysql> GRANT ALL on synnefo.* TO username IDENTIFIED BY 'password';
84
 
85
-Postgres
86

    
87
#Ubuntu - Debian
88
	$ sudo apt-get install postgresql-8.4 libpq-dev
89

    
90
#MacPorts
91
	$ sudo port install postgresql84
92

    
93
Install the postgres Python library
94

    
95
	$ bin/pip install psycopg2
96

    
97
Configure a postgres db/account for synnefo
98
	Become the postgres user, connect to PostgreSQL:
99
	$ sudo su - postgres 
100
	$ psql
101
	
102
	Run the following commands:
103
	DROP DATABASE synnefo;
104
	DROP USER username;
105
	CREATE USER username WITH PASSWORD 'password';
106
	CREATE DATABASE synnefo;
107
	GRANT ALL PRIVILEGES ON DATABASE synnefo TO username;
108
	ALTER DATABASE synnefo OWNER TO username;
109
	ALTER USER username CREATEDB;
110

    
111
The last line enables the newly created user to create own databases. This is
112
needed for Django to create and drop the test_synnefo database for unit
113
testing.
114
	
115
4. At this point you should have a working DB. Now configure Django to access it: 
116
Copy the default configuration file 
117

    
118
    $ cp settings.py.dist settings.py
119
    
120
and then copy/edit according to the database used:  
121
    
122
-SQLite
123

    
124
	PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + '/'
125

    
126
	DATABASES = {
127
	    'default': {
128
		'ENGINE': 'django.db.backends.sqlite3',
129
		'NAME': PROJECT_PATH + 'synnefo.db' #WARN: This must be an absolute path
130
	    }
131
	}
132

    
133
-MySQL
134
	DATABASES = {
135
	    'default': {
136
		'ENGINE': 'django.db.backends.mysql', 
137
		'NAME': 'synnefo',
138
		'USER': 'USERNAME'
139
		'PASSWORD': 'PASSWORD',
140
		'HOST': 'HOST',
141
		'PORT': 'PORT',
142
		'OPTIONS': {
143
		    'init_command': 'SET storage_engine=INNODB',
144
		}
145
	    }
146
	}
147

    
148
-Postgres    
149

    
150
    DATABASES = {
151
	    'default': {
152
		'ENGINE': 'django.db.backends.postgresql_psycopg2',
153
		'NAME': 'DATABASE',
154
		'USER': 'USERNAME',
155
		'PASSWORD': 'PASSWORD',
156
		'HOST': 'HOST',
157
		'PORT': 'PORT',
158
	    }
159
	}
160

    
161
5. Try it out. The following command will attempt to connect to the DB and 
162
print out DDL statements. It should not fail.
163

    
164
	$ ./bin/python manage.py sql db
165
	
166
6. Create the DB and (optionally) load test data
167
    
168
    $ ./bin/python manage.py syncdb
169
	$ ./bin/python manage.py loaddata db/fixtures/flavors.json
170
	$ ./bin/python manage.py loaddata db/fixtures/images.json
171

    
172
The following fictures can be loaded optionally depending on
173
testing requirements:
174

    
175
	$ ./bin/python manage.py loaddata db/fixtures/vms.json
176
	$ ./bin/python manage.py loaddata db/fixtures/initial_data.json
177
	$ ./bin/python manage.py loaddata db/fixtures/disks.json
178

    
179
7. Set the BACKEND_PREFIX_ID variable to some unique prefix, e.g. your commit
180
username 
181

    
182
8. Start the system
183
    $ ./bin/python db/db_controller.py  #DB synch daemon
184
    $ ./bin/python manage.py runserver  #Django
185

    
186
9. (Hopefully) Done
187

    
188
UI Testing
189
----------
190
The functional ui tests require the Selenium server and the synnefo app to 
191
be running.
192

    
193
    $ wget http://selenium.googlecode.com/files/selenium-server-standalone-2.0b2.jar
194
    $ java -jar selenium-server-standalone-2.0b2.jar &
195
    $ ./bin/python manage.py runserver &
196
    $ ./bin/python manage.py test ui
197

    
198
Test coverage
199
-------------
200

    
201
In order to get code coverage reports you need to install django-test-coverage
202
   
203
   $ ./bin/pip install django-test-coverage
204

    
205
Then edit your settings.py and configure the test runner:
206

    
207
   TEST_RUNNER = 'django-test-coverage.runner.run_tests'