# Client closed - check that the host connection also closed.
        self.assertTrue(host.poll(TIMEOUT))
        with self.assertRaises(EOFError):
            host.recv()

    def testConnection_badAddress(self):
        """Tests that connecting to a bad address fails."""
        # Make a bogus address, then assert that the client fails.
        address = '%s.foobar' % self.address
        with self.assertRaises(socket.error):
            client.Client(address, 0)

    def testConnection_timeout(self):
        """Tests that connection attempts time out properly."""
        with tempfile.NamedTemporaryFile(dir=self.test_dir) as tmp:
            with self.assertRaises(socket.timeout):
                client.Client(tmp.name, 0)

    def testConnection_deadLine(self):
        """Tests that the connection times out if no action is ever taken."""
        id = 3
        short_timeout = TIMEOUT / 2
        with client.Client.connect(self.address, TIMEOUT) as c:
            self.assertIsNone(c.get_container(id, short_timeout))


if __name__ == '__main__':
    unittest_setup.setup(require_sudo=False)
    unittest.main()
Exemple #2
0
    Sets up a test directory along with a reference container that is used by
    tests that need an existing base container.
    """
    global test_dir
    global reference_container
    global cleanup_ref_container

    test_dir = tempfile.mkdtemp(dir=lxc.DEFAULT_CONTAINER_PATH,
                                prefix='base_container_manager_unittest_')
    # Unfortunately, aside from duping the BaseImage code completely, there
    # isn't an easy way to download and configure a base container.  So even
    # though this is the BaseImage unittest, we use a BaseImage to set it up.
    bcm = BaseImage()
    if bcm.base_container is None:
        bcm.setup()
        cleanup_ref_container = True
    reference_container = bcm.base_container


def tearDownModule():
    """Deletes the test dir and reference container."""
    if not unittest_setup.config.skip_cleanup:
        if cleanup_ref_container:
            reference_container.destroy()
        shutil.rmtree(test_dir)


if __name__ == '__main__':
    unittest_setup.setup()
    unittest.main()
 def setUpClass(cls):
     unittest_setup.setup()