All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] devtool: Add IPv6 deploy targets targets
@ 2020-04-28 13:52 breno.debian
  2020-05-21 12:28 ` breno.debian
  0 siblings, 1 reply; 5+ messages in thread
From: breno.debian @ 2020-04-28 13:52 UTC (permalink / raw)
  To: poky

From: Breno Leitao <leit@fb.com>

Unfortunately devtool is not able to deploy (and undeploy) into IPv6
hosts.

This patch simply adds a way to use IPv6 target address similarly to
ssh/scp, as foo@[xxxx:yyyy::zzzz]:/destdir.

In order to do it, I've created a function that parses the hostname,
user and destdir, and then create a target_ssh (for ssh like parameter
 -- foo@xxx:yyyy::zzz) and target_scp for scp paramers as
 -- foo@[xxxx:yyyy::zzz]:/destdir. The urlparsing is done by urlparse
module and ip version discovery is done by ipaddress module.

This is the tests I have been using to validate my patch

IPV4_FORMATS="
      root@11.11.11.2:/tmp
      root@11.11.11.2
      11.11.11.2:/tmp
      11.11.11.2
      "

IPV6_FORMATS="
      root@[2620:10d:c0bb:403:dac4:97ff:feda:3325]:/tmp
      root@[2620:10d:c0bb:403:dac4:97ff:feda:3325]
      [2620:10d:c0bb:403:dac4:97ff:feda:3325]:/tmp
      [2620:10d:c0bb:403:dac4:97ff:feda:3325]
      "

HOSTNAMES="
      root@foo.bar:/tmp
      root@foo.bar
      foo.bar:/tmp
      foo.bar
      "

for I in $IPV6_FORMATS
do
  devtool deploy-target -6 -s mypkg ${I}
  devtool undeploy-target -6 -s mypkg ${I}
done

for I in $HOSTNAMES
do
  devtool deploy-target -s mypkg ${I}
  devtool undeploy-target -s mypkg ${I}
done

for I in $IPV4_FORMATS
do
  devtool deploy-target -s mypkg ${I}
  devtool undeploy-target -s mypkg ${I}
done
---
 scripts/lib/devtool/deploy.py | 61 +++++++++++++++++++++++++++--------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
index 6a997735fc..1580256e2a 100644
--- a/scripts/lib/devtool/deploy.py
+++ b/scripts/lib/devtool/deploy.py
@@ -11,6 +11,8 @@ import os
 import shutil
 import subprocess
 import tempfile
+import urllib
+import ipaddress
 
 import bb.utils
 import argparse_oe
@@ -134,6 +136,18 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals
     return '\n'.join(lines)
 
 
+def parse_ip(args):
+    t = urllib.parse.urlparse("ssh://" + args.target)
+
+    try:
+        ip = ipaddress.ip_address(t.hostname)
+        version = ip.version
+    except ValueError:
+        # hostname instead of ip return version  0
+        version = None;
+
+    return t.username, t.hostname, t.path, version
+
 
 def deploy(args, config, basepath, workspace):
     """Entry point for the devtool 'deploy' subcommand"""
@@ -143,14 +157,7 @@ def deploy(args, config, basepath, workspace):
 
     check_workspace_recipe(workspace, args.recipename, checksrc=False)
 
-    try:
-        host, destdir = args.target.split(':')
-    except ValueError:
-        destdir = '/'
-    else:
-        args.target = host
-    if not destdir.endswith('/'):
-        destdir += '/'
+    user, host, destdir, ipversion = parse_ip(args)
 
     tinfoil = setup_tinfoil(basepath=basepath)
     try:
@@ -235,16 +242,30 @@ def deploy(args, config, basepath, workspace):
                 f.write('%d\n' % ftotalsize)
                 for fpath, fsize in filelist:
                     f.write('%s %d\n' % (fpath, fsize))
+
+            # Need to generate target as a scp format
+            if ipversion == 6:
+                target_scp = "[%s]:%s" % (host, os.path.dirname(tmpscript))
+            else:
+                target_scp = "%s:%s" % (host, os.path.dirname(tmpscript))
+            if user:
+                target_scp = "%s@%s" % (user, target_scp)
+
             # Copy them to the target
-            ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
+            ret = subprocess.call("scp %s %s %s %s/* %s" % (scp_sshexec, scp_port, extraoptions, tmpdir, target_scp), shell=True)
             if ret != 0:
                 raise DevtoolError('Failed to copy script to %s - rerun with -s to '
                                 'get a complete error message' % args.target)
         finally:
             shutil.rmtree(tmpdir)
 
+        if user:
+            target_ssh = "%s@%s" % (user, host)
+        else:
+            target_ssh = host
+
         # Now run the script
-        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)
+        ret = exec_fakeroot(rd, 'tar cf - . | %s  %s %s %s \'sh %s %s %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, target_ssh, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True)
         if ret != 0:
             raise DevtoolError('Deploy failed - rerun with -s to get a complete '
                             'error message')
@@ -268,6 +289,8 @@ def undeploy(args, config, basepath, workspace):
     elif not args.recipename and not args.all:
         raise argparse_oe.ArgumentUsageError('If you don\'t specify a recipe, you must specify -a/--all', 'undeploy-target')
 
+    user, host, destdir, ipversion = parse_ip(args)
+
     extraoptions = ''
     if args.no_host_check:
         extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
@@ -285,8 +308,6 @@ def undeploy(args, config, basepath, workspace):
         scp_port = "-P %s" % args.port
         ssh_port = "-p %s" % args.port
 
-    args.target = args.target.split(':')[0]
-
     tmpdir = tempfile.mkdtemp(prefix='devtool')
     try:
         tmpscript = '/tmp/devtool_undeploy.sh'
@@ -294,16 +315,28 @@ def undeploy(args, config, basepath, workspace):
         # Write out the script to a file
         with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
             f.write(shellscript)
+
+        # Format for scp
+        if ipversion == 6:
+            target_scp = "[%s]:%s" % (host, os.path.dirname(tmpscript))
+        else:
+            target_scp = "%s:%s" % (host, os.path.dirname(tmpscript))
+        if user:
+            target_scp = "%s@%s" % (user, target_scp)
+
         # Copy it to the target
-        ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
+        ret = subprocess.call("scp %s %s %s %s/* %s" % (scp_sshexec, scp_port, extraoptions, tmpdir, target_scp), shell=True)
         if ret != 0:
             raise DevtoolError('Failed to copy script to %s - rerun with -s to '
                                 'get a complete error message' % args.target)
     finally:
         shutil.rmtree(tmpdir)
 
+    target_ssh = host
+    if user:
+        target_ssh = "%s@%s" % (user, target_ssh)
     # Now run the script
-    ret = subprocess.call('%s %s %s %s \'sh %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename), shell=True)
+    ret = subprocess.call('%s %s %s %s \'sh %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, target_ssh, tmpscript, args.recipename), shell=True)
     if ret != 0:
         raise DevtoolError('Undeploy failed - rerun with -s to get a complete '
                            'error message')
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] devtool: Add IPv6 deploy targets targets
  2020-04-28 13:52 [PATCH] devtool: Add IPv6 deploy targets targets breno.debian
@ 2020-05-21 12:28 ` breno.debian
  2020-05-21 13:14   ` [poky] " Richard Purdie
  0 siblings, 1 reply; 5+ messages in thread
From: breno.debian @ 2020-05-21 12:28 UTC (permalink / raw)
  To: poky

Hello,

I've sent this message 3 weeks ago and I haven't heard any feedback about it.
I am wondering if I have sent it to the right mainling list.

Thanks
Breno


On 28/04/2020 14:52, breno.debian@gmail.com wrote:
> From: Breno Leitao <leit@fb.com>
> 
> Unfortunately devtool is not able to deploy (and undeploy) into IPv6
> hosts.
> 
> This patch simply adds a way to use IPv6 target address similarly to
> ssh/scp, as foo@[xxxx:yyyy::zzzz]:/destdir.
> 
> In order to do it, I've created a function that parses the hostname,
> user and destdir, and then create a target_ssh (for ssh like parameter
>  -- foo@xxx:yyyy::zzz) and target_scp for scp paramers as
>  -- foo@[xxxx:yyyy::zzz]:/destdir. The urlparsing is done by urlparse
> module and ip version discovery is done by ipaddress module.

<snip>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [poky] [PATCH] devtool: Add IPv6 deploy targets targets
  2020-05-21 12:28 ` breno.debian
@ 2020-05-21 13:14   ` Richard Purdie
  2020-06-01  8:18     ` Breno Leitao
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Purdie @ 2020-05-21 13:14 UTC (permalink / raw)
  To: breno.debian, poky

Hi,

On Thu, 2020-05-21 at 13:28 +0100, breno.debian@gmail.com wrote:
> I've sent this message 3 weeks ago and I haven't heard any feedback
> about it.
> I am wondering if I have sent it to the right mainling list.

I'm not sure what happened to it here, I don't remember seeing it and I
can't find a copy of it in my email. It is in the archives.

Patches for oe-core like this one need to go to the openembedded-core
mailing list so this is the wrong list.

(https://lists.openembedded.org/g/openembedded-core/topics)

Other than that the patch looks reasonable at a quick glance so could
you resend it there please?

Cheers,

Richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [poky] [PATCH] devtool: Add IPv6 deploy targets targets
  2020-05-21 13:14   ` [poky] " Richard Purdie
@ 2020-06-01  8:18     ` Breno Leitao
  0 siblings, 0 replies; 5+ messages in thread
From: Breno Leitao @ 2020-06-01  8:18 UTC (permalink / raw)
  To: Richard Purdie, breno.debian, poky

Hi Richard,

On 21/05/2020 14:14, Richard Purdie wrote:
> Hi,
> 
> On Thu, 2020-05-21 at 13:28 +0100, breno.debian@gmail.com wrote:
>> I've sent this message 3 weeks ago and I haven't heard any feedback
>> about it.
>> I am wondering if I have sent it to the right mainling list.
> 
> I'm not sure what happened to it here, I don't remember seeing it and I
> can't find a copy of it in my email. It is in the archives.
> 
> Patches for oe-core like this one need to go to the openembedded-core
> mailing list so this is the wrong list.

Sorry about sending it to the wrong place.
 
> (https://lists.openembedded.org/g/openembedded-core/topics)
> 
> Other than that the patch looks reasonable at a quick glance so could
> you resend it there please?

Sure. I sent it to openembedded-core mailing list now:

https://lists.openembedded.org/g/openembedded-core/message/138771

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] devtool: Add IPv6 deploy targets targets
       [not found] <600e41e7-645c-7806-9580-6db458004a25@debian.org>
@ 2020-05-27  9:51 ` breno.debian
  0 siblings, 0 replies; 5+ messages in thread
From: breno.debian @ 2020-05-27  9:51 UTC (permalink / raw)
  To: openembedded-core

From: Breno Leitao <leit@fb.com>

Unfortunately devtool is not able to deploy (and undeploy) into IPv6
hosts.

This patch simply adds a way to use IPv6 target address similarly to
ssh/scp, as foo@[xxxx:yyyy::zzzz]:/destdir.

In order to do it, I've created a function that parses the hostname,
user and destdir, and then create a target_ssh (for ssh like parameter
 -- foo@xxx:yyyy::zzz) and target_scp for scp paramers as
 -- foo@[xxxx:yyyy::zzz]:/destdir. The urlparsing is done by urlparse
module and ip version discovery is done by ipaddress module.

This is the tests I have been using to validate my patch

IPV4_FORMATS="
      root@11.11.11.2:/tmp
      root@11.11.11.2
      11.11.11.2:/tmp
      11.11.11.2
      "

IPV6_FORMATS="
      root@[2620:10d:c0bb:403:dac4:97ff:feda:3325]:/tmp
      root@[2620:10d:c0bb:403:dac4:97ff:feda:3325]
      [2620:10d:c0bb:403:dac4:97ff:feda:3325]:/tmp
      [2620:10d:c0bb:403:dac4:97ff:feda:3325]
      "

HOSTNAMES="
      root@foo.bar:/tmp
      root@foo.bar
      foo.bar:/tmp
      foo.bar
      "

for I in $IPV6_FORMATS
do
  devtool deploy-target -6 -s mypkg ${I}
  devtool undeploy-target -6 -s mypkg ${I}
done

for I in $HOSTNAMES
do
  devtool deploy-target -s mypkg ${I}
  devtool undeploy-target -s mypkg ${I}
done

for I in $IPV4_FORMATS
do
  devtool deploy-target -s mypkg ${I}
  devtool undeploy-target -s mypkg ${I}
done
---
 scripts/lib/devtool/deploy.py | 61 +++++++++++++++++++++++++++--------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
index 6a997735fc..1580256e2a 100644
--- a/scripts/lib/devtool/deploy.py
+++ b/scripts/lib/devtool/deploy.py
@@ -11,6 +11,8 @@ import os
 import shutil
 import subprocess
 import tempfile
+import urllib
+import ipaddress
 
 import bb.utils
 import argparse_oe
@@ -134,6 +136,18 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals
     return '\n'.join(lines)
 
 
+def parse_ip(args):
+    t = urllib.parse.urlparse("ssh://" + args.target)
+
+    try:
+        ip = ipaddress.ip_address(t.hostname)
+        version = ip.version
+    except ValueError:
+        # hostname instead of ip return version  0
+        version = None;
+
+    return t.username, t.hostname, t.path, version
+
 
 def deploy(args, config, basepath, workspace):
     """Entry point for the devtool 'deploy' subcommand"""
@@ -143,14 +157,7 @@ def deploy(args, config, basepath, workspace):
 
     check_workspace_recipe(workspace, args.recipename, checksrc=False)
 
-    try:
-        host, destdir = args.target.split(':')
-    except ValueError:
-        destdir = '/'
-    else:
-        args.target = host
-    if not destdir.endswith('/'):
-        destdir += '/'
+    user, host, destdir, ipversion = parse_ip(args)
 
     tinfoil = setup_tinfoil(basepath=basepath)
     try:
@@ -235,16 +242,30 @@ def deploy(args, config, basepath, workspace):
                 f.write('%d\n' % ftotalsize)
                 for fpath, fsize in filelist:
                     f.write('%s %d\n' % (fpath, fsize))
+
+            # Need to generate target as a scp format
+            if ipversion == 6:
+                target_scp = "[%s]:%s" % (host, os.path.dirname(tmpscript))
+            else:
+                target_scp = "%s:%s" % (host, os.path.dirname(tmpscript))
+            if user:
+                target_scp = "%s@%s" % (user, target_scp)
+
             # Copy them to the target
-            ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
+            ret = subprocess.call("scp %s %s %s %s/* %s" % (scp_sshexec, scp_port, extraoptions, tmpdir, target_scp), shell=True)
             if ret != 0:
                 raise DevtoolError('Failed to copy script to %s - rerun with -s to '
                                 'get a complete error message' % args.target)
         finally:
             shutil.rmtree(tmpdir)
 
+        if user:
+            target_ssh = "%s@%s" % (user, host)
+        else:
+            target_ssh = host
+
         # Now run the script
-        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)
+        ret = exec_fakeroot(rd, 'tar cf - . | %s  %s %s %s \'sh %s %s %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, target_ssh, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True)
         if ret != 0:
             raise DevtoolError('Deploy failed - rerun with -s to get a complete '
                             'error message')
@@ -268,6 +289,8 @@ def undeploy(args, config, basepath, workspace):
     elif not args.recipename and not args.all:
         raise argparse_oe.ArgumentUsageError('If you don\'t specify a recipe, you must specify -a/--all', 'undeploy-target')
 
+    user, host, destdir, ipversion = parse_ip(args)
+
     extraoptions = ''
     if args.no_host_check:
         extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
@@ -285,8 +308,6 @@ def undeploy(args, config, basepath, workspace):
         scp_port = "-P %s" % args.port
         ssh_port = "-p %s" % args.port
 
-    args.target = args.target.split(':')[0]
-
     tmpdir = tempfile.mkdtemp(prefix='devtool')
     try:
         tmpscript = '/tmp/devtool_undeploy.sh'
@@ -294,16 +315,28 @@ def undeploy(args, config, basepath, workspace):
         # Write out the script to a file
         with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
             f.write(shellscript)
+
+        # Format for scp
+        if ipversion == 6:
+            target_scp = "[%s]:%s" % (host, os.path.dirname(tmpscript))
+        else:
+            target_scp = "%s:%s" % (host, os.path.dirname(tmpscript))
+        if user:
+            target_scp = "%s@%s" % (user, target_scp)
+
         # Copy it to the target
-        ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
+        ret = subprocess.call("scp %s %s %s %s/* %s" % (scp_sshexec, scp_port, extraoptions, tmpdir, target_scp), shell=True)
         if ret != 0:
             raise DevtoolError('Failed to copy script to %s - rerun with -s to '
                                 'get a complete error message' % args.target)
     finally:
         shutil.rmtree(tmpdir)
 
+    target_ssh = host
+    if user:
+        target_ssh = "%s@%s" % (user, target_ssh)
     # Now run the script
-    ret = subprocess.call('%s %s %s %s \'sh %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename), shell=True)
+    ret = subprocess.call('%s %s %s %s \'sh %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, target_ssh, tmpscript, args.recipename), shell=True)
     if ret != 0:
         raise DevtoolError('Undeploy failed - rerun with -s to get a complete '
                            'error message')
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-01  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 13:52 [PATCH] devtool: Add IPv6 deploy targets targets breno.debian
2020-05-21 12:28 ` breno.debian
2020-05-21 13:14   ` [poky] " Richard Purdie
2020-06-01  8:18     ` Breno Leitao
     [not found] <600e41e7-645c-7806-9580-6db458004a25@debian.org>
2020-05-27  9:51 ` breno.debian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.