Example #1
0
 def test_wrapped_command(self):
     """Test shell wrapping for Docker chdir"""
     cmd = DockerBuildCommand(["pip", "install", "requests"], cwd="/tmp/foobar")
     self.assertEqual(cmd.get_wrapped_command(), ("/bin/sh -c " "'cd /tmp/foobar && " "pip install requests'"))
     cmd = DockerBuildCommand(
         ["python", "/tmp/foo/pip", "install", "Django>1.7"], cwd="/tmp/foobar", bin_path="/tmp/foo"
     )
     self.assertEqual(
         cmd.get_wrapped_command(),
         ("/bin/sh -c " "'cd /tmp/foobar && PATH=/tmp/foo:$PATH " "python /tmp/foo/pip install Django\>1.7'"),
     )
    def test_command_build(self):
        '''Test building of command'''
        cmd = DockerBuildCommand('/home/docs/run.sh pip')
        with cmd:
            self.assertEqual(
                cmd.get_command(),
                'docker run -i --rm=true rtfd-build /home/docs/run.sh pip')

        cmd = DockerBuildCommand(['/home/docs/run.sh', 'pip'])
        with cmd:
            self.assertEqual(
                cmd.get_command(),
                'docker run -i --rm=true rtfd-build /home/docs/run.sh pip')

        cmd = DockerBuildCommand(
            ['/home/docs/run.sh', 'pip'],
            name='swayze-express',
            mounts=[('/some/path/checkouts',
                     '/home/docs/checkouts')]
        )
        with cmd:
            self.assertEqual(
                cmd.get_command(),
                ('docker run -i -v /some/path/checkouts:/home/docs/checkouts '
                 '--name=swayze-express --rm=true rtfd-build '
                 '/home/docs/run.sh pip')
            )

        cmd = DockerBuildCommand(
            ['/home/docs/run.sh', 'pip'],
            user='pswayze',
            image='swayze-express',
        )
        with cmd:
            self.assertEqual(
                cmd.get_command(),
                ('docker run -i --user=pswayze --rm=true swayze-express '
                 '/home/docs/run.sh pip')
            )

        cmd = DockerBuildCommand(
            ['/home/docs/run.sh', 'pip'],
            user='pswayze',
            image='swayze-express',
            remove=False,
        )
        with cmd:
            self.assertEqual(
                cmd.get_command(),
                ('docker run -i --user=pswayze swayze-express '
                 '/home/docs/run.sh pip')
            )
 def test_command_oom_kill(self):
     '''Command is OOM killed'''
     self.mocks.configure_mock('docker_client', {
         'exec_create.return_value': {'Id': 'container-foobar'},
         'exec_start.return_value': b'Killed\n',
         'exec_inspect.return_value': {'ExitCode': 137},
     })
     cmd = DockerBuildCommand(['echo', 'test'], cwd='/tmp/foobar')
     cmd.build_env = Mock()
     cmd.build_env.get_client.return_value = self.mocks.docker_client
     type(cmd.build_env).container_id = PropertyMock(return_value='foo')
     cmd.run()
     self.assertEqual(
         str(cmd.output),
         u'Command killed due to excessive memory consumption\n')
 def test_wrapped_command(self):
     '''Test shell wrapping for Docker chdir'''
     cmd = DockerBuildCommand(['pip', 'install', 'requests'],
                              cwd='/tmp/foobar')
     self.assertEqual(
         cmd.get_wrapped_command(),
         ("/bin/sh -c "
          "'cd /tmp/foobar && "
          "pip install requests'"))
     cmd = DockerBuildCommand(['pip', 'install', 'Django>1.7'],
                              cwd='/tmp/foobar')
     self.assertEqual(
         cmd.get_wrapped_command(),
         ("/bin/sh -c "
          "'cd /tmp/foobar && "
          "pip install Django\>1.7'"))
Example #5
0
 def test_command_oom_kill(self):
     """Command is OOM killed"""
     self.mocks.configure_mock(
         "docker_client",
         {
             "exec_create.return_value": {"Id": "container-foobar"},
             "exec_start.return_value": b"Killed\n",
             "exec_inspect.return_value": {"ExitCode": 137},
         },
     )
     cmd = DockerBuildCommand(["echo", "test"], cwd="/tmp/foobar")
     cmd.build_env = Mock()
     cmd.build_env.get_client.return_value = self.mocks.docker_client
     type(cmd.build_env).container_id = PropertyMock(return_value="foo")
     cmd.run()
     self.assertEqual(str(cmd.output), u"Command killed due to excessive memory consumption\n")
 def test_wrapped_command(self):
     '''Test shell wrapping for Docker chdir'''
     cmd = DockerBuildCommand(['pip', 'install', 'requests'],
                              cwd='/tmp/foobar')
     self.assertEqual(
         cmd.get_wrapped_command(),
         ("/bin/sh -c "
          "'cd /tmp/foobar && "
          "READTHEDOCS=True pip install requests'"))
     cmd = DockerBuildCommand(['python', '/tmp/foo/pip', 'install',
                               'Django>1.7'],
                              cwd='/tmp/foobar',
                              bin_path='/tmp/foo')
     self.assertEqual(
         cmd.get_wrapped_command(),
         ("/bin/sh -c "
          "'cd /tmp/foobar && READTHEDOCS=True PATH=/tmp/foo:$PATH "
          "python /tmp/foo/pip install Django\>1.7'"))
 def test_unicode_output(self):
     '''Unicode output from command'''
     self.mocks.configure_mock('docker_client', {
         'exec_create.return_value': {'Id': b'container-foobar'},
         'exec_start.return_value': SAMPLE_UTF8_BYTES,
         'exec_inspect.return_value': {'ExitCode': 0},
     })
     cmd = DockerBuildCommand(['echo', 'test'], cwd='/tmp/foobar')
     cmd.build_env = Mock()
     cmd.build_env.get_client.return_value = self.mocks.docker_client
     type(cmd.build_env).container_id = PropertyMock(return_value='foo')
     cmd.run()
     self.assertEqual(
         cmd.output,
         u'H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9')
     self.assertEqual(self.mocks.docker_client.exec_start.call_count, 1)
     self.assertEqual(self.mocks.docker_client.exec_create.call_count, 1)
     self.assertEqual(self.mocks.docker_client.exec_inspect.call_count, 1)
 def test_wrapped_command(self):
     """Test shell wrapping for Docker chdir."""
     cmd = DockerBuildCommand(['pip', 'install', 'requests'],
                              cwd='/tmp/foobar')
     self.assertEqual(
         cmd.get_wrapped_command(),
         "/bin/sh -c 'cd /tmp/foobar && pip install requests'",
     )
     cmd = DockerBuildCommand(
         ['python', '/tmp/foo/pip', 'install', 'Django>1.7'],
         cwd='/tmp/foobar',
         bin_path='/tmp/foo',
     )
     self.assertEqual(
         cmd.get_wrapped_command(),
         ('/bin/sh -c '
          "'cd /tmp/foobar && PATH=/tmp/foo:$PATH "
          "python /tmp/foo/pip install Django\>1.7'"),
     )
                                 cwd='/tmp/foobar',
                                 bin_path='/tmp/foo')
        self.assertEqual(
            cmd.get_wrapped_command(),
            ("/bin/sh -c "
             "'cd /tmp/foobar && PATH=/tmp/foo:$PATH "
             "python /tmp/foo/pip install Django\>1.7'"))

    def test_unicode_output(self):
        '''Unicode output from command'''
        self.mocks.configure_mock('docker_client', {
            'exec_create.return_value': {'Id': 'container-foobar'},
            'exec_start.return_value': b'HérÉ îß sömê ünïçó∂é',
            'exec_inspect.return_value': {'ExitCode': 0},
        })
        cmd = DockerBuildCommand(['echo', 'test'], cwd='/tmp/foobar')
        cmd.build_env = Mock()
        cmd.build_env.get_client.return_value = self.mocks.docker_client
        type(cmd.build_env).container_id = PropertyMock(return_value='foo')
        cmd.run()
        self.assertEqual(
            cmd.output,
            u'H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9')
        self.assertEqual(self.mocks.docker_client.exec_start.call_count, 1)
        self.assertEqual(self.mocks.docker_client.exec_create.call_count, 1)
        self.assertEqual(self.mocks.docker_client.exec_inspect.call_count, 1)

    def test_command_oom_kill(self):
        '''Command is OOM killed'''
        self.mocks.configure_mock('docker_client', {
            'exec_create.return_value': {'Id': 'container-foobar'},