コード例 #1
0
ファイル: isolator.py プロジェクト: baseclue/codev
    def _environment(self):
        env = {}
        ssh_auth_sock_local = self.performer.execute('echo $SSH_AUTH_SOCK')
        performer_background_runner = None
        machine_background_runner = None
        ssh_auth_sock_remote = None
        if ssh_auth_sock_local and self.performer.check_execute(
            '[ -S {ssh_auth_sock_local} ]'.format(
                ssh_auth_sock_local=ssh_auth_sock_local
            )
        ):
            performer_background_runner = BackgroundExecutor(self.performer)
            machine_background_runner = BackgroundExecutor(self.machine)

            ssh_auth_sock_remote = '/tmp/{ident}-ssh-agent-sock'.format(ident=machine_background_runner.ident)

            # TODO avoid tcp because security reason
            performer_background_runner.execute(
                'socat TCP-LISTEN:44444,bind={gateway},fork UNIX-CONNECT:{ssh_auth_sock_local}'.format(
                    gateway=self.machine._gateway,
                    ssh_auth_sock_local=ssh_auth_sock_local
                ),
                wait=False
            )
            machine_background_runner.execute(
                'socat UNIX-LISTEN:{ssh_auth_sock_remote},fork TCP:{gateway}:44444'.format(
                    gateway=self.machine._gateway,
                    ssh_auth_sock_remote=ssh_auth_sock_remote,
                ),
                wait=False
            )
            env['SSH_AUTH_SOCK'] = ssh_auth_sock_remote
        try:
            yield env
        finally:
            if ssh_auth_sock_remote:
                machine_background_runner.kill()
                performer_background_runner.kill()
コード例 #2
0
ファイル: machines.py プロジェクト: baseclue/codev
    def share(self, source, target, bidirectional=False):
        share_target = '{share_directory}/{target}'.format(
            share_directory=self.share_directory,
            target=target
        )

        # copy all files to share directory
        # sequence /. just after source paramater makes cp command idempotent
        self.performer.execute(
            'cp -Ru {source}/. {share_target}'.format(
                source=source,
                share_target=share_target
            )
        )

        if bidirectional:
            self.performer.execute(
                'chmod -R go+w {share_target}'.format(
                    share_target=share_target
                )
            )

        source_target_background_runner = BackgroundExecutor(
            self.performer, ident='share_{ident}'.format(
                ident=self.ident
            )
        )
        dir_path = path.dirname(__file__)

        # prevent sync loop - if there is no change in file don't sync
        # This option may eat a lot of memory on huge file trees. see 'man clsync'
        modification_signature = ' --modification-signature "*"' if bidirectional else ''

        # TODO keep in mind relative and abs paths
        try:
            source_target_background_runner.execute(
                'TO={share_target}'
                ' clsync'
                ' --label live'
                ' --mode rsyncshell'
                ' --delay-sync 2'
                ' --delay-collect 3'
                ' --watch-dir {source}'
                '{modification_signature}'
                ' --sync-handler {dir_path}/scripts/clsync-synchandler-rsyncshell.sh'.format(
                    modification_signature=modification_signature,
                    share_target=share_target,
                    source=source,
                    dir_path=dir_path
                ),
                wait=False
            )
        except PerformerError:
            pass

        if bidirectional:
            target_source_background_runner = BackgroundExecutor(
                self.performer, ident='share_back_{ident}'.format(
                    ident=self.ident
                )
            )
            try:
                target_source_background_runner.execute(
                    'TO={source}'
                    ' clsync'
                    ' --label live'
                    ' --mode rsyncshell'
                    ' --delay-sync 2'
                    ' --delay-collect 3'
                    ' --watch-dir {share_target}'
                    ' --modification-signature "*"'
                    ' --sync-handler {dir_path}/scripts/clsync-synchandler-rsyncshell.sh'.format(
                        share_target=share_target,
                        source=source,
                        dir_path=dir_path
                    ),
                    wait=False
                )
            except PerformerError:
                pass

        if not self.check_execute('[ -L {target} ]'.format(target=target)):
            self.execute(
                'ln -s /share/{target} {target}'.format(
                    target=target,
                )
            )