def test_bad_version(self):
        """Test ContainerSandbox.create_and_run_containers.

        With a bad version, construction of the sandbox should fail.
        """
        docker.Client.version = lambda _: {'Version': '1.6.0'}
        with self.assertRaises(utils.AppstartAbort):
            container_sandbox.ContainerSandbox(image_name='temp')
 def test_start_no_api_server(self):
     """Test ContainerSandbox.start (with no api server)."""
     sb = container_sandbox.ContainerSandbox(self.conf_file.name,
                                                     run_api_server=False)
     sb.start()
     self.assertIsNotNone(sb.app_container)
     self.assertIsNotNone(sb.app_container)
     self.assertIsNone(sb.devappserver_container)
    def test_start_from_conf(self):
        """Test ContainerSandbox.start."""
        sb = container_sandbox.ContainerSandbox(self.conf_file.name)
        sb.start()

        self.assertIsNotNone(sb.app_container)
        self.assertIsNotNone(sb.devappserver_container)
        self.assertIsNotNone(sb.app_container)
    def test_start_from_image(self):
        sb = container_sandbox.ContainerSandbox(image_name='test_image')
        with self.assertRaises(utils.AppstartAbort):
            sb.start()

        fake_docker.reset()
        fake_docker.images.append('test_image')
        sb.start()

        self.assertEqual(len(fake_docker.images),
                         len(fake_docker.DEFAULT_IMAGES) + 2,
                         'Too many images created')
Exemple #5
0
    def setUpClass(cls):
        """Create an actual sandbox.

        This depends on a properly set up docker environment.
        """
        test_directory = os.path.dirname(os.path.realpath(__file__))
        cls.conf_file = os.path.join(test_directory, 'app.yaml')

        # Use temporary storage, generating unique name with a timestamp.
        temp_storage_path = '/tmp/storage/%s' % str(time.time())
        cls.sandbox = container_sandbox.ContainerSandbox(
            cls.conf_file, storage_path=temp_storage_path)

        # Set up the containers
        cls.sandbox.start()
    def setUp(self):
        """Populate the sandbox fake containers.

        This simulates the scenario where create_and_run_containers() has
        just run successfully.
        """
        super(ExitTest, self).setUp()
        self.sandbox = container_sandbox.ContainerSandbox(
            self.conf_file.name)
        # Add the containers to the sandbox. Mock them out (we've tested the
        # containers elsewhere, and we just need the appropriate methods to be
        # called).
        self.sandbox.app_container = (
            self.mocker.CreateMock(container.ApplicationContainer))

        self.sandbox.devappserver_container = (
            self.mocker.CreateMock(container.Container))

        self.sandbox.pinger_container = (
            self.mocker.CreateMock(container.PingerContainer))

        # TODO(gouzenko): Figure out how to make order not matter (among the
        # three containers).
        self.sandbox.app_container.running().AndReturn(True)
        self.sandbox.app_container.get_id().AndReturn('456')
        self.sandbox.app_container.kill()
        self.sandbox.app_container.remove()

        self.sandbox.devappserver_container.running().AndReturn(True)
        self.sandbox.devappserver_container.get_id().AndReturn('123')
        self.sandbox.devappserver_container.kill()
        self.sandbox.devappserver_container.remove()

        self.sandbox.pinger_container.running().AndReturn(True)
        self.sandbox.pinger_container.get_id().AndReturn('123')
        self.sandbox.pinger_container.kill()
        self.sandbox.pinger_container.remove()
        self.mocker.ReplayAll()
Exemple #7
0
    def setUpClass(cls):
        """Create an actual sandbox.

        This depends on a properly set up docker environment.
        """

        utils.build_from_directory(os.path.dirname(devappserver_init.__file__),
                                   APPSTART_BASE_IMAGE,
                                   nocache=True)

        test_directory = os.path.dirname(os.path.realpath(__file__))
        cls.conf_file = os.path.join(test_directory, 'app.yaml')

        # Use temporary storage, generating unique name with a timestamp.
        temp_storage_path = '/tmp/storage/%s' % str(time.time())
        cls.sandbox = container_sandbox.ContainerSandbox(
            cls.conf_file,
            storage_path=temp_storage_path,
            devbase_image=APPSTART_BASE_IMAGE,
            force_version=True,
            extra_ports={1000: 1111})

        # Set up the containers
        cls.sandbox.start()
 def test_start_no_image_no_conf(self):
     with self.assertRaises(utils.AppstartAbort):
         container_sandbox.ContainerSandbox()