1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
1 |
#!/usr/bin/env python
|
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
2 |
"""Test juju update-mongo command."""
|
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
3 |
|
4 |
from __future__ import print_function |
|
5 |
||
6 |
import argparse |
|
7 |
import logging |
|
8 |
import sys |
|
9 |
||
10 |
from deploy_stack import ( |
|
11 |
BootstrapManager, |
|
12 |
)
|
|
1485.1.1
by Martin
Switch all imports of local_charm_path to using jujucharm over utility |
13 |
from jujucharm import ( |
14 |
local_charm_path, |
|
15 |
)
|
|
1258.2.7
by Curtis Hovey
Added DEP_script run via remote. |
16 |
from remote import remote_from_address |
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
17 |
from utility import ( |
18 |
add_basic_testing_arguments, |
|
19 |
configure_logging, |
|
20 |
)
|
|
21 |
||
22 |
||
1260.2.14
by Aaron Bentley
Fake merge of rollback. |
23 |
__metaclass__ = type |
24 |
||
25 |
||
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
26 |
log = logging.getLogger("assess_update_mongo") |
27 |
||
1258.2.6
by Curtis Hovey
Revised test. |
28 |
DEP_SCRIPT = """\ |
29 |
export DEBIAN_FRONTEND=noninteractive
|
|
1258.2.7
by Curtis Hovey
Added DEP_script run via remote. |
30 |
sudo apt-get update
|
31 |
sudo apt-get install -y software-properties-common
|
|
1258.2.6
by Curtis Hovey
Revised test. |
32 |
sudo apt-add-repository -y ppa:juju/experimental
|
33 |
sudo apt-get update
|
|
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
34 |
"""
|
35 |
||
36 |
VERIFY_SCRIPT = """\ |
|
37 |
ps ax | grep 'mongo3/bin/mongod --dbpath /var/lib/juju/db' | grep -v grep
|
|
1258.2.6
by Curtis Hovey
Revised test. |
38 |
"""
|
39 |
||
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
40 |
|
1258.2.7
by Curtis Hovey
Added DEP_script run via remote. |
41 |
def assess_update_mongo(client, series, bootstrap_host): |
1258.2.9
by Curtis Hovey
Add informatiom about what is happening in the test. |
42 |
log.info('series={}, bootstrap_host={}'.format(series, bootstrap_host)) |
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
43 |
return_code = 1 |
1345.1.3
by Seman
Deploy charm by path. |
44 |
charm = local_charm_path( |
45 |
charm='ubuntu', juju_ver=client.version, series=series) |
|
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
46 |
log.info("Setting up test.") |
1345.1.3
by Seman
Deploy charm by path. |
47 |
client.deploy(charm, series=series) |
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
48 |
client.wait_for_started() |
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
49 |
log.info("Setup complete.") |
1258.2.6
by Curtis Hovey
Revised test. |
50 |
log.info("Test started.") |
51 |
# Instrument the case where Juju can install the new mongo packages from
|
|
52 |
# Ubuntu.
|
|
1258.2.7
by Curtis Hovey
Added DEP_script run via remote. |
53 |
remote = remote_from_address(bootstrap_host, series=series) |
54 |
remote.run(DEP_SCRIPT) |
|
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
55 |
# upgrade-mongo returns 0 if all is well. status will work but not
|
56 |
# explicitly show that mongo3 is running.
|
|
1258.2.6
by Curtis Hovey
Revised test. |
57 |
client.upgrade_mongo() |
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
58 |
client.show_status() |
1258.2.9
by Curtis Hovey
Add informatiom about what is happening in the test. |
59 |
log.info("Checking bootstrap host for mongo3:") |
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
60 |
mongo_proc = remote.run(VERIFY_SCRIPT) |
1258.2.9
by Curtis Hovey
Add informatiom about what is happening in the test. |
61 |
log.info(mongo_proc) |
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
62 |
if '--port 37017' in mongo_proc and '--replSet juju' in mongo_proc: |
63 |
return_code = 0 |
|
1258.2.9
by Curtis Hovey
Add informatiom about what is happening in the test. |
64 |
log.info("Controller upgraded to MongoDB 3.") |
1258.2.6
by Curtis Hovey
Revised test. |
65 |
log.info("Test complete.") |
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
66 |
return return_code |
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
67 |
|
68 |
||
69 |
def parse_args(argv): |
|
70 |
"""Parse all arguments."""
|
|
1258.2.4
by Curtis Hovey
Reluctantly accept mock client instead of fake client. |
71 |
parser = argparse.ArgumentParser( |
72 |
description="Test juju update-mongo command") |
|
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
73 |
add_basic_testing_arguments(parser) |
74 |
return parser.parse_args(argv) |
|
75 |
||
76 |
||
77 |
def main(argv=None): |
|
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
78 |
return_code = 1 |
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
79 |
args = parse_args(argv) |
80 |
configure_logging(args.verbose) |
|
81 |
bs_manager = BootstrapManager.from_args(args) |
|
82 |
with bs_manager.booted_context(args.upload_tools): |
|
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
83 |
return_code = assess_update_mongo( |
1258.2.9
by Curtis Hovey
Add informatiom about what is happening in the test. |
84 |
bs_manager.client, args.series, bs_manager.known_hosts['0']) |
85 |
log.info("Tearing down test.") |
|
86 |
log.info("Teardown complete.") |
|
1258.2.8
by Curtis Hovey
Verify mongo3 is running after upgrade. |
87 |
if return_code == 0: |
88 |
log.info('TEST PASS') |
|
89 |
else: |
|
90 |
log.info('TEST FAIL') |
|
91 |
return return_code |
|
1258.2.2
by Curtis Hovey
Added assess_update_mongo tests. |
92 |
|
93 |
||
94 |
if __name__ == '__main__': |
|
95 |
sys.exit(main()) |