Merge lp:~pwlars/snappy-proposed-selftest-agent/rename-agent-code into lp:snappy-proposed-selftest-agent

Proposed by Paul Larson
Status: Merged
Approved by: Paul Larson
Approved revision: 10
Merged at revision: 7
Proposed branch: lp:~pwlars/snappy-proposed-selftest-agent/rename-agent-code
Merge into: lp:snappy-proposed-selftest-agent
Diff against target: 733 lines (+308/-307)
15 files modified
README.rst (+5/-5)
called-by-tarmac.py (+2/-2)
core-selftest-agent.py (+0/-7)
core_selftest_agent/__init__.py (+0/-116)
core_selftest_agent/constants.py (+0/-49)
core_selftest_agent/tests/__init__.py (+0/-16)
core_selftest_agent/tests/test_worker.py (+0/-53)
core_selftest_agent/worker.py (+0/-52)
setup.py (+7/-7)
snappy-proposed-selftest-agent.py (+7/-0)
snappy_proposed_selftest_agent/__init__.py (+117/-0)
snappy_proposed_selftest_agent/constants.py (+49/-0)
snappy_proposed_selftest_agent/tests/__init__.py (+16/-0)
snappy_proposed_selftest_agent/tests/test_worker.py (+53/-0)
snappy_proposed_selftest_agent/worker.py (+52/-0)
To merge this branch: bzr merge lp:~pwlars/snappy-proposed-selftest-agent/rename-agent-code
Reviewer Review Type Date Requested Status
Para Siva (community) Approve
Paul Larson Needs Resubmitting
Review via email: mp+260295@code.launchpad.net

Commit message

Rename core-selftest-agent to snappy-proposed-selftest-agent.

Description of the change

Rename core-selftest-agent to snappy-proposed-selftest-agent. I've left behind some worker names like CoreSelftestWorker and such as they are internal and will be getting worked on soon as other MPs anyway. Same for queue names which still need some tweaking.

To post a comment you must log in.
Revision history for this message
Para Siva (psivaa) wrote :

+1, Thanks for the comment about the worker code as incoming MPs

review: Approve
8. By Paul Larson

add back snappy-proposed-selftest-agent.py and snappy_proposed_selftest_agent/

Revision history for this message
Paul Larson (pwlars) wrote :

argh, I forgot to do bzr before the mv when renaming the module and the cli. I've just added them back, which makes this a bit long, but it's just a rename and s/core-/snappy-proposed/ for the most part. If you need me to start over for this to make sense, just say so.

review: Needs Resubmitting
Revision history for this message
Para Siva (psivaa) wrote :

Thanks for adding the worker code, Paul. I've got some inline comments about the queue names etc, since we're renaming. Let me know if they dont make sense.

review: Needs Fixing
9. By Paul Larson

change conf file name

10. By Paul Larson

Add .v1 to exchanges as discussed

Revision history for this message
Paul Larson (pwlars) wrote :

I was going to handle the exchange .v1 addition we discussed this morning in a separate mp, but no good reason not to do it here. Also change the .conf file name as is being done elsewhere.

review: Needs Resubmitting
Revision history for this message
Para Siva (psivaa) wrote :

Thanks for that. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.rst'
--- README.rst 2015-05-20 22:00:00 +0000
+++ README.rst 2015-05-27 17:01:56 +0000
@@ -1,10 +1,10 @@
1Core Selftest Agent1Snappy Proposed Selftest Agent
2###################2##############################
33
4A micro-service that watches for britney-announcer events of new4A micro-service that watches for britney-announcer events of new
5packages to test, checks if they are in the manifest for core images in5packages to test, checks if they are in the manifest for core images in
6the channel we want to test, and triggers core-image-builder to start6the channel we want to test, and triggers snappy-proposed-image-builder
7building an image with the proposed changes. This service is only7to start building an image with the proposed changes. This service is only
8responsible for triggering test runs of the snappy selftests.8responsible for triggering test runs of the snappy selftests.
99
10Get the Source10Get the Source
@@ -12,7 +12,7 @@
1212
13Branch the code::13Branch the code::
1414
15 $ bzr branch lp:core-selftest-agent15 $ bzr branch lp:snappy-proposed-selftest-agent
1616
17Install the Service17Install the Service
18===================18===================
1919
=== modified file 'called-by-tarmac.py'
--- called-by-tarmac.py 2015-05-22 16:26:11 +0000
+++ called-by-tarmac.py 2015-05-27 17:01:56 +0000
@@ -1,6 +1,6 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2#2#
3# core-selftest-agent3# snappy-proposed-selftest-agent
4# Copyright (C) 2015 Canonical4# Copyright (C) 2015 Canonical
5#5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
@@ -33,7 +33,7 @@
33import sys33import sys
34import tempfile34import tempfile
3535
36SERVICE_NAME = 'core-selftest-agent'36SERVICE_NAME = 'snappy-proposed-selftest-agent'
37VENV_DIR = 'venv-{}'.format(SERVICE_NAME)37VENV_DIR = 'venv-{}'.format(SERVICE_NAME)
38PIP_DIR = 'pip-cache-'.format(SERVICE_NAME)38PIP_DIR = 'pip-cache-'.format(SERVICE_NAME)
39PIP_CACHE_BRANCH = 'lp:~canonical-ci-engineering/{}/' \39PIP_CACHE_BRANCH = 'lp:~canonical-ci-engineering/{}/' \
4040
=== removed file 'core-selftest-agent.py'
--- core-selftest-agent.py 2015-05-20 17:20:50 +0000
+++ core-selftest-agent.py 1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
1#!/usr/bin/env python3
2
3from core_selftest_agent import main
4
5
6if __name__ == '__main__':
7 main()
80
=== removed directory 'core_selftest_agent'
=== removed file 'core_selftest_agent/__init__.py'
--- core_selftest_agent/__init__.py 2015-05-22 19:49:10 +0000
+++ core_selftest_agent/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,116 +0,0 @@
1# core-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import argparse
19import configparser
20import kombu
21import logging
22import os
23
24from uservice_utils.logging import (
25 configure_service_logging,
26 ExtraLogger,
27)
28
29from core_selftest_agent import constants
30from core_selftest_agent.worker import CoreSelftestAgentWorker
31
32
33class CoreImageResultPublisher(object):
34 """A callable that can notify a results exchange that the test is running
35
36 This will be a fanout exchange so multiple consumers can pick up these
37 messages and decide whether to take action or ignore them.
38 """
39
40 def __init__(self, connection):
41 self.connection = connection
42 exchange = kombu.Exchange(constants.RESULTS_EXCHANGE,
43 type='fanout', durable=False)
44 self.queue = kombu.Queue(constants.RESULTS_QUEUE, exchange)
45
46 def __call__(self, payload):
47 """Take 'payload' and enqueue it on the rabbit exchange."""
48 queue = self.connection.SimpleQueue(self.queue)
49 queue.put(payload)
50 queue.close()
51
52
53class CoreImageBuilder(object):
54 """A callable that knows how to queue message for the image builder
55
56 For now we're using a simple queue, but this can easily be extended to use
57 a full-blown topic exchange in the future.
58 """
59
60 def __init__(self, connection):
61 self.connection = connection
62
63 def __call__(self, payload):
64 """Take 'payload' and enqueue it on the rabbit queue."""
65 queue = self.connection.SimpleQueue(constants.IMAGE_BUILD_QUEUE)
66 queue.put(payload)
67 queue.close()
68
69
70def read_config():
71 parser = argparse.ArgumentParser(description='Core Selftest Agent.')
72 parser.add_argument(
73 '-c',
74 '--conf',
75 default='core-service.conf',
76 help='Configuration file path'
77 )
78 args = parser.parse_args()
79
80 # Load configuration options.
81 config = configparser.ConfigParser()
82 config.read(args.conf)
83 return config
84
85
86def get_logger(name, extra={}):
87 if logging.getLoggerClass() != ExtraLogger:
88 logging.setLoggerClass(ExtraLogger)
89 logger = logging.getLogger(name)
90 e = constants.LOGGING_EXTRA.copy()
91 e.update(extra)
92 logger.set_extra_args(e)
93 return logger
94
95
96def main():
97 config = read_config()
98 log_path = os.path.abspath(
99 os.path.join(__file__, '../../logs/core-selftest-agent.log'))
100 configure_service_logging(
101 log_path,
102 config['logstash'] if 'logstash' in config else None
103 )
104
105 ampq_uris = config.get('amqp', 'uris').split()
106 try:
107 with kombu.Connection(ampq_uris) as connection:
108 monitor = CoreSelftestAgentWorker(
109 connection,
110 constants,
111 CoreImageBuilder(connection),
112 CoreImageResultPublisher(connection),
113 )
114 monitor.run()
115 except KeyboardInterrupt:
116 print("Bye!")
1170
=== removed file 'core_selftest_agent/constants.py'
--- core_selftest_agent/constants.py 2015-05-26 14:57:41 +0000
+++ core_selftest_agent/constants.py 1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
1# core-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18"""Constants for this service."""
19import socket
20
21# Queue names are constant, rather than being defined in the config.
22
23# We listen to a fanout exchange for candidate packages to test
24INPUT_EXCHANGE = "candidates.exchange"
25
26# The queue needs to be unique to selftest agents
27INPUT_QUEUE = "core.selftest.candidates"
28
29# The queue we send events on to request image build and test
30IMAGE_BUILD_QUEUE = "snappy-proposed-migration.package.v1"
31
32# We need to notify the results exchange that the test is in progress
33RESULTS_EXCHANGE = "results.exchange"
34RESULTS_QUEUE = "core.selftest.results"
35
36# The queue we put fatally error'd payloads into:
37DEAD_LETTER_QUEUE = "core.deadletters.v1"
38
39SOLUTION_NAME = "core-image-testing"
40
41SERVICE_NAME = "core-selftest-agent"
42
43HOSTNAME = socket.gethostname()
44
45LOGGING_EXTRA = {
46 'solution': SOLUTION_NAME,
47 'service': SERVICE_NAME,
48 'hostname': HOSTNAME,
49}
500
=== removed directory 'core_selftest_agent/tests'
=== removed file 'core_selftest_agent/tests/__init__.py'
--- core_selftest_agent/tests/__init__.py 2015-05-22 19:49:10 +0000
+++ core_selftest_agent/tests/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1# core-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
170
=== removed file 'core_selftest_agent/tests/test_worker.py'
--- core_selftest_agent/tests/test_worker.py 2015-05-26 14:57:41 +0000
+++ core_selftest_agent/tests/test_worker.py 1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
1# core-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import kombu
19from testtools import TestCase
20
21from core_selftest_agent import constants
22from core_selftest_agent.worker import CoreSelftestAgentWorker
23
24
25class WorkerTests(TestCase):
26 def test_can_read_message(self):
27 conn = kombu.Connection('memory:///')
28 queue_message(conn, {'test': 'value'})
29
30 build_worker = LoggingConsumer()
31 result_worker = LoggingConsumer()
32 q = CoreSelftestAgentWorker(conn, constants,
33 build_worker, result_worker)
34 next(q.consume(limit=1, timeout=5.0))
35 self.assertEqual(build_worker.messages_seen, [dict(test='value')])
36 self.assertEqual(result_worker.messages_seen, [dict(test='value')])
37
38
39class LoggingConsumer(object):
40 """A consumer callback object that acks and logs all received payloads."""
41 def __init__(self):
42 self.messages_seen = []
43
44 def __call__(self, message):
45 self.messages_seen.append(message)
46
47
48def queue_message(conn, message):
49 exchange = kombu.Exchange(constants.INPUT_EXCHANGE,
50 type='fanout', durable=False)
51 queue = kombu.Queue(constants.INPUT_QUEUE, exchange)
52 with conn.SimpleQueue(queue) as q:
53 q.put(message)
540
=== removed file 'core_selftest_agent/worker.py'
--- core_selftest_agent/worker.py 2015-05-22 19:49:10 +0000
+++ core_selftest_agent/worker.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
1# core-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import kombu
19
20from kombu.mixins import ConsumerMixin
21
22
23class CoreSelftestAgentWorker(ConsumerMixin):
24
25 def __init__(self, connection, config, build_worker, result_worker):
26 self.config = config
27 self.connection = connection
28 self.build_worker = build_worker
29 self.result_worker = result_worker
30
31 exchange = kombu.Exchange(self.config.INPUT_EXCHANGE,
32 type='fanout', durable=False)
33 self.queue = kombu.Queue(self.config.INPUT_QUEUE, exchange)
34
35 def get_consumers(self, Consumer, channel):
36 """Return consumers instances for all configured queues."""
37 queues = [self.queue]
38 return [kombu.Consumer(
39 channel, queues=queues, callbacks=[self.process])]
40
41 def process(self, body, message):
42 """ Process incoming messages about candidate packages
43
44 TODO: Check if we care about this package, if so, send a message
45 to the image builder to create the image and start the tests, and
46 a message to the results exchange to mark it as in progress.
47
48 For now, just blindly post messages for these
49 """
50
51 self.build_worker(body)
52 self.result_worker(body)
530
=== modified file 'setup.py'
--- setup.py 2015-05-22 19:49:10 +0000
+++ setup.py 2015-05-27 17:01:56 +0000
@@ -1,6 +1,6 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
22
3# core-selftest-agent3# snappy-proposed-selftest-agent
4# Copyright (C) 2015 Canonical4# Copyright (C) 2015 Canonical
5#5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
@@ -27,15 +27,15 @@
2727
2828
29setup(29setup(
30 name='core-selftest-agent',30 name='snappy-proposed-selftest-agent',
31 version=VERSION,31 version=VERSION,
32 description=('A microservice for triggering snappy selftest on changes to '32 description=('A microservice for triggering snappy selftest on changes '
33 'core packages.'),33 'to core packages.'),
34 author='Canonical CI Engineering Team',34 author='Canonical CI Engineering Team',
35 author_email='canonical-ci-engineering@lists.launchpad.net',35 author_email='canonical-ci-engineering@lists.launchpad.net',
36 url='https://launchpad.net/core-selftest-agent',36 url='https://launchpad.net/snappy-proposed-selftest-agent',
37 license='GPLv3',37 license='GPLv3',
38 packages=find_packages(),38 packages=find_packages(),
39 scripts=['core-selftest-agent.py'],39 scripts=['snappy-proposed-selftest-agent.py'],
40 test_suite='core_selftest_agent.tests',40 test_suite='snappy_proposed_selftest_agent.tests',
41)41)
4242
=== added file 'snappy-proposed-selftest-agent.py'
--- snappy-proposed-selftest-agent.py 1970-01-01 00:00:00 +0000
+++ snappy-proposed-selftest-agent.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,7 @@
1#!/usr/bin/env python3
2
3from snappy_proposed_selftest_agent import main
4
5
6if __name__ == '__main__':
7 main()
08
=== added directory 'snappy_proposed_selftest_agent'
=== added file 'snappy_proposed_selftest_agent/__init__.py'
--- snappy_proposed_selftest_agent/__init__.py 1970-01-01 00:00:00 +0000
+++ snappy_proposed_selftest_agent/__init__.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,117 @@
1# snappy-proposed-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import argparse
19import configparser
20import kombu
21import logging
22import os
23
24from uservice_utils.logging import (
25 configure_service_logging,
26 ExtraLogger,
27)
28
29from snappy_proposed_selftest_agent import constants
30from snappy_proposed_selftest_agent.worker import CoreSelftestAgentWorker
31
32
33class CoreImageResultPublisher(object):
34 """A callable that can notify a results exchange that the test is running
35
36 This will be a fanout exchange so multiple consumers can pick up these
37 messages and decide whether to take action or ignore them.
38 """
39
40 def __init__(self, connection):
41 self.connection = connection
42 exchange = kombu.Exchange(constants.RESULTS_EXCHANGE,
43 type='fanout', durable=False)
44 self.queue = kombu.Queue(constants.RESULTS_QUEUE, exchange)
45
46 def __call__(self, payload):
47 """Take 'payload' and enqueue it on the rabbit exchange."""
48 queue = self.connection.SimpleQueue(self.queue)
49 queue.put(payload)
50 queue.close()
51
52
53class CoreImageBuilder(object):
54 """A callable that knows how to queue message for the image builder
55
56 For now we're using a simple queue, but this can easily be extended to use
57 a full-blown topic exchange in the future.
58 """
59
60 def __init__(self, connection):
61 self.connection = connection
62
63 def __call__(self, payload):
64 """Take 'payload' and enqueue it on the rabbit queue."""
65 queue = self.connection.SimpleQueue(constants.IMAGE_BUILD_QUEUE)
66 queue.put(payload)
67 queue.close()
68
69
70def read_config():
71 parser = argparse.ArgumentParser(description='Core Selftest Agent.')
72 parser.add_argument(
73 '-c',
74 '--conf',
75 default='snappy-proposed-service.conf',
76 help='Configuration file path'
77 )
78 args = parser.parse_args()
79
80 # Load configuration options.
81 config = configparser.ConfigParser()
82 config.read(args.conf)
83 return config
84
85
86def get_logger(name, extra={}):
87 if logging.getLoggerClass() != ExtraLogger:
88 logging.setLoggerClass(ExtraLogger)
89 logger = logging.getLogger(name)
90 e = constants.LOGGING_EXTRA.copy()
91 e.update(extra)
92 logger.set_extra_args(e)
93 return logger
94
95
96def main():
97 config = read_config()
98 log_path = os.path.abspath(
99 os.path.join(__file__,
100 '../../logs/snappy-proposed-selftest-agent.log'))
101 configure_service_logging(
102 log_path,
103 config['logstash'] if 'logstash' in config else None
104 )
105
106 ampq_uris = config.get('amqp', 'uris').split()
107 try:
108 with kombu.Connection(ampq_uris) as connection:
109 monitor = CoreSelftestAgentWorker(
110 connection,
111 constants,
112 CoreImageBuilder(connection),
113 CoreImageResultPublisher(connection),
114 )
115 monitor.run()
116 except KeyboardInterrupt:
117 print("Bye!")
0118
=== added file 'snappy_proposed_selftest_agent/constants.py'
--- snappy_proposed_selftest_agent/constants.py 1970-01-01 00:00:00 +0000
+++ snappy_proposed_selftest_agent/constants.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,49 @@
1# snappy-proposed-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18"""Constants for this service."""
19import socket
20
21# Queue names are constant, rather than being defined in the config.
22
23# We listen to a fanout exchange for candidate packages to test
24INPUT_EXCHANGE = "candidates.exchange.v1"
25
26# The queue needs to be unique to selftest agents
27INPUT_QUEUE = "core.selftest.candidates"
28
29# The queue we send events on to request image build and test
30IMAGE_BUILD_QUEUE = "snappy-proposed-migration.package.v1"
31
32# We need to notify the results exchange that the test is in progress
33RESULTS_EXCHANGE = "results.exchange.v1"
34RESULTS_QUEUE = "core.selftest.results"
35
36# The queue we put fatally error'd payloads into:
37DEAD_LETTER_QUEUE = "core.deadletters.v1"
38
39SOLUTION_NAME = "snappy-proposed-image-testing"
40
41SERVICE_NAME = "snappy-proposed-selftest-agent"
42
43HOSTNAME = socket.gethostname()
44
45LOGGING_EXTRA = {
46 'solution': SOLUTION_NAME,
47 'service': SERVICE_NAME,
48 'hostname': HOSTNAME,
49}
050
=== added directory 'snappy_proposed_selftest_agent/tests'
=== added file 'snappy_proposed_selftest_agent/tests/__init__.py'
--- snappy_proposed_selftest_agent/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ snappy_proposed_selftest_agent/tests/__init__.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,16 @@
1# snappy-proposed-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
017
=== added file 'snappy_proposed_selftest_agent/tests/test_worker.py'
--- snappy_proposed_selftest_agent/tests/test_worker.py 1970-01-01 00:00:00 +0000
+++ snappy_proposed_selftest_agent/tests/test_worker.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,53 @@
1# snappy-proposed-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import kombu
19from testtools import TestCase
20
21from snappy_proposed_selftest_agent import constants
22from snappy_proposed_selftest_agent.worker import CoreSelftestAgentWorker
23
24
25class WorkerTests(TestCase):
26 def test_can_read_message(self):
27 conn = kombu.Connection('memory:///')
28 queue_message(conn, {'test': 'value'})
29
30 build_worker = LoggingConsumer()
31 result_worker = LoggingConsumer()
32 q = CoreSelftestAgentWorker(conn, constants,
33 build_worker, result_worker)
34 next(q.consume(limit=1, timeout=5.0))
35 self.assertEqual(build_worker.messages_seen, [dict(test='value')])
36 self.assertEqual(result_worker.messages_seen, [dict(test='value')])
37
38
39class LoggingConsumer(object):
40 """A consumer callback object that acks and logs all received payloads."""
41 def __init__(self):
42 self.messages_seen = []
43
44 def __call__(self, message):
45 self.messages_seen.append(message)
46
47
48def queue_message(conn, message):
49 exchange = kombu.Exchange(constants.INPUT_EXCHANGE,
50 type='fanout', durable=False)
51 queue = kombu.Queue(constants.INPUT_QUEUE, exchange)
52 with conn.SimpleQueue(queue) as q:
53 q.put(message)
054
=== added file 'snappy_proposed_selftest_agent/worker.py'
--- snappy_proposed_selftest_agent/worker.py 1970-01-01 00:00:00 +0000
+++ snappy_proposed_selftest_agent/worker.py 2015-05-27 17:01:56 +0000
@@ -0,0 +1,52 @@
1# snappy-proposed-selftest-agent
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18import kombu
19
20from kombu.mixins import ConsumerMixin
21
22
23class CoreSelftestAgentWorker(ConsumerMixin):
24
25 def __init__(self, connection, config, build_worker, result_worker):
26 self.config = config
27 self.connection = connection
28 self.build_worker = build_worker
29 self.result_worker = result_worker
30
31 exchange = kombu.Exchange(self.config.INPUT_EXCHANGE,
32 type='fanout', durable=False)
33 self.queue = kombu.Queue(self.config.INPUT_QUEUE, exchange)
34
35 def get_consumers(self, Consumer, channel):
36 """Return consumers instances for all configured queues."""
37 queues = [self.queue]
38 return [kombu.Consumer(
39 channel, queues=queues, callbacks=[self.process])]
40
41 def process(self, body, message):
42 """ Process incoming messages about candidate packages
43
44 TODO: Check if we care about this package, if so, send a message
45 to the image builder to create the image and start the tests, and
46 a message to the results exchange to mark it as in progress.
47
48 For now, just blindly post messages for these
49 """
50
51 self.build_worker(body)
52 self.result_worker(body)

Subscribers

People subscribed via source and target branches