Skip to content

Commit

Permalink
Merge pull request #99 from jookies/v0.6-beta
Browse files Browse the repository at this point in the history
V0.6 beta
  • Loading branch information
farirat committed Feb 26, 2015
2 parents bd0e1ca + 7a6e433 commit 7c5cc10
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 253 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.6b0.tar.gz
- sudo pip install dist/jasmin-0.6b2.tar.gz
# Commands to run tests:
script:
# Add jasmind to system autostartup:
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Architecture
.. figure:: https://github.com/jookies/jasmin/raw/master/misc/doc/sources/resources/architecture/hld.png
:alt: HLD Architecture
:align: Center
:figwidth: 100%

Jasmin core and its external connectors (used for AMQP, Redis, SMPP, HTTP, Telnet ...) are written in Python
and are mainly based on `Twisted matrix <https://twistedmatrix.com/>`_, an event-driven networking engine.
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 = 0
PATCH = 2
META = 'b'

def get_version():
Expand Down
81 changes: 55 additions & 26 deletions jasmin/protocols/cli/smppccm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import pickle
import logging
from twisted.internet import defer, reactor
from jasmin.protocols.smpp.configs import SMPPClientConfig
from jasmin.protocols.smpp.configs import SMPPClientConfig, UnknownValue
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.vendor.smpp.pdu.constants import (addr_npi_name_map, addr_ton_name_map,
replace_if_present_flap_name_map, priority_flag_name_map)
from jasmin.vendor.smpp.pdu.constants import addr_ton_name_map, addr_ton_value_map
from jasmin.vendor.smpp.pdu.constants import addr_npi_name_map, addr_npi_value_map
from jasmin.vendor.smpp.pdu.constants import replace_if_present_flap_name_map, replace_if_present_flap_value_map
from jasmin.vendor.smpp.pdu.constants import priority_flag_name_map, priority_flag_value_map
from jasmin.protocols.cli.protocol import str2num

# A config map between console-configuration keys and SMPPClientConfig keys.
Expand All @@ -25,11 +28,11 @@
# When updating a key from RequireRestartKeys, the connector need restart for update to take effect
RequireRestartKeys = ['host', 'port', 'username', 'password', 'systemType', 'log_file', 'log_level']

def castToBuiltInType(key, value):
def castOutputToBuiltInType(key, value):
'Will cast value to the correct type depending on the key'

if isinstance(value, bool):
return 1 if value else 0
return 'yes' if value else 'no'
if key in ['bind_npi', 'dst_npi', 'src_npi']:
return addr_npi_name_map[str(value)]
if key in ['bind_ton', 'dst_ton', 'src_ton']:
Expand All @@ -38,8 +41,35 @@ def castToBuiltInType(key, value):
return replace_if_present_flap_name_map[str(value)]
if key == 'priority':
return priority_flag_name_map[str(value)]
return value
else:
return value

def castInputToBuiltInType(key, value):
'Will cast value to the correct type depending on the key'

try:
if key in ['bind_npi', 'dst_npi', 'src_npi']:
return addr_npi_value_map[value]
elif key in ['bind_ton', 'dst_ton', 'src_ton']:
return addr_ton_value_map[value]
elif key == 'ripf':
return replace_if_present_flap_value_map[value]
elif key == 'priority':
return priority_flag_value_map[value]
elif key in ['con_fail_retry', 'con_loss_retry']:
if value == 'yes':
return True
elif value == 'no':
return False
else:
raise KeyError('Boolean value must be expressed by yes or no.')
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.')
except KeyError:
raise UnknownValue('Unknown value for key %s: %s' % (key, value))

return value

class JCliSMPPClientConfig(SMPPClientConfig):
'Overload SMPPClientConfig with getters and setters for JCli'
Expand All @@ -54,7 +84,7 @@ def set(self, key, value):
def getAll(self):
r = {}
for key, value in SMPPClientConfigKeyMap.iteritems():
r[key] = castToBuiltInType(key, getattr(self, value))
r[key] = castOutputToBuiltInType(key, getattr(self, value))
return r

def SMPPClientConfigBuild(fCallback):
Expand Down Expand Up @@ -85,19 +115,15 @@ def parse_args_and_call_with_instance(self, *args, **kwargs):
if not SMPPClientConfigKeyMap.has_key(cmd):
return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)

# Cast to boolean
if cmd in ['con_loss_retry', 'con_fail_retry']:
if arg.lower() in ['yes', 'y', '1']:
arg = True
elif arg.lower() in ['no', 'n', '0']:
arg = False

# Buffer key for later SMPPClientConfig initiating
SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
self.sessBuffer[SMPPClientConfigKey] = str2num(arg)
else:
self.sessBuffer[SMPPClientConfigKey] = arg
try:
# Buffer key for later SMPPClientConfig initiating
SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
else:
self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
except Exception, e:
return self.protocol.sendData('Error: %s' % str(e))

return self.protocol.sendData()
return parse_args_and_call_with_instance
Expand Down Expand Up @@ -134,12 +160,15 @@ def log_update_requests_and_call(self, *args, **kwargs):
if cmd == 'cid':
return self.protocol.sendData('Connector id can not be modified !')

# Buffer key for later (when receiving 'ok')
SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
self.sessBuffer[SMPPClientConfigKey] = str2num(arg)
else:
self.sessBuffer[SMPPClientConfigKey] = arg
try:
# Buffer key for later (when receiving 'ok')
SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
else:
self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
except Exception, e:
return self.protocol.sendData('Error: %s' % str(e))

return self.protocol.sendData()
return log_update_requests_and_call
Expand Down
6 changes: 5 additions & 1 deletion jasmin/protocols/cli/test/test_cmdprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def _test(self, finalPrompt, commands):
if 'expect' in cmd:
if isinstance(cmd['expect'], str):
self.assertGreaterEqual(len(receivedLines), 4, 'Got no return from command %s: %s' % (cmd['command'], receivedLines))
self.assertRegexpMatches(receivedLines[3], cmd['expect'])
receivedContent = ''
for line in range(len(receivedLines)):
if line % 3 == 0:
receivedContent+= receivedLines[line]
self.assertRegexpMatches(receivedContent, cmd['expect'])
elif isinstance(cmd['expect'], list):
self.assertGreaterEqual(len(receivedLines), 3+(len(cmd['expect']) * 3), 'Got no return from command %s: %s' % (cmd['command'], receivedLines))

Expand Down

0 comments on commit 7c5cc10

Please sign in to comment.