Skip to content

Commit

Permalink
Merge pull request #230 from kayrus/gnocci
Browse files Browse the repository at this point in the history
Fix gnocchi EOF results
  • Loading branch information
kayrus authored Oct 8, 2024
2 parents 46e6234 + dc029e4 commit 7cbb8fd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
14 changes: 8 additions & 6 deletions gnocchi/metric/v1/archivepolicies/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {

// Get retrieves a specific Gnocchi archive policy based on its name.
func Get(ctx context.Context, c *gophercloud.ServiceClient, archivePolicyName string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, archivePolicyName), &r.Body, nil)
resp, err := c.Get(ctx, getURL(c, archivePolicyName), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -72,10 +73,10 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateO
r.Err = err
return
}
_, r.Err = client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})

_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -103,10 +104,10 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, archivePolic
r.Err = err
return
}
_, r.Err = client.Patch(ctx, updateURL(client, archivePolicyName), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Patch(ctx, updateURL(client, archivePolicyName), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})

_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand All @@ -117,6 +118,7 @@ func Delete(ctx context.Context, c *gophercloud.ServiceClient, archivePolicyName
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(ctx, deleteURL(c, archivePolicyName), requestOpts)
resp, err := c.Delete(ctx, deleteURL(c, archivePolicyName), requestOpts)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
9 changes: 6 additions & 3 deletions gnocchi/metric/v1/measures/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, metricID str
r.Err = err
return
}
_, r.Err = client.Post(ctx, createURL(client, metricID), b["measures"], &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, createURL(client, metricID), b["measures"], nil, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -210,12 +211,13 @@ func BatchCreateMetrics(ctx context.Context, client *gophercloud.ServiceClient,
return
}

_, r.Err = client.Post(ctx, batchCreateMetricsURL(client), b["batchCreateMetrics"], &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, batchCreateMetricsURL(client), b["batchCreateMetrics"], nil, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -390,11 +392,12 @@ func BatchCreateResourcesMetrics(ctx context.Context, client *gophercloud.Servic
return
}

_, r.Err = client.Post(ctx, url, b["batchCreateResourcesMetrics"], &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, url, b["batchCreateResourcesMetrics"], nil, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
11 changes: 4 additions & 7 deletions gnocchi/metric/v1/measures/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestCreateMeasures(t *testing.T) {
th.TestHeader(t, r, "Accept", "application/json, */*")
th.TestJSONRequest(t, r, MeasuresCreateRequest)
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `{}`)
})

firstMeasureTimestamp := time.Date(2018, 1, 18, 12, 31, 0, 0, time.UTC)
Expand Down Expand Up @@ -97,7 +96,6 @@ func TestBatchCreateMetrics(t *testing.T) {
th.TestHeader(t, r, "Accept", "application/json, */*")
th.TestJSONRequest(t, r, MeasuresBatchCreateMetricsRequest)
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `{}`)
})

firstTimestamp := time.Date(2018, 1, 10, 01, 00, 0, 0, time.UTC)
Expand Down Expand Up @@ -130,8 +128,8 @@ func TestBatchCreateMetrics(t *testing.T) {
},
},
}
res := measures.BatchCreateMetrics(context.TODO(), fake.ServiceClient(), createOpts)
th.AssertNoErr(t, res.Err)
err := measures.BatchCreateMetrics(context.TODO(), fake.ServiceClient(), createOpts).ExtractErr()
th.AssertNoErr(t, err)
}

func TestBatchCreateResourcesMetrics(t *testing.T) {
Expand All @@ -145,7 +143,6 @@ func TestBatchCreateResourcesMetrics(t *testing.T) {
th.TestHeader(t, r, "Accept", "application/json, */*")
th.TestJSONRequest(t, r, MeasuresBatchCreateResourcesMetricsRequest)
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `{}`)
})

firstTimestamp := time.Date(2018, 1, 20, 12, 30, 0, 0, time.UTC)
Expand Down Expand Up @@ -210,6 +207,6 @@ func TestBatchCreateResourcesMetrics(t *testing.T) {
},
},
}
res := measures.BatchCreateResourcesMetrics(context.TODO(), fake.ServiceClient(), createOpts)
th.AssertNoErr(t, res.Err)
err := measures.BatchCreateResourcesMetrics(context.TODO(), fake.ServiceClient(), createOpts).ExtractErr()
th.AssertNoErr(t, err)
}
9 changes: 6 additions & 3 deletions gnocchi/metric/v1/metrics/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {

// Get retrieves a specific Gnocchi metric based on its id.
func Get(ctx context.Context, c *gophercloud.ServiceClient, metricID string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, metricID), &r.Body, nil)
resp, err := c.Get(ctx, getURL(c, metricID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -117,9 +118,10 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateO
r.Err = err
return
}
_, r.Err = client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand All @@ -130,6 +132,7 @@ func Delete(ctx context.Context, c *gophercloud.ServiceClient, metricID string)
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(ctx, deleteURL(c, metricID), requestOpts)
resp, err := c.Delete(ctx, deleteURL(c, metricID), requestOpts)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
12 changes: 8 additions & 4 deletions gnocchi/metric/v1/resources/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder, resourceType strin

// Get retrieves a specific Gnocchi resource based on its type and ID.
func Get(ctx context.Context, c *gophercloud.ServiceClient, resourceType string, resourceID string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, resourceType, resourceID), &r.Body, nil)
resp, err := c.Get(ctx, getURL(c, resourceType, resourceID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -132,9 +133,10 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, resourceType
r.Err = err
return
}
_, r.Err = client.Post(ctx, createURL(client, resourceType), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, createURL(client, resourceType), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -200,9 +202,10 @@ func Update(ctx context.Context, c *gophercloud.ServiceClient, resourceType, res
r.Err = err
return
}
_, r.Err = c.Patch(ctx, updateURL(c, resourceType, resourceID), b, &r.Body, &gophercloud.RequestOpts{
resp, err := c.Patch(ctx, updateURL(c, resourceType, resourceID), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand All @@ -213,6 +216,7 @@ func Delete(ctx context.Context, c *gophercloud.ServiceClient, resourceType, res
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(ctx, deleteURL(c, resourceType, resourceID), requestOpts)
resp, err := c.Delete(ctx, deleteURL(c, resourceType, resourceID), requestOpts)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
12 changes: 8 additions & 4 deletions gnocchi/metric/v1/resourcetypes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {

// Get retrieves a specific Gnocchi resource type based on its name.
func Get(ctx context.Context, c *gophercloud.ServiceClient, resourceTypeName string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, resourceTypeName), &r.Body, nil)
resp, err := c.Get(ctx, getURL(c, resourceTypeName), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -92,9 +93,10 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateO
r.Err = err
return
}
_, r.Err = client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand Down Expand Up @@ -182,12 +184,13 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, resourceType
r.Err = err
return
}
_, r.Err = client.Patch(ctx, updateURL(client, resourceTypeName), b, &r.Body, &gophercloud.RequestOpts{
resp, err := client.Patch(ctx, updateURL(client, resourceTypeName), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json-patch+json",
},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

Expand All @@ -198,6 +201,7 @@ func Delete(ctx context.Context, c *gophercloud.ServiceClient, resourceTypeName
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(ctx, deleteURL(c, resourceTypeName), requestOpts)
resp, err := c.Delete(ctx, deleteURL(c, resourceTypeName), requestOpts)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
3 changes: 2 additions & 1 deletion gnocchi/metric/v1/status/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Get(ctx context.Context, c *gophercloud.ServiceClient, opts GetOptsBuilder)
}
url += query
}
_, r.Err = c.Get(ctx, url, &r.Body, nil)
resp, err := c.Get(ctx, url, &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

0 comments on commit 7cbb8fd

Please sign in to comment.