testing: add CLI for interacting with Pulse
authorGregory Szorc <gps@mozilla.com>
Wed, 21 Jan 2015 10:32:58 -0500
changeset 360211 2080078907df4889619ab6071e9eada17dfda0ec
parent 360210 5fcf702c2193b810ed8ac037e8104ea1a4991975
child 360212 d7e762f814b422b3a726efcb8ad6b5cd2fae6ce6
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
testing: add CLI for interacting with Pulse We are starting to integrate with Pulse in MozReview. Add a mach-based CLI for interacting with a Pulse instance. Currently, it just creates an exchange. Functionality will be expanded in the future.
pulse
testing/vcttesting/pulse_mach_commands.py
new file mode 100755
--- /dev/null
+++ b/pulse
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+
+HERE = os.path.abspath(os.path.dirname(__file__))
+
+def main(args):
+    activate = os.path.join(HERE, 'venv', 'bin', 'activate_this.py')
+    execfile(activate, dict(__file__=activate))
+    sys.executable = os.path.join(HERE, 'venv', 'bin', 'python')
+
+    sys.path.insert(0, os.path.join(HERE, 'testing'))
+
+    from mach.main import Mach
+
+    m = Mach(os.getcwd())
+
+    m.define_category('pulse', 'Pulse',
+        'Control and Interact with the Pulse Message Broker', 50)
+    import vcttesting.pulse_mach_commands
+
+    return m.run(args)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))
new file mode 100644
--- /dev/null
+++ b/testing/vcttesting/pulse_mach_commands.py
@@ -0,0 +1,40 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+
+from mach.decorators import (
+    CommandArgument,
+    CommandProvider,
+    Command,
+)
+
+@CommandProvider
+class PulseCommands(object):
+    def _get_consumer(self, class_name):
+        import mozillapulse.consumers as consumers
+
+        cls = getattr(consumers, class_name)
+        pulse_host = None
+        pulse_port = None
+
+        if 'PULSE_HOST' in os.environ:
+            pulse_host = os.environ['PULSE_HOST']
+        if 'PULSE_PORT' in os.environ:
+            pulse_port = int(os.environ['PULSE_PORT'])
+
+        if not pulse_host:
+            raise Exception('Can not find Pulse host. Try setting PULSE_HOST')
+        if not pulse_port:
+            raise Exception('Can not find Pulse port. Try setting PULSE_PORT')
+
+        return cls(user='guest', password='guest', host=pulse_host,
+                port=pulse_port)
+
+    @Command('create-exchange', category='pulse',
+        description='Create an exchange')
+    @CommandArgument('classname',
+        help='Pulse class name of exchange to initialize')
+    def create_exchange(self, classname):
+        self._get_consumer(classname)