Skip to content

Commit

Permalink
Merge pull request #296 from zoufou/v0.6-beta
Browse files Browse the repository at this point in the history
0.6rc41
  • Loading branch information
farirat committed Aug 20, 2015
2 parents 13974f0 + 2e54367 commit 9b4f960
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
# Command to install dependencies
install:
- python setup.py sdist
- sudo pip install dist/jasmin-0.6rc40.tar.gz
- sudo pip install dist/jasmin-0.6rc41.tar.gz
- sudo cp misc/config/init-script/jasmind-ubuntu /etc/init.d/jasmind
- sudo update-rc.d jasmind defaults
# Commands to run tests:
Expand Down
2 changes: 1 addition & 1 deletion jasmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MAJOR = 0
MINOR = 6
PATCH = 40
PATCH = 41
META = 'rc'

def get_version():
Expand Down
7 changes: 7 additions & 0 deletions jasmin/protocols/cli/filtersm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pylint: disable-msg=W0401,W0611
import re
import inspect
import pickle
import time
Expand Down Expand Up @@ -78,6 +79,12 @@ def parse_args_and_call_with_instance(self, *args, **kwargs):
fa = self.sessBuffer['filter_args']
if cmd not in FilterKeyMap and cmd not in fa:
return self.protocol.sendData('Unknown Filter key: %s' % cmd)

# Validate fid syntax
if cmd == 'fid':
regex = re.compile(r'^[A-Za-z0-9_-]{1,16}$')
if regex.match(arg) == None:
return self.protocol.sendData('Invalid Filter fid syntax: %s' % arg)

# IF we got the type, check if it's a correct one
if cmd == 'type':
Expand Down
10 changes: 8 additions & 2 deletions jasmin/protocols/cli/mtrouterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,14 @@ def list(self, arg, opts):
filters += ', '
filters += repr(f)

# Prepare display for rate
rate = str('%.5f' % mtroute.getRate())
# Prepare display for rate:
# #295
# jcli: when route is not rated,
# add some differentiation markup to get the user's attention on it
if mtroute.getRate() == 0:
rate = '0 (!)'
else:
rate = str('%.5f' % mtroute.getRate())

self.protocol.sendData("#%s %s %s %s %s" % (str(order).ljust(5),
str(mtroute.__class__.__name__).ljust(23),
Expand Down
2 changes: 2 additions & 0 deletions jasmin/protocols/cli/smppccm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def castInputToBuiltInType(key, value):
elif (key == 'loglevel' and
value not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]):
raise KeyError('loglevel must be numeric value of 10, 20, 30, 40 or 50.')
elif type(value) == str and value.lower() == 'none':
value = None
except KeyError:
raise UnknownValue('Unknown value for key %s: %s' % (key, value))

Expand Down
60 changes: 36 additions & 24 deletions jasmin/protocols/cli/test/test_filtersm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ def test_add_with_minimum_args(self):
{'command': 'type TransparentFilter'}]
return self.add_filter(r'jcli : ', extraCommands)

def test_add_with_empty_fid(self):
extraCommands = [{'command': 'fid ', 'expect': 'Invalid Filter fid syntax: '},
{'command': 'type TransparentFilter'},
{'command': 'ok', 'expect': r'You must set these options before saving: type, fid'}]
return self.add_filter(r'> ', extraCommands)

def test_add_with_invalid_fid(self):
extraCommands = [{'command': 'fid With Space', 'expect': 'Invalid Filter fid syntax: With Space'},
{'command': 'type TransparentFilter'},
{'command': 'ok', 'expect': r'You must set these options before saving: type, fid'}]
return self.add_filter(r'> ', extraCommands)

def test_add_without_minimum_args(self):
extraCommands = [{'command': 'ok', 'expect': r'You must set these options before saving: type, fid'}]
return self.add_filter(r'> ', extraCommands)
Expand All @@ -51,7 +63,7 @@ def test_add_and_list(self):
self.add_filter('jcli : ', extraCommands)

expectedList = ['#Filter id Type Routes Description',
'#filter_4 TransparentFilter MO MT <TransparentFilter>',
'#filter_4 TransparentFilter MO MT <T>',
'Total Filters: 1']
commands = [{'command': 'filter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand Down Expand Up @@ -105,7 +117,7 @@ def test_remove_and_list(self):

# List
expectedList = ['#Filter id Type Routes Description',
'#%s TransparentFilter MO MT <TransparentFilter>' % fid.ljust(16),
'#%s TransparentFilter MO MT <T>' % fid.ljust(16),
'Total Filters: 1']
commands = [{'command': 'filter -l', 'expect': expectedList}]
self._test(r'jcli : ', commands)
Expand Down Expand Up @@ -148,7 +160,7 @@ def test_available_filters(self):
def test_add_TransparentFilter(self):
ftype = 'TransparentFilter'
_str_ = '%s' % ftype
_repr_ = '<%s>' % ftype
_repr_ = '<T>'

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -167,7 +179,7 @@ def test_add_UserFilter(self):
uid = '1'
ftype = 'UserFilter'
_str_ = ['%s:' % ftype, 'uid = %s' % uid]
_repr_ = '<%s \(uid=%s\)>' % (ftype, uid)
_repr_ = '<U \(uid=%s\)>' % (uid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -187,7 +199,7 @@ def test_add_GroupFilter(self):
gid = '1'
ftype = 'GroupFilter'
_str_ = ['%s:' % ftype, 'gid = %s' % gid]
_repr_ = '<%s \(gid=%s\)>' % (ftype, gid)
_repr_ = '<G \(gid=%s\)>' % (gid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -207,7 +219,7 @@ def test_add_ConnectorFilter(self):
cid = '1'
ftype = 'ConnectorFilter'
_str_ = ['%s:' % ftype, 'cid = %s' % cid]
_repr_ = '<%s \(cid=%s\)>' % (ftype, cid)
_repr_ = '<C \(cid=%s\)>' % (cid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -227,7 +239,7 @@ def test_add_SourceAddrFilter(self):
source_addr = '16'
ftype = 'SourceAddrFilter'
_str_ = ['%s:' % ftype, 'source_addr = %s' % source_addr]
_repr_ = '<%s \(src_addr=%s\)>' % (ftype, source_addr)
_repr_ = '<SA \(src_addr=%s\)>' % (source_addr)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -247,7 +259,7 @@ def test_add_DestinationAddrFilter(self):
destination_addr = '16'
ftype = 'DestinationAddrFilter'
_str_ = ['%s:' % ftype, 'destination_addr = %s' % destination_addr]
_repr_ = '<%s \(dst_addr=%s\)>' % (ftype, destination_addr)
_repr_ = '<DA \(dst_addr=%s\)>' % (destination_addr)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -267,7 +279,7 @@ def test_add_ShortMessageFilter(self):
short_message = 'Hello'
ftype = 'ShortMessageFilter'
_str_ = ['%s:' % ftype, 'short_message = %s' % short_message]
_repr_ = '<%s \(msg=%s\)>' % (ftype, short_message)
_repr_ = '<SM \(msg=%s\)>' % (short_message)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -289,7 +301,7 @@ def test_add_DateIntervalFilter(self):
dateInterval = '%s;%s' % (leftBorder, rightBorder)
ftype = 'DateIntervalFilter'
_str_ = ['%s:' % ftype, 'Left border = %s' % leftBorder, 'Right border = %s' % rightBorder]
_repr_ = '<%s \(%s,%s\)>' % (ftype, leftBorder, rightBorder)
_repr_ = '<DI \(%s,%s\)>' % (leftBorder, rightBorder)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -311,7 +323,7 @@ def test_add_TimeIntervalFilter(self):
timeInterval = '%s;%s' % (leftBorder, rightBorder)
ftype = 'TimeIntervalFilter'
_str_ = ['%s:' % ftype, 'Left border = %s' % leftBorder, 'Right border = %s' % rightBorder]
_repr_ = '<%s \(%s,%s\)>' % (ftype, leftBorder, rightBorder)
_repr_ = '<TI \(%s,%s\)>' % (leftBorder, rightBorder)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -334,7 +346,7 @@ def test_add_EvalPyFilter(self):

ftype = 'EvalPyFilter'
_str_ = ['%s:' % ftype, '']
_repr_ = '<%s \(pyCode= ..\)>' % ftype
_repr_ = '<Ev \(pyCode= ..\)>'

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand Down Expand Up @@ -369,7 +381,7 @@ def test_add_EvalPyFilter_withCode(self):
ftype = 'EvalPyFilter'
_str_ = ['%s:' % ftype]
_str_.extend([y for y in (re.escape(x.strip()) for x in pyCode.splitlines()) if y])
_repr_ = '<%s \(pyCode=%s ..\)>' % (ftype, pyCode[:10].replace('\n', ''))
_repr_ = '<Ev \(pyCode=%s ..\)>' % (pyCode[:10].replace('\n', ''))

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand Down Expand Up @@ -406,7 +418,7 @@ def tearDown(self):
def test_TransparentFilter(self):
ftype = 'TransparentFilter'
_str_ = '%s' % ftype
_repr_ = '<%s>' % ftype
_repr_ = '<T>'

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -430,7 +442,7 @@ def test_UserFilter(self):
uid = '1'
ftype = 'UserFilter'
_str_ = ['%s:' % ftype, 'uid = %s' % uid]
_repr_ = '<%s \(uid=%s\)>' % (ftype, uid)
_repr_ = '<U \(uid=%s\)>' % (uid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -455,7 +467,7 @@ def test_GroupFilter(self):
gid = '1'
ftype = 'GroupFilter'
_str_ = ['%s:' % ftype, 'gid = %s' % gid]
_repr_ = '<%s \(gid=%s\)>' % (ftype, gid)
_repr_ = '<G \(gid=%s\)>' % (gid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -480,7 +492,7 @@ def test_ConnectorFilter(self):
cid = '1'
ftype = 'ConnectorFilter'
_str_ = ['%s:' % ftype, 'cid = %s' % cid]
_repr_ = '<%s \(cid=%s\)>' % (ftype, cid)
_repr_ = '<C \(cid=%s\)>' % (cid)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -505,7 +517,7 @@ def test_SourceAddrFilter(self):
source_addr = '16'
ftype = 'SourceAddrFilter'
_str_ = ['%s:' % ftype, 'source_addr = %s' % source_addr]
_repr_ = '<%s \(src_addr=%s\)>' % (ftype, source_addr)
_repr_ = '<SA \(src_addr=%s\)>' % (source_addr)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -530,7 +542,7 @@ def test_DestinationAddrFilter(self):
destination_addr = '16'
ftype = 'DestinationAddrFilter'
_str_ = ['%s:' % ftype, 'destination_addr = %s' % destination_addr]
_repr_ = '<%s \(dst_addr=%s\)>' % (ftype, destination_addr)
_repr_ = '<DA \(dst_addr=%s\)>' % (destination_addr)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -555,7 +567,7 @@ def test_ShortMessageFilter(self):
short_message = 'Hello'
ftype = 'ShortMessageFilter'
_str_ = ['%s:' % ftype, 'short_message = %s' % short_message]
_repr_ = '<%s \(msg=%s\)>' % (ftype, short_message)
_repr_ = '<SM \(msg=%s\)>' % (short_message)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -582,7 +594,7 @@ def test_DateIntervalFilter(self):
dateInterval = '%s;%s' % (leftBorder, rightBorder)
ftype = 'DateIntervalFilter'
_str_ = ['%s:' % ftype, 'Left border = %s' % leftBorder, 'Right border = %s' % rightBorder]
_repr_ = '<%s \(%s,%s\)>' % (ftype, leftBorder, rightBorder)
_repr_ = '<DI \(%s,%s\)>' % (leftBorder, rightBorder)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand All @@ -609,7 +621,7 @@ def test_TimeIntervalFilter(self):
timeInterval = '%s;%s' % (leftBorder, rightBorder)
ftype = 'TimeIntervalFilter'
_str_ = ['%s:' % ftype, 'Left border = %s' % leftBorder, 'Right border = %s' % rightBorder]
_repr_ = '<%s \(%s,%s\)>' % (ftype, leftBorder, rightBorder)
_repr_ = '<TI \(%s,%s\)>' % (leftBorder, rightBorder)

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand Down Expand Up @@ -637,7 +649,7 @@ def test_EvalPyFilter(self):

ftype = 'EvalPyFilter'
_str_ = ['%s:' % ftype, '']
_repr_ = '<%s \(pyCode= ..\)>' % ftype
_repr_ = '<Ev \(pyCode= ..\)>'

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand Down Expand Up @@ -677,7 +689,7 @@ def test_EvalPyFilter_withCode(self):
ftype = 'EvalPyFilter'
_str_ = ['%s:' % ftype]
_str_.extend([y for y in (re.escape(x.strip()) for x in pyCode.splitlines()) if y])
_repr_ = '<%s \(pyCode=%s ..\)>' % (ftype, pyCode[:10].replace('\n', ''))
_repr_ = '<Ev \(pyCode=%s ..\)>' % (pyCode[:10].replace('\n', ''))

# Add filter
extraCommands = [{'command': 'fid filter_id'},
Expand Down
10 changes: 10 additions & 0 deletions jasmin/protocols/cli/test/test_groupm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def test_add_with_minimum_args(self):
extraCommands = [{'command': 'gid group_1'}]
return self.add_group(r'jcli : ', extraCommands)

def test_add_with_empty_gid(self):
extraCommands = [{'command': 'gid '},
{'command': 'ok', 'expect': r'Error: Group gid syntax is invalid'},]
return self.add_group(r'> ', extraCommands)

def test_add_with_invalid_gid(self):
extraCommands = [{'command': 'gid With Space'},
{'command': 'ok', 'expect': r'Error: Group gid syntax is invalid'},]
return self.add_group(r'> ', extraCommands)

def test_add_without_minimum_args(self):
extraCommands = [{'command': 'ok', 'expect': r'You must set Group id \(gid\) before saving !'}]
return self.add_group(r'> ', extraCommands)
Expand Down
14 changes: 7 additions & 7 deletions jasmin/protocols/cli/test/test_morouterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_flush(self):

# List
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#20 StaticMORoute smpps\(smpp_user\) \<TransparentFilter\>',
'#20 StaticMORoute smpps\(smpp_user\) \<T\>',
'#0 DefaultRoute http\(http1\)',
'Total MO Routes: 2']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_add_StaticMORoute_http(self):
expectedList = ['%s' % _str_]
self._test('jcli : ', [{'command': 'morouter -s %s' % rorder, 'expect': expectedList}])
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#%s %s %s <TransparentFilter>' % (rorder.ljust(5), rtype.ljust(23), re.escape(typed_cid).ljust(48)),
'#%s %s %s <T>' % (rorder.ljust(5), rtype.ljust(23), re.escape(typed_cid).ljust(48)),
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand All @@ -294,7 +294,7 @@ def test_add_StaticMORoute_smpps(self):
expectedList = ['%s' % _str_]
self._test('jcli : ', [{'command': 'morouter -s %s' % rorder, 'expect': expectedList}])
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#%s %s %s <TransparentFilter>' % (rorder.ljust(5), rtype.ljust(23), re.escape(typed_cid).ljust(48)),
'#%s %s %s <T>' % (rorder.ljust(5), rtype.ljust(23), re.escape(typed_cid).ljust(48)),
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand All @@ -320,7 +320,7 @@ def test_add_RandomRoundrobinMORoute_http(self):
expectedList = _str_
self._test('jcli : ', [{'command': 'morouter -s %s' % rorder, 'expect': expectedList}])
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#%s %s %s <TransparentFilter>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'#%s %s %s <T>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand All @@ -346,7 +346,7 @@ def test_add_RandomRoundrobinMORoute_smpps(self):
expectedList = _str_
self._test('jcli : ', [{'command': 'morouter -s %s' % rorder, 'expect': expectedList}])
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#%s %s %s <TransparentFilter>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'#%s %s %s <T>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand All @@ -372,7 +372,7 @@ def test_add_RandomRoundrobinMORoute_hybrid(self):
expectedList = _str_
self._test('jcli : ', [{'command': 'morouter -s %s' % rorder, 'expect': expectedList}])
expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#%s %s %s <TransparentFilter>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'#%s %s %s <T>' % (rorder.ljust(5), rtype.ljust(23), (re.escape(typed_cid1)+', '+re.escape(typed_cid2)).ljust(48)),
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_list_with_filter(self):
self.add_moroute(r'jcli : ', extraCommands)

expectedList = ['#Order Type Connector ID\(s\) Filter\(s\)',
'#20 StaticMORoute http\(http1\) <ConnectorFilter \(cid=Any\)>',
'#20 StaticMORoute http\(http1\) <C \(cid=Any\)>',
'Total MO Routes: 1']
commands = [{'command': 'morouter -l', 'expect': expectedList}]
return self._test(r'jcli : ', commands)

0 comments on commit 9b4f960

Please sign in to comment.