[lxc-devel] [lxd/master] client: fix image copy
albertodonato on Github
lxc-bot at linuxcontainers.org
Tue Aug 1 09:12:14 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170801/3260f301/attachment.bin>
-------------- next part --------------
From d738dafc2d754eac19f50bc7cdd562fa9719659c Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Mon, 31 Jul 2017 17:15:45 +0200
Subject: [PATCH] client: fix image copy
Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
lxc/image.go | 37 +++++++++++++++++++------------------
test/suites/remote.sh | 5 ++---
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/lxc/image.go b/lxc/image.go
index 8b214375b..21fbb3561 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -359,7 +359,7 @@ func (c *imageCmd) run(conf *config.Config, args []string) error {
return c.doImageAlias(conf, args)
case "copy":
- /* copy [<remote>:]<image> [<rmeote>:]<image> */
+ /* copy [<remote>:]<image> [<remote>:]<image> */
if len(args) != 3 {
return errArgs
}
@@ -388,26 +388,27 @@ func (c *imageCmd) run(conf *config.Config, args []string) error {
return err
}
+ // Check if an alias
+ fingerprint := c.dereferenceAlias(d, inName)
+
// Attempt to resolve an image alias
var imgInfo *api.Image
- image := inName
- if c.copyAliases {
- alias, _, err := d.GetImageAlias(image)
- if err == nil {
- image = alias.Target
- }
-
- // Get the image info
- imgInfo, _, err = d.GetImage(image)
- if err != nil {
- return err
- }
- } else {
- // Don't fetch full image info if we don't need aliases (since it's
- // an expensive operation)
+ if conf.Remotes[remote].Protocol == "simplestreams" {
imgInfo = &api.Image{}
- imgInfo.Fingerprint = image
+ imgInfo.Fingerprint = fingerprint
imgInfo.Public = true
+ } else {
+ if c.copyAliases {
+ // Get the image info
+ imgInfo, _, err = d.GetImage(fingerprint)
+ if err != nil {
+ return err
+ }
+
+ } else {
+ imgInfo = &api.Image{}
+ imgInfo.Fingerprint = fingerprint
+ }
}
if imgInfo.Public && imgInfo.Fingerprint != inName && !strings.HasPrefix(imgInfo.Fingerprint, inName) {
@@ -454,7 +455,7 @@ func (c *imageCmd) run(conf *config.Config, args []string) error {
aliases = append(aliases, alias)
}
}
- err = ensureImageAliases(dest, aliases, image)
+ err = ensureImageAliases(dest, aliases, fingerprint)
return err
case "delete":
diff --git a/test/suites/remote.sh b/test/suites/remote.sh
index 79a168a52..301de89a5 100644
--- a/test/suites/remote.sh
+++ b/test/suites/remote.sh
@@ -147,9 +147,8 @@ test_remote_usage() {
mv "${LXD_CONF}/client.crt" "${LXD_CONF}/client.crt.bak"
mv "${LXD_CONF}/client.key" "${LXD_CONF}/client.key.bak"
- # testimage should still exist on the local server. Count the number of
- # matches so the output isn't polluted with the results.
- lxc_remote image list local: | grep -c testimage
+ # testimage should still exist on the local server.
+ lxc_remote image list local: | grep -q testimage
# Skip the truly remote servers in offline mode. There should always be
# Ubuntu images in the results for the remote servers.
More information about the lxc-devel
mailing list