From a05263f111ef79e134200936815bb0a8a389c2d2 Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Thu, 22 Apr 2021 04:13:40 -0700 Subject: [PATCH] Update nova tests (#563) Add test for the new nova_cc charm action syncing AZs The new action is meant to sync the availability zones from the underlying Juju provider with the OpenStack availability zones. It is useful within MAAS environments to map the MAAZ AZs to OpenStack AZs. Also fix output check logic for sync az test. The validation logic for the sync az test checks the specific output of the command text, but this is dependent on ordering. The code also validates that the hypervisors are added to the appropriate host aggregates, so this changes the test to verify the action was successful and has some output. Also use the availability-zone based on the configured settings. In the attempt to sync the az test, the availability zone is assumed to be the JUJU_AVAILABILITY_ZONE environment setting. In various scenarios, this is not what is used for the availability zone of a compute node. This change mimics the logic that's contained within the nova-compute charm to determine which availability zone should be used for the compute node. Signed-off-by: Billy Olsen Co-authored-by: Ionut Balutoiu --- zaza/openstack/charm_tests/nova/tests.py | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/zaza/openstack/charm_tests/nova/tests.py b/zaza/openstack/charm_tests/nova/tests.py index f2c68e0..1e44e31 100644 --- a/zaza/openstack/charm_tests/nova/tests.py +++ b/zaza/openstack/charm_tests/nova/tests.py @@ -319,6 +319,62 @@ class NovaComputeActionTest(test_utils.OpenStackBaseTest): "The action failed: {}".format(action.data["message"])) +class NovaCloudControllerActionTest(test_utils.OpenStackBaseTest): + """Run nova-cloud-controller specific tests. + + Add this test class for new nova-cloud-controller action + to avoid breaking older version. + """ + + def test_sync_compute_az_action(self): + """Test sync-compute-availability-zones action.""" + juju_units_az_map = {} + compute_config = zaza.model.get_application_config('nova-compute') + default_az = compute_config['default-availability-zone']['value'] + use_juju_az = compute_config['customize-failure-domain']['value'] + + for unit in zaza.model.get_units('nova-compute', + model_name=self.model_name): + zone = default_az + if use_juju_az: + result = zaza.model.run_on_unit(unit.name, + 'echo $JUJU_AVAILABILITY_ZONE', + model_name=self.model_name, + timeout=60) + self.assertEqual(int(result['Code']), 0) + juju_az = result['Stdout'].strip() + if juju_az: + zone = juju_az + + juju_units_az_map[unit.public_address] = zone + continue + + session = openstack_utils.get_overcloud_keystone_session() + nova = openstack_utils.get_nova_session_client(session) + + result = zaza.model.run_action_on_leader( + 'nova-cloud-controller', + 'sync-compute-availability-zones', + model_name=self.model_name) + + # For validating the action results, we simply want to validate that + # the action was completed and we have something in the output. The + # functional validation really occurs below, in that the hosts are + # checked to be in the appropriate host aggregates. + self.assertEqual(result.status, 'completed') + self.assertNotEqual('', result.results['output']) + + unique_az_list = list(set(juju_units_az_map.values())) + aggregates = nova.aggregates.list() + self.assertEqual(len(aggregates), len(unique_az_list)) + for unit_address in juju_units_az_map: + az = juju_units_az_map[unit_address] + aggregate = nova.aggregates.find( + name='{}_az'.format(az), availability_zone=az) + hypervisor = nova.hypervisors.find(host_ip=unit_address) + self.assertIn(hypervisor.hypervisor_hostname, aggregate.hosts) + + class NovaCloudController(test_utils.OpenStackBaseTest): """Run nova-cloud-controller specific tests."""