From b1e5c8a2f5d4cae5dc74fc30834f7e69171524ed Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 21 Mar 2022 10:52:54 +0000 Subject: [PATCH] Add additional info about errored machines for openstack provider --- .../test_zaza_charm_lifecycle_destroy.py | 4 +++ zaza/charm_lifecycle/destroy.py | 7 +++-- zaza/utilities/openstack_provider.py | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/unit_tests/test_zaza_charm_lifecycle_destroy.py b/unit_tests/test_zaza_charm_lifecycle_destroy.py index 320129fa0..03d924b7e 100644 --- a/unit_tests/test_zaza_charm_lifecycle_destroy.py +++ b/unit_tests/test_zaza_charm_lifecycle_destroy.py @@ -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') diff --git a/zaza/charm_lifecycle/destroy.py b/zaza/charm_lifecycle/destroy.py index e929e2c1d..b18989507 100644 --- a/zaza/charm_lifecycle/destroy.py +++ b/zaza/charm_lifecycle/destroy.py @@ -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): diff --git a/zaza/utilities/openstack_provider.py b/zaza/utilities/openstack_provider.py index 33e9f2d05..7e16af068 100644 --- a/zaza/utilities/openstack_provider.py +++ b/zaza/utilities/openstack_provider.py @@ -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