Ejemplo n.º 1
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project, self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True
            )

            all_output = ''
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() != None:
                    break

                all_output += nextline

                yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(nextline, ' '*1024)
                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
Ejemplo n.º 2
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project,
                            self.object.task.name) is None:
            return

        preyield = True  # Use to balance <ul> tags upon error since we're streaming output
        try:
            process = subprocess.Popen(build_command(self.object,
                                                     self.request.session),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       shell=True)

            all_output = ''
            yield '<ul class="output">'
            preyield = False
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                nextline = '<li class="outputline">{}</li>'.format(nextline)
                if nextline.find('\x1b[32m') != -1:
                    nextline = nextline.replace(
                        '\x1b[32m',
                        '<ul class="outputgreen"><li class="outputline">')
                elif nextline.find('\x1b[31m') != -1:
                    nextline = nextline.replace(
                        '\x1b[31m',
                        '<ul class="outputred"><li class="outputline">')
                if nextline.find('\x1b[0m') != -1:
                    nextline = nextline.replace('\x1b[0m', '</ul></li>')

                all_output += nextline

                yield nextline
                sys.stdout.flush()
            yield '</ul>'
            preyield = True

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(
                self.object.status, ' ' * 1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            if not preyield:
                yield '</ul>'
            message = "An error occurred: " + e.message
            # yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span class="erroroutput">{} </span><br /> {}'.format(
                message, ' ' * 1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format(
                '*1024')
Ejemplo n.º 3
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project, self.object.task.name) is None:
            return

        preyield = True  # Use to balance <ul> tags upon error since we're streaming output
        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True
            )

            all_output = ''
            yield '<ul class="output">'
            preyield = False
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                nextline = '<li class="outputline">{}</li>'.format(nextline)
                if nextline.find('\x1b[32m') != -1:
                    nextline = nextline.replace('\x1b[32m', '<ul class="outputgreen"><li class="outputline">')
                elif nextline.find('\x1b[31m') != -1:
                    nextline = nextline.replace('\x1b[31m', '<ul class="outputred"><li class="outputline">')
                if nextline.find('\x1b[0m') != -1:
                    nextline = nextline.replace('\x1b[0m', '</ul></li>')

                all_output += nextline

                yield nextline
                sys.stdout.flush()
            yield '</ul>'
            preyield = True

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            if not preyield:
                yield '</ul>'
            message = "An error occurred: " + e.message
            # yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span class="erroroutput">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
Ejemplo n.º 4
0
    def test_build_command_with_args(self):
        deployment = mommy.make(models.Deployment, task__name='test_env')

        configuration = mommy.make(models.Configuration, key='arg', value='arg_value', task_argument=True)
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})
        fabfile_path, active_loc = get_fabfile_path(deployment.stage.project)

        self.assertEqual(
            command,
            'fab test_env:arg="arg_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )
Ejemplo n.º 5
0
    def test_build_command_with_args(self):
        deployment = mommy.make(models.Deployment, task__name='test_env')

        configuration = mommy.make(models.Configuration, key='arg', value='arg_value', task_argument=True,
                                   task_name='test_env')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})
        fabfile_path, active_loc = get_fabfile_path(deployment.stage.project)

        self.assertEqual(
            command,
            'fab test_env:arg="arg_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )
Ejemplo n.º 6
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project,
                            self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() != None:
                    break

                all_output += nextline

                yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(
                    nextline, ' ' * 1024)
                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(
                self.object.status, ' ' * 1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(
                message, ' ' * 1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format(
                '*1024')
Ejemplo n.º 7
0
    def output_stream_generator(self):
        if get_task_details(self.project, self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            yield '<link rel="stylesheet" type="text/css" href="/static/css/console-style.css">'
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                all_output += nextline
                nextline = '<span class="output-line">{}</span>'.format(ansiconv.to_html(nextline))
                yield nextline + ' '*1024

                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span class="output-line">{}</span>'.format(message) + ' '*1024
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
Ejemplo n.º 8
0
    def test_build_command_injection(self):
        deployment = mommy.make(models.Deployment, task__name='test_env')

        configuration = mommy.make(models.Configuration, key='foo=bar -i /path/to/keyfile --set foo2', value='bar')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})
        fabfile_path, active_loc = get_fabfile_path(deployment.stage.project)

        self.assertEqual(
            command,
            'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value,x=y')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key=dummy_value\,x\=y" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key=blah,x', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=blah\,x=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )
Ejemplo n.º 9
0
    def test_build_command_injection(self):
        deployment = mommy.make(models.Deployment, task__name='test_env')

        cache.delete_many(['project_{}_fabfile_tasks'.format(deployment.stage.project_id),
                   'project_{}_fabfile_path'.format(deployment.stage.project_id)])

        configuration = mommy.make(models.Configuration, key='foo=bar -i /path/to/keyfile --set foo2', value='bar')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})
        fabfile_path, active_loc = get_fabfile_path(deployment.stage.project)

        self.assertEqual(
            command,
            'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value,x=y')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key=dummy_value\,x\=y" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key=blah,x', value='dummy_value')
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=blah\,x=dummy_value" '
            '--abort-on-prompts --fabfile={}'.format(fabfile_path)
        )
Ejemplo n.º 10
0
    def test_build_command_injection(self):
        deployment = mommy.make(models.Deployment, task__name="test_env")

        cache.delete_many(
            [
                "project_{}_fabfile_tasks".format(deployment.stage.project_id),
                "project_{}_fabfile_path".format(deployment.stage.project_id),
            ]
        )

        configuration = mommy.make(models.Configuration, key="foo=bar -i /path/to/keyfile --set foo2", value="bar")
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})
        fabfile_path, active_loc = get_fabfile_path(deployment.stage.project)

        self.assertEqual(
            command,
            'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" '
            "--abort-on-prompts --fabfile={}".format(fabfile_path),
        )

        configuration = mommy.make(models.Configuration, key="dummy_key", value="dummy_value")
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" '
            "--abort-on-prompts --fabfile={}".format(fabfile_path),
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value="dummy_value")
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" '
            "--abort-on-prompts --fabfile={}".format(fabfile_path),
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key="dummy_key", value="dummy_value,x=y")
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key=dummy_value\,x\=y" ' "--abort-on-prompts --fabfile={}".format(fabfile_path),
        )

        deployment.stage.configuration_set.clear()
        configuration = mommy.make(models.Configuration, key="dummy_key=blah,x", value="dummy_value")
        deployment.stage.configuration_set.add(configuration)

        command = build_command(deployment, {})

        self.assertEqual(
            command,
            'fab test_env --set "dummy_key\=blah\,x=dummy_value" '
            "--abort-on-prompts --fabfile={}".format(fabfile_path),
        )