Esempio n. 1
0
    def createZygote(self,
                     name=None,
                     attribute_values=None,
                     snapshot=True,
                     host_path=None):
        """Clones a zygote from the test base container.
        Use this to ensure that zygotes got properly cleaned up after each test.

        @param container_path: The LXC path for the new container.
        @param host_path: The host path for the new container.
        @param name: The name of the new container.
        @param attribute_values: Any attribute values for the new container.
        @param snapshot: Whether to create a snapshot clone.
        """
        if name is None:
            name = self.id().split('.')[-1]
        if host_path is None:
            host_path = os.path.join(self.shared_host_path, name)
        if attribute_values is None:
            attribute_values = {}
        zygote = lxc.Zygote(self.test_dir, name, attribute_values,
                            self.base_container, snapshot, host_path)
        try:
            yield zygote
        finally:
            if not options.skip_cleanup:
                zygote.destroy()
Esempio n. 2
0
 def testFindHostMount(self):
     """Verifies that zygotes pick up the correct host dirs."""
     with self.createZygote() as zygote0:
         # Not a clone, this just instantiates zygote1 on top of the LXC
         # container created by zygote0.
         zygote1 = lxc.Zygote(container_path=zygote0.container_path,
                              name=zygote0.name,
                              attribute_values={})
         # Verify that the new zygote picked up the correct host path
         # from the existing LXC container.
         self.assertEquals(zygote0.host_path, zygote1.host_path)
         self.assertEquals(zygote0.host_path_ro, zygote1.host_path_ro)
Esempio n. 3
0
    def testDetectExistingMounts(self):
        """Verifies that host mounts are properly reconstructed.

        When a Zygote is instantiated on top of an already-running container,
        any previously-created bind mounts have to be detected.  This enables
        proper cleanup later.
        """
        with lxc_utils.TempDir() as tmpdir, self.createZygote() as zygote0:
            zygote0.start(wait_for_network=False)
            # Create a bind mounted directory.
            zygote0.mount_dir(tmpdir, 'foo')
            # Create another zygote on top of the existing container.
            zygote1 = lxc.Zygote(container_path=zygote0.container_path,
                                 name=zygote0.name,
                                 attribute_values={})
            # Verify that the new zygote contains the same bind mounts.
            self.assertEqual(zygote0.mounts, zygote1.mounts)