124
124
return new_log_dir
127
class ModelCheckFailed(Exception):
128
"""Exception used to signify a model status check failed or timed out."""
131
def _wait_for_model_check(client, model_check, timeout):
132
"""Wrapper to have a client wait for a model_check callable to succeed.
134
:param client: ModelClient object to act on and pass into model_check
135
:param model_check: Callable that takes a ModelClient object. When the
136
callable reaches a success state it returns True. If model_check never
137
returns True within `timeout`, the exception ModelCheckFailed will be
140
with client.check_timeouts():
141
with client.ignore_soft_deadline():
142
for _ in until_timeout(timeout):
143
if model_check(client):
146
raise ModelCheckFailed()
149
def wait_until_model_disappears(client, model_name, timeout=60):
150
"""Waits for a while for 'model_name' model to no longer be listed.
152
:raises JujuAssertionError: If the named model continues to be listed in
153
list-models after specified timeout.
155
def model_check(client):
157
models = client.get_controller_client().get_models()
158
except CalledProcessError as e:
159
# It's possible that we've tried to get status from the model as
160
# it's being removed.
161
if 'cannot get model details' in e.stderr:
164
if model_name not in [m['name'] for m in models['models']]:
168
_wait_for_model_check(client, model_check, timeout)
169
except ModelCheckFailed:
170
raise JujuAssertionError(
171
'Model "{}" failed to be removed after {} seconds'.format(
172
model_name, timeout))
127
175
def wait_for_model(client, model_name, timeout=60):
128
176
"""Wait for a given timeout for the client to see the model_name.
130
Defaults to 10 seconds timeout.
132
:raises AssertionError: If the named model does not appear in the specified
178
:raises JujuAssertionError: If the named model does not appear in the
135
with client.check_timeouts():
136
with client.ignore_soft_deadline():
137
for _ in until_timeout(timeout):
138
models = client.get_controller_client().get_models()
139
if model_name in [m['name'] for m in models['models']]:
142
raise JujuAssertionError(
143
'Model \'{}\' failed to appear after {} seconds'.format(
144
model_name, timeout))
181
def model_check(client):
182
models = client.get_controller_client().get_models()
183
if model_name in [m['name'] for m in models['models']]:
186
_wait_for_model_check(client, model_check, timeout)
187
except ModelCheckFailed:
188
raise JujuAssertionError(
189
'Model "{}" failed to appear after {} seconds'.format(
190
model_name, timeout))
147
193
def wait_for_migrating(client, timeout=60):