github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/volumeactions/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	fake "github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func MockAttachResponse(t *testing.T) {
    13  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
    14  		func(w http.ResponseWriter, r *http.Request) {
    15  			th.TestMethod(t, r, "POST")
    16  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    17  			th.TestHeader(t, r, "Content-Type", "application/json")
    18  			th.TestHeader(t, r, "Accept", "application/json")
    19  			th.TestJSONRequest(t, r, `
    20  {
    21      "os-attach":
    22      {
    23          "mountpoint": "/mnt",
    24          "mode": "rw",
    25          "instance_uuid": "50902f4f-a974-46a0-85e9-7efc5e22dfdd"
    26      }
    27  }
    28            `)
    29  
    30  			w.Header().Add("Content-Type", "application/json")
    31  			w.WriteHeader(http.StatusAccepted)
    32  
    33  			fmt.Fprintf(w, `{}`)
    34  		})
    35  }
    36  
    37  func MockBeginDetachingResponse(t *testing.T) {
    38  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
    39  		func(w http.ResponseWriter, r *http.Request) {
    40  			th.TestMethod(t, r, "POST")
    41  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    42  			th.TestHeader(t, r, "Content-Type", "application/json")
    43  			th.TestHeader(t, r, "Accept", "application/json")
    44  			th.TestJSONRequest(t, r, `
    45  {
    46      "os-begin_detaching": {}
    47  }
    48            `)
    49  
    50  			w.Header().Add("Content-Type", "application/json")
    51  			w.WriteHeader(http.StatusAccepted)
    52  
    53  			fmt.Fprintf(w, `{}`)
    54  		})
    55  }
    56  
    57  func MockDetachResponse(t *testing.T) {
    58  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
    59  		func(w http.ResponseWriter, r *http.Request) {
    60  			th.TestMethod(t, r, "POST")
    61  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    62  			th.TestHeader(t, r, "Content-Type", "application/json")
    63  			th.TestHeader(t, r, "Accept", "application/json")
    64  			th.TestJSONRequest(t, r, `
    65  {
    66      "os-detach": {}
    67  }
    68            `)
    69  
    70  			w.Header().Add("Content-Type", "application/json")
    71  			w.WriteHeader(http.StatusAccepted)
    72  
    73  			fmt.Fprintf(w, `{}`)
    74  		})
    75  }
    76  
    77  func MockUploadImageResponse(t *testing.T) {
    78  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
    79  		func(w http.ResponseWriter, r *http.Request) {
    80  			th.TestMethod(t, r, "POST")
    81  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    82  			th.TestHeader(t, r, "Content-Type", "application/json")
    83  			th.TestHeader(t, r, "Accept", "application/json")
    84  			th.TestJSONRequest(t, r, `
    85  {
    86      "os-volume_upload_image": {
    87          "container_format": "bare",
    88          "force": true,
    89          "image_name": "test",
    90          "disk_format": "raw"
    91      }
    92  }
    93            `)
    94  
    95  			w.Header().Add("Content-Type", "application/json")
    96  			w.WriteHeader(http.StatusAccepted)
    97  
    98  			fmt.Fprintf(w, `
    99  {
   100      "os-volume_upload_image": {
   101          "container_format": "bare",
   102          "display_description": null,
   103          "id": "cd281d77-8217-4830-be95-9528227c105c",
   104          "image_id": "ecb92d98-de08-45db-8235-bbafe317269c",
   105          "image_name": "test",
   106          "disk_format": "raw",
   107          "size": 5,
   108          "status": "uploading",
   109          "updated_at": "2017-07-17T09:29:22.000000",
   110          "volume_type": {
   111              "created_at": "2016-05-04T08:54:14.000000",
   112              "deleted": false,
   113              "deleted_at": null,
   114              "description": null,
   115              "extra_specs": {
   116                  "volume_backend_name": "basic.ru-2a"
   117              },
   118              "id": "b7133444-62f6-4433-8da3-70ac332229b7",
   119              "is_public": true,
   120              "name": "basic.ru-2a",
   121              "updated_at": "2016-05-04T09:15:33.000000"
   122          }
   123      }
   124  }
   125            `)
   126  		})
   127  }
   128  
   129  func MockReserveResponse(t *testing.T) {
   130  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
   131  		func(w http.ResponseWriter, r *http.Request) {
   132  			th.TestMethod(t, r, "POST")
   133  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   134  			th.TestHeader(t, r, "Content-Type", "application/json")
   135  			th.TestHeader(t, r, "Accept", "application/json")
   136  			th.TestJSONRequest(t, r, `
   137  {
   138      "os-reserve": {}
   139  }
   140            `)
   141  
   142  			w.Header().Add("Content-Type", "application/json")
   143  			w.WriteHeader(http.StatusAccepted)
   144  
   145  			fmt.Fprintf(w, `{}`)
   146  		})
   147  }
   148  
   149  func MockUnreserveResponse(t *testing.T) {
   150  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
   151  		func(w http.ResponseWriter, r *http.Request) {
   152  			th.TestMethod(t, r, "POST")
   153  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   154  			th.TestHeader(t, r, "Content-Type", "application/json")
   155  			th.TestHeader(t, r, "Accept", "application/json")
   156  			th.TestJSONRequest(t, r, `
   157  {
   158      "os-unreserve": {}
   159  }
   160            `)
   161  
   162  			w.Header().Add("Content-Type", "application/json")
   163  			w.WriteHeader(http.StatusAccepted)
   164  
   165  			fmt.Fprintf(w, `{}`)
   166  		})
   167  }
   168  
   169  func MockInitializeConnectionResponse(t *testing.T) {
   170  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
   171  		func(w http.ResponseWriter, r *http.Request) {
   172  			th.TestMethod(t, r, "POST")
   173  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   174  			th.TestHeader(t, r, "Content-Type", "application/json")
   175  			th.TestHeader(t, r, "Accept", "application/json")
   176  			th.TestJSONRequest(t, r, `
   177  {
   178      "os-initialize_connection":
   179      {
   180          "connector":
   181          {
   182          "ip":"127.0.0.1",
   183          "host":"stack",
   184          "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
   185          "multipath": false,
   186          "platform": "x86_64",
   187          "os_type": "linux2"
   188          }
   189      }
   190  }
   191            `)
   192  
   193  			w.Header().Add("Content-Type", "application/json")
   194  			w.WriteHeader(http.StatusAccepted)
   195  
   196  			fmt.Fprintf(w, `{
   197  "connection_info": {
   198      "data": {
   199        "target_portals": [
   200          "172.31.17.48:3260"
   201        ],
   202        "auth_method": "CHAP",
   203        "auth_username": "5MLtcsTEmNN5jFVcT6ui",
   204        "access_mode": "rw",
   205        "target_lun": 0,
   206        "volume_id": "cd281d77-8217-4830-be95-9528227c105c",
   207        "target_luns": [
   208          0
   209        ],
   210        "target_iqns": [
   211          "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c"
   212        ],
   213        "auth_password": "x854ZY5Re3aCkdNL",
   214        "target_discovered": false,
   215        "encrypted": false,
   216        "qos_specs": null,
   217        "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c",
   218        "target_portal": "172.31.17.48:3260"
   219      },
   220      "driver_volume_type": "iscsi"
   221    }
   222              }`)
   223  		})
   224  }
   225  
   226  func MockTerminateConnectionResponse(t *testing.T) {
   227  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
   228  		func(w http.ResponseWriter, r *http.Request) {
   229  			th.TestMethod(t, r, "POST")
   230  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   231  			th.TestHeader(t, r, "Content-Type", "application/json")
   232  			th.TestHeader(t, r, "Accept", "application/json")
   233  			th.TestJSONRequest(t, r, `
   234  {
   235      "os-terminate_connection":
   236      {
   237          "connector":
   238          {
   239          "ip":"127.0.0.1",
   240          "host":"stack",
   241          "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
   242          "multipath": true,
   243          "platform": "x86_64",
   244          "os_type": "linux2"
   245          }
   246      }
   247  }
   248            `)
   249  
   250  			w.Header().Add("Content-Type", "application/json")
   251  			w.WriteHeader(http.StatusAccepted)
   252  
   253  			fmt.Fprintf(w, `{}`)
   254  		})
   255  }
   256  
   257  func MockExtendSizeResponse(t *testing.T) {
   258  	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
   259  		func(w http.ResponseWriter, r *http.Request) {
   260  			th.TestMethod(t, r, "POST")
   261  			th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   262  			th.TestHeader(t, r, "Content-Type", "application/json")
   263  			th.TestHeader(t, r, "Accept", "application/json")
   264  			th.TestJSONRequest(t, r, `
   265  {
   266      "os-extend":
   267      {
   268          "new_size": 3
   269      }
   270  }
   271            `)
   272  
   273  			w.Header().Add("Content-Type", "application/json")
   274  			w.WriteHeader(http.StatusAccepted)
   275  
   276  			fmt.Fprintf(w, `{}`)
   277  		})
   278  }
   279  
   280  func MockForceDeleteResponse(t *testing.T) {
   281  	th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22/action", func(w http.ResponseWriter, r *http.Request) {
   282  		th.TestMethod(t, r, "POST")
   283  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   284  		th.TestJSONRequest(t, r, `
   285  {
   286      "os-force_delete": ""
   287  }
   288  		`)
   289  		w.WriteHeader(http.StatusAccepted)
   290  	})
   291  }