diff --git a/etc/sample_stacktach_verifier_config.json b/etc/sample_stacktach_verifier_config.json index a017a65..826c144 100644 --- a/etc/sample_stacktach_verifier_config.json +++ b/etc/sample_stacktach_verifier_config.json @@ -11,6 +11,7 @@ "userid": "rabbit", "password": "rabbit", "virtual_host": "/", - "exchange_name": "stacktach" + "exchange_name": "stacktach", + "routing_keys": ["notifications.info"] } } \ No newline at end of file diff --git a/migrations/006_populate_rebuilds_from_rawdata.py b/migrations/006_populate_rebuilds_from_rawdata.py index a2e9161..839ae61 100644 --- a/migrations/006_populate_rebuilds_from_rawdata.py +++ b/migrations/006_populate_rebuilds_from_rawdata.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import os @@ -34,7 +52,7 @@ def add_past_usage(raws): print "%s events to be processed" % count last_update = datetime.datetime.utcnow() for raw in raws: - json_dict = json.dumps(raw.json) + json_dict = json.loads(raw.json) views.aggregate_usage(raw, json_dict[1]) processed += 1 if processed % 50 == 0: diff --git a/migrations/006_populate_usage_from_rawdata.py b/migrations/006_populate_usage_from_rawdata.py index 813696e..42d2c6f 100644 --- a/migrations/006_populate_usage_from_rawdata.py +++ b/migrations/006_populate_usage_from_rawdata.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import os @@ -92,7 +110,7 @@ for event in events: new_loc = loc + 500 for raw in raws[loc:new_loc]: try: - json_dict = json.dumps(raw.json) + json_dict = json.loads(raw.json) populate_usage(raw, json_dict[1]) completed += 1 except Exception: diff --git a/stacktach/dbapi.py b/stacktach/dbapi.py index a66f5a5..223add4 100644 --- a/stacktach/dbapi.py +++ b/stacktach/dbapi.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import decimal import functools diff --git a/stacktach/test_utils.py b/stacktach/test_utils.py index 3c967e2..8baec96 100644 --- a/stacktach/test_utils.py +++ b/stacktach/test_utils.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import json import views diff --git a/stacktach/tests.py b/stacktach/tests.py index 83a8ee9..55280a0 100644 --- a/stacktach/tests.py +++ b/stacktach/tests.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import decimal diff --git a/tests/__init__.py b/tests/__init__.py index 859c9d2..0202ddc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,19 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 0a1974c..c8535ec 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import os import sys diff --git a/tests/unit/test_datetime_to_decimal.py b/tests/unit/test_datetime_to_decimal.py index 069ff29..ac42886 100644 --- a/tests/unit/test_datetime_to_decimal.py +++ b/tests/unit/test_datetime_to_decimal.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import decimal diff --git a/tests/unit/test_dbapi.py b/tests/unit/test_dbapi.py index c0fe015..5a124cb 100644 --- a/tests/unit/test_dbapi.py +++ b/tests/unit/test_dbapi.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import unittest diff --git a/tests/unit/test_stacktach.py b/tests/unit/test_stacktach.py index 102f82b..347854d 100644 --- a/tests/unit/test_stacktach.py +++ b/tests/unit/test_stacktach.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import json diff --git a/tests/unit/test_stacktach_utils.py b/tests/unit/test_stacktach_utils.py index a8a8152..0c1377c 100644 --- a/tests/unit/test_stacktach_utils.py +++ b/tests/unit/test_stacktach_utils.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import unittest diff --git a/tests/unit/test_stacky_server.py b/tests/unit/test_stacky_server.py index 60f88de..b791eef 100644 --- a/tests/unit/test_stacky_server.py +++ b/tests/unit/test_stacky_server.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import json diff --git a/tests/unit/test_verifier_db.py b/tests/unit/test_verifier_db.py index b96fb14..64c44ee 100644 --- a/tests/unit/test_verifier_db.py +++ b/tests/unit/test_verifier_db.py @@ -1,9 +1,28 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import decimal import json import unittest +import uuid import kombu.common import kombu.entity @@ -459,12 +478,18 @@ class VerifierTestCase(unittest.TestCase): self.assertEqual(exist2.status, 'verifying') self.mox.VerifyAll() - def test_send_verified_notification(self): + def test_send_verified_notification_default_routing_key(self): connection = self.mox.CreateMockAnything() exchange = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything() exist.raw = self.mox.CreateMockAnything() - exist_dict = ['monitor.info', {'event_type': 'test', 'key': 'value'}] + exist_dict = [ + 'monitor.info', + { + 'event_type': 'test', + 'message_id': 'some_uuid' + } + ] exist_str = json.dumps(exist_dict) exist.raw.json = exist_str self.mox.StubOutWithMock(kombu.pools, 'producers') @@ -475,8 +500,11 @@ class VerifierTestCase(unittest.TestCase): producer.acquire(block=True).AndReturn(producer) producer.__enter__().AndReturn(producer) kombu.common.maybe_declare(exchange, producer.channel) + self.mox.StubOutWithMock(uuid, 'uuid4') + uuid.uuid4().AndReturn('some_other_uuid') message = {'event_type': 'compute.instance.exists.verified.old', - 'key': 'value'} + 'message_id': 'some_other_uuid', + 'original_message_id': 'some_uuid'} producer.publish(message, exist_dict[0]) producer.__exit__(None, None, None) self.mox.ReplayAll() @@ -484,6 +512,43 @@ class VerifierTestCase(unittest.TestCase): dbverifier.send_verified_notification(exist, exchange, connection) self.mox.VerifyAll() + def test_send_verified_notification_routing_keys(self): + connection = self.mox.CreateMockAnything() + exchange = self.mox.CreateMockAnything() + exist = self.mox.CreateMockAnything() + exist.raw = self.mox.CreateMockAnything() + exist_dict = [ + 'monitor.info', + { + 'event_type': 'test', + 'message_id': 'some_uuid' + } + ] + exist_str = json.dumps(exist_dict) + exist.raw.json = exist_str + self.mox.StubOutWithMock(uuid, 'uuid4') + uuid.uuid4().AndReturn('some_other_uuid') + self.mox.StubOutWithMock(kombu.pools, 'producers') + self.mox.StubOutWithMock(kombu.common, 'maybe_declare') + routing_keys = ['notifications.info', 'monitor.info'] + for key in routing_keys: + producer = self.mox.CreateMockAnything() + producer.channel = self.mox.CreateMockAnything() + kombu.pools.producers[connection].AndReturn(producer) + producer.acquire(block=True).AndReturn(producer) + producer.__enter__().AndReturn(producer) + kombu.common.maybe_declare(exchange, producer.channel) + message = {'event_type': 'compute.instance.exists.verified.old', + 'message_id': 'some_other_uuid', + 'original_message_id': 'some_uuid'} + producer.publish(message, key) + producer.__exit__(None, None, None) + self.mox.ReplayAll() + + dbverifier.send_verified_notification(exist, exchange, connection, + routing_keys=routing_keys) + self.mox.VerifyAll() + def test_run_notifications(self): config = { "tick_time": 30, @@ -519,6 +584,41 @@ class VerifierTestCase(unittest.TestCase): dbverifier.run(config) self.mox.VerifyAll() + def test_run_notifications_with_routing_keys(self): + config = { + "tick_time": 30, + "settle_time": 5, + "settle_units": "minutes", + "pool_size": 2, + "enable_notifications": True, + "rabbit": { + "durable_queue": False, + "host": "10.0.0.1", + "port": 5672, + "userid": "rabbit", + "password": "rabbit", + "virtual_host": "/", + "exchange_name": "stacktach", + } + } + self.mox.StubOutWithMock(multiprocessing, 'Pool') + pool = self.mox.CreateMockAnything() + multiprocessing.Pool(2).AndReturn(pool) + self.mox.StubOutWithMock(dbverifier, '_create_exchange') + exchange = self.mox.CreateMockAnything() + dbverifier._create_exchange('stacktach', 'topic', durable=False) \ + .AndReturn(exchange) + self.mox.StubOutWithMock(dbverifier, '_create_connection') + conn = self.mox.CreateMockAnything() + dbverifier._create_connection(config).AndReturn(conn) + conn.__enter__().AndReturn(conn) + self.mox.StubOutWithMock(dbverifier, '_run') + dbverifier._run(config, pool, callback=mox.IgnoreArg()) + conn.__exit__(None, None, None) + self.mox.ReplayAll() + dbverifier.run(config) + self.mox.VerifyAll() + def test_run_no_notifications(self): config = { "tick_time": 30, diff --git a/tests/unit/test_worker.py b/tests/unit/test_worker.py index b9f7764..661d780 100644 --- a/tests/unit/test_worker.py +++ b/tests/unit/test_worker.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import json import unittest diff --git a/tests/unit/utils.py b/tests/unit/utils.py index cc6541d..43a1da5 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import datetime import os diff --git a/verifier/__init__.py b/verifier/__init__.py index bdd6565..eb30360 100644 --- a/verifier/__init__.py +++ b/verifier/__init__.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. class VerificationException(Exception): def __init__(self, reason): diff --git a/verifier/dbverifier.py b/verifier/dbverifier.py index e98afb9..2d11c6e 100644 --- a/verifier/dbverifier.py +++ b/verifier/dbverifier.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import argparse import datetime @@ -7,6 +25,7 @@ import logging import os import sys from time import sleep +import uuid from django.db import transaction import kombu.common @@ -256,11 +275,17 @@ def _send_notification(message, routing_key, connection, exchange): producer.publish(message, routing_key) -def send_verified_notification(exist, connection, exchange): +def send_verified_notification(exist, connection, exchange, routing_keys=None): body = exist.raw.json json_body = json.loads(body) json_body[1]['event_type'] = 'compute.instance.exists.verified.old' - _send_notification(json_body[1], json_body[0], connection, exchange) + json_body[1]['original_message_id'] = json_body[1]['message_id'] + json_body[1]['message_id'] = str(uuid.uuid4()) + if routing_keys is None: + _send_notification(json_body[1], json_body[0], connection, exchange) + else: + for key in routing_keys: + _send_notification(json_body[1], key, connection, exchange) def _create_exchange(name, type, exclusive=False, auto_delete=False, @@ -303,12 +328,16 @@ def run(config): exchange = _create_exchange(config['rabbit']['exchange_name'], 'topic', durable=config['rabbit']['durable_queue']) + routing_keys = None + if config['rabbit'].get('routing_keys') is not None: + routing_keys = config['rabbit']['routing_keys'] with _create_connection(config) as conn: def callback(result): (verified, exist) = result if verified: - send_verified_notification(exist, conn, exchange) + send_verified_notification(exist, conn, exchange, + routing_keys=routing_keys) _run(config, pool, callback=callback) else: @@ -337,12 +366,16 @@ def run_once(config): exchange = _create_exchange(config['rabbit']['exchange_name'], 'topic', durable=config['rabbit']['durable_queue']) + routing_keys = None + if config['rabbit'].get('routing_keys') is not None: + routing_keys = config['rabbit']['routing_keys'] with _create_connection(config) as conn: def callback(result): (verified, exist) = result if verified: - send_verified_notification(exist, conn, exchange) + send_verified_notification(exist, conn, exchange, + routing_keys=routing_keys) _run_once(config, pool, callback=callback) else: diff --git a/verifier/start_verifier.py b/verifier/start_verifier.py index ece37cb..625497c 100644 --- a/verifier/start_verifier.py +++ b/verifier/start_verifier.py @@ -1,4 +1,22 @@ -# Copyright 2012 - Rackspace Inc. +# Copyright (c) 2012 - Rackspace Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. import json import os