diff --git a/PubSubConsumer.py b/PubSubConsumer.py index 85fd9182..99af14fe 100644 --- a/PubSubConsumer.py +++ b/PubSubConsumer.py @@ -16,7 +16,7 @@ class PubSubConsumer(object): """ - def __init__(self, amqp_url, logger): + def __init__(self, amqp_prefix, logger): """Create a new instance of the consumer class, passing in the AMQP URL used to connect to RabbitMQ. @@ -27,7 +27,7 @@ class PubSubConsumer(object): self._channel = None self._closing = False self._consumer_tag = None - self._url = amqp_url + self._prefix = amqp_prefix self.logger = logger def connect(self): @@ -38,8 +38,15 @@ class PubSubConsumer(object): :rtype: pika.SelectConnection """ - self.logger.info('Connecting to %s', self._url) - return pika.SelectConnection(pika.URLParameters(self._url), + self.logger.info('Connecting to %s', self._prefix) + account = 'opensuse' + server = 'rabbit.opensuse.org' + if self._prefix == 'suse': + account = 'suse' + server = 'rabbit.suse.de' + credentials = pika.PlainCredentials(account, account) + parameters = pika.ConnectionParameters(server, 5671, '/', credentials, ssl=True, socket_timeout=10) + return pika.SelectConnection(parameters, self.on_connection_open, stop_ioloop_on_close=False) diff --git a/rabbit-openqa.py b/rabbit-openqa.py index d08ae476..d99b91b1 100755 --- a/rabbit-openqa.py +++ b/rabbit-openqa.py @@ -160,8 +160,8 @@ class Project(object): class Listener(PubSubConsumer): - def __init__(self, amqp_prefix, amqp_url, openqa_url): - super(Listener, self).__init__(amqp_url, logging.getLogger(__name__)) + def __init__(self, amqp_prefix, openqa_url): + super(Listener, self).__init__(amqp_prefix, logging.getLogger(__name__)) self.projects = [] self.amqp_prefix = amqp_prefix self.openqa_url = openqa_url @@ -249,16 +249,14 @@ if __name__ == '__main__': if apiurl.endswith('suse.de'): amqp_prefix = 'suse' - amqp_url = "amqps://suse:suse@rabbit.suse.de" openqa_url = 'https://openqa.suse.de' else: amqp_prefix = 'opensuse' - amqp_url = "amqps://opensuse:opensuse@rabbit.opensuse.org" openqa_url = 'https://openqa.opensuse.org' logging.basicConfig(level=logging.INFO) - l = Listener(amqp_prefix, amqp_url, openqa_url) + l = Listener(amqp_prefix, openqa_url) url = makeurl(apiurl, ['search', 'project', 'id'], {'match': 'attribute/@name="OSRT:OpenQAMapping"'}) f = http_GET(url) root = ET.parse(f).getroot()