Add os-volume_upload_image action to volumeactions (#240)
* Add os-volume_upload_image action to volumeactions
* Code updates to align with style guide
diff --git a/openstack/blockstorage/extensions/volumeactions/testing/fixtures.go b/openstack/blockstorage/extensions/volumeactions/testing/fixtures.go
index 4c3c0dd..d914097 100644
--- a/openstack/blockstorage/extensions/volumeactions/testing/fixtures.go
+++ b/openstack/blockstorage/extensions/volumeactions/testing/fixtures.go
@@ -74,6 +74,31 @@
})
}
+func MockUploadImageResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-volume_upload_image": {
+ "container_format": "bare",
+ "force": true,
+ "image_name": "test",
+ "disk_format": "raw"
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
+
func MockReserveResponse(t *testing.T) {
th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
func(w http.ResponseWriter, r *http.Request) {
diff --git a/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go b/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go
index b1f7af7..6132161 100644
--- a/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go
+++ b/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go
@@ -44,6 +44,21 @@
th.AssertNoErr(t, err)
}
+func TestUploadImage(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ MockUploadImageResponse(t)
+ options := &volumeactions.UploadImageOpts{
+ ContainerFormat: "bare",
+ DiskFormat: "raw",
+ ImageName: "test",
+ Force: true,
+ }
+
+ err := volumeactions.UploadImage(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
func TestReserve(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()