LEFT | RIGHT |
(no file at all) | |
| 1 from __future__ import print_function |
| 2 |
| 3 import json |
| 4 import shelltoolbox |
| 5 import sys |
| 6 import time |
| 7 |
| 8 |
| 9 juju_command = shelltoolbox.command('juju') |
| 10 |
| 11 |
| 12 def juju(s): |
| 13 juju_command(*s.split()) |
| 14 |
| 15 |
| 16 def get_branch_url(argv): |
| 17 """Extract the requested branch URL (if any).""" |
| 18 if len(argv) > 1: |
| 19 branch = argv[1] |
| 20 else: |
| 21 branch = None # trunk |
| 22 |
| 23 return branch |
| 24 |
| 25 |
| 26 def get_status(): |
| 27 """Get the current status info as a JSON document.""" |
| 28 return juju('status --environment juju-gui-testing --format json') |
| 29 |
| 30 |
| 31 def get_state(get_status=get_status): |
| 32 status = json.loads(get_status()) |
| 33 unit = status['services']['juju-gui']['units']['juju-gui/0'] |
| 34 return unit['agent-state'] |
| 35 |
| 36 |
| 37 def wait_for_service(get_state=get_state, sleep=time.sleep): |
| 38 """Wait for the service to start or for it to enter an error state.""" |
| 39 while True: |
| 40 state = get_state() |
| 41 if 'error' in state: |
| 42 raise RuntimeError('error deploying service') |
| 43 if state == 'started': |
| 44 break |
| 45 sleep(10) |
| 46 |
| 47 |
| 48 def main(argv, print=print, juju=juju, wait_for_service=wait_for_service): |
| 49 """Deploy the Juju GUI service and wait for it to become available.""" |
| 50 branch = get_branch_url(argv) |
| 51 print('Bootstrapping...') |
| 52 juju('bootstrap --environment juju-gui-testing') |
| 53 print('Deploying service...') |
| 54 juju('deploy juju-gui --environment juju-gui-testing') |
| 55 if branch is not None: |
| 56 print('Setting branch for charm to deploy...') |
| 57 juju('set juju-gui juju-gui-source={} --environment juju-gui-testing' |
| 58 .format(branch)) |
| 59 print('Waiting for service to start...') |
| 60 wait_for_service() |
| 61 print('Exposing the service...') |
| 62 juju('expose juju-gui --environment juju-gui-testing') |
| 63 |
| 64 |
| 65 if __name__ == '__main__': |
| 66 sys.exit(main(sys.argv)) |
LEFT | RIGHT |