Revision 2cd99e7a

b/aai/middleware.py
19 19
        # test user on first access
20 20
        # TODO: REMOVE THE FOLLOWING BEFORE DEPLOYMENT
21 21
        if request.GET.get('test') is not None:
22
            u = SynnefoUser.objects.get(auth_token='46e427d657b20defe352804f0eb6f8a2')
23
            return self._redirect_shib_auth_user(user = u)
22
            usr = SynnefoUser.objects.get(auth_token='46e427d657b20defe352804f0eb6f8a2')
23
            return self._redirect_shib_auth_user(user = usr)
24 24

  
25 25
        token = None
26 26
        #Try to find token in a cookie
b/aai/shibboleth.py
6 6

  
7 7
from synnefo.logic import users
8 8

  
9

  
9 10
class Tokens:
10 11
    SIB_NAME = "Shib-InetOrgPerson-givenName"
11 12
    SIB_SURNAME = "Shib-Person-surname"
......
17 18
    SIB_GR_EDU_PERSON_UNDERGRADUATE_BRANCH = "grEduPersonUndergraduateBranch"
18 19
    SIB_SESSION_ID = "Shib-Session-ID"
19 20

  
20
class NoUniqueToken(object):
21
class NoUniqueToken(BaseException):
21 22

  
22 23
    def __init__(self, msg):
23 24
        self.msg = msg
24
    
25
    pass
26 25

  
27
class NoRealName(object):
26
class NoRealName(BaseException):
28 27

  
29 28
    def __init__(self, msg):
30 29
        self.msg = msg
31 30

  
32
    pass
33

  
34 31
def register_shibboleth_user(tokens):
35 32
    """Registers a sibbolleth user using the input hash as a source for data.
36 33
       The token requirements are described in:
......
61 58
        raise NoRealName("Authentication does not return the user's name")
62 59

  
63 60
    if is_student:
64
        users.register_student(realname, '' ,unq)
61
        users.register_student(realname, '' , unq)
65 62
    else:
66
        users.register_professor(realname, '' ,unq)
63
        users.register_professor(realname, '' , unq)
67 64

  
68 65
    return True
b/aai/tests.py
5 5
#
6 6
# Copyright 2011 Greek Research and Technology Network
7 7
#
8
from Cookie import Cookie
9 8

  
10 9
from django.test import TestCase
11 10
from django.test.client import Client
......
15 14

  
16 15
from datetime import datetime, timedelta
17 16

  
18
from synnefo.aai.shibboleth import Tokens, NoUniqueToken
17
from synnefo.aai.shibboleth import Tokens
18

  
19 19

  
20 20
class AaiTestCase(TestCase):
21 21
    fixtures = ['api_test_data', 'auth_test_data']
......
45 45
        self.assertEquals(response['X-Auth-Token'], user.auth_token)
46 46
        #self.assertNotEquals(response.cookies['X-Auth-Token'].find(user.auth_token), -1)
47 47

  
48

  
49 48
    def test_shibboleth_no_uniq_request(self):
50 49
        """test a request with no unique field
51 50
        """
......
55 54
                                  'TEST-AAI': 'true'})
56 55
        self._test_redirect(response)
57 56

  
58

  
59 57
    def test_shibboleth_expired_token(self):
60 58
        """ test request from expired token
61 59
        """
62 60
        user = SynnefoUser.objects.get(uniq="test@synnefo.gr")
63 61
        self.assertNotEqual(user.auth_token_created, None)
64
        self._update_user_ts(user)
62
        _update_user_ts(user)
65 63
        response = self.client.get('/index.html', {},
66 64
                               **{'X-Auth-Token': user.auth_token,
67 65
                                  'TEST-AAI': 'true'})
......
89 87
        self.assertTrue('Location' in response)
90 88
        self.assertTrue(response['Location'].endswith(settings.LOGIN_PATH))
91 89

  
92
    def _update_user_ts(self, user):
93
        user.auth_token_created = (datetime.now() -
94
                                   timedelta(hours = settings.AUTH_TOKEN_DURATION))
95
        user.save()
90
def _update_user_ts(user):
91
    user.auth_token_created = (datetime.now() -
92
                               timedelta(hours = settings.AUTH_TOKEN_DURATION))
93
    user.save()
b/ganeti/ganeti-eventd.py
30 30

  
31 31
from amqplib import client_0_8 as amqp
32 32

  
33
from threading import Thread, Event, currentThread
34

  
35 33
from ganeti import utils
36 34
from ganeti import jqueue
37 35
from ganeti import constants
......
54 52
                     virtual_host=settings.RABBIT_VHOST)
55 53
            except socket.error:
56 54
                time.sleep(1)
57
                pass
58 55
        
59 56
        handler_logger.info("Connection succesful, opening channel")
60 57
        return conn.channel()
......
135 132
    global handler_logger
136 133

  
137 134
    handler_logger.info("Caught fatal signal %d, will raise SystemExit",
138
            signum)
135
                        signum)
139 136
    raise SystemExit
140 137

  
141 138
def parse_arguments(args):
......
143 140

  
144 141
    parser = OptionParser()
145 142
    parser.add_option("-d", "--debug", action="store_true", dest="debug",
146
            help="Enable debugging information")
143
                      help="Enable debugging information")
147 144
    parser.add_option("-l", "--log", dest="log_file",
148
            default=settings.GANETI_EVENTD_LOG_FILE,
149
            metavar="FILE",
150
            help="Write log to FILE instead of %s" %
151
            settings.GANETI_EVENTD_LOG_FILE),
145
                      default=settings.GANETI_EVENTD_LOG_FILE,
146
                      metavar="FILE",
147
                      help="Write log to FILE instead of %s" %
148
                           settings.GANETI_EVENTD_LOG_FILE)
152 149
    parser.add_option('--pid-file', dest="pid_file",
153
            default=settings.GANETI_EVENTD_PID_FILE,
154
            metavar='PIDFILE',
155
            help="Save PID to file (default: %s)" %
156
            settings.GANETI_EVENTD_PID_FILE)
150
                      default=settings.GANETI_EVENTD_PID_FILE,
151
                      metavar='PIDFILE',
152
                      help="Save PID to file (default: %s)" %
153
                           settings.GANETI_EVENTD_PID_FILE)
157 154

  
158 155
    return parser.parse_args(args)
159 156

  
b/logic/dispatcher.py
2 2
#
3 3
# Copyright (c) 2011 Greek Research and Technology Network
4 4
#
5
"""Connect to a queue 
6

  
7
This daemon receives job notifications from a number of queues
5
""" Message queue setup and dispatch
8 6

  
7
This program sets up connections to the queues configured in settings.py
8
and implements the message wait and dispatch loops. Actual messages are
9
handled in the dispatched functions.
9 10

  
10 11
"""
11 12

  
......
20 21
setup_environ(settings)
21 22

  
22 23
from amqplib import client_0_8 as amqp
23

  
24 24
from signal import signal, SIGINT, SIGTERM
25 25

  
26 26
import logging
......
29 29

  
30 30
from synnefo.logic import dispatcher_callbacks
31 31

  
32
# List of worker ids
33
global children
34 32

  
35 33
class Dispatcher:
36 34

  
......
53 51
            except socket.error:
54 52
                self.logger.error("Server went away, reconnecting...")
55 53
                self._init()
56
                pass
57 54

  
58 55
        [self.chan.basic_cancel(clienttag) for clienttag in self.clienttags]
59 56
        self.chan.close()
......
73 70
                                       virtual_host=settings.RABBIT_VHOST)
74 71
            except socket.error:
75 72
                time.sleep(1)
76
                pass
77 73

  
78 74
        self.logger.info("Connection succesful, opening channel")
79 75
        self.chan = conn.channel()
......
98 94
        # Bind queues to handler methods
99 95
        for binding in bindings:
100 96
            try:
101
                cb = getattr(dispatcher_callbacks, binding[3])
97
                callback = getattr(dispatcher_callbacks, binding[3])
102 98
            except AttributeError:
103 99
                self.logger.error("Cannot find callback %s" % binding[3])
104 100
                continue
105 101

  
106 102
            self.chan.queue_bind(queue=binding[0], exchange=binding[1],
107 103
                                 routing_key=binding[2])
108
            tag = self.chan.basic_consume(queue=binding[0], callback=cb)
104
            tag = self.chan.basic_consume(queue=binding[0], callback=callback)
109 105
            self.logger.debug("Binding %s(%s) to queue %s with handler %s" %
110 106
                              (binding[1], binding[2], binding[0], binding[3]))
111 107
            self.clienttags.append(tag)
......
113 109

  
114 110
def _exit_handler(signum, frame):
115 111
    """"Catch exit signal in children processes."""
116
    print "%d: Caught signal %d, will raise SystemExit" % (os.getpid(),signum)
112
    print "%d: Caught signal %d, will raise SystemExit" % (os.getpid(), signum)
117 113
    raise SystemExit
118 114

  
119 115

  
......
129 125

  
130 126
    # Cmd line argument parsing
131 127
    (opts, args) = parse_arguments(cmdline)
132
    d = Dispatcher(debug = opts.debug, logger = logger)
128
    disp = Dispatcher(debug = opts.debug, logger = logger)
133 129

  
134 130
    # Start the event loop
135
    d.wait()
131
    disp.wait()
136 132

  
137 133

  
138 134
def parse_arguments(args):
......
140 136

  
141 137
    parser = OptionParser()
142 138
    parser.add_option("-d", "--debug", action="store_true", default=False,
143
                      dest="debug",
144
            help="Enable debug mode")
139
                      dest="debug", help="Enable debug mode")
145 140
    parser.add_option("-l", "--log", dest="log_file",
146
            default=settings.DISPATCHER_LOG_FILE,
147
            metavar="FILE",
148
            help="Write log to FILE instead of %s" %
149
            settings.DISPATCHER_LOG_FILE)
141
                      default=settings.DISPATCHER_LOG_FILE, metavar="FILE",
142
                      help="Write log to FILE instead of %s" %
143
                           settings.DISPATCHER_LOG_FILE)
150 144
    parser.add_option("-c", "--cleanup-queues", action="store_true",
151 145
                      default=False, dest="cleanup_queues",
152
            help="Remove all queues declared in settings.py (DANGEROUS!)")
146
                      help="Remove all queues declared in settings.py (DANGEROUS!)")
153 147
    parser.add_option("-w", "--workers", default=2, dest="workers",
154
            help="Number of workers to spawn", type="int")
148
                      help="Number of workers to spawn", type="int")
155 149
    
156 150
    return parser.parse_args(args)
157 151

  
......
197 191
    logger = logging.getLogger("synnefo.dispatcher")
198 192
    logger.setLevel(lvl)
199 193
    formatter = logging.Formatter(
200
            "%(asctime)s %(module)s[%(process)d] %(levelname)s: %(message)s",
201
            "%Y-%m-%d %H:%M:%S")
194
        "%(asctime)s %(module)s[%(process)d] %(levelname)s: %(message)s",
195
        "%Y-%m-%d %H:%M:%S")
202 196
    handler = logging.FileHandler(opts.log_file)
203 197
    handler.setFormatter(formatter)
204 198
    logger.addHandler(handler)
......
231 225
    signal(SIGTERM, _parent_handler)
232 226

  
233 227
    # Wait for all children process to die, one by one
234
    for c in children:
228
    for pid in children:
235 229
        try:
236
            os.wait()
230
            os.waitpid(pid)
237 231
        except Exception:
238 232
            pass
239 233

  

Also available in: Unified diff