Skip to content

Commit

Permalink
Add additional info about errored machines for openstack provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Young committed May 22, 2022
1 parent d5f57e5 commit b1e5c8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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

0 comments on commit b1e5c8a

Please sign in to comment.