Skip to content

Commit

Permalink
Merge tag 'vumi-0.5.33' into release/0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Giesler committed Nov 17, 2015
2 parents e9d8982 + a54d663 commit 55e8b34
Show file tree
Hide file tree
Showing 87 changed files with 2,650 additions and 969 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dropin.cache
/django_test_results.xml
/pep8.txt
/.tox
/.cache/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ matrix:
# are orthogonal and any failures should be easily attributable to either
# Twisted version or Riak version without adding an additional build job.
- python: "2.7"
env: TWISTED_VERSION="Twisted==13.1.0" RIAK_VERSION="2.1.1"
env: TWISTED_VERSION="Twisted==13.2.0" RIAK_VERSION="2.1.1"
# Test on pypy without coverage, because it's unnecessary and very slow.
# Also, we hit an obscure GC bug in pypy<=2.6.0 so we need at least 2.6.1.
- python: "pypy"
Expand Down
2 changes: 0 additions & 2 deletions config/example_http_relay.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions config/smpp_test_dispatcher.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# The short X.Y version.
version = '0.5'
# The full version, including alpha/beta/rc tags.
release = '0.5.32'
release = '0.5.33'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
36 changes: 0 additions & 36 deletions etc/supervisord.smpp_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
serverurl=http://127.0.0.1:7010 ; use an http:// url to specify an inet socket


[program:smpp_test_smsc_transport]
numprocs=1
numprocs_start=1
process_name=%(program_name)s_%(process_num)s
command=twistd -n
--pidfile=./tmp/pids/%(program_name)s_%(process_num)s.pid
vumi_worker
--worker_class=vumi.transports.smpp.service.SmppService
--vhost=/develop
--config=./config/smpp_test.yaml
stdout_logfile=./logs/%(program_name)s_%(process_num)s.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=./logs/%(program_name)s_%(process_num)s.err
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
autorestart=true

[program:smpp_test_esme_transport]
numprocs=1
numprocs_start=0
Expand All @@ -57,24 +39,6 @@ stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
autorestart=true

[program:smpp_test_dispatcher]
numprocs=1
numprocs_start=1
process_name=%(program_name)s_%(process_num)s
command=twistd -n
--pidfile=./tmp/pids/%(program_name)s_%(process_num)s.pid
vumi_worker
--worker_class=vumi.dispatchers.simple.dispatcher.SimpleDispatcher
--vhost=/develop
--config=./config/smpp_test_dispatcher.yaml
stdout_logfile=./logs/%(program_name)s_%(process_num)s.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=./logs/%(program_name)s_%(process_num)s.err
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
autorestart=true

[program:smpp_test_http_poster]
numprocs=1
numprocs_start=1
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="vumi",
version="0.5.32",
version="0.5.33",
url='http://github.com/praekelt/vumi',
license='BSD',
description="Super-scalable messaging engine for the delivery of SMS, "
Expand All @@ -36,7 +36,7 @@
install_requires=[
cryptography, # See above for pypy-version-dependent requirement.
'zope.interface',
'Twisted>=13.1.0',
'Twisted>=13.2.0',
'txAMQP>=0.6.2',
'PyYAML',
'iso8601',
Expand Down
2 changes: 1 addition & 1 deletion vumi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Vumi scalable text messaging engine.
"""

__version__ = "0.5.32"
__version__ = "0.5.33"
17 changes: 10 additions & 7 deletions vumi/application/http_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HTTPRelayApplication(ApplicationWorker):
CONFIG_CLASS = HTTPRelayConfig

reply_header = 'X-Vumi-HTTPRelay-Reply'
agent_factory = None # For swapping out the Agent we use in tests.

def validate_config(self):
self.supported_auth_methods = {
Expand All @@ -48,7 +49,7 @@ def validate_config(self):
config = self.get_static_config()
if config.auth_method not in self.supported_auth_methods:
raise HTTPRelayError(
'HTTP Authentication method %s not supported' % (
'HTTP Authentication method %s not supported' % (
repr(config.auth_method,)))

def generate_basic_auth_headers(self, username, password):
Expand All @@ -68,8 +69,9 @@ def get_auth_headers(self, config):
def consume_user_message(self, message):
config = yield self.get_config(message)
headers = self.get_auth_headers(config)
response = yield http_request_full(config.url.geturl(),
message.to_json(), headers, config.http_method)
response = yield http_request_full(
config.url.geturl(), message.to_json(), headers,
config.http_method, agent_class=self.agent_factory)
headers = response.headers
if response.code == http.OK:
if headers.hasHeader(self.reply_header):
Expand All @@ -78,15 +80,16 @@ def consume_user_message(self, message):
if (raw_headers[0].lower() == 'true') and content:
self.reply_to(message, content)
else:
log.err('%s responded with %s' % (config.url.geturl(),
response.code))
log.err('%s responded with %s' % (
config.url.geturl(), response.code))

@inlineCallbacks
def relay_event(self, event):
config = yield self.get_config(event)
headers = self.get_auth_headers(config)
yield http_request_full(config.event_url.geturl(),
event.to_json(), headers, config.http_method)
yield http_request_full(
config.event_url.geturl(), event.to_json(), headers,
config.http_method, agent_class=self.agent_factory)

@inlineCallbacks
def consume_ack(self, event):
Expand Down
8 changes: 5 additions & 3 deletions vumi/application/rapidsms_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class RapidSMSRelay(ApplicationWorker):

ALLOWED_ENDPOINTS = None

agent_factory = None # For swapping out the Agent we use in tests.

def validate_config(self):
self.supported_auth_methods = {
'basic': self.generate_basic_auth_headers,
Expand Down Expand Up @@ -303,9 +305,9 @@ def _call_rapidsms(self, message):
http_method = config.rapidsms_http_method.encode("utf-8")
headers = self.get_auth_headers(config)
yield self._store_message(message, config.vumi_reply_timeout)
response = http_request_full(config.rapidsms_url.geturl(),
message.to_json(),
headers, http_method)
response = http_request_full(
config.rapidsms_url.geturl(), message.to_json(), headers,
http_method, agent_class=self.agent_factory)
response.addCallback(lambda response: log.info(response.code))
response.addErrback(lambda failure: log.err(failure))
yield response
Expand Down
9 changes: 6 additions & 3 deletions vumi/application/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,17 @@ def test_application_prefetch_count_custom(self):
'amqp_prefetch_count': 10,
})
for consumer in self.get_app_consumers(app):
self.assertEqual(consumer.channel.qos_prefetch_count, 10)
fake_channel = consumer.channel._fake_channel
self.assertEqual(fake_channel.qos_prefetch_count, 10)

@inlineCallbacks
def test_application_prefetch_count_default(self):
app = yield self.app_helper.get_application({
'transport_name': 'test',
})
for consumer in self.get_app_consumers(app):
self.assertEqual(consumer.channel.qos_prefetch_count, 20)
fake_channel = consumer.channel._fake_channel
self.assertEqual(fake_channel.qos_prefetch_count, 20)

@inlineCallbacks
def test_application_prefetch_count_none(self):
Expand All @@ -194,7 +196,8 @@ def test_application_prefetch_count_none(self):
'amqp_prefetch_count': None,
})
for consumer in self.get_app_consumers(app):
self.assertFalse(consumer.channel.qos_prefetch_count)
fake_channel = consumer.channel._fake_channel
self.assertEqual(fake_channel.qos_prefetch_count, 0)

def assertNotRaises(self, error_class, f, *args, **kw):
try:
Expand Down
10 changes: 4 additions & 6 deletions vumi/application/tests/test_http_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from twisted.internet.defer import inlineCallbacks
from twisted.web import http

from vumi.tests.utils import MockHttpServer
from vumi.application.http_relay import HTTPRelayApplication
from vumi.message import TransportEvent

from vumi.application.tests.helpers import ApplicationHelper
from vumi.tests.fake_connection import FakeHttpServer
from vumi.tests.helpers import VumiTestCase


Expand All @@ -16,20 +16,18 @@ class TestHTTPRelay(VumiTestCase):
@inlineCallbacks
def setUp(self):
yield super(TestHTTPRelay, self).setUp()
self.path = '/path'
self.app_helper = self.add_helper(
ApplicationHelper(HTTPRelayApplication))

@inlineCallbacks
def setup_resource_with_callback(self, callback):
self.mock_server = MockHttpServer(callback)
self.add_cleanup(self.mock_server.stop)
yield self.mock_server.start()
self.fake_http = FakeHttpServer(callback)
self.app = yield self.app_helper.get_application({
'url': '%s%s' % (self.mock_server.url, self.path),
'url': 'http://relay.example.com/path',
'username': 'username',
'password': 'password',
})
self.app.agent_factory = self.fake_http.get_agent

def setup_resource(self, code, content, headers):
def handler(request):
Expand Down
15 changes: 7 additions & 8 deletions vumi/application/tests/test_rapidsms_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from twisted.internet.defer import inlineCallbacks
from twisted.web import http

from vumi.tests.utils import LogCatcher, MockHttpServer
from vumi.tests.utils import LogCatcher
from vumi.application.rapidsms_relay import RapidSMSRelay, BadRequestError
from vumi.utils import http_request_full, basic_auth_string, to_kwargs
from vumi.message import TransportUserMessage, from_json
from vumi.application.tests.helpers import ApplicationHelper
from vumi.tests.fake_connection import FakeHttpServer
from vumi.tests.helpers import VumiTestCase


Expand All @@ -22,16 +23,14 @@ def setUp(self):
def setup_resource(self, callback=None, auth=None, config=None):
if callback is None:
callback = lambda r: self.fail("No RapidSMS requests expected.")
self.mock_server = MockHttpServer(callback)
self.add_cleanup(self.mock_server.stop)
yield self.mock_server.start()
url = '%s%s' % (self.mock_server.url, '/test/resource/path')
self.app = yield self.setup_app(url, auth=auth, config=config)
self.fake_http = FakeHttpServer(callback)
self.app = yield self.setup_app(auth=auth, config=config)
self.app.agent_factory = self.fake_http.get_agent

def setup_app(self, url, auth=None, config=None):
def setup_app(self, auth=None, config=None):
vumi_username, vumi_password = auth if auth else (None, None)
app_config = {
'rapidsms_url': url,
'rapidsms_url': 'http://rapidsms.example.com/test/resource/path',
'web_path': '/send/',
'web_port': '0',
'rapidsms_username': 'username',
Expand Down
10 changes: 5 additions & 5 deletions vumi/blinkenlights/heartbeat/tests/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

from twisted.internet.defer import inlineCallbacks

from vumi.tests.utils import get_stubbed_channel
from vumi.tests.fake_amqp import FakeAMQPBroker
from vumi.blinkenlights.heartbeat import publisher
from vumi.errors import MissingMessageField
from vumi.tests.helpers import VumiTestCase
from vumi.tests.helpers import VumiTestCase, WorkerHelper


class MockHeartBeatPublisher(publisher.HeartBeatPublisher):
Expand All @@ -36,13 +35,14 @@ def gen_fake_attrs(self):

@inlineCallbacks
def test_publish_heartbeat(self):
self.broker = FakeAMQPBroker()
channel = yield get_stubbed_channel(self.broker)
broker = FakeAMQPBroker()
client = WorkerHelper.get_fake_amqp_client(broker)
channel = yield client.get_channel()
pub = MockHeartBeatPublisher(self.gen_fake_attrs)
pub.start(channel)
pub._beat()

[msg] = self.broker.get_dispatched("vumi.health", "heartbeat.inbound")
[msg] = broker.get_dispatched("vumi.health", "heartbeat.inbound")
self.assertEqual(json.loads(msg.body), self.gen_fake_attrs())

def test_message_validation(self):
Expand Down
3 changes: 2 additions & 1 deletion vumi/blinkenlights/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def stop_polling(self):
Stop the metric polling and publishing task.
"""
if self._task:
self._task.stop()
if self._task.running:
self._task.stop()
self._task = None

def publish_metrics(self):
Expand Down
Loading

0 comments on commit 55e8b34

Please sign in to comment.