xref: /OK3568_Linux_fs/yocto/poky/scripts/lib/devtool/deploy.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Development tool - deploy/undeploy command plugin
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Copyright (C) 2014-2016 Intel Corporation
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun"""Devtool plugin containing the deploy subcommands"""
8*4882a593Smuzhiyun
9*4882a593Smuzhiyunimport logging
10*4882a593Smuzhiyunimport os
11*4882a593Smuzhiyunimport shutil
12*4882a593Smuzhiyunimport subprocess
13*4882a593Smuzhiyunimport tempfile
14*4882a593Smuzhiyun
15*4882a593Smuzhiyunimport bb.utils
16*4882a593Smuzhiyunimport argparse_oe
17*4882a593Smuzhiyunimport oe.types
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunfrom devtool import exec_fakeroot, setup_tinfoil, check_workspace_recipe, DevtoolError
20*4882a593Smuzhiyun
21*4882a593Smuzhiyunlogger = logging.getLogger('devtool')
22*4882a593Smuzhiyun
23*4882a593Smuzhiyundeploylist_path = '/.devtool'
24*4882a593Smuzhiyun
25*4882a593Smuzhiyundef _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=False, nopreserve=False, nocheckspace=False):
26*4882a593Smuzhiyun    """
27*4882a593Smuzhiyun    Prepare a shell script for running on the target to
28*4882a593Smuzhiyun    deploy/undeploy files. We have to be careful what we put in this
29*4882a593Smuzhiyun    script - only commands that are likely to be available on the
30*4882a593Smuzhiyun    target are suitable (the target might be constrained, e.g. using
31*4882a593Smuzhiyun    busybox rather than bash with coreutils).
32*4882a593Smuzhiyun    """
33*4882a593Smuzhiyun    lines = []
34*4882a593Smuzhiyun    lines.append('#!/bin/sh')
35*4882a593Smuzhiyun    lines.append('set -e')
36*4882a593Smuzhiyun    if undeployall:
37*4882a593Smuzhiyun        # Yes, I know this is crude - but it does work
38*4882a593Smuzhiyun        lines.append('for entry in %s/*.list; do' % deploylist_path)
39*4882a593Smuzhiyun        lines.append('[ ! -f $entry ] && exit')
40*4882a593Smuzhiyun        lines.append('set `basename $entry | sed "s/.list//"`')
41*4882a593Smuzhiyun    if dryrun:
42*4882a593Smuzhiyun        if not deploy:
43*4882a593Smuzhiyun            lines.append('echo "Previously deployed files for $1:"')
44*4882a593Smuzhiyun    lines.append('manifest="%s/$1.list"' % deploylist_path)
45*4882a593Smuzhiyun    lines.append('preservedir="%s/$1.preserve"' % deploylist_path)
46*4882a593Smuzhiyun    lines.append('if [ -f $manifest ] ; then')
47*4882a593Smuzhiyun    # Read manifest in reverse and delete files / remove empty dirs
48*4882a593Smuzhiyun    lines.append('    sed \'1!G;h;$!d\' $manifest | while read file')
49*4882a593Smuzhiyun    lines.append('    do')
50*4882a593Smuzhiyun    if dryrun:
51*4882a593Smuzhiyun        lines.append('        if [ ! -d $file ] ; then')
52*4882a593Smuzhiyun        lines.append('            echo $file')
53*4882a593Smuzhiyun        lines.append('        fi')
54*4882a593Smuzhiyun    else:
55*4882a593Smuzhiyun        lines.append('        if [ -d $file ] ; then')
56*4882a593Smuzhiyun        # Avoid deleting a preserved directory in case it has special perms
57*4882a593Smuzhiyun        lines.append('            if [ ! -d $preservedir/$file ] ; then')
58*4882a593Smuzhiyun        lines.append('                rmdir $file > /dev/null 2>&1 || true')
59*4882a593Smuzhiyun        lines.append('            fi')
60*4882a593Smuzhiyun        lines.append('        else')
61*4882a593Smuzhiyun        lines.append('            rm -f $file')
62*4882a593Smuzhiyun        lines.append('        fi')
63*4882a593Smuzhiyun    lines.append('    done')
64*4882a593Smuzhiyun    if not dryrun:
65*4882a593Smuzhiyun        lines.append('    rm $manifest')
66*4882a593Smuzhiyun    if not deploy and not dryrun:
67*4882a593Smuzhiyun        # May as well remove all traces
68*4882a593Smuzhiyun        lines.append('    rmdir `dirname $manifest` > /dev/null 2>&1 || true')
69*4882a593Smuzhiyun    lines.append('fi')
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun    if deploy:
72*4882a593Smuzhiyun        if not nocheckspace:
73*4882a593Smuzhiyun            # Check for available space
74*4882a593Smuzhiyun            # FIXME This doesn't take into account files spread across multiple
75*4882a593Smuzhiyun            # partitions, but doing that is non-trivial
76*4882a593Smuzhiyun            # Find the part of the destination path that exists
77*4882a593Smuzhiyun            lines.append('checkpath="$2"')
78*4882a593Smuzhiyun            lines.append('while [ "$checkpath" != "/" ] && [ ! -e $checkpath ]')
79*4882a593Smuzhiyun            lines.append('do')
80*4882a593Smuzhiyun            lines.append('    checkpath=`dirname "$checkpath"`')
81*4882a593Smuzhiyun            lines.append('done')
82*4882a593Smuzhiyun            lines.append(r'freespace=$(df -P $checkpath | sed -nre "s/^(\S+\s+){3}([0-9]+).*/\2/p")')
83*4882a593Smuzhiyun            # First line of the file is the total space
84*4882a593Smuzhiyun            lines.append('total=`head -n1 $3`')
85*4882a593Smuzhiyun            lines.append('if [ $total -gt $freespace ] ; then')
86*4882a593Smuzhiyun            lines.append('    echo "ERROR: insufficient space on target (available ${freespace}, needed ${total})"')
87*4882a593Smuzhiyun            lines.append('    exit 1')
88*4882a593Smuzhiyun            lines.append('fi')
89*4882a593Smuzhiyun        if not nopreserve:
90*4882a593Smuzhiyun            # Preserve any files that exist. Note that this will add to the
91*4882a593Smuzhiyun            # preserved list with successive deployments if the list of files
92*4882a593Smuzhiyun            # deployed changes, but because we've deleted any previously
93*4882a593Smuzhiyun            # deployed files at this point it will never preserve anything
94*4882a593Smuzhiyun            # that was deployed, only files that existed prior to any deploying
95*4882a593Smuzhiyun            # (which makes the most sense)
96*4882a593Smuzhiyun            lines.append('cat $3 | sed "1d" | while read file fsize')
97*4882a593Smuzhiyun            lines.append('do')
98*4882a593Smuzhiyun            lines.append('    if [ -e $file ] ; then')
99*4882a593Smuzhiyun            lines.append('    dest="$preservedir/$file"')
100*4882a593Smuzhiyun            lines.append('    mkdir -p `dirname $dest`')
101*4882a593Smuzhiyun            lines.append('    mv $file $dest')
102*4882a593Smuzhiyun            lines.append('    fi')
103*4882a593Smuzhiyun            lines.append('done')
104*4882a593Smuzhiyun            lines.append('rm $3')
105*4882a593Smuzhiyun        lines.append('mkdir -p `dirname $manifest`')
106*4882a593Smuzhiyun        lines.append('mkdir -p $2')
107*4882a593Smuzhiyun        if verbose:
108*4882a593Smuzhiyun            lines.append('    tar xv -C $2 -f - | tee $manifest')
109*4882a593Smuzhiyun        else:
110*4882a593Smuzhiyun            lines.append('    tar xv -C $2 -f - > $manifest')
111*4882a593Smuzhiyun        lines.append('sed -i "s!^./!$2!" $manifest')
112*4882a593Smuzhiyun    elif not dryrun:
113*4882a593Smuzhiyun        # Put any preserved files back
114*4882a593Smuzhiyun        lines.append('if [ -d $preservedir ] ; then')
115*4882a593Smuzhiyun        lines.append('    cd $preservedir')
116*4882a593Smuzhiyun        # find from busybox might not have -exec, so we don't use that
117*4882a593Smuzhiyun        lines.append('    find . -type f | while read file')
118*4882a593Smuzhiyun        lines.append('    do')
119*4882a593Smuzhiyun        lines.append('        mv $file /$file')
120*4882a593Smuzhiyun        lines.append('    done')
121*4882a593Smuzhiyun        lines.append('    cd /')
122*4882a593Smuzhiyun        lines.append('    rm -rf $preservedir')
123*4882a593Smuzhiyun        lines.append('fi')
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun    if undeployall:
126*4882a593Smuzhiyun        if not dryrun:
127*4882a593Smuzhiyun            lines.append('echo "NOTE: Successfully undeployed $1"')
128*4882a593Smuzhiyun        lines.append('done')
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun    # Delete the script itself
131*4882a593Smuzhiyun    lines.append('rm $0')
132*4882a593Smuzhiyun    lines.append('')
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun    return '\n'.join(lines)
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun
138*4882a593Smuzhiyundef deploy(args, config, basepath, workspace):
139*4882a593Smuzhiyun    """Entry point for the devtool 'deploy' subcommand"""
140*4882a593Smuzhiyun    import math
141*4882a593Smuzhiyun    import oe.recipeutils
142*4882a593Smuzhiyun    import oe.package
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun    check_workspace_recipe(workspace, args.recipename, checksrc=False)
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun    try:
147*4882a593Smuzhiyun        host, destdir = args.target.split(':')
148*4882a593Smuzhiyun    except ValueError:
149*4882a593Smuzhiyun        destdir = '/'
150*4882a593Smuzhiyun    else:
151*4882a593Smuzhiyun        args.target = host
152*4882a593Smuzhiyun    if not destdir.endswith('/'):
153*4882a593Smuzhiyun        destdir += '/'
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun    tinfoil = setup_tinfoil(basepath=basepath)
156*4882a593Smuzhiyun    try:
157*4882a593Smuzhiyun        try:
158*4882a593Smuzhiyun            rd = tinfoil.parse_recipe(args.recipename)
159*4882a593Smuzhiyun        except Exception as e:
160*4882a593Smuzhiyun            raise DevtoolError('Exception parsing recipe %s: %s' %
161*4882a593Smuzhiyun                            (args.recipename, e))
162*4882a593Smuzhiyun        recipe_outdir = rd.getVar('D')
163*4882a593Smuzhiyun        if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir):
164*4882a593Smuzhiyun            raise DevtoolError('No files to deploy - have you built the %s '
165*4882a593Smuzhiyun                            'recipe? If so, the install step has not installed '
166*4882a593Smuzhiyun                            'any files.' % args.recipename)
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun        if args.strip and not args.dry_run:
169*4882a593Smuzhiyun            # Fakeroot copy to new destination
170*4882a593Smuzhiyun            srcdir = recipe_outdir
171*4882a593Smuzhiyun            recipe_outdir = os.path.join(rd.getVar('WORKDIR'), 'devtool-deploy-target-stripped')
172*4882a593Smuzhiyun            if os.path.isdir(recipe_outdir):
173*4882a593Smuzhiyun                exec_fakeroot(rd, "rm -rf %s" % recipe_outdir, shell=True)
174*4882a593Smuzhiyun            exec_fakeroot(rd, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True)
175*4882a593Smuzhiyun            os.environ['PATH'] = ':'.join([os.environ['PATH'], rd.getVar('PATH') or ''])
176*4882a593Smuzhiyun            oe.package.strip_execs(args.recipename, recipe_outdir, rd.getVar('STRIP'), rd.getVar('libdir'),
177*4882a593Smuzhiyun                        rd.getVar('base_libdir'), rd)
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun        filelist = []
180*4882a593Smuzhiyun        inodes = set({})
181*4882a593Smuzhiyun        ftotalsize = 0
182*4882a593Smuzhiyun        for root, _, files in os.walk(recipe_outdir):
183*4882a593Smuzhiyun            for fn in files:
184*4882a593Smuzhiyun                fstat = os.lstat(os.path.join(root, fn))
185*4882a593Smuzhiyun                # Get the size in kiB (since we'll be comparing it to the output of du -k)
186*4882a593Smuzhiyun                # MUST use lstat() here not stat() or getfilesize() since we don't want to
187*4882a593Smuzhiyun                # dereference symlinks
188*4882a593Smuzhiyun                if fstat.st_ino in inodes:
189*4882a593Smuzhiyun                    fsize = 0
190*4882a593Smuzhiyun                else:
191*4882a593Smuzhiyun                    fsize = int(math.ceil(float(fstat.st_size)/1024))
192*4882a593Smuzhiyun                inodes.add(fstat.st_ino)
193*4882a593Smuzhiyun                ftotalsize += fsize
194*4882a593Smuzhiyun                # The path as it would appear on the target
195*4882a593Smuzhiyun                fpath = os.path.join(destdir, os.path.relpath(root, recipe_outdir), fn)
196*4882a593Smuzhiyun                filelist.append((fpath, fsize))
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun        if args.dry_run:
199*4882a593Smuzhiyun            print('Files to be deployed for %s on target %s:' % (args.recipename, args.target))
200*4882a593Smuzhiyun            for item, _ in filelist:
201*4882a593Smuzhiyun                print('  %s' % item)
202*4882a593Smuzhiyun            return 0
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun        extraoptions = ''
205*4882a593Smuzhiyun        if args.no_host_check:
206*4882a593Smuzhiyun            extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
207*4882a593Smuzhiyun        if not args.show_status:
208*4882a593Smuzhiyun            extraoptions += ' -q'
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun        scp_sshexec = ''
211*4882a593Smuzhiyun        ssh_sshexec = 'ssh'
212*4882a593Smuzhiyun        if args.ssh_exec:
213*4882a593Smuzhiyun            scp_sshexec = "-S %s" % args.ssh_exec
214*4882a593Smuzhiyun            ssh_sshexec = args.ssh_exec
215*4882a593Smuzhiyun        scp_port = ''
216*4882a593Smuzhiyun        ssh_port = ''
217*4882a593Smuzhiyun        if args.port:
218*4882a593Smuzhiyun            scp_port = "-P %s" % args.port
219*4882a593Smuzhiyun            ssh_port = "-p %s" % args.port
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun        if args.key:
222*4882a593Smuzhiyun            extraoptions += ' -i %s' % args.key
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun        # In order to delete previously deployed files and have the manifest file on
225*4882a593Smuzhiyun        # the target, we write out a shell script and then copy it to the target
226*4882a593Smuzhiyun        # so we can then run it (piping tar output to it).
227*4882a593Smuzhiyun        # (We cannot use scp here, because it doesn't preserve symlinks.)
228*4882a593Smuzhiyun        tmpdir = tempfile.mkdtemp(prefix='devtool')
229*4882a593Smuzhiyun        try:
230*4882a593Smuzhiyun            tmpscript = '/tmp/devtool_deploy.sh'
231*4882a593Smuzhiyun            tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list')
232*4882a593Smuzhiyun            shellscript = _prepare_remote_script(deploy=True,
233*4882a593Smuzhiyun                                                verbose=args.show_status,
234*4882a593Smuzhiyun                                                nopreserve=args.no_preserve,
235*4882a593Smuzhiyun                                                nocheckspace=args.no_check_space)
236*4882a593Smuzhiyun            # Write out the script to a file
237*4882a593Smuzhiyun            with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
238*4882a593Smuzhiyun                f.write(shellscript)
239*4882a593Smuzhiyun            # Write out the file list
240*4882a593Smuzhiyun            with open(os.path.join(tmpdir, os.path.basename(tmpfilelist)), 'w') as f:
241*4882a593Smuzhiyun                f.write('%d\n' % ftotalsize)
242*4882a593Smuzhiyun                for fpath, fsize in filelist:
243*4882a593Smuzhiyun                    f.write('%s %d\n' % (fpath, fsize))
244*4882a593Smuzhiyun            # Copy them to the target
245*4882a593Smuzhiyun            ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
246*4882a593Smuzhiyun            if ret != 0:
247*4882a593Smuzhiyun                raise DevtoolError('Failed to copy script to %s - rerun with -s to '
248*4882a593Smuzhiyun                                'get a complete error message' % args.target)
249*4882a593Smuzhiyun        finally:
250*4882a593Smuzhiyun            shutil.rmtree(tmpdir)
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun        # Now run the script
253*4882a593Smuzhiyun        ret = exec_fakeroot(rd, 'tar cf - . | %s  %s %s %s \'sh %s %s %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True)
254*4882a593Smuzhiyun        if ret != 0:
255*4882a593Smuzhiyun            raise DevtoolError('Deploy failed - rerun with -s to get a complete '
256*4882a593Smuzhiyun                            'error message')
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun        logger.info('Successfully deployed %s' % recipe_outdir)
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun        files_list = []
261*4882a593Smuzhiyun        for root, _, files in os.walk(recipe_outdir):
262*4882a593Smuzhiyun            for filename in files:
263*4882a593Smuzhiyun                filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
264*4882a593Smuzhiyun                files_list.append(os.path.join(destdir, filename))
265*4882a593Smuzhiyun    finally:
266*4882a593Smuzhiyun        tinfoil.shutdown()
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun    return 0
269*4882a593Smuzhiyun
270*4882a593Smuzhiyundef undeploy(args, config, basepath, workspace):
271*4882a593Smuzhiyun    """Entry point for the devtool 'undeploy' subcommand"""
272*4882a593Smuzhiyun    if args.all and args.recipename:
273*4882a593Smuzhiyun        raise argparse_oe.ArgumentUsageError('Cannot specify -a/--all with a recipe name', 'undeploy-target')
274*4882a593Smuzhiyun    elif not args.recipename and not args.all:
275*4882a593Smuzhiyun        raise argparse_oe.ArgumentUsageError('If you don\'t specify a recipe, you must specify -a/--all', 'undeploy-target')
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun    extraoptions = ''
278*4882a593Smuzhiyun    if args.no_host_check:
279*4882a593Smuzhiyun        extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
280*4882a593Smuzhiyun    if not args.show_status:
281*4882a593Smuzhiyun        extraoptions += ' -q'
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun    scp_sshexec = ''
284*4882a593Smuzhiyun    ssh_sshexec = 'ssh'
285*4882a593Smuzhiyun    if args.ssh_exec:
286*4882a593Smuzhiyun        scp_sshexec = "-S %s" % args.ssh_exec
287*4882a593Smuzhiyun        ssh_sshexec = args.ssh_exec
288*4882a593Smuzhiyun    scp_port = ''
289*4882a593Smuzhiyun    ssh_port = ''
290*4882a593Smuzhiyun    if args.port:
291*4882a593Smuzhiyun        scp_port = "-P %s" % args.port
292*4882a593Smuzhiyun        ssh_port = "-p %s" % args.port
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun    args.target = args.target.split(':')[0]
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun    tmpdir = tempfile.mkdtemp(prefix='devtool')
297*4882a593Smuzhiyun    try:
298*4882a593Smuzhiyun        tmpscript = '/tmp/devtool_undeploy.sh'
299*4882a593Smuzhiyun        shellscript = _prepare_remote_script(deploy=False, dryrun=args.dry_run, undeployall=args.all)
300*4882a593Smuzhiyun        # Write out the script to a file
301*4882a593Smuzhiyun        with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
302*4882a593Smuzhiyun            f.write(shellscript)
303*4882a593Smuzhiyun        # Copy it to the target
304*4882a593Smuzhiyun        ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
305*4882a593Smuzhiyun        if ret != 0:
306*4882a593Smuzhiyun            raise DevtoolError('Failed to copy script to %s - rerun with -s to '
307*4882a593Smuzhiyun                                'get a complete error message' % args.target)
308*4882a593Smuzhiyun    finally:
309*4882a593Smuzhiyun        shutil.rmtree(tmpdir)
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun    # Now run the script
312*4882a593Smuzhiyun    ret = subprocess.call('%s %s %s %s \'sh %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename), shell=True)
313*4882a593Smuzhiyun    if ret != 0:
314*4882a593Smuzhiyun        raise DevtoolError('Undeploy failed - rerun with -s to get a complete '
315*4882a593Smuzhiyun                           'error message')
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun    if not args.all and not args.dry_run:
318*4882a593Smuzhiyun        logger.info('Successfully undeployed %s' % args.recipename)
319*4882a593Smuzhiyun    return 0
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun
322*4882a593Smuzhiyundef register_commands(subparsers, context):
323*4882a593Smuzhiyun    """Register devtool subcommands from the deploy plugin"""
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun    parser_deploy = subparsers.add_parser('deploy-target',
326*4882a593Smuzhiyun                                          help='Deploy recipe output files to live target machine',
327*4882a593Smuzhiyun                                          description='Deploys a recipe\'s build output (i.e. the output of the do_install task) to a live target machine over ssh. By default, any existing files will be preserved instead of being overwritten and will be restored if you run devtool undeploy-target. Note: this only deploys the recipe itself and not any runtime dependencies, so it is assumed that those have been installed on the target beforehand.',
328*4882a593Smuzhiyun                                          group='testbuild')
329*4882a593Smuzhiyun    parser_deploy.add_argument('recipename', help='Recipe to deploy')
330*4882a593Smuzhiyun    parser_deploy.add_argument('target', help='Live target machine running an ssh server: user@hostname[:destdir]')
331*4882a593Smuzhiyun    parser_deploy.add_argument('-c', '--no-host-check', help='Disable ssh host key checking', action='store_true')
332*4882a593Smuzhiyun    parser_deploy.add_argument('-s', '--show-status', help='Show progress/status output', action='store_true')
333*4882a593Smuzhiyun    parser_deploy.add_argument('-n', '--dry-run', help='List files to be deployed only', action='store_true')
334*4882a593Smuzhiyun    parser_deploy.add_argument('-p', '--no-preserve', help='Do not preserve existing files', action='store_true')
335*4882a593Smuzhiyun    parser_deploy.add_argument('--no-check-space', help='Do not check for available space before deploying', action='store_true')
336*4882a593Smuzhiyun    parser_deploy.add_argument('-e', '--ssh-exec', help='Executable to use in place of ssh')
337*4882a593Smuzhiyun    parser_deploy.add_argument('-P', '--port', help='Specify port to use for connection to the target')
338*4882a593Smuzhiyun    parser_deploy.add_argument('-I', '--key',
339*4882a593Smuzhiyun                               help='Specify ssh private key for connection to the target')
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun    strip_opts = parser_deploy.add_mutually_exclusive_group(required=False)
342*4882a593Smuzhiyun    strip_opts.add_argument('-S', '--strip',
343*4882a593Smuzhiyun                               help='Strip executables prior to deploying (default: %(default)s). '
344*4882a593Smuzhiyun                                    'The default value of this option can be controlled by setting the strip option in the [Deploy] section to True or False.',
345*4882a593Smuzhiyun                               default=oe.types.boolean(context.config.get('Deploy', 'strip', default='0')),
346*4882a593Smuzhiyun                               action='store_true')
347*4882a593Smuzhiyun    strip_opts.add_argument('--no-strip', help='Do not strip executables prior to deploy', dest='strip', action='store_false')
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun    parser_deploy.set_defaults(func=deploy)
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun    parser_undeploy = subparsers.add_parser('undeploy-target',
352*4882a593Smuzhiyun                                            help='Undeploy recipe output files in live target machine',
353*4882a593Smuzhiyun                                            description='Un-deploys recipe output files previously deployed to a live target machine by devtool deploy-target.',
354*4882a593Smuzhiyun                                            group='testbuild')
355*4882a593Smuzhiyun    parser_undeploy.add_argument('recipename', help='Recipe to undeploy (if not using -a/--all)', nargs='?')
356*4882a593Smuzhiyun    parser_undeploy.add_argument('target', help='Live target machine running an ssh server: user@hostname')
357*4882a593Smuzhiyun    parser_undeploy.add_argument('-c', '--no-host-check', help='Disable ssh host key checking', action='store_true')
358*4882a593Smuzhiyun    parser_undeploy.add_argument('-s', '--show-status', help='Show progress/status output', action='store_true')
359*4882a593Smuzhiyun    parser_undeploy.add_argument('-a', '--all', help='Undeploy all recipes deployed on the target', action='store_true')
360*4882a593Smuzhiyun    parser_undeploy.add_argument('-n', '--dry-run', help='List files to be undeployed only', action='store_true')
361*4882a593Smuzhiyun    parser_undeploy.add_argument('-e', '--ssh-exec', help='Executable to use in place of ssh')
362*4882a593Smuzhiyun    parser_undeploy.add_argument('-P', '--port', help='Specify port to use for connection to the target')
363*4882a593Smuzhiyun    parser_undeploy.add_argument('-I', '--key',
364*4882a593Smuzhiyun                               help='Specify ssh private key for connection to the target')
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun    parser_undeploy.set_defaults(func=undeploy)
367