[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Fri Mar 24 19:43:52 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/20170324/f7be0e6e/attachment.bin>
-------------- next part --------------
From 3210ab9b3bef4f8efa26a39b58682382bf1b6f75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 24 Mar 2017 02:53:05 -0400
Subject: [PATCH 1/2] api: Properly define the image creation source
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/images.go       | 24 ++++++++++++------------
 shared/api/image.go | 20 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index f869e96..98d7782 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -224,8 +224,8 @@ type imageMetadata struct {
 func imgPostContInfo(d *Daemon, r *http.Request, req api.ImagesPost, builddir string) (*api.Image, error) {
 	info := api.Image{}
 	info.Properties = map[string]string{}
-	name := req.Source["name"]
-	ctype := req.Source["type"]
+	name := req.Source.Name
+	ctype := req.Source.Type
 	if ctype == "" || name == "" {
 		return nil, fmt.Errorf("No source provided")
 	}
@@ -330,15 +330,15 @@ func imgPostRemoteInfo(d *Daemon, req api.ImagesPost, op *operation) (*api.Image
 	var err error
 	var hash string
 
-	if req.Source["fingerprint"] != "" {
-		hash = req.Source["fingerprint"]
-	} else if req.Source["alias"] != "" {
-		hash = req.Source["alias"]
+	if req.Source.Fingerprint != "" {
+		hash = req.Source.Fingerprint
+	} else if req.Source.Alias != "" {
+		hash = req.Source.Alias
 	} else {
 		return nil, fmt.Errorf("must specify one of alias or fingerprint for init from image")
 	}
 
-	hash, err = d.ImageDownload(op, req.Source["server"], req.Source["protocol"], req.Source["certificate"], req.Source["secret"], hash, false, req.AutoUpdate, "")
+	hash, err = d.ImageDownload(op, req.Source.Server, req.Source.Protocol, req.Source.Certificate, req.Source.Secret, hash, false, req.AutoUpdate, "")
 	if err != nil {
 		return nil, err
 	}
@@ -367,7 +367,7 @@ func imgPostRemoteInfo(d *Daemon, req api.ImagesPost, op *operation) (*api.Image
 func imgPostURLInfo(d *Daemon, req api.ImagesPost, op *operation) (*api.Image, error) {
 	var err error
 
-	if req.Source["url"] == "" {
+	if req.Source.URL == "" {
 		return nil, fmt.Errorf("Missing URL")
 	}
 
@@ -377,7 +377,7 @@ func imgPostURLInfo(d *Daemon, req api.ImagesPost, op *operation) (*api.Image, e
 	}
 
 	// Resolve the image URL
-	head, err := http.NewRequest("HEAD", req.Source["url"], nil)
+	head, err := http.NewRequest("HEAD", req.Source.URL, nil)
 	if err != nil {
 		return nil, err
 	}
@@ -699,7 +699,7 @@ func imagesPost(d *Daemon, r *http.Request) Response {
 		imageUpload = true
 	}
 
-	if !imageUpload && !shared.StringInSlice(req.Source["type"], []string{"container", "snapshot", "image", "url"}) {
+	if !imageUpload && !shared.StringInSlice(req.Source.Type, []string{"container", "snapshot", "image", "url"}) {
 		cleanup(builddir, post)
 		return InternalError(fmt.Errorf("Invalid images JSON"))
 	}
@@ -712,13 +712,13 @@ func imagesPost(d *Daemon, r *http.Request) Response {
 		defer cleanup(builddir, post)
 
 		if !imageUpload {
-			if req.Source["type"] == "image" {
+			if req.Source.Type == "image" {
 				/* Processing image copy from remote */
 				info, err = imgPostRemoteInfo(d, req, op)
 				if err != nil {
 					return err
 				}
-			} else if req.Source["type"] == "url" {
+			} else if req.Source.Type == "url" {
 				/* Processing image copy from URL */
 				info, err = imgPostURLInfo(d, req, op)
 				if err != nil {
diff --git a/shared/api/image.go b/shared/api/image.go
index 789e887..814c098 100644
--- a/shared/api/image.go
+++ b/shared/api/image.go
@@ -9,7 +9,7 @@ type ImagesPost struct {
 	ImagePut `yaml:",inline"`
 
 	Filename string            `json:"filename" yaml:"filename"`
-	Source   map[string]string `json:"source" yaml:"source"`
+	Source   *ImagesPostSource `json:"source" yaml:"source"`
 
 	// API extension: image_compression_algorithm
 	CompressionAlgorithm string `json:"compression_algorithm" yaml:"compression_algorithm"`
@@ -18,6 +18,24 @@ type ImagesPost struct {
 	Aliases []ImageAlias `json:"aliases" yaml:"aliases"`
 }
 
+// ImagesPostSource represents the source of a new LXD image
+type ImagesPostSource struct {
+	ImageSource `yaml:",inline"`
+
+	Mode string `json:"mode" yaml:"mode"`
+	Type string `json:"type" yaml:"type"`
+
+	// For protocol "direct"
+	URL string `json:"url" yaml:"url"`
+
+	// For type "container"
+	Name string `json:"name" yaml:"name"`
+
+	// For type "image"
+	Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
+	Secret      string `json:"secret" yaml:"secret"`
+}
+
 // ImagePut represents the modifiable fields of a LXD image
 type ImagePut struct {
 	AutoUpdate bool              `json:"auto_update" yaml:"auto_update"`

From a21654acb20fe37060a2d1179457358ca0128ae7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 24 Mar 2017 15:41:29 -0400
Subject: [PATCH 2/2] tests: Record how long the tests take
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 test/main.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/test/main.sh b/test/main.sh
index 9a705b2..63564a0 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -534,8 +534,11 @@ run_test() {
   TEST_CURRENT_DESCRIPTION=${2:-${1}}
 
   echo "==> TEST BEGIN: ${TEST_CURRENT_DESCRIPTION}"
+  START_TIME=$(date +%s)
   ${TEST_CURRENT}
-  echo "==> TEST DONE: ${TEST_CURRENT_DESCRIPTION}"
+  END_TIME=$(date +%s)
+
+  echo "==> TEST DONE: ${TEST_CURRENT_DESCRIPTION} ($((END_TIME-START_TIME))s)"
 }
 
 # allow for running a specific set of tests


More information about the lxc-devel mailing list