[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Thu Apr 27 15:48:45 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/20170427/cf0e6edd/attachment.bin>
-------------- next part --------------
From b6070ce3dd6670f62739b8768c8d9f97b33599de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 27 Apr 2017 11:44:22 -0400
Subject: [PATCH 1/3] tests: Remove invalid test for Jenkins
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Jenkins does set LXD_BACKEND

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

diff --git a/test/main.sh b/test/main.sh
index 90125a7..8738ec3 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -54,16 +54,9 @@ for backend_sh in backends/*.sh; do
   . "${backend_sh}"
 done
 
+# Set default backend to dir
 if [ -z "${LXD_BACKEND:-}" ]; then
-
-    # XXX The Jenkins lxd-github-pull-test job sets "backend" as environment
-    #     variable as opposed to LXD_BACKEND, so we want to honor that. This
-    #     should probably be fixed in the Jenkins configuration.
-    if [ -n "${JENKINS_URL:-}" ] && [ -n "${backend:-}" ]; then
-	LXD_BACKEND="${backend}"
-    else
-	LXD_BACKEND=dir
-    fi
+    LXD_BACKEND=dir
 fi
 
 echo "==> Using storage backend ${LXD_BACKEND}"

From 4491abae06751fcdbdfd5ffa84f9d373b5b77410 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 26 Apr 2017 20:44:08 -0400
Subject: [PATCH 2/3] client: Allow passing custom headers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is required for custom image uploads.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 client/lxd.go                 | 25 ++++++++++++++++++-------
 client/lxd_certificates.go    |  6 +++---
 client/lxd_containers.go      |  4 ++--
 client/lxd_images.go          | 10 +++++-----
 client/lxd_networks.go        |  8 ++++----
 client/lxd_operations.go      |  2 +-
 client/lxd_profiles.go        |  8 ++++----
 client/lxd_server.go          |  2 +-
 client/lxd_storage_pools.go   |  6 +++---
 client/lxd_storage_volumes.go |  6 +++---
 10 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/client/lxd.go b/client/lxd.go
index 8b2f01a..dff7db6 100644
--- a/client/lxd.go
+++ b/client/lxd.go
@@ -34,7 +34,7 @@ func (r *ProtocolLXD) RawQuery(method string, path string, data interface{}, ETa
 	// Generate the URL
 	url := fmt.Sprintf("%s%s", r.httpHost, path)
 
-	return r.rawQuery(method, url, data, ETag)
+	return r.rawQuery(method, url, data, ETag, nil)
 }
 
 // RawWebsocket allows directly connection to LXD API websockets
@@ -48,7 +48,7 @@ func (r *ProtocolLXD) RawWebsocket(path string) (*websocket.Conn, error) {
 }
 
 // Internal functions
-func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag string) (*api.Response, string, error) {
+func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag string, headers map[string]string) (*api.Response, string, error) {
 	var req *http.Request
 	var err error
 
@@ -99,6 +99,13 @@ func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag
 		req.Header.Set("If-Match", ETag)
 	}
 
+	// Set the custom headers
+	if headers != nil {
+		for k, v := range headers {
+			req.Header.Set(k, v)
+		}
+	}
+
 	// Send the request
 	resp, err := r.http.Do(req)
 	if err != nil {
@@ -131,15 +138,15 @@ func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag
 	return &response, etag, nil
 }
 
-func (r *ProtocolLXD) query(method string, path string, data interface{}, ETag string) (*api.Response, string, error) {
+func (r *ProtocolLXD) query(method string, path string, data interface{}, ETag string, headers map[string]string) (*api.Response, string, error) {
 	// Generate the URL
 	url := fmt.Sprintf("%s/1.0%s", r.httpHost, path)
 
-	return r.rawQuery(method, url, data, ETag)
+	return r.rawQuery(method, url, data, ETag, headers)
 }
 
 func (r *ProtocolLXD) queryStruct(method string, path string, data interface{}, ETag string, target interface{}) (string, error) {
-	resp, etag, err := r.query(method, path, data, ETag)
+	resp, etag, err := r.query(method, path, data, ETag, nil)
 	if err != nil {
 		return "", err
 	}
@@ -156,9 +163,9 @@ func (r *ProtocolLXD) queryStruct(method string, path string, data interface{},
 	return etag, nil
 }
 
-func (r *ProtocolLXD) queryOperation(method string, path string, data interface{}, ETag string) (*Operation, string, error) {
+func (r *ProtocolLXD) queryOperationHeaders(method string, path string, data interface{}, ETag string, headers map[string]string) (*Operation, string, error) {
 	// Send the query
-	resp, etag, err := r.query(method, path, data, ETag)
+	resp, etag, err := r.query(method, path, data, ETag, headers)
 	if err != nil {
 		return nil, "", err
 	}
@@ -183,6 +190,10 @@ func (r *ProtocolLXD) queryOperation(method string, path string, data interface{
 	return &op, etag, nil
 }
 
+func (r *ProtocolLXD) queryOperation(method string, path string, data interface{}, ETag string) (*Operation, string, error) {
+	return r.queryOperationHeaders(method, path, data, ETag, nil)
+}
+
 func (r *ProtocolLXD) rawWebsocket(url string) (*websocket.Conn, error) {
 	// Grab the http transport handler
 	httpTransport := r.http.Transport.(*http.Transport)
diff --git a/client/lxd_certificates.go b/client/lxd_certificates.go
index bf53495..81a5e47 100644
--- a/client/lxd_certificates.go
+++ b/client/lxd_certificates.go
@@ -58,7 +58,7 @@ func (r *ProtocolLXD) GetCertificate(fingerprint string) (*api.Certificate, stri
 // CreateCertificate adds a new certificate to the LXD trust store
 func (r *ProtocolLXD) CreateCertificate(certificate api.CertificatesPost) error {
 	// Send the request
-	_, _, err := r.query("POST", "/certificates", certificate, "")
+	_, _, err := r.query("POST", "/certificates", certificate, "", nil)
 	if err != nil {
 		return err
 	}
@@ -73,7 +73,7 @@ func (r *ProtocolLXD) UpdateCertificate(fingerprint string, certificate api.Cert
 	}
 
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/certificates/%s", fingerprint), certificate, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/certificates/%s", fingerprint), certificate, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -84,7 +84,7 @@ func (r *ProtocolLXD) UpdateCertificate(fingerprint string, certificate api.Cert
 // DeleteCertificate removes a certificate from the LXD trust store
 func (r *ProtocolLXD) DeleteCertificate(fingerprint string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/certificates/%s", fingerprint), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/certificates/%s", fingerprint), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_containers.go b/client/lxd_containers.go
index fb7e9fc..3789a56 100644
--- a/client/lxd_containers.go
+++ b/client/lxd_containers.go
@@ -368,7 +368,7 @@ func (r *ProtocolLXD) DeleteContainerFile(containerName string, path string) err
 	}
 
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/files?path=%s", containerName, path), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/files?path=%s", containerName, path), nil, "", nil)
 	if err != nil {
 		return err
 	}
@@ -553,7 +553,7 @@ func (r *ProtocolLXD) GetContainerLogfile(name string, filename string) (io.Read
 // DeleteContainerLogfile deletes the requested logfile
 func (r *ProtocolLXD) DeleteContainerLogfile(name string, filename string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/logs/%s", name, filename), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/logs/%s", name, filename), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_images.go b/client/lxd_images.go
index 6eb96db..4a7124f 100644
--- a/client/lxd_images.go
+++ b/client/lxd_images.go
@@ -314,7 +314,7 @@ func (r *ProtocolLXD) CopyImage(image api.Image, target ContainerServer, args *I
 // UpdateImage updates the image definition
 func (r *ProtocolLXD) UpdateImage(fingerprint string, image api.ImagePut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/images/%s", fingerprint), image, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/images/%s", fingerprint), image, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -347,7 +347,7 @@ func (r *ProtocolLXD) CreateImageSecret(fingerprint string) (*Operation, error)
 // CreateImageAlias sets up a new image alias
 func (r *ProtocolLXD) CreateImageAlias(alias api.ImageAliasesPost) error {
 	// Send the request
-	_, _, err := r.query("POST", "/images/aliases", alias, "")
+	_, _, err := r.query("POST", "/images/aliases", alias, "", nil)
 	if err != nil {
 		return err
 	}
@@ -358,7 +358,7 @@ func (r *ProtocolLXD) CreateImageAlias(alias api.ImageAliasesPost) error {
 // UpdateImageAlias updates the image alias definition
 func (r *ProtocolLXD) UpdateImageAlias(name string, alias api.ImageAliasesEntryPut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/images/aliases/%s", name), alias, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/images/aliases/%s", name), alias, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -369,7 +369,7 @@ func (r *ProtocolLXD) UpdateImageAlias(name string, alias api.ImageAliasesEntryP
 // RenameImageAlias renames an existing image alias
 func (r *ProtocolLXD) RenameImageAlias(name string, alias api.ImageAliasesEntryPost) error {
 	// Send the request
-	_, _, err := r.query("POST", fmt.Sprintf("/images/aliases/%s", name), alias, "")
+	_, _, err := r.query("POST", fmt.Sprintf("/images/aliases/%s", name), alias, "", nil)
 	if err != nil {
 		return err
 	}
@@ -380,7 +380,7 @@ func (r *ProtocolLXD) RenameImageAlias(name string, alias api.ImageAliasesEntryP
 // DeleteImageAlias removes an alias from the LXD image store
 func (r *ProtocolLXD) DeleteImageAlias(name string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/images/aliases/%s", name), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/images/aliases/%s", name), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_networks.go b/client/lxd_networks.go
index cbc3fd3..7936b93 100644
--- a/client/lxd_networks.go
+++ b/client/lxd_networks.go
@@ -60,7 +60,7 @@ func (r *ProtocolLXD) CreateNetwork(network api.NetworksPost) error {
 	}
 
 	// Send the request
-	_, _, err := r.query("POST", "/networks", network, "")
+	_, _, err := r.query("POST", "/networks", network, "", nil)
 	if err != nil {
 		return err
 	}
@@ -71,7 +71,7 @@ func (r *ProtocolLXD) CreateNetwork(network api.NetworksPost) error {
 // UpdateNetwork updates the network to match the provided Network struct
 func (r *ProtocolLXD) UpdateNetwork(name string, network api.NetworkPut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/networks/%s", name), network, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/networks/%s", name), network, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -82,7 +82,7 @@ func (r *ProtocolLXD) UpdateNetwork(name string, network api.NetworkPut, ETag st
 // RenameNetwork renames an existing network entry
 func (r *ProtocolLXD) RenameNetwork(name string, network api.NetworkPost) error {
 	// Send the request
-	_, _, err := r.query("POST", fmt.Sprintf("/networks/%s", name), network, "")
+	_, _, err := r.query("POST", fmt.Sprintf("/networks/%s", name), network, "", nil)
 	if err != nil {
 		return err
 	}
@@ -93,7 +93,7 @@ func (r *ProtocolLXD) RenameNetwork(name string, network api.NetworkPost) error
 // DeleteNetwork deletes an existing network
 func (r *ProtocolLXD) DeleteNetwork(name string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/networks/%s", name), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/networks/%s", name), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_operations.go b/client/lxd_operations.go
index fe39c02..8f9922e 100644
--- a/client/lxd_operations.go
+++ b/client/lxd_operations.go
@@ -34,7 +34,7 @@ func (r *ProtocolLXD) GetOperationWebsocket(uuid string, secret string) (*websoc
 // DeleteOperation deletes (cancels) a running operation
 func (r *ProtocolLXD) DeleteOperation(uuid string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/operations/%s", uuid), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/operations/%s", uuid), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_profiles.go b/client/lxd_profiles.go
index a11f4cb..f4b68ed 100644
--- a/client/lxd_profiles.go
+++ b/client/lxd_profiles.go
@@ -58,7 +58,7 @@ func (r *ProtocolLXD) GetProfile(name string) (*api.Profile, string, error) {
 // CreateProfile defines a new container profile
 func (r *ProtocolLXD) CreateProfile(profile api.ProfilesPost) error {
 	// Send the request
-	_, _, err := r.query("POST", "/profiles", profile, "")
+	_, _, err := r.query("POST", "/profiles", profile, "", nil)
 	if err != nil {
 		return err
 	}
@@ -69,7 +69,7 @@ func (r *ProtocolLXD) CreateProfile(profile api.ProfilesPost) error {
 // UpdateProfile updates the profile to match the provided Profile struct
 func (r *ProtocolLXD) UpdateProfile(name string, profile api.ProfilePut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/profiles/%s", name), profile, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/profiles/%s", name), profile, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -80,7 +80,7 @@ func (r *ProtocolLXD) UpdateProfile(name string, profile api.ProfilePut, ETag st
 // RenameProfile renames an existing profile entry
 func (r *ProtocolLXD) RenameProfile(name string, profile api.ProfilePost) error {
 	// Send the request
-	_, _, err := r.query("POST", fmt.Sprintf("/profiles/%s", name), profile, "")
+	_, _, err := r.query("POST", fmt.Sprintf("/profiles/%s", name), profile, "", nil)
 	if err != nil {
 		return err
 	}
@@ -91,7 +91,7 @@ func (r *ProtocolLXD) RenameProfile(name string, profile api.ProfilePost) error
 // DeleteProfile deletes a profile
 func (r *ProtocolLXD) DeleteProfile(name string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/profiles/%s", name), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/profiles/%s", name), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_server.go b/client/lxd_server.go
index fbae67f..c60a755 100644
--- a/client/lxd_server.go
+++ b/client/lxd_server.go
@@ -30,7 +30,7 @@ func (r *ProtocolLXD) GetServer() (*api.Server, string, error) {
 // UpdateServer updates the server status to match the provided Server struct
 func (r *ProtocolLXD) UpdateServer(server api.ServerPut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", "", server, ETag)
+	_, _, err := r.query("PUT", "", server, ETag, nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_storage_pools.go b/client/lxd_storage_pools.go
index fb49058..a8896bc 100644
--- a/client/lxd_storage_pools.go
+++ b/client/lxd_storage_pools.go
@@ -66,7 +66,7 @@ func (r *ProtocolLXD) CreateStoragePool(pool api.StoragePoolsPost) error {
 	}
 
 	// Send the request
-	_, _, err := r.query("POST", "/storage-pools", pool, "")
+	_, _, err := r.query("POST", "/storage-pools", pool, "", nil)
 	if err != nil {
 		return err
 	}
@@ -77,7 +77,7 @@ func (r *ProtocolLXD) CreateStoragePool(pool api.StoragePoolsPost) error {
 // UpdateStoragePool updates the pool to match the provided StoragePool struct
 func (r *ProtocolLXD) UpdateStoragePool(name string, pool api.StoragePoolPut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/storage-pools/%s", name), pool, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/storage-pools/%s", name), pool, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -88,7 +88,7 @@ func (r *ProtocolLXD) UpdateStoragePool(name string, pool api.StoragePoolPut, ET
 // DeleteStoragePool deletes a storage pool
 func (r *ProtocolLXD) DeleteStoragePool(name string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/storage-pools/%s", name), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/storage-pools/%s", name), nil, "", nil)
 	if err != nil {
 		return err
 	}
diff --git a/client/lxd_storage_volumes.go b/client/lxd_storage_volumes.go
index 980b9c3..9afa1a7 100644
--- a/client/lxd_storage_volumes.go
+++ b/client/lxd_storage_volumes.go
@@ -62,7 +62,7 @@ func (r *ProtocolLXD) GetStoragePoolVolume(pool string, name string) (*api.Stora
 // CreateStoragePoolVolume defines a new storage volume
 func (r *ProtocolLXD) CreateStoragePoolVolume(pool string, volume api.StorageVolumesPost) error {
 	// Send the request
-	_, _, err := r.query("POST", fmt.Sprintf("/storage-pools/%s/volumes", pool), volume, "")
+	_, _, err := r.query("POST", fmt.Sprintf("/storage-pools/%s/volumes", pool), volume, "", nil)
 	if err != nil {
 		return err
 	}
@@ -73,7 +73,7 @@ func (r *ProtocolLXD) CreateStoragePoolVolume(pool string, volume api.StorageVol
 // UpdateStoragePoolVolume updates the volume to match the provided StoragePoolVolume struct
 func (r *ProtocolLXD) UpdateStoragePoolVolume(pool string, name string, volume api.StorageVolumePut, ETag string) error {
 	// Send the request
-	_, _, err := r.query("PUT", fmt.Sprintf("/storage-pools/%s/volumes/%s", pool, name), volume, ETag)
+	_, _, err := r.query("PUT", fmt.Sprintf("/storage-pools/%s/volumes/%s", pool, name), volume, ETag, nil)
 	if err != nil {
 		return err
 	}
@@ -84,7 +84,7 @@ func (r *ProtocolLXD) UpdateStoragePoolVolume(pool string, name string, volume a
 // DeleteStoragePoolVolume deletes a storage pool
 func (r *ProtocolLXD) DeleteStoragePoolVolume(pool string, name string) error {
 	// Send the request
-	_, _, err := r.query("DELETE", fmt.Sprintf("/storage-pools/%s/volumes/%s", pool, name), nil, "")
+	_, _, err := r.query("DELETE", fmt.Sprintf("/storage-pools/%s/volumes/%s", pool, name), nil, "", nil)
 	if err != nil {
 		return err
 	}

From f0c8a56cbdc1507193f96096a59ff4c06552764a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 26 Apr 2017 20:45:06 -0400
Subject: [PATCH 3/3] lxc: Implement progress tracking for operations
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>
---
 lxc/utils.go | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lxc/utils.go b/lxc/utils.go
index 0611f9b..e9c0187 100644
--- a/lxc/utils.go
+++ b/lxc/utils.go
@@ -4,6 +4,8 @@ import (
 	"fmt"
 	"strings"
 
+	"github.com/lxc/lxd/client"
+	"github.com/lxc/lxd/shared/api"
 	"github.com/lxc/lxd/shared/i18n"
 )
 
@@ -46,6 +48,24 @@ func (p *ProgressRenderer) Update(status string) {
 	fmt.Print(msg)
 }
 
+func (p *ProgressRenderer) UpdateProgress(progress lxd.ProgressData) {
+	p.Update(progress.Text)
+}
+
+func (p *ProgressRenderer) UpdateOp(op api.Operation) {
+	if op.Metadata == nil {
+		return
+	}
+
+	for _, key := range []string{"fs_progress", "download_progress"} {
+		value, ok := op.Metadata[key]
+		if ok {
+			p.Update(value.(string))
+			break
+		}
+	}
+}
+
 // Image fingerprint and alias sorting
 type SortImage [][]string
 


More information about the lxc-devel mailing list