Revision e6f3e652
b/.gitignore | ||
---|---|---|
25 | 25 |
*/synnefo/versions/*.py |
26 | 26 |
!*/synnefo/versions/__init__.py |
27 | 27 |
snf-tools/synnefo_tools/version.py |
28 |
|
|
28 |
snf-quotaholder-app/quotaholder_django/version.py |
|
29 | 29 |
*.iml |
30 | 30 |
*.graffle |
b/snf-quotaholder-app/MANIFEST.in | ||
---|---|---|
1 |
include README Changelog |
|
2 |
include distribute_setup.py |
|
3 |
recursive-include quotaholder_django/quotaholder_app/fixtures *.json |
b/snf-quotaholder-app/distribute_setup.py | ||
---|---|---|
1 |
#!python |
|
2 |
"""Bootstrap distribute installation |
|
3 |
|
|
4 |
If you want to use setuptools in your package's setup.py, just include this |
|
5 |
file in the same directory with it, and add this to the top of your setup.py:: |
|
6 |
|
|
7 |
from distribute_setup import use_setuptools |
|
8 |
use_setuptools() |
|
9 |
|
|
10 |
If you want to require a specific version of setuptools, set a download |
|
11 |
mirror, or use an alternate download directory, you can do so by supplying |
|
12 |
the appropriate options to ``use_setuptools()``. |
|
13 |
|
|
14 |
This file can also be run as a script to install or upgrade setuptools. |
|
15 |
""" |
|
16 |
import os |
|
17 |
import sys |
|
18 |
import time |
|
19 |
import fnmatch |
|
20 |
import tempfile |
|
21 |
import tarfile |
|
22 |
from distutils import log |
|
23 |
|
|
24 |
try: |
|
25 |
from site import USER_SITE |
|
26 |
except ImportError: |
|
27 |
USER_SITE = None |
|
28 |
|
|
29 |
try: |
|
30 |
import subprocess |
|
31 |
|
|
32 |
def _python_cmd(*args): |
|
33 |
args = (sys.executable,) + args |
|
34 |
return subprocess.call(args) == 0 |
|
35 |
|
|
36 |
except ImportError: |
|
37 |
# will be used for python 2.3 |
|
38 |
def _python_cmd(*args): |
|
39 |
args = (sys.executable,) + args |
|
40 |
# quoting arguments if windows |
|
41 |
if sys.platform == 'win32': |
|
42 |
def quote(arg): |
|
43 |
if ' ' in arg: |
|
44 |
return '"%s"' % arg |
|
45 |
return arg |
|
46 |
args = [quote(arg) for arg in args] |
|
47 |
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 |
|
48 |
|
|
49 |
DEFAULT_VERSION = "0.6.10" |
|
50 |
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" |
|
51 |
SETUPTOOLS_FAKED_VERSION = "0.6c11" |
|
52 |
|
|
53 |
SETUPTOOLS_PKG_INFO = """\ |
|
54 |
Metadata-Version: 1.0 |
|
55 |
Name: setuptools |
|
56 |
Version: %s |
|
57 |
Summary: xxxx |
|
58 |
Home-page: xxx |
|
59 |
Author: xxx |
|
60 |
Author-email: xxx |
|
61 |
License: xxx |
|
62 |
Description: xxx |
|
63 |
""" % SETUPTOOLS_FAKED_VERSION |
|
64 |
|
|
65 |
|
|
66 |
def _install(tarball): |
|
67 |
# extracting the tarball |
|
68 |
tmpdir = tempfile.mkdtemp() |
|
69 |
log.warn('Extracting in %s', tmpdir) |
|
70 |
old_wd = os.getcwd() |
|
71 |
try: |
|
72 |
os.chdir(tmpdir) |
|
73 |
tar = tarfile.open(tarball) |
|
74 |
_extractall(tar) |
|
75 |
tar.close() |
|
76 |
|
|
77 |
# going in the directory |
|
78 |
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) |
|
79 |
os.chdir(subdir) |
|
80 |
log.warn('Now working in %s', subdir) |
|
81 |
|
|
82 |
# installing |
|
83 |
log.warn('Installing Distribute') |
|
84 |
if not _python_cmd('setup.py', 'install'): |
|
85 |
log.warn('Something went wrong during the installation.') |
|
86 |
log.warn('See the error message above.') |
|
87 |
finally: |
|
88 |
os.chdir(old_wd) |
|
89 |
|
|
90 |
|
|
91 |
def _build_egg(egg, tarball, to_dir): |
|
92 |
# extracting the tarball |
|
93 |
tmpdir = tempfile.mkdtemp() |
|
94 |
log.warn('Extracting in %s', tmpdir) |
|
95 |
old_wd = os.getcwd() |
|
96 |
try: |
|
97 |
os.chdir(tmpdir) |
|
98 |
tar = tarfile.open(tarball) |
|
99 |
_extractall(tar) |
|
100 |
tar.close() |
|
101 |
|
|
102 |
# going in the directory |
|
103 |
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) |
|
104 |
os.chdir(subdir) |
|
105 |
log.warn('Now working in %s', subdir) |
|
106 |
|
|
107 |
# building an egg |
|
108 |
log.warn('Building a Distribute egg in %s', to_dir) |
|
109 |
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) |
|
110 |
|
|
111 |
finally: |
|
112 |
os.chdir(old_wd) |
|
113 |
# returning the result |
|
114 |
log.warn(egg) |
|
115 |
if not os.path.exists(egg): |
|
116 |
raise IOError('Could not build the egg.') |
|
117 |
|
|
118 |
|
|
119 |
def _do_download(version, download_base, to_dir, download_delay): |
|
120 |
egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' |
|
121 |
% (version, sys.version_info[0], sys.version_info[1])) |
|
122 |
if not os.path.exists(egg): |
|
123 |
tarball = download_setuptools(version, download_base, |
|
124 |
to_dir, download_delay) |
|
125 |
_build_egg(egg, tarball, to_dir) |
|
126 |
sys.path.insert(0, egg) |
|
127 |
import setuptools |
|
128 |
setuptools.bootstrap_install_from = egg |
|
129 |
|
|
130 |
|
|
131 |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
|
132 |
to_dir=os.curdir, download_delay=15, no_fake=True): |
|
133 |
# making sure we use the absolute path |
|
134 |
to_dir = os.path.abspath(to_dir) |
|
135 |
was_imported = 'pkg_resources' in sys.modules or \ |
|
136 |
'setuptools' in sys.modules |
|
137 |
try: |
|
138 |
try: |
|
139 |
import pkg_resources |
|
140 |
if not hasattr(pkg_resources, '_distribute'): |
|
141 |
if not no_fake: |
|
142 |
_fake_setuptools() |
|
143 |
raise ImportError |
|
144 |
except ImportError: |
|
145 |
return _do_download(version, download_base, to_dir, download_delay) |
|
146 |
try: |
|
147 |
pkg_resources.require("distribute>="+version) |
|
148 |
return |
|
149 |
except pkg_resources.VersionConflict: |
|
150 |
e = sys.exc_info()[1] |
|
151 |
if was_imported: |
|
152 |
sys.stderr.write( |
|
153 |
"The required version of distribute (>=%s) is not available,\n" |
|
154 |
"and can't be installed while this script is running. Please\n" |
|
155 |
"install a more recent version first, using\n" |
|
156 |
"'easy_install -U distribute'." |
|
157 |
"\n\n(Currently using %r)\n" % (version, e.args[0])) |
|
158 |
sys.exit(2) |
|
159 |
else: |
|
160 |
del pkg_resources, sys.modules['pkg_resources'] # reload ok |
|
161 |
return _do_download(version, download_base, to_dir, |
|
162 |
download_delay) |
|
163 |
except pkg_resources.DistributionNotFound: |
|
164 |
return _do_download(version, download_base, to_dir, |
|
165 |
download_delay) |
|
166 |
finally: |
|
167 |
if not no_fake: |
|
168 |
_create_fake_setuptools_pkg_info(to_dir) |
|
169 |
|
|
170 |
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
|
171 |
to_dir=os.curdir, delay=15): |
|
172 |
"""Download distribute from a specified location and return its filename |
|
173 |
|
|
174 |
`version` should be a valid distribute version number that is available |
|
175 |
as an egg for download under the `download_base` URL (which should end |
|
176 |
with a '/'). `to_dir` is the directory where the egg will be downloaded. |
|
177 |
`delay` is the number of seconds to pause before an actual download |
|
178 |
attempt. |
|
179 |
""" |
|
180 |
# making sure we use the absolute path |
|
181 |
to_dir = os.path.abspath(to_dir) |
|
182 |
try: |
|
183 |
from urllib.request import urlopen |
|
184 |
except ImportError: |
|
185 |
from urllib2 import urlopen |
|
186 |
tgz_name = "distribute-%s.tar.gz" % version |
|
187 |
url = download_base + tgz_name |
|
188 |
saveto = os.path.join(to_dir, tgz_name) |
|
189 |
src = dst = None |
|
190 |
if not os.path.exists(saveto): # Avoid repeated downloads |
|
191 |
try: |
|
192 |
log.warn("Downloading %s", url) |
|
193 |
src = urlopen(url) |
|
194 |
# Read/write all in one block, so we don't create a corrupt file |
|
195 |
# if the download is interrupted. |
|
196 |
data = src.read() |
|
197 |
dst = open(saveto, "wb") |
|
198 |
dst.write(data) |
|
199 |
finally: |
|
200 |
if src: |
|
201 |
src.close() |
|
202 |
if dst: |
|
203 |
dst.close() |
|
204 |
return os.path.realpath(saveto) |
|
205 |
|
|
206 |
def _no_sandbox(function): |
|
207 |
def __no_sandbox(*args, **kw): |
|
208 |
try: |
|
209 |
from setuptools.sandbox import DirectorySandbox |
|
210 |
if not hasattr(DirectorySandbox, '_old'): |
|
211 |
def violation(*args): |
|
212 |
pass |
|
213 |
DirectorySandbox._old = DirectorySandbox._violation |
|
214 |
DirectorySandbox._violation = violation |
|
215 |
patched = True |
|
216 |
else: |
|
217 |
patched = False |
|
218 |
except ImportError: |
|
219 |
patched = False |
|
220 |
|
|
221 |
try: |
|
222 |
return function(*args, **kw) |
|
223 |
finally: |
|
224 |
if patched: |
|
225 |
DirectorySandbox._violation = DirectorySandbox._old |
|
226 |
del DirectorySandbox._old |
|
227 |
|
|
228 |
return __no_sandbox |
|
229 |
|
|
230 |
def _patch_file(path, content): |
|
231 |
"""Will backup the file then patch it""" |
|
232 |
existing_content = open(path).read() |
|
233 |
if existing_content == content: |
|
234 |
# already patched |
|
235 |
log.warn('Already patched.') |
|
236 |
return False |
|
237 |
log.warn('Patching...') |
|
238 |
_rename_path(path) |
|
239 |
f = open(path, 'w') |
|
240 |
try: |
|
241 |
f.write(content) |
|
242 |
finally: |
|
243 |
f.close() |
|
244 |
return True |
|
245 |
|
|
246 |
_patch_file = _no_sandbox(_patch_file) |
|
247 |
|
|
248 |
def _same_content(path, content): |
|
249 |
return open(path).read() == content |
|
250 |
|
|
251 |
def _rename_path(path): |
|
252 |
new_name = path + '.OLD.%s' % time.time() |
|
253 |
log.warn('Renaming %s into %s', path, new_name) |
|
254 |
os.rename(path, new_name) |
|
255 |
return new_name |
|
256 |
|
|
257 |
def _remove_flat_installation(placeholder): |
|
258 |
if not os.path.isdir(placeholder): |
|
259 |
log.warn('Unkown installation at %s', placeholder) |
|
260 |
return False |
|
261 |
found = False |
|
262 |
for file in os.listdir(placeholder): |
|
263 |
if fnmatch.fnmatch(file, 'setuptools*.egg-info'): |
|
264 |
found = True |
|
265 |
break |
|
266 |
if not found: |
|
267 |
log.warn('Could not locate setuptools*.egg-info') |
|
268 |
return |
|
269 |
|
|
270 |
log.warn('Removing elements out of the way...') |
|
271 |
pkg_info = os.path.join(placeholder, file) |
|
272 |
if os.path.isdir(pkg_info): |
|
273 |
patched = _patch_egg_dir(pkg_info) |
|
274 |
else: |
|
275 |
patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) |
|
276 |
|
|
277 |
if not patched: |
|
278 |
log.warn('%s already patched.', pkg_info) |
|
279 |
return False |
|
280 |
# now let's move the files out of the way |
|
281 |
for element in ('setuptools', 'pkg_resources.py', 'site.py'): |
|
282 |
element = os.path.join(placeholder, element) |
|
283 |
if os.path.exists(element): |
|
284 |
_rename_path(element) |
|
285 |
else: |
|
286 |
log.warn('Could not find the %s element of the ' |
|
287 |
'Setuptools distribution', element) |
|
288 |
return True |
|
289 |
|
|
290 |
_remove_flat_installation = _no_sandbox(_remove_flat_installation) |
|
291 |
|
|
292 |
def _after_install(dist): |
|
293 |
log.warn('After install bootstrap.') |
|
294 |
placeholder = dist.get_command_obj('install').install_purelib |
|
295 |
_create_fake_setuptools_pkg_info(placeholder) |
|
296 |
|
|
297 |
def _create_fake_setuptools_pkg_info(placeholder): |
|
298 |
if not placeholder or not os.path.exists(placeholder): |
|
299 |
log.warn('Could not find the install location') |
|
300 |
return |
|
301 |
pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) |
|
302 |
setuptools_file = 'setuptools-%s-py%s.egg-info' % \ |
|
303 |
(SETUPTOOLS_FAKED_VERSION, pyver) |
|
304 |
pkg_info = os.path.join(placeholder, setuptools_file) |
|
305 |
if os.path.exists(pkg_info): |
|
306 |
log.warn('%s already exists', pkg_info) |
|
307 |
return |
|
308 |
|
|
309 |
log.warn('Creating %s', pkg_info) |
|
310 |
f = open(pkg_info, 'w') |
|
311 |
try: |
|
312 |
f.write(SETUPTOOLS_PKG_INFO) |
|
313 |
finally: |
|
314 |
f.close() |
|
315 |
|
|
316 |
pth_file = os.path.join(placeholder, 'setuptools.pth') |
|
317 |
log.warn('Creating %s', pth_file) |
|
318 |
f = open(pth_file, 'w') |
|
319 |
try: |
|
320 |
f.write(os.path.join(os.curdir, setuptools_file)) |
|
321 |
finally: |
|
322 |
f.close() |
|
323 |
|
|
324 |
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) |
|
325 |
|
|
326 |
def _patch_egg_dir(path): |
|
327 |
# let's check if it's already patched |
|
328 |
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') |
|
329 |
if os.path.exists(pkg_info): |
|
330 |
if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): |
|
331 |
log.warn('%s already patched.', pkg_info) |
|
332 |
return False |
|
333 |
_rename_path(path) |
|
334 |
os.mkdir(path) |
|
335 |
os.mkdir(os.path.join(path, 'EGG-INFO')) |
|
336 |
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') |
|
337 |
f = open(pkg_info, 'w') |
|
338 |
try: |
|
339 |
f.write(SETUPTOOLS_PKG_INFO) |
|
340 |
finally: |
|
341 |
f.close() |
|
342 |
return True |
|
343 |
|
|
344 |
_patch_egg_dir = _no_sandbox(_patch_egg_dir) |
|
345 |
|
|
346 |
def _before_install(): |
|
347 |
log.warn('Before install bootstrap.') |
|
348 |
_fake_setuptools() |
|
349 |
|
|
350 |
|
|
351 |
def _under_prefix(location): |
|
352 |
if 'install' not in sys.argv: |
|
353 |
return True |
|
354 |
args = sys.argv[sys.argv.index('install')+1:] |
|
355 |
for index, arg in enumerate(args): |
|
356 |
for option in ('--root', '--prefix'): |
|
357 |
if arg.startswith('%s=' % option): |
|
358 |
top_dir = arg.split('root=')[-1] |
|
359 |
return location.startswith(top_dir) |
|
360 |
elif arg == option: |
|
361 |
if len(args) > index: |
|
362 |
top_dir = args[index+1] |
|
363 |
return location.startswith(top_dir) |
|
364 |
if arg == '--user' and USER_SITE is not None: |
|
365 |
return location.startswith(USER_SITE) |
|
366 |
return True |
|
367 |
|
|
368 |
|
|
369 |
def _fake_setuptools(): |
|
370 |
log.warn('Scanning installed packages') |
|
371 |
try: |
|
372 |
import pkg_resources |
|
373 |
except ImportError: |
|
374 |
# we're cool |
|
375 |
log.warn('Setuptools or Distribute does not seem to be installed.') |
|
376 |
return |
|
377 |
ws = pkg_resources.working_set |
|
378 |
try: |
|
379 |
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', |
|
380 |
replacement=False)) |
|
381 |
except TypeError: |
|
382 |
# old distribute API |
|
383 |
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) |
|
384 |
|
|
385 |
if setuptools_dist is None: |
|
386 |
log.warn('No setuptools distribution found') |
|
387 |
return |
|
388 |
# detecting if it was already faked |
|
389 |
setuptools_location = setuptools_dist.location |
|
390 |
log.warn('Setuptools installation detected at %s', setuptools_location) |
|
391 |
|
|
392 |
# if --root or --preix was provided, and if |
|
393 |
# setuptools is not located in them, we don't patch it |
|
394 |
if not _under_prefix(setuptools_location): |
|
395 |
log.warn('Not patching, --root or --prefix is installing Distribute' |
|
396 |
' in another location') |
|
397 |
return |
|
398 |
|
|
399 |
# let's see if its an egg |
|
400 |
if not setuptools_location.endswith('.egg'): |
|
401 |
log.warn('Non-egg installation') |
|
402 |
res = _remove_flat_installation(setuptools_location) |
|
403 |
if not res: |
|
404 |
return |
|
405 |
else: |
|
406 |
log.warn('Egg installation') |
|
407 |
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') |
|
408 |
if (os.path.exists(pkg_info) and |
|
409 |
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)): |
|
410 |
log.warn('Already patched.') |
|
411 |
return |
|
412 |
log.warn('Patching...') |
|
413 |
# let's create a fake egg replacing setuptools one |
|
414 |
res = _patch_egg_dir(setuptools_location) |
|
415 |
if not res: |
|
416 |
return |
|
417 |
log.warn('Patched done.') |
|
418 |
_relaunch() |
|
419 |
|
|
420 |
|
|
421 |
def _relaunch(): |
|
422 |
log.warn('Relaunching...') |
|
423 |
# we have to relaunch the process |
|
424 |
# pip marker to avoid a relaunch bug |
|
425 |
if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']: |
|
426 |
sys.argv[0] = 'setup.py' |
|
427 |
args = [sys.executable] + sys.argv |
|
428 |
sys.exit(subprocess.call(args)) |
|
429 |
|
|
430 |
|
|
431 |
def _extractall(self, path=".", members=None): |
|
432 |
"""Extract all members from the archive to the current working |
|
433 |
directory and set owner, modification time and permissions on |
|
434 |
directories afterwards. `path' specifies a different directory |
|
435 |
to extract to. `members' is optional and must be a subset of the |
|
436 |
list returned by getmembers(). |
|
437 |
""" |
|
438 |
import copy |
|
439 |
import operator |
|
440 |
from tarfile import ExtractError |
|
441 |
directories = [] |
|
442 |
|
|
443 |
if members is None: |
|
444 |
members = self |
|
445 |
|
|
446 |
for tarinfo in members: |
|
447 |
if tarinfo.isdir(): |
|
448 |
# Extract directories with a safe mode. |
|
449 |
directories.append(tarinfo) |
|
450 |
tarinfo = copy.copy(tarinfo) |
|
451 |
tarinfo.mode = 448 # decimal for oct 0700 |
|
452 |
self.extract(tarinfo, path) |
|
453 |
|
|
454 |
# Reverse sort directories. |
|
455 |
if sys.version_info < (2, 4): |
|
456 |
def sorter(dir1, dir2): |
|
457 |
return cmp(dir1.name, dir2.name) |
|
458 |
directories.sort(sorter) |
|
459 |
directories.reverse() |
|
460 |
else: |
|
461 |
directories.sort(key=operator.attrgetter('name'), reverse=True) |
|
462 |
|
|
463 |
# Set correct owner, mtime and filemode on directories. |
|
464 |
for tarinfo in directories: |
|
465 |
dirpath = os.path.join(path, tarinfo.name) |
|
466 |
try: |
|
467 |
self.chown(tarinfo, dirpath) |
|
468 |
self.utime(tarinfo, dirpath) |
|
469 |
self.chmod(tarinfo, dirpath) |
|
470 |
except ExtractError: |
|
471 |
e = sys.exc_info()[1] |
|
472 |
if self.errorlevel > 1: |
|
473 |
raise |
|
474 |
else: |
|
475 |
self._dbg(1, "tarfile: %s" % e) |
|
476 |
|
|
477 |
|
|
478 |
def main(argv, version=DEFAULT_VERSION): |
|
479 |
"""Install or upgrade setuptools and EasyInstall""" |
|
480 |
tarball = download_setuptools() |
|
481 |
_install(tarball) |
|
482 |
|
|
483 |
|
|
484 |
if __name__ == '__main__': |
|
485 |
main(sys.argv[1:]) |
b/snf-quotaholder-app/quotaholder_django/synnefo_settings.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
apps = ['south', 'quotaholder_django'] |
b/snf-quotaholder-app/quotaholder_django/test/__init__.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
# placeholder |
b/snf-quotaholder-app/quotaholder_django/test/__main__.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from sys import argv,executable |
|
35 |
from os.path import dirname |
|
36 |
from config import run_test_cases |
|
37 |
from config import printf |
|
38 |
from limits import LimitsTest |
|
39 |
from createrelease import CreateReleaseListAPITest |
|
40 |
|
|
41 |
HERE = dirname(__file__) |
|
42 |
|
|
43 |
# Enumerate all test cases to run. |
|
44 |
# In the command line use |
|
45 |
# $ python test |
|
46 |
# to run them all |
|
47 |
|
|
48 |
all_cases = [ |
|
49 |
CreateReleaseListAPITest, |
|
50 |
LimitsTest |
|
51 |
] |
|
52 |
|
|
53 |
printf("=======================================================") |
|
54 |
printf("Using {0} {1}", executable, ' '.join(argv)) |
|
55 |
printf("Running tests from {0}", HERE) |
|
56 |
printf("=======================================================") |
|
57 |
printf("All tests are:") |
|
58 |
for test_case in all_cases: |
|
59 |
printf(" {0}", test_case.__name__) |
|
60 |
run_test_cases(all_cases) |
|
61 |
printf("=======================================================") |
|
62 |
printf("") |
b/snf-quotaholder-app/quotaholder_django/test/config.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
### IMPORTS ### |
|
35 |
import sys |
|
36 |
import os |
|
37 |
import subprocess |
|
38 |
import time |
|
39 |
from socket import socket, AF_INET, SOCK_STREAM, IPPROTO_TCP, error as socket_error |
|
40 |
from errno import ECONNREFUSED |
|
41 |
from os.path import dirname |
|
42 |
|
|
43 |
# The following import is copied from snf-tools/syneffo_tools/burnin.py |
|
44 |
# Thank you John Giannelos <johngian@grnet.gr> |
|
45 |
# Use backported unittest functionality if Python < 2.7 |
|
46 |
try: |
|
47 |
import unittest2 as unittest |
|
48 |
except ImportError: |
|
49 |
if sys.version_info < (2, 7): |
|
50 |
raise Exception("The unittest2 package is required for Python < 2.7") |
|
51 |
import unittest |
|
52 |
|
|
53 |
from kamaki.clients.quotaholder import QuotaholderClient |
|
54 |
from synnefo.lib.quotaholder.api import (InvalidKeyError, NoEntityError, |
|
55 |
NoQuantityError, NoCapacityError, |
|
56 |
ExportLimitError, ImportLimitError) |
|
57 |
|
|
58 |
import random |
|
59 |
|
|
60 |
def printf(fmt, *args): |
|
61 |
print(fmt.format(*args)) |
|
62 |
|
|
63 |
def environ_get(key, default_value = ''): |
|
64 |
if os.environ.has_key(key): |
|
65 |
return os.environ.get(key) |
|
66 |
else: |
|
67 |
return default_value |
|
68 |
|
|
69 |
# Use environ vars [TEST_]QH_{HOST, PORT} |
|
70 |
QH_HOST = environ_get("TEST_QH_HOST", environ_get("QH_HOST", "127.0.0.1")) |
|
71 |
QH_PORT = environ_get("TEST_QH_PORT", environ_get("QH_PORT", "8008")) |
|
72 |
|
|
73 |
assert QH_HOST != None |
|
74 |
assert QH_PORT != None |
|
75 |
|
|
76 |
printf("Will connect to QH_HOST = {0}", QH_HOST) |
|
77 |
printf(" and QH_PORT = {0}", QH_PORT) |
|
78 |
|
|
79 |
QH_SERVER = '{0}:{1}'.format(QH_HOST, QH_PORT) |
|
80 |
QH_URL = "http://{0}/api/quotaholder/v".format(QH_SERVER) |
|
81 |
|
|
82 |
### DEFS ### |
|
83 |
def new_quota_holder_client(): |
|
84 |
""" |
|
85 |
Create a new quota holder api client |
|
86 |
""" |
|
87 |
return QuotaholderClient(QH_URL) |
|
88 |
|
|
89 |
def run_test_case(test_case): |
|
90 |
""" |
|
91 |
Runs the test_case and returns the result |
|
92 |
""" |
|
93 |
# Again from snf-tools/synnefo_tools/burnin.py |
|
94 |
# Thank you John Giannelos <johngian@grnet.gr> |
|
95 |
printf("Running {0}", test_case) |
|
96 |
import sys |
|
97 |
suite = unittest.TestLoader().loadTestsFromTestCase(test_case) |
|
98 |
runner = unittest.TextTestRunner(stream=sys.stderr, verbosity=2, |
|
99 |
failfast=True, buffer=False) |
|
100 |
return runner.run(suite) |
|
101 |
|
|
102 |
def run_test_cases(test_cases): |
|
103 |
for test_case in test_cases: |
|
104 |
run_test_case(test_case) |
|
105 |
|
|
106 |
def rand_string(): |
|
107 |
alphabet = 'abcdefghijklmnopqrstuvwxyz' |
|
108 |
min = 5 |
|
109 |
max = 15 |
|
110 |
string='' |
|
111 |
for x in random.sample(alphabet,random.randint(min,max)): |
|
112 |
string += x |
|
113 |
return string |
|
114 |
|
|
115 |
HERE = dirname(__file__) |
|
116 |
|
|
117 |
def init_server(): |
|
118 |
p = subprocess.Popen(['setsid', HERE+'/qh_init', QH_SERVER]) |
|
119 |
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) |
|
120 |
while True: |
|
121 |
try: |
|
122 |
s.connect((QH_HOST, int(QH_PORT))) |
|
123 |
break |
|
124 |
except socket_error, e: |
|
125 |
if e.errno != ECONNREFUSED: |
|
126 |
raise |
|
127 |
time.sleep(0.1) |
|
128 |
return p.pid |
|
129 |
|
|
130 |
### CLASSES ### |
|
131 |
class QHTestCase(unittest.TestCase): |
|
132 |
@classmethod |
|
133 |
def setUpClass(self): |
|
134 |
self.server = init_server() |
|
135 |
self.qh = new_quota_holder_client() |
|
136 |
# self.qh.create_entity(create_entity=[("pgerakios", "system", "key1", "")]) |
|
137 |
|
|
138 |
def setUp(self): |
|
139 |
|
|
140 |
|
|
141 |
@classmethod |
|
142 |
def tearDownClass(self): |
|
143 |
from signal import SIGTERM |
|
144 |
os.kill(-self.server, SIGTERM) |
|
145 |
os.remove('/tmp/qh_testdb') |
|
146 |
del self.qh |
|
147 |
|
|
148 |
|
|
149 |
### VARS ### |
|
150 |
DefaultOrCustom = { |
|
151 |
True: "default", |
|
152 |
False: "custom" |
|
153 |
} |
|
154 |
|
b/snf-quotaholder-app/quotaholder_django/test/createrelease.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from config import QHTestCase |
|
35 |
from config import run_test_case |
|
36 |
from config import rand_string |
|
37 |
from config import printf |
|
38 |
import os |
|
39 |
|
|
40 |
#def create_entity OK |
|
41 |
#def set_entity_key OK |
|
42 |
#def list_entities OK |
|
43 |
#def get_entity OK |
|
44 |
#def get_limits LOVERDOS |
|
45 |
#def set_limits LOVERDOS |
|
46 |
#def release_entity OK |
|
47 |
#def get_holding |
|
48 |
#def set_holding |
|
49 |
#def list_resources |
|
50 |
#def get_quota |
|
51 |
#def set_quota |
|
52 |
#def issue_commission |
|
53 |
#def accept_commission |
|
54 |
#def reject_commission |
|
55 |
#def get_pending_commissions |
|
56 |
#def resolve_pending_commissions |
|
57 |
#def get_timeline |
|
58 |
|
|
59 |
class Context(object): |
|
60 |
entityName = rand_string() |
|
61 |
entityKey = "key1" |
|
62 |
parentName = "pgerakios" |
|
63 |
parentKey = "key1" |
|
64 |
|
|
65 |
class create_release(object): |
|
66 |
|
|
67 |
def __init__(self, f): |
|
68 |
""" |
|
69 |
If there are no decorator arguments, the function |
|
70 |
to be decorated is passed to the constructor. |
|
71 |
""" |
|
72 |
print "Inside __init__()" |
|
73 |
self.f = f |
|
74 |
|
|
75 |
def __call__(self, *args): |
|
76 |
""" |
|
77 |
The __call__ method is not called until the |
|
78 |
decorated function is called. |
|
79 |
""" |
|
80 |
print "Inside __call__()" |
|
81 |
self.f(*args) |
|
82 |
print "After self.f(*args)" |
|
83 |
|
|
84 |
|
|
85 |
class CreateReleaseListAPITest(QHTestCase): |
|
86 |
|
|
87 |
entityName = rand_string() |
|
88 |
entityKey = "key1" |
|
89 |
parentName = "pgerakios" |
|
90 |
parentKey = "key1" |
|
91 |
|
|
92 |
def createEntity(self): |
|
93 |
printf("Creating entity: {0}", self.entityName) |
|
94 |
rejected = self.qh.create_entity(context={}, |
|
95 |
create_entity=[(self.entityName, |
|
96 |
self.parentName, |
|
97 |
self.entityKey, |
|
98 |
self.parentKey)]) |
|
99 |
self.assertEqual(rejected,[]) |
|
100 |
|
|
101 |
def releaseEntity(self): |
|
102 |
printf("Releasing entity: {0}", self.entityName) |
|
103 |
rejected = self.qh.release_entity(context={},release_entity=[(self.entityName, |
|
104 |
self.entityKey)]) |
|
105 |
self.assertEqual(rejected,[]) |
|
106 |
|
|
107 |
def checkEntityList(self,exists): |
|
108 |
entityList = self.qh.list_entities(context={},entity=self.parentName,key=self.parentKey) |
|
109 |
if(exists): |
|
110 |
self.assertTrue(self.entityName in entityList) |
|
111 |
else: |
|
112 |
self.assertFalse(self.entityName in entityList) |
|
113 |
|
|
114 |
def setNewEntityKey(self): |
|
115 |
entityKey2 = rand_string() |
|
116 |
rejected = self.qh.set_entity_key(context={},set_entity_key=[(self.entityName, |
|
117 |
self.entityKey, |
|
118 |
entityKey2)]) |
|
119 |
self.assertEqual(rejected,[]) |
|
120 |
self.entityKey = entityKey2 |
|
121 |
|
|
122 |
def checkGetEntity(self,exists): |
|
123 |
entityList = self.qh.get_entity(context={},get_entity=[(self.entityName, |
|
124 |
self.entityKey)]) |
|
125 |
if(exists): |
|
126 |
self.assertEqual([(self.entityName,self.parentName)],entityList) |
|
127 |
else: |
|
128 |
self.assertEqual(entityList,[]) |
|
129 |
|
|
130 |
def listResources(self,expected): |
|
131 |
resList = self.qh.list_resources(context={},entity=self.entityName,key=self.entityKey) |
|
132 |
self.assertEqual(expected,resList) |
|
133 |
|
|
134 |
def setQuota(self,r,q,c,i,e,f): |
|
135 |
rejected = self.qh.set_quota(context={},set_quota=[(self.entityName,r,self.entityKey,q,c,i,e,f)]) |
|
136 |
self.assertEqual(rejected,[]) |
|
137 |
resList = self.qh.get_quota(context={},get_quota=[(self.entityName,r,self.entityKey)]) |
|
138 |
(e0,r1,q1,c1,i1,e1,t0,t1,t2,t3,f1),tail = resList[0],resList[1:] |
|
139 |
self.assertEqual(tail,[]) |
|
140 |
self.assertEqual((self.entityName,r,q,c,i,e,f), |
|
141 |
(e0,r1,q1,c1,i1,e1,f1)) |
|
142 |
|
|
143 |
# def issueCommission(self): |
|
144 |
# self.qh.issue_commission |
|
145 |
def setUp(self): |
|
146 |
self.qh.create_entity(create_entity=[("pgerakios", "system", "key1", "")]) |
|
147 |
self.parentName = "pgerakios" |
|
148 |
self.parentKey = "key1" |
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
#BUG: max empty name <= 72 |
|
153 |
def test_001(self): |
|
154 |
self.createEntity() |
|
155 |
self.releaseEntity() |
|
156 |
|
|
157 |
# Test create, list and release |
|
158 |
def test_002(self): |
|
159 |
self.checkEntityList(False) |
|
160 |
self.createEntity() |
|
161 |
self.checkEntityList(True) |
|
162 |
self.releaseEntity() |
|
163 |
self.checkEntityList(False) |
|
164 |
|
|
165 |
|
|
166 |
# Test create,set key and release |
|
167 |
def test_003(self): |
|
168 |
self.createEntity() |
|
169 |
self.setNewEntityKey() |
|
170 |
self.setNewEntityKey() |
|
171 |
self.releaseEntity() |
|
172 |
|
|
173 |
# test get_entity |
|
174 |
def test_004(self): |
|
175 |
self.checkGetEntity(False) |
|
176 |
self.createEntity() |
|
177 |
self.checkGetEntity(True) |
|
178 |
self.releaseEntity() |
|
179 |
self.checkGetEntity(False) |
|
180 |
|
|
181 |
def test_005(self): |
|
182 |
self.createEntity() |
|
183 |
self.setQuota("res1",10,100,10,10,0) |
|
184 |
# self.listResources([]) |
|
185 |
self.releaseEntity() |
|
186 |
|
|
187 |
if __name__ == "__main__": |
|
188 |
import sys |
|
189 |
printf("Using {0}", sys.executable) |
|
190 |
run_test_case(CreateReleaseListAPITest) |
b/snf-quotaholder-app/quotaholder_django/test/django.conf | ||
---|---|---|
1 |
|
|
2 |
DEBUG = True |
|
3 |
TEMPLATE_DEBUG = DEBUG |
|
4 |
|
|
5 |
DATABASES = { |
|
6 |
'default': { |
|
7 |
'ENGINE': 'django.db.backends.sqlite3', |
|
8 |
'NAME': '/tmp/qh_testdb', |
|
9 |
} |
|
10 |
} |
b/snf-quotaholder-app/quotaholder_django/test/limits.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from config import QHTestCase |
|
35 |
from config import run_test_case |
|
36 |
from config import printf |
|
37 |
from config import rand_string |
|
38 |
from random import randint |
|
39 |
|
|
40 |
from synnefo.lib.quotaholder.api import InvalidDataError |
|
41 |
|
|
42 |
class Data: |
|
43 |
def __init__(self, parent, **kwd): |
|
44 |
self.context = kwd.get('context', parent.context) |
|
45 |
self.policy = kwd.get('policy', parent.policy) |
|
46 |
self.capacity = kwd.get('capacity', parent.capacity) |
|
47 |
self.quantity = kwd.get('quantity', parent.quantity) |
|
48 |
self.import_limit = kwd.get('import_limit', parent.import_limit) |
|
49 |
self.export_limit = kwd.get('export_limit', parent.export_limit) |
|
50 |
# set_limits_has_rejected indicates whether the test expects a non-empty rejected list |
|
51 |
# after calling set_limits |
|
52 |
self.set_limits_has_rejected = kwd.get('set_limits_has_rejected', False) |
|
53 |
# get_limits_expected_length indicates the exact length of the limits list |
|
54 |
# returned by get_limits |
|
55 |
self.get_limits_expected_length = kwd.get('get_limits_expected_length', 1) |
|
56 |
|
|
57 |
class LimitsTest(QHTestCase): |
|
58 |
context = {} |
|
59 |
policy = rand_string() |
|
60 |
capacity1 = 0 |
|
61 |
capacity2 = 100 |
|
62 |
capacity = capacity1 |
|
63 |
quantity1 = capacity2 |
|
64 |
quantity2 = capacity1 |
|
65 |
quantity = quantity1 |
|
66 |
import_limit_empty = 0 |
|
67 |
import_limit_full_capacity = capacity |
|
68 |
import_limit_half_capacity = capacity / 2 |
|
69 |
import_limit = import_limit_half_capacity |
|
70 |
export_limit_empty = 0 |
|
71 |
export_limit_full_capacity = capacity |
|
72 |
export_limit_half_capacity = capacity / 2 |
|
73 |
export_limit = export_limit_half_capacity |
|
74 |
|
|
75 |
def helper_set_limits(self, **kwd): |
|
76 |
""" |
|
77 |
Calls set_limits and returns the rejected list (from the original API). |
|
78 |
""" |
|
79 |
data = Data(self, **kwd) |
|
80 |
rejected = self.qh.set_limits( |
|
81 |
context = data.context, |
|
82 |
set_limits = [ |
|
83 |
(data.policy, |
|
84 |
data.quantity, |
|
85 |
data.capacity, |
|
86 |
data.import_limit, |
|
87 |
data.export_limit) |
|
88 |
] |
|
89 |
) |
|
90 |
|
|
91 |
if data.set_limits_has_rejected: |
|
92 |
self.assertTrue(len(rejected) > 1) |
|
93 |
else: |
|
94 |
self.assertTrue(len(rejected) == 0) |
|
95 |
|
|
96 |
return rejected |
|
97 |
|
|
98 |
def helper_get_limits(self, **kwd): |
|
99 |
""" |
|
100 |
Calls get_limits and returns the limits list (from the original API).. |
|
101 |
""" |
|
102 |
data = Data(self, **kwd) |
|
103 |
limits = self.qh.get_limits( |
|
104 |
context = data.context, |
|
105 |
get_limits = [data.policy] |
|
106 |
) |
|
107 |
|
|
108 |
self.assertEqual(len(limits), data.get_limits_expected_length) |
|
109 |
|
|
110 |
return limits |
|
111 |
|
|
112 |
def test_010_set_get(self): |
|
113 |
""" |
|
114 |
quantity = 0, capacity = 100 |
|
115 |
""" |
|
116 |
self.helper_set_limits(quantity = 0, capacity = 100, should_have_rejected = False) |
|
117 |
self.helper_get_limits(get_limits_expected_length = 1) |
|
118 |
|
|
119 |
def test_011_set_get(self): |
|
120 |
""" |
|
121 |
quantity = 100, capacity = 0 |
|
122 |
""" |
|
123 |
self.helper_set_limits(quantity = 100, capacity = 0, should_have_rejected = False) |
|
124 |
self.helper_get_limits(get_limits_expected_length = 1) |
|
125 |
|
|
126 |
def test_020_set_get_empty_policy_name(self): |
|
127 |
""" |
|
128 |
Tests empty policy name |
|
129 |
""" |
|
130 |
with self.assertRaises(InvalidDataError): |
|
131 |
self.helper_set_limits(policy = '', set_limits_has_rejected = False) |
|
132 |
self.helper_get_limits(policy = '', get_limits_expected_length = 1) |
|
133 |
|
|
134 |
|
|
135 |
if __name__ == "__main__": |
|
136 |
import sys |
|
137 |
printf("Using {0}", sys.executable) |
|
138 |
run_test_case(LimitsTest) |
b/snf-quotaholder-app/quotaholder_django/test/qh_init | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
d=`dirname $0` |
|
3 |
export COMMISSIONING_CONF_DIR=$d |
|
4 |
quotaholder-manage syncdb |
|
5 |
quotaholder-manage runserver "$@" 2> $d/server_stderr & |
b/snf-quotaholder-app/quotaholder_django/test/simpletests.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from config import QHTestCase |
|
35 |
from config import run_test_case |
|
36 |
from config import rand_string |
|
37 |
from config import printf |
|
38 |
|
|
39 |
from synnefo.lib.commissioning import CallError |
|
40 |
|
|
41 |
class QHAPITest(QHTestCase): |
|
42 |
|
|
43 |
def test_001(self): |
|
44 |
r = self.qh.list_entities(entity='system', key='') |
|
45 |
self.assertEqual(r, ['system']) |
|
46 |
|
|
47 |
def test_002(self): |
|
48 |
with self.assertRaises(CallError): |
|
49 |
self.qh.list_entities(entity='systems', key='') |
|
50 |
|
|
51 |
|
|
52 |
if __name__ == "__main__": |
|
53 |
import sys |
|
54 |
printf("Using {0}", sys.executable) |
|
55 |
run_test_case(QHAPITest) |
b/snf-quotaholder-app/setup.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
# |
|
1 | 34 |
|
2 |
from distutils.core import setup |
|
35 |
import distribute_setup |
|
36 |
distribute_setup.use_setuptools() |
|
3 | 37 |
|
4 |
setup ( |
|
5 |
name = 'quotaholder_django', |
|
6 |
version = '0.5', |
|
7 |
packages = [ |
|
8 |
'quotaholder_django', |
|
9 |
'quotaholder_django.quotaholder_app', |
|
10 |
], |
|
38 |
import os |
|
11 | 39 |
|
12 |
package_data = { |
|
13 |
'quotaholder_django.quotaholder_app': ['fixtures/*.json'] |
|
14 |
}, |
|
40 |
from distutils.util import convert_path |
|
41 |
from fnmatch import fnmatchcase |
|
42 |
from setuptools import setup, find_packages |
|
43 |
|
|
44 |
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__))) |
|
45 |
|
|
46 |
try: |
|
47 |
# try to update the version file |
|
48 |
from synnefo.util.version import update_version |
|
49 |
update_version('quotaholder_django', 'version', HERE) |
|
50 |
except ImportError: |
|
51 |
pass |
|
52 |
|
|
53 |
from quotaholder_django.version import __version__ |
|
54 |
|
|
55 |
# Package info |
|
56 |
VERSION = __version__ |
|
57 |
README = open(os.path.join(HERE, 'README')).read() |
|
58 |
CHANGES = open(os.path.join(HERE, 'Changelog')).read() |
|
59 |
SHORT_DESCRIPTION = 'snf-quotaholder django app' |
|
60 |
|
|
61 |
PACKAGES_ROOT = '.' |
|
62 |
PACKAGES = find_packages(PACKAGES_ROOT, exclude=('test',)) |
|
15 | 63 |
|
16 |
scripts = [ |
|
17 |
'quotaholder_django/quotaholder-manage', |
|
18 |
] |
|
64 |
# Package meta |
|
65 |
CLASSIFIERS = [] |
|
66 |
INSTALL_REQUIRES = [ |
|
67 |
'Django >=1.2, <1.3', |
|
68 |
'South>=0.7', |
|
69 |
'snf-common', |
|
70 |
] |
|
71 |
|
|
72 |
setup( |
|
73 |
name = 'snf-quotaholder-app', |
|
74 |
version = VERSION, |
|
75 |
license = 'BSD', |
|
76 |
url = 'http://code.grnet.gr/', |
|
77 |
description = SHORT_DESCRIPTION, |
|
78 |
long_description=README + '\n\n' + CHANGES, |
|
79 |
classifiers = CLASSIFIERS, |
|
80 |
|
|
81 |
author = 'Package author', |
|
82 |
author_email = 'author@grnet.gr', |
|
83 |
maintainer = 'Package maintainer', |
|
84 |
maintainer_email = 'maintainer@grnet.gr', |
|
85 |
|
|
86 |
packages = PACKAGES, |
|
87 |
include_package_data = True, |
|
88 |
package_data = { |
|
89 |
'quotaholder_django.quotaholder_app': ['fixtures/*.json'] |
|
90 |
}, |
|
91 |
zip_safe = False, |
|
92 |
install_requires = INSTALL_REQUIRES, |
|
93 |
dependency_links = ['http://docs.dev.grnet.gr/pypi'], |
|
94 |
entry_points = { |
|
95 |
'synnefo': [ |
|
96 |
'web_apps = quotaholder_django.synnefo_settings:apps', |
|
97 |
'urls = quotaholder_django.urls:urlpatterns', |
|
98 |
] |
|
99 |
}, |
|
19 | 100 |
) |
101 |
|
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
# placeholder |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
from sys import argv,executable |
|
35 |
from os.path import dirname |
|
36 |
from config import run_test_cases |
|
37 |
from config import printf |
|
38 |
from limits import LimitsTest |
|
39 |
from createrelease import CreateReleaseListAPITest |
|
40 |
|
|
41 |
HERE = dirname(__file__) |
|
42 |
|
|
43 |
# Enumerate all test cases to run. |
|
44 |
# In the command line use |
|
45 |
# $ python test |
|
46 |
# to run them all |
|
47 |
|
|
48 |
all_cases = [ |
|
49 |
CreateReleaseListAPITest, |
|
50 |
LimitsTest |
|
51 |
] |
|
52 |
|
|
53 |
printf("=======================================================") |
|
54 |
printf("Using {0} {1}", executable, ' '.join(argv)) |
|
55 |
printf("Running tests from {0}", HERE) |
|
56 |
printf("=======================================================") |
|
57 |
printf("All tests are:") |
|
58 |
for test_case in all_cases: |
|
59 |
printf(" {0}", test_case.__name__) |
|
60 |
run_test_cases(all_cases) |
|
61 |
printf("=======================================================") |
|
62 |
printf("") |
/dev/null | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
Also available in: Unified diff