From dc029e457bb99424e571cdbc93d7dd60c4d22806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?p=C3=BDrus?= Date: Thu, 26 Sep 2024 23:01:12 +0200 Subject: [PATCH] Fix gnocchi EOF results --- gnocchi/metric/v1/archivepolicies/requests.go | 14 ++++++++------ gnocchi/metric/v1/measures/requests.go | 9 ++++++--- .../metric/v1/measures/testing/requests_test.go | 11 ++++------- gnocchi/metric/v1/metrics/requests.go | 9 ++++++--- gnocchi/metric/v1/resources/requests.go | 12 ++++++++---- gnocchi/metric/v1/resourcetypes/requests.go | 12 ++++++++---- gnocchi/metric/v1/status/requests.go | 3 ++- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/gnocchi/metric/v1/archivepolicies/requests.go b/gnocchi/metric/v1/archivepolicies/requests.go index f43b1e7..dd0c037 100644 --- a/gnocchi/metric/v1/archivepolicies/requests.go +++ b/gnocchi/metric/v1/archivepolicies/requests.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/gnocchi/metric/v1/measures/requests.go b/gnocchi/metric/v1/measures/requests.go index 5d9bae0..dba9861 100644 --- a/gnocchi/metric/v1/measures/requests.go +++ b/gnocchi/metric/v1/measures/requests.go @@ -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 } @@ -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 } @@ -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 } diff --git a/gnocchi/metric/v1/measures/testing/requests_test.go b/gnocchi/metric/v1/measures/testing/requests_test.go index 3c64928..befe5c3 100644 --- a/gnocchi/metric/v1/measures/testing/requests_test.go +++ b/gnocchi/metric/v1/measures/testing/requests_test.go @@ -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) @@ -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) @@ -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) { @@ -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) @@ -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) } diff --git a/gnocchi/metric/v1/metrics/requests.go b/gnocchi/metric/v1/metrics/requests.go index dc3e239..f22fb08 100644 --- a/gnocchi/metric/v1/metrics/requests.go +++ b/gnocchi/metric/v1/metrics/requests.go @@ -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 } @@ -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 } @@ -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 } diff --git a/gnocchi/metric/v1/resources/requests.go b/gnocchi/metric/v1/resources/requests.go index 0b294bd..481637e 100644 --- a/gnocchi/metric/v1/resources/requests.go +++ b/gnocchi/metric/v1/resources/requests.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/gnocchi/metric/v1/resourcetypes/requests.go b/gnocchi/metric/v1/resourcetypes/requests.go index 97f19dc..bd1cdb1 100644 --- a/gnocchi/metric/v1/resourcetypes/requests.go +++ b/gnocchi/metric/v1/resourcetypes/requests.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/gnocchi/metric/v1/status/requests.go b/gnocchi/metric/v1/status/requests.go index 1a91351..fd58179 100644 --- a/gnocchi/metric/v1/status/requests.go +++ b/gnocchi/metric/v1/status/requests.go @@ -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 }