796.2.1
by John George
Add quickstart_deploy.py |
1 |
#!/usr/bin/env python
|
2 |
from argparse import ArgumentParser |
|
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
3 |
import logging |
915.1.3
by John George
sys.exit(1) if exceptions are raised up to quickstart_deploy main(). |
4 |
import sys |
796.2.1
by John George
Add quickstart_deploy.py |
5 |
|
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
6 |
from deploy_stack import ( |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
7 |
BootstrapManager, |
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
8 |
)
|
9 |
from utility import ( |
|
10 |
add_basic_testing_arguments, |
|
11 |
configure_logging, |
|
1211.2.6
by Aaron Bentley
Handle LoggedException in quickstart_deploy, assess_bootstrap. |
12 |
LoggedException, |
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
13 |
)
|
14 |
||
15 |
||
1092.2.2
by Aaron Bentley
Fix lint. |
16 |
__metaclass__ = type |
17 |
||
18 |
||
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
19 |
class QuickstartTest: |
20 |
||
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
21 |
def __init__(self, bs_manager, bundle_path, service_count): |
22 |
self.bs_manager = bs_manager |
|
23 |
self.client = bs_manager.client |
|
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
24 |
self.bundle_path = bundle_path |
25 |
self.service_count = service_count |
|
26 |
||
27 |
def run(self): |
|
28 |
bootstrap_host = None |
|
796.2.1
by John George
Add quickstart_deploy.py |
29 |
try: |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
30 |
step_iter = self.iter_steps() |
31 |
for step in step_iter: |
|
32 |
try: |
|
33 |
logging.info('{}'.format(step)) |
|
34 |
if not bootstrap_host: |
|
35 |
bootstrap_host = step.get('bootstrap_host') |
|
36 |
except BaseException as e: |
|
37 |
step_iter.throw(e) |
|
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
38 |
finally: |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
39 |
step_iter.close() |
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
40 |
|
41 |
def iter_steps(self): |
|
42 |
# Start the quickstart job
|
|
43 |
step = {'juju-quickstart': 'Returned from quickstart'} |
|
1173.2.5
by Aaron Bentley
top_context doesn't yield bootstrap_host. |
44 |
with self.bs_manager.top_context() as machines: |
1173.2.4
by Aaron Bentley
bootstrap_context doesn't accept bootstrap_host. |
45 |
with self.bs_manager.bootstrap_context(machines): |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
46 |
self.client.quickstart(self.bundle_path) |
47 |
yield step |
|
1173.2.3
by Aaron Bentley
runtime_context doesn't take bootstrap_host as a parameter. |
48 |
with self.bs_manager.runtime_context(machines): |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
49 |
# Get the hostname for machine 0
|
1173.2.3
by Aaron Bentley
runtime_context doesn't take bootstrap_host as a parameter. |
50 |
step['bootstrap_host'] = self.bs_manager.known_hosts['0'] |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
51 |
yield step |
52 |
# Wait for deploy to start
|
|
53 |
self.client.wait_for_deploy_started(self.service_count) |
|
54 |
step['deploy_started'] = 'Deploy stated' |
|
55 |
yield step |
|
56 |
# Wait for all agents to start
|
|
57 |
self.client.wait_for_started(3600) |
|
58 |
step['agents_started'] = 'All Agents started' |
|
59 |
yield step |
|
796.2.1
by John George
Add quickstart_deploy.py |
60 |
|
61 |
||
62 |
def main(): |
|
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
63 |
parser = add_basic_testing_arguments(ArgumentParser()) |
796.2.4
by John George
Added support for setting the juju path, series and agent_url. |
64 |
parser.add_argument('bundle_path', |
65 |
help='URL or path to a bundle') |
|
801.1.1
by John George
Added the --service-count option to quickstart_deploy.py |
66 |
parser.add_argument('--service-count', type=int, default=2, |
67 |
help='Minimum number of expected services.') |
|
796.2.1
by John George
Add quickstart_deploy.py |
68 |
args = parser.parse_args() |
908.2.1
by John George
Re-write quickstart_deploy.py to use EnvJujuClient. |
69 |
configure_logging(args.verbose) |
1162.2.13
by Aaron Bentley
Switch quickstart to BootstrapManager. |
70 |
bs_manager = BootstrapManager.from_args(args) |
71 |
quickstart = QuickstartTest( |
|
72 |
bs_manager, args.bundle_path, args.service_count) |
|
915.1.3
by John George
sys.exit(1) if exceptions are raised up to quickstart_deploy main(). |
73 |
try: |
74 |
quickstart.run() |
|
1211.2.6
by Aaron Bentley
Handle LoggedException in quickstart_deploy, assess_bootstrap. |
75 |
except LoggedException: |
76 |
sys.exit(1) |
|
915.1.3
by John George
sys.exit(1) if exceptions are raised up to quickstart_deploy main(). |
77 |
except Exception as e: |
915.1.4
by John George
quickstart_deploy main() indent correction. |
78 |
print('%s (%s)' % (e, type(e).__name__)) |
79 |
sys.exit(1) |
|
796.2.1
by John George
Add quickstart_deploy.py |
80 |
|
81 |
if __name__ == '__main__': |
|
82 |
main() |