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 the concept of atexit hooks to Zaza #459

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 17, 2021

  1. Add the concept of atexit hooks to Zaza

    These hooks will be run after a test run completes via the
    test portion of Zaza's lifecycle. An example situation where
    atexit hooks can be beneficial to Zaza would be the case where
    resources are created and verified in one test, and then the
    thing under test is modified, and then the resources should
    be re-verified. A specific example of the above would be for
    a charm or payload upgrade.
    
    An minimal example test using `atexit`:
    
        import zaza.atexit
    
        def cleanup_vm():
            for vm in cls.nova_client.servers.list():
                if vm.name == 'ins-1':
                    vm.delete()
                    openstack_utils.resource_removed(
                        cls.nova_client.servers,
                        vm.id,
                        msg="Waiting for the Nova VM {} to be deleted".format(vm.name))
    
        class VMTests(test_utils.OpenStackBaseTest):
            """Encapsulate VM tests."""
    
            @classmethod
            def setUpClass(cls):
                """Run class setup for running tests."""
                super(VMTests, cls).setUpClass()
                zaza.atexit(cleanup_vm)
    
            def test_share(self):
                instance = None
                for vm in cls.nova_client.servers.list():
                    if vm.name == 'ins-1':
                        instance = vm
               id instance is None:
                    instance = self.launch_guest(
                        guest_name='ins-1')
               fip = neutron_tests.floating_ips_from_instance(instance)[0]
               openstack_utils.ping_response(fip)
    
    In the above example, a VM is spawned on the first pass through
    the test case but not cleaned up. The second time through the
    test case, the previous VM is used, and the verification is that
    the instance is pinged.
    
    When Zaza finishes the entire test run, it will call the atexit
    function that was registered and cleanup the server.
    ChrisMacNaughton committed Aug 17, 2021
    Configuration menu
    Copy the full SHA
    fbf4529 View commit details
    Browse the repository at this point in the history