Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manila V2: Add get export location support #1932

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions acceptance/openstack/sharedfilesystems/v2/shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,43 @@ func TestShareCreate(t *testing.T) {
tools.PrintResource(t, created)
}

func TestShareExportLocations(t *testing.T) {
clients.SkipRelease(t, "stable/mitaka")
clients.SkipRelease(t, "stable/newton")

client, err := clients.NewSharedFileSystemV2Client()
if err != nil {
t.Fatalf("Unable to create a shared file system client: %v", err)
}

share, err := CreateShare(t, client)
if err != nil {
t.Fatalf("Unable to create a share: %v", err)
}

defer DeleteShare(t, client, share)

err = waitForStatus(t, client, share.ID, "available", 120)
if err != nil {
t.Fatalf("Share status error: %v", err)
}

client.Microversion = "2.9"

exportLocations, err := shares.ListExportLocations(client, share.ID).Extract()
if err != nil {
t.Errorf("Unable to list share export locations: %v", err)
}
tools.PrintResource(t, exportLocations)

exportLocation, err := shares.GetExportLocation(client, share.ID, exportLocations[0].ID).Extract()
if err != nil {
t.Errorf("Unable to get share export location: %v", err)
}
tools.PrintResource(t, exportLocation)
th.AssertEquals(t, exportLocations[0], *exportLocation)
}

func TestShareUpdate(t *testing.T) {
clients.SkipRelease(t, "stable/mitaka")
clients.SkipRelease(t, "stable/newton")
Expand Down
15 changes: 11 additions & 4 deletions openstack/sharedfilesystems/v2/shares/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,17 @@ func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
return
}

// GetExportLocations will get shareID's export locations.
// Client must have Microversion set; minimum supported microversion for GetExportLocations is 2.14.
func GetExportLocations(client *gophercloud.ServiceClient, id string) (r GetExportLocationsResult) {
_, r.Err = client.Get(getExportLocationsURL(client, id), &r.Body, nil)
// ListExportLocations will list shareID's export locations.
// Client must have Microversion set; minimum supported microversion for ListExportLocations is 2.9.
func ListExportLocations(client *gophercloud.ServiceClient, id string) (r ListExportLocationsResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this change and will make note of it in the CHANGELOG. Originally, I think Get was found acceptable since there wasn't any paging.

_, r.Err = client.Get(listExportLocationsURL(client, id), &r.Body, nil)
return
}

// GetExportLocation will get shareID's export location by an ID.
// Client must have Microversion set; minimum supported microversion for GetExportLocation is 2.9.
func GetExportLocation(client *gophercloud.ServiceClient, shareID string, id string) (r GetExportLocationResult) {
_, r.Err = client.Get(getExportLocationURL(client, shareID, id), &r.Body, nil)
return
}

Expand Down
25 changes: 20 additions & 5 deletions openstack/sharedfilesystems/v2/shares/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,15 @@ type UpdateResult struct {
commonResult
}

// GetExportLocationsResult contains the result body and error from an
// GetExportLocations request.
type GetExportLocationsResult struct {
// ListExportLocationsResult contains the result body and error from a
// ListExportLocations request.
type ListExportLocationsResult struct {
gophercloud.Result
}

// GetExportLocationResult contains the result body and error from a
// GetExportLocation request.
type GetExportLocationResult struct {
gophercloud.Result
}

Expand All @@ -232,15 +238,24 @@ type ExportLocation struct {
Preferred bool `json:"preferred"`
}

// Extract will get the Export Locations from the commonResult
func (r GetExportLocationsResult) Extract() ([]ExportLocation, error) {
// Extract will get the Export Locations from the ListExportLocationsResult
func (r ListExportLocationsResult) Extract() ([]ExportLocation, error) {
var s struct {
ExportLocations []ExportLocation `json:"export_locations"`
}
err := r.ExtractInto(&s)
return s.ExportLocations, err
}

// Extract will get the Export Location from the GetExportLocationResult
func (r GetExportLocationResult) Extract() (*ExportLocation, error) {
var s struct {
ExportLocation *ExportLocation `json:"export_location"`
}
err := r.ExtractInto(&s)
return s.ExportLocation, err
}

// AccessRight contains all information associated with an OpenStack share
// Grant Access Response
type AccessRight struct {
Expand Down
29 changes: 25 additions & 4 deletions openstack/sharedfilesystems/v2/shares/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func MockListDetailResponse(t *testing.T) {
})
}

var getExportLocationsResponse = `{
var listExportLocationsResponse = `{
"export_locations": [
{
"path": "127.0.0.1:/var/lib/manila/mnt/share-9a922036-ad26-4d27-b955-7a1e285fa74d",
Expand All @@ -285,14 +285,35 @@ var getExportLocationsResponse = `{
]
}`

// MockGetExportLocationsResponse creates a mock get export locations response
func MockGetExportLocationsResponse(t *testing.T) {
// MockListExportLocationsResponse creates a mock get export locations response
func MockListExportLocationsResponse(t *testing.T) {
th.Mux.HandleFunc(shareEndpoint+"/"+shareID+"/export_locations", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, getExportLocationsResponse)
fmt.Fprintf(w, listExportLocationsResponse)
})
}

var getExportLocationResponse = `{
"export_location": {
"path": "127.0.0.1:/var/lib/manila/mnt/share-9a922036-ad26-4d27-b955-7a1e285fa74d",
"share_instance_id": "011d21e2-fbc3-4e4a-9993-9ea223f73264",
"is_admin_only": false,
"id": "80ed63fc-83bc-4afc-b881-da4a345ac83d",
"preferred": false
}
}`

// MockGetExportLocationResponse creates a mock get export location response
func MockGetExportLocationResponse(t *testing.T) {
th.Mux.HandleFunc(shareEndpoint+"/"+shareID+"/export_locations/80ed63fc-83bc-4afc-b881-da4a345ac83d", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, getExportLocationResponse)
})
}

Expand Down
32 changes: 27 additions & 5 deletions openstack/sharedfilesystems/v2/shares/testing/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ func TestListDetail(t *testing.T) {
})
}

func TestGetExportLocationsSuccess(t *testing.T) {
func TestListExportLocationsSuccess(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

MockGetExportLocationsResponse(t)
MockListExportLocationsResponse(t)

c := client.ServiceClient()
// Client c must have Microversion set; minimum supported microversion for Get Export Locations is 2.14
c.Microversion = "2.14"
// Client c must have Microversion set; minimum supported microversion for List Export Locations is 2.9
c.Microversion = "2.9"

s, err := shares.GetExportLocations(c, shareID).Extract()
s, err := shares.ListExportLocations(c, shareID).Extract()

th.AssertNoErr(t, err)
th.AssertDeepEquals(t, s, []shares.ExportLocation{
Expand All @@ -185,6 +185,28 @@ func TestGetExportLocationsSuccess(t *testing.T) {
})
}

func TestGetExportLocationSuccess(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

MockGetExportLocationResponse(t)

c := client.ServiceClient()
// Client c must have Microversion set; minimum supported microversion for Get Export Location is 2.9
c.Microversion = "2.9"

s, err := shares.GetExportLocation(c, shareID, "80ed63fc-83bc-4afc-b881-da4a345ac83d").Extract()

th.AssertNoErr(t, err)
th.AssertDeepEquals(t, s, &shares.ExportLocation{
Path: "127.0.0.1:/var/lib/manila/mnt/share-9a922036-ad26-4d27-b955-7a1e285fa74d",
ShareInstanceID: "011d21e2-fbc3-4e4a-9993-9ea223f73264",
IsAdminOnly: false,
ID: "80ed63fc-83bc-4afc-b881-da4a345ac83d",
Preferred: false,
})
}

func TestGrantAcessSuccess(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down
6 changes: 5 additions & 1 deletion openstack/sharedfilesystems/v2/shares/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ func updateURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("shares", id)
}

func getExportLocationsURL(c *gophercloud.ServiceClient, id string) string {
func listExportLocationsURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("shares", id, "export_locations")
}

func getExportLocationURL(c *gophercloud.ServiceClient, shareID, id string) string {
return c.ServiceURL("shares", shareID, "export_locations", id)
}

func grantAccessURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("shares", id, "action")
}
Expand Down