Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional info about errored machines for openstack provider #499

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions unit_tests/test_zaza_charm_lifecycle_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ def test_destroy_on_openstack_provider(self):
return_value={'machines': "the-machines"})
self.patch_object(lc_destroy.juju_utils, 'get_provider_type',
return_value="openstack")
self.patch("zaza.utilities.openstack_provider.report_machine_errors",
name='report_machine_errors')
self.patch("zaza.utilities.openstack_provider.clean_up_instances",
name='clean_up_instances')
lc_destroy.destroy('doomed')
self.destroy_model.assert_called_once_with('doomed')
self.report_machine_errors.assert_called_once_with(
'doomed', 'the-machines')
self.clean_up_instances.assert_called_once_with(
'doomed', 'the-machines')

Expand Down
7 changes: 5 additions & 2 deletions zaza/charm_lifecycle/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ def destroy(model_name):
:param model: Name of model to remove
:type bundle: str
"""
machines = model.get_status()["machines"]
zaza.controller.destroy_model(model_name)
if juju_utils.get_provider_type() == "openstack":
# only import openstack_provider if it's needed. This avoids forcing
# zaza to have dependencies for providers that the user isn't using.
import zaza.utilities.openstack_provider as op
machines = model.get_status()["machines"]
op.report_machine_errors(model_name, machines)
zaza.controller.destroy_model(model_name)
op.clean_up_instances(model_name, machines)
else:
zaza.controller.destroy_model(model_name)


def parse_args(args):
Expand Down
28 changes: 28 additions & 0 deletions zaza/utilities/openstack_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,31 @@ def clean_up_instances(model_name, machines):
# depite being in the list, so just ignore this error.
logging.info("Server {} already removed - race due to async."
" id:{}" .format(server.name, server.id))


def report_machine_errors(model_name, machines):
"""Display information about machines in an error state.

:param model_name: the model to destroy.
:type model_name: str
:param machines: List of machines in model.
:type machines: List
"""
machine_ids = {v.instance_id: k for k, v in machines.items()}
session = get_undercloud_keystone_session()
nova_client = get_nova_session_client(session)
servers = [
s for s in nova_client.servers.list() if s.id in machine_ids.keys()]
for server in servers:
logging.info("Juju Machine {}. Openstack ID {}. Status {}".format(
machine_ids[server.id],
server.id,
server.status))
if server.status == 'ACTIVE':
logging.warning("Detected Error Status")
logging.warning(dir(server))
try:
logging.warning(server.fault)
logging.warning(dir(server.fault))
except Exception:
pass