Exemplo n.º 1
0
    def setUp(self):
        yield HappySMSCTestCase.setUp(self)

        # Init
        self.group1 = Group('g1')
        self.user1 = User('1', self.group1, 'u1', 'password')
        self.c1 = SmppClientConnector('smpp_c1')
Exemplo n.º 2
0
    def setUp(self):
        SMPPClientTestCases.setUp(self)

        # Provision a user and default route into RouterPB
        # Add throughput limit on user
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.foo.mt_credential.setQuota('smpps_throughput', 2)
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)

        self.stats = SMPPServerStatsCollector().get(cid=self.smpps_config.id)
Exemplo n.º 3
0
    def setUp(self):
        HTTPApiTestCases.setUp(self)

        # Provision Router with additional Users and Routes
        u2 = User(2, Group(2), 'user2', 'correct')
        u3 = User(3, Group(2), 'user3', 'correct')
        u3.mt_credential.setQuota('balance', 10)
        self.RouterPB_f.users.append(u2)
        self.RouterPB_f.users.append(u3)
        filters = [GroupFilter(Group(2))]
        route = StaticMTRoute(filters, SmppClientConnector('abc'), 1.5)
        self.RouterPB_f.mt_routing_table.add(route, 2)
Exemplo n.º 4
0
    def setUp(self):
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        self.routerpb_config = RouterPBConfig()

        # Instanciate RouterPB but will not launch a server
        # we only need the instance to access its .users attribute
        # for authentication
        self.routerpb_factory = RouterPB(self.routerpb_config, persistenceTimer=False)

        # Provision a user and default route into RouterPB
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)
Exemplo n.º 5
0
def runScenario():
    try:
        ## First part, SMPP Client connector management
        ###############################################
        # Connect to SMPP Client management PB proxy
        proxy_smpp = SMPPClientManagerPBProxy()
        yield proxy_smpp.connect('127.0.0.1', 8989, 'cmadmin', 'cmpwd')

        # Provision SMPPClientManagerPBProxy with a connector and start it
        connector1 = {
            'id': 'abc',
            'username': '******',
            'reconnectOnConnectionFailure': True
        }
        config1 = SMPPClientConfig(**connector1)
        yield proxy_smpp.add(config1)
        yield proxy_smpp.start('abc')

        ## Second part, User and Routing management
        ###########################################
        # Connect to Router PB proxy
        proxy_router = RouterPBProxy()
        yield proxy_router.connect('127.0.0.1', 8988, 'radmin', 'rpwd')

        # Provision RouterPBProxy with MT routes
        yield proxy_router.mtroute_add(
            DefaultRoute(SmppClientConnector('abc')), 0)
        routes = yield proxy_router.mtroute_get_all()
        print "Configured routes: \n\t%s" % pickle.loads(routes)

        # Provisiong router with users
        g1 = Group(1)
        u1 = User(uid=1, group=g1, username='******', password='******')
        yield proxy_router.group_add(g1)
        yield proxy_router.user_add(u1)
        users = yield proxy_router.user_get_all()
        print "Users: \n\t%s" % pickle.loads(users)

        ## Last, tear down
        ##################
        # Stop connector
        yield proxy_smpp.stop('abc')
    except Exception, e:
        print "ERROR RUNNING SCENARIO: %s" % str(e)
Exemplo n.º 6
0
    def setUp(self):
        # Instanciate a RouterPB (a requirement for HTTPApi)
        RouterPBConfigInstance = RouterPBConfig()
        self.RouterPB_f = RouterPB()
        self.RouterPB_f.setConfig(RouterPBConfigInstance)
        
        # Provision Router with User and Route
        self.u1 = User(1, Group(1), 'fourat', 'correct')
        self.RouterPB_f.users.append(self.u1)
        self.RouterPB_f.mt_routing_table.add(DefaultRoute(SmppClientConnector('abc')), 0)

        # Instanciate a SMPPClientManagerPB (a requirement for HTTPApi)
        SMPPClientPBConfigInstance = SMPPClientPBConfig()
        SMPPClientPBConfigInstance.authentication = False
        clientManager_f = SMPPClientManagerPB()
        clientManager_f.setConfig(SMPPClientPBConfigInstance)
        
        httpApiConfigInstance = HTTPApiConfig()
        self.web = DummySite(HTTPApi(self.RouterPB_f, clientManager_f, httpApiConfigInstance))
Exemplo n.º 7
0
                        return self.protocol.sendData(
                            'Route order must be a positive integer')
                    else:
                        arg = int(arg)

                # Validate connector
                if cmd == 'connector':
                    try:
                        ctype, cid = validate_typed_connector_id(arg)
                        if ctype == 'smppc':
                            if self.pb['smppcm'].getConnector(cid) is None:
                                raise Exception('Unknown smppc cid: %s' %
                                                (cid))

                            # Make instance of SmppClientConnector
                            arg = SmppClientConnector(
                                self.pb['smppcm'].getConnector(cid)['id'])
                        else:
                            raise NotImplementedError("Not implemented yet !")
                    except Exception, e:
                        return self.protocol.sendData(str(e))

                # Validate connectors
                if cmd == 'connectors':
                    CIDs = arg.split(';')
                    if len(CIDs) == 1:
                        return self.protocol.sendData(
                            '%s option value must contain a minimum of 2 connector IDs separated with ";".'
                            % (cmd))

                    arg = []
                    for typed_cid in CIDs:
Exemplo n.º 8
0
                        return self.protocol.sendData("This route order (0) is reserved for DefaultRoute only")
                    elif not arg.isdigit() or int(arg) < 0:
                        return self.protocol.sendData("Route order must be a positive integer")
                    else:
                        arg = int(arg)

                # Validate connector
                if cmd == "connector":
                    try:
                        ctype, cid = validate_typed_connector_id(arg)
                        if ctype == "smppc":
                            if self.pb["smppcm"].getConnector(cid) is None:
                                raise Exception("Unknown smppc cid: %s" % (cid))

                            # Make instance of SmppClientConnector
                            arg = SmppClientConnector(self.pb["smppcm"].getConnector(cid)["id"])
                        else:
                            raise NotImplementedError("Not implemented yet !")
                    except Exception, e:
                        return self.protocol.sendData(str(e))

                # Validate connectors
                if cmd == "connectors":
                    CIDs = arg.split(";")
                    if len(CIDs) == 1:
                        return self.protocol.sendData(
                            '%s option value must contain a minimum of 2 connector IDs separated with ";".' % (cmd)
                        )

                    arg = []
                    for typed_cid in CIDs:
Exemplo n.º 9
0
                        self.sessBuffer['order'] = 0
                        return self.protocol.sendData('Route order forced to 0 since it is a DefaultRoute')
                    elif arg == '0' and 'type' in self.sessBuffer and self.sessBuffer['type'] != 'DefaultRoute':
                        return self.protocol.sendData('This route order (0) is reserved for DefaultRoute only')
                    elif not arg.isdigit() or int(arg) < 0:
                        return self.protocol.sendData('Route order must be a positive integer')
                    else:
                        arg = int(arg)
                    
                # Validate connector
                if cmd == 'connector':
                    if self.pb['smppcm'].getConnector(arg) is None:
                        return self.protocol.sendData('Unknown cid: %s' % (arg))
                    else:
                        # Make instance of SmppClientConnector
                        arg = SmppClientConnector(self.pb['smppcm'].getConnector(arg)['id'])
                
                # Validate rate and convert it to float
                if cmd == 'rate':
                    try:
                        arg = float(arg)
                    except ValueError:
                        return self.protocol.sendData('Incorrect rate (must be float): %s' % (arg))
                    
                # Validate connectors
                if cmd == 'connectors':
                    CIDs = arg.split(';')
                    if len(CIDs) == 1:
                        return self.protocol.sendData('%s option value must contain a minimum of 2 connector IDs separated with ";".' % (cmd))

                    arg = []
Exemplo n.º 10
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate a route from jasmin.routing.Routes with sessBuffer content
        if cmd == 'ok':
            # Remove route_class and route_args from self.sessBuffer before checking options
            # as these 2 options are not user-typed
            if len(self.sessBuffer) - 2 < len(self.protocol.sessionCompletitions):
                return self.protocol.sendData('You must set these options before saving: %s' % ', '.join(
                    self.protocol.sessionCompletitions))

            route = {}
            for key, value in self.sessBuffer.iteritems():
                if key not in ['order', 'type', 'route_class', 'route_args']:
                    route[key] = value
            try:
                # Instanciate a Route
                RouteInstance = self.sessBuffer['route_class'](**route)

                # Hand the instance to fCallback
                return fCallback(self, self.sessBuffer['order'], RouteInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            ra = []
            if 'route_args' in self.sessBuffer:
                ra = self.sessBuffer['route_args']
            if cmd not in MTRouteKeyMap and cmd not in ra:
                return self.protocol.sendData('Unknown Route key: %s' % cmd)

            # IF we got the type, check if it's a correct one
            if cmd == 'type':
                _type = None
                for route in MTROUTES:
                    if arg.lower() == route.lower():
                        _type = route
                        break

                if _type is None:
                    return self.protocol.sendData(
                        'Unknown MT Route type:%s, available types: %s' % (arg, ', '.join(MTROUTES)))
                elif _type == 'DefaultRoute':
                    self.sessBuffer['order'] = 0

                # Before setting a new route class, remove any previous route
                # sessBuffer keys
                if 'order' in self.sessBuffer:
                    self.sessBuffer = {'order': self.sessBuffer['order']}
                else:
                    self.sessBuffer = {}

                self.sessBuffer['type'] = _type
                # Route class name must be already imported from jasmin.routing.Routes
                # in order to get it from globals()
                self.sessBuffer['route_class'] = globals()[_type]

                # Show Route help and save Route args
                RouteClassArgs = inspect.getargspec(self.sessBuffer['route_class'].__init__).args
                if 'self' in RouteClassArgs:
                    # Remove 'self' from args
                    RouteClassArgs.remove('self')
                self.sessBuffer['route_args'] = RouteClassArgs

                if len(RouteClassArgs) > 0:
                    # Update completitions
                    self.protocol.sessionCompletitions = MTRouteKeyMap.keys() + RouteClassArgs

                    return self.protocol.sendData('%s arguments:\n%s' % (
                        self.sessBuffer['route_class'], ', '.join(RouteClassArgs)))
            else:
                # DefaultRoute's order is always zero
                if cmd == 'order':
                    if (arg != '0' and 'type' in self.sessBuffer and
                                self.sessBuffer['type'] == 'DefaultRoute'):
                        self.sessBuffer['order'] = 0
                        return self.protocol.sendData('Route order forced to 0 since it is a DefaultRoute')
                    elif (arg == '0' and 'type' in self.sessBuffer and
                                  self.sessBuffer['type'] != 'DefaultRoute'):
                        return self.protocol.sendData(
                            'This route order (0) is reserved for DefaultRoute only')
                    elif not arg.isdigit() or int(arg) < 0:
                        return self.protocol.sendData('Route order must be a positive integer')
                    else:
                        arg = int(arg)

                # Validate connector
                if cmd == 'connector':
                    try:
                        ctype, cid = validate_typed_connector_id(arg)
                        if ctype == 'smppc':
                            if self.pb['smppcm'].getConnector(cid) is None:
                                raise Exception('Unknown smppc cid: %s' % (cid))

                            # Make instance of SmppClientConnector
                            arg = SmppClientConnector(self.pb['smppcm'].getConnector(cid)['id'])
                        else:
                            raise NotImplementedError("Not implemented yet !")
                    except Exception as e:
                        return self.protocol.sendData(str(e))

                # Validate connectors
                if cmd == 'connectors':
                    CIDs = arg.split(';')
                    if len(CIDs) == 1:
                        return self.protocol.sendData(
                            '%s option value must contain a minimum of 2 connector IDs separated with ";".' % (cmd))

                    arg = []
                    for typed_cid in CIDs:
                        try:
                            ctype, cid = validate_typed_connector_id(typed_cid)
                            if ctype == 'smppc':
                                if self.pb['smppcm'].getConnector(cid) is None:
                                    raise Exception('Unknown smppc cid: %s' % (cid))

                                # Make instance of SmppClientConnector
                                arg.append(SmppClientConnector(self.pb['smppcm'].getConnector(cid)['id']))
                            else:
                                raise NotImplementedError("Not implemented yet !")
                        except Exception as e:
                            return self.protocol.sendData(str(e))

                # Validate rate and convert it to float
                if cmd == 'rate':
                    try:
                        arg = float(arg)
                    except ValueError:
                        return self.protocol.sendData('Incorrect rate (must be float): %s' % (arg))

                # Validate filters
                if cmd == 'filters':
                    FIDs = arg.split(';')

                    arg = []
                    for fid in FIDs:
                        if fid not in self.protocol.managers['filter'].filters:
                            return self.protocol.sendData('Unknown fid: %s' % (fid))
                        else:
                            _Filter = self.protocol.managers['filter'].filters[fid]

                            if _Filter.__class__.__name__ not in MTFILTERS:
                                return self.protocol.sendData(
                                    '%s#%s is not a valid filter for MTRoute (not in MTFILTERS)' % (
                                        _Filter.__class__.__name__, fid))
                            else:
                                arg.append(_Filter)

                # Buffer key for later Route initiating
                if cmd not in ra:
                    RouteKey = MTRouteKeyMap[cmd]
                else:
                    RouteKey = cmd
                self.sessBuffer[RouteKey] = arg

            return self.protocol.sendData()
Exemplo n.º 11
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate a route from jasmin.routing.Routes with sessBuffer content
        if cmd == 'ok':
            # Remove route_class and route_args from self.sessBuffer before checking options
            # as these 2 options are not user-typed
            if len(self.sessBuffer) - 2 < len(
                    self.protocol.sessionCompletitions):
                return self.protocol.sendData(
                    'You must set these options before saving: %s' %
                    ', '.join(self.protocol.sessionCompletitions))

            route = {}
            for key, value in self.sessBuffer.items():
                if key not in ['order', 'type', 'route_class', 'route_args']:
                    route[key] = value
            try:
                # Instanciate a Route
                RouteInstance = self.sessBuffer['route_class'](**route)

                # Hand the instance to fCallback
                return fCallback(self, self.sessBuffer['order'], RouteInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            ra = []
            if 'route_args' in self.sessBuffer:
                ra = self.sessBuffer['route_args']
            if cmd not in MTRouteKeyMap and cmd not in ra:
                return self.protocol.sendData('Unknown Route key: %s' % cmd)

            # IF we got the type, check if it's a correct one
            if cmd == 'type':
                _type = None
                for route in MTROUTES:
                    if arg.lower() == route.lower():
                        _type = route
                        break

                if _type is None:
                    return self.protocol.sendData(
                        'Unknown MT Route type:%s, available types: %s' %
                        (arg, ', '.join(MTROUTES)))
                elif _type == 'DefaultRoute':
                    self.sessBuffer['order'] = 0

                # Before setting a new route class, remove any previous route
                # sessBuffer keys
                if 'order' in self.sessBuffer:
                    self.sessBuffer = {'order': self.sessBuffer['order']}
                else:
                    self.sessBuffer = {}

                self.sessBuffer['type'] = _type
                # Route class name must be already imported from jasmin.routing.Routes
                # in order to get it from globals()
                self.sessBuffer['route_class'] = globals()[_type]

                # Show Route help and save Route args
                RouteClassArgs = inspect.getargspec(
                    self.sessBuffer['route_class'].__init__).args
                if 'self' in RouteClassArgs:
                    # Remove 'self' from args
                    RouteClassArgs.remove('self')
                self.sessBuffer['route_args'] = RouteClassArgs

                if len(RouteClassArgs) > 0:
                    # Update completitions
                    self.protocol.sessionCompletitions = list(
                        MTRouteKeyMap) + RouteClassArgs

                    return self.protocol.sendData(
                        '%s arguments:\n%s' % (self.sessBuffer['route_class'],
                                               ', '.join(RouteClassArgs)))
            else:
                # DefaultRoute's order is always zero
                if cmd == 'order':
                    if (arg != '0' and 'type' in self.sessBuffer
                            and self.sessBuffer['type'] == 'DefaultRoute'):
                        self.sessBuffer['order'] = 0
                        return self.protocol.sendData(
                            'Route order forced to 0 since it is a DefaultRoute'
                        )
                    elif (arg == '0' and 'type' in self.sessBuffer
                          and self.sessBuffer['type'] != 'DefaultRoute'):
                        return self.protocol.sendData(
                            'This route order (0) is reserved for DefaultRoute only'
                        )
                    elif not arg.isdigit() or int(arg) < 0:
                        return self.protocol.sendData(
                            'Route order must be a positive integer')
                    else:
                        arg = int(arg)

                # Validate connector
                if cmd == 'connector':
                    try:
                        ctype, cid = validate_typed_connector_id(arg)
                        if ctype == 'smppc':
                            if self.pb['smppcm'].getConnector(cid) is None:
                                raise Exception('Unknown smppc cid: %s' %
                                                (cid))

                            # Make instance of SmppClientConnector
                            arg = SmppClientConnector(
                                self.pb['smppcm'].getConnector(cid)['id'])
                        else:
                            raise NotImplementedError("Not implemented yet !")
                    except Exception as e:
                        return self.protocol.sendData(str(e))

                # Validate connectors
                if cmd == 'connectors':
                    CIDs = arg.split(';')
                    if len(CIDs) == 1:
                        return self.protocol.sendData(
                            '%s option value must contain a minimum of 2 connector IDs separated with ";".'
                            % (cmd))

                    arg = []
                    for typed_cid in CIDs:
                        try:
                            ctype, cid = validate_typed_connector_id(typed_cid)
                            if ctype == 'smppc':
                                if self.pb['smppcm'].getConnector(cid) is None:
                                    raise Exception('Unknown smppc cid: %s' %
                                                    (cid))

                                # Make instance of SmppClientConnector
                                arg.append(
                                    SmppClientConnector(
                                        self.pb['smppcm'].getConnector(
                                            cid)['id']))
                            else:
                                raise NotImplementedError(
                                    "Not implemented yet !")
                        except Exception as e:
                            return self.protocol.sendData(str(e))

                # Validate rate and convert it to float
                if cmd == 'rate':
                    try:
                        arg = float(arg)
                    except ValueError:
                        return self.protocol.sendData(
                            'Incorrect rate (must be float): %s' % (arg))

                # Validate filters
                if cmd == 'filters':
                    FIDs = arg.split(';')

                    arg = []
                    for fid in FIDs:
                        if fid not in self.protocol.managers['filter'].filters:
                            return self.protocol.sendData('Unknown fid: %s' %
                                                          (fid))
                        else:
                            _Filter = self.protocol.managers['filter'].filters[
                                fid]

                            if _Filter.__class__.__name__ not in MTFILTERS:
                                return self.protocol.sendData(
                                    '%s#%s is not a valid filter for MTRoute (not in MTFILTERS)'
                                    % (_Filter.__class__.__name__, fid))
                            else:
                                arg.append(_Filter)

                # Buffer key for later Route initiating
                if cmd not in ra:
                    RouteKey = MTRouteKeyMap[cmd]
                else:
                    RouteKey = cmd
                self.sessBuffer[RouteKey] = arg

            return self.protocol.sendData()