~abentley/juju-ci-tools/python-canary

« back to all changes in this revision

Viewing changes to assess_recovery.py

  • Committer: Aaron Bentley
  • Date: 2016-02-17 14:13:08 UTC
  • mfrom: (1273.1.2 bootstrap-restore)
  • Revision ID: aaron.bentley@canonical.com-20160217141308-qqzdrw1t2p14od08
Support new restore method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from __future__ import print_function
5
5
 
6
6
from argparse import ArgumentParser
 
7
import logging
7
8
import re
8
9
from subprocess import CalledProcessError
9
10
import sys
22
23
    terminate_instances,
23
24
)
24
25
from utility import (
 
26
    configure_logging,
25
27
    print_now,
26
28
)
27
29
 
60
62
        print_now(
61
63
            "juju-restore correctly refused to restore "
62
64
            "because the state-server was still up.")
63
 
        match = running_instance_pattern.search(e.stderr)
 
65
        stderr = getattr(e, 'stderr', None)
 
66
        if stderr is None:
 
67
            return None
 
68
        match = running_instance_pattern.search(stderr)
64
69
        if match is None:
65
70
            print_now("WARNING: Could not find the instance_id in output:")
66
 
            print_now(e.stderr)
 
71
            print_now(stderr)
67
72
            print_now("")
68
73
            return None
69
74
        return match.group(1)
99
104
        output = client.restore_backup(backup_file)
100
105
    except CalledProcessError as e:
101
106
        print_now('Call of juju restore exited with an error\n')
102
 
        message = 'Restore failed: \n%s' % e.stderr
 
107
        stderr = getattr(e, 'stderr', None)
 
108
        if stderr is None:
 
109
            raise
 
110
        message = 'Restore failed: \n%s' % stderr
103
111
        print_now(message)
104
112
        print_now('\n')
105
113
        raise Exception(message)
146
154
 
147
155
def main(argv):
148
156
    args = parse_args(argv)
 
157
    configure_logging(logging.INFO)
149
158
    client = make_client_from_args(args)
150
159
    jes_enabled = client.is_jes_enabled()
151
160
    bs_manager = BootstrapManager(
171
180
            if args.strategy == 'ha':
172
181
                client.get_status(600)
173
182
            else:
 
183
                client = client.get_restore_client(
 
184
                    client.env.environment + '-restore')
174
185
                restore_missing_state_server(client, backup_file)
175
186
        except Exception as e:
176
187
            bs_manager.known_hosts['0'] = parse_new_state_server_from_error(e)