Feature/filestorage sharenetworks update (#126)
* sfs: Add update for share networks
* sfs: Add acceptance tests for share network Update
* sfs: Add possiblity to update the network for share network
* sfs: Improve share network Update unit tests
* sfs: Improve share network Update acceptance tests
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
index 1b3cb9b..8b753e9 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
@@ -251,3 +251,57 @@
}`)
})
}
+
+func MockUpdateNeutronResponse(t *testing.T) {
+ th.Mux.HandleFunc("/share-networks/713df749-aac0-4a54-af52-10f6c991e80c", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+ {
+ "share_network": {
+ "name": "net_my2",
+ "segmentation_id": null,
+ "created_at": "2015-09-04T14:54:25.000000",
+ "neutron_subnet_id": "new-neutron-subnet-id",
+ "updated_at": "2015-09-07T08:02:53.512184",
+ "id": "713df749-aac0-4a54-af52-10f6c991e80c",
+ "neutron_net_id": "new-neutron-id",
+ "ip_version": 4,
+ "nova_net_id": null,
+ "cidr": null,
+ "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
+ "network_type": null,
+ "description": "new description"
+ }
+ }
+ `)
+ })
+}
+
+func MockUpdateNovaResponse(t *testing.T) {
+ th.Mux.HandleFunc("/share-networks/713df749-aac0-4a54-af52-10f6c991e80c", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+ {
+ "share_network": {
+ "name": "net_my2",
+ "segmentation_id": null,
+ "created_at": "2015-09-04T14:54:25.000000",
+ "neutron_subnet_id": null,
+ "updated_at": "2015-09-07T08:02:53.512184",
+ "id": "713df749-aac0-4a54-af52-10f6c991e80c",
+ "neutron_net_id": null,
+ "ip_version": 4,
+ "nova_net_id": "new-nova-id",
+ "cidr": null,
+ "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
+ "network_type": null,
+ "description": "new description"
+ }
+ }
+ `)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
index a66199f..0b28623 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
@@ -168,3 +168,72 @@
th.CheckDeepEquals(t, &expected, n)
}
+
+// Verifies that it is possible to update a share network using neutron network
+func TestUpdateNeutron(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockUpdateNeutronResponse(t)
+
+ expected := sharenetworks.ShareNetwork{
+ ID: "713df749-aac0-4a54-af52-10f6c991e80c",
+ Name: "net_my2",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
+ Description: "new description",
+ NetworkType: "",
+ CIDR: "",
+ NovaNetID: "",
+ NeutronNetID: "new-neutron-id",
+ NeutronSubnetID: "new-neutron-subnet-id",
+ IPVersion: 4,
+ SegmentationID: 0,
+ UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)),
+ ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
+ }
+
+ options := sharenetworks.UpdateOpts{
+ Name: "net_my2",
+ Description: "new description",
+ NeutronNetID: "new-neutron-id",
+ NeutronSubnetID: "new-neutron-subnet-id",
+ }
+
+ v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, &expected, v)
+}
+
+// Verifies that it is possible to update a share network using nova network
+func TestUpdateNova(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockUpdateNovaResponse(t)
+
+ expected := sharenetworks.ShareNetwork{
+ ID: "713df749-aac0-4a54-af52-10f6c991e80c",
+ Name: "net_my2",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
+ Description: "new description",
+ NetworkType: "",
+ CIDR: "",
+ NovaNetID: "new-nova-id",
+ NeutronNetID: "",
+ NeutronSubnetID: "",
+ IPVersion: 4,
+ SegmentationID: 0,
+ UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)),
+ ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
+ }
+
+ options := sharenetworks.UpdateOpts{
+ Name: "net_my2",
+ Description: "new description",
+ NovaNetID: "new-nova-id",
+ }
+
+ v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, &expected, v)
+}