-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LTS] API Update fix #428 Reviewed-by: Artem Lifshits Reviewed-by: Anton Sidelnikov Reviewed-by: Aloento
- Loading branch information
Showing
21 changed files
with
851 additions
and
270 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package v2 | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/lts/v2/groups" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/lts/v2/streams" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/lts/v2/transfers" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/obs" | ||
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
) | ||
|
||
func TestLtsLifecycle(t *testing.T) { | ||
client, err := clients.NewLtsV2Client() | ||
th.AssertNoErr(t, err) | ||
|
||
name := tools.RandomString("test-group-", 3) | ||
createOpts := groups.CreateOpts{ | ||
LogGroupName: name, | ||
TTLInDays: 7, | ||
} | ||
|
||
created, err := groups.CreateLogGroup(client, createOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = groups.DeleteLogGroup(client, created) | ||
th.AssertNoErr(t, err) | ||
}) | ||
|
||
group, err := groups.UpdateLogGroup(client, groups.UpdateLogGroupOpts{ | ||
LogGroupId: created, | ||
TTLInDays: 3, | ||
}) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, 3, group.TTLInDays) | ||
|
||
got, err := groups.ListLogGroups(client) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, true, len(got) > 0) | ||
tools.PrintResource(t, got) | ||
|
||
sname := tools.RandomString("test-stream-", 3) | ||
stream, err := streams.CreateLogStream(client, streams.CreateOpts{ | ||
GroupId: created, | ||
LogStreamName: sname, | ||
}) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = streams.DeleteLogStream(client, streams.DeleteOpts{ | ||
GroupId: created, | ||
StreamId: stream, | ||
}) | ||
th.AssertNoErr(t, err) | ||
}) | ||
|
||
slist, err := streams.ListLogStream(client, created) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, true, len(slist) > 0) | ||
tools.PrintResource(t, slist) | ||
} | ||
|
||
func TestLtsTransferLifecycle(t *testing.T) { | ||
t.Skipf("Released API are not working properly") | ||
client, err := clients.NewLtsV2Client() | ||
th.AssertNoErr(t, err) | ||
|
||
name := tools.RandomString("test-group-", 3) | ||
createOpts := groups.CreateOpts{ | ||
LogGroupName: name, | ||
TTLInDays: 7, | ||
} | ||
|
||
logId, err := groups.CreateLogGroup(client, createOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = groups.DeleteLogGroup(client, logId) | ||
th.AssertNoErr(t, err) | ||
}) | ||
|
||
sname := tools.RandomString("test-stream-", 3) | ||
streamId, err := streams.CreateLogStream(client, streams.CreateOpts{ | ||
GroupId: logId, | ||
LogStreamName: sname, | ||
}) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = streams.DeleteLogStream(client, streams.DeleteOpts{ | ||
GroupId: logId, | ||
StreamId: streamId, | ||
}) | ||
th.AssertNoErr(t, err) | ||
}) | ||
|
||
obsClient, err := clients.NewOBSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
bucketName := strings.ToLower(tools.RandomString("obs-test", 5)) | ||
|
||
_, err = obsClient.CreateBucket(&obs.CreateBucketInput{ | ||
Bucket: bucketName, | ||
}) | ||
t.Cleanup(func() { | ||
_, err = obsClient.DeleteBucket(bucketName) | ||
th.AssertNoErr(t, err) | ||
}) | ||
th.AssertNoErr(t, err) | ||
|
||
switchOn := false | ||
createTransferOpts := transfers.CreateLogDumpObsOpts{ | ||
LogGroupId: logId, | ||
LogStreamIds: []string{ | ||
streamId, | ||
}, | ||
ObsBucketName: bucketName, | ||
Type: "cycle", | ||
StorageFormat: "RAW", | ||
SwitchOn: &switchOn, | ||
PrefixName: "test", | ||
DirPrefixName: "dir-test", | ||
Period: 3, | ||
PeriodUnit: "hour", | ||
} | ||
logDumpId, err := transfers.CreateLogDumpObs(client, createTransferOpts) | ||
th.AssertNoErr(t, err) | ||
t.Logf("Obs log dump created, id: %s", logDumpId) | ||
|
||
// GET API is currently not working | ||
|
||
listLogs, err := transfers.ListTransfers(client, transfers.ListTransfersOpts{}) | ||
th.AssertNoErr(t, err) | ||
if len(listLogs) < 1 { | ||
t.Error("Log dump wasn't found") | ||
} | ||
|
||
err = transfers.DeleteTransfer(client, logDumpId) | ||
th.AssertNoErr(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package groups | ||
|
||
import ( | ||
"github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
// CreateOpts is a struct that contains all the parameters. | ||
type CreateOpts struct { | ||
// Name of the log group to be created. | ||
// Minimum length: 1 character | ||
// Maximum length: 64 characters | ||
// Enumerated value: | ||
// lts-group-01nh | ||
LogGroupName string `json:"log_group_name" required:"true"` | ||
// Log retention duration, in days (fixed to 7 days). | ||
TTLInDays int `json:"ttl_in_days"` | ||
} | ||
|
||
func CreateLogGroup(client *golangsdk.ServiceClient, opts CreateOpts) (string, error) { | ||
b, err := build.RequestBody(opts, "") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// POST /v2/{project_id}/groups | ||
raw, err := client.Post(client.ServiceURL("groups"), b, nil, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var res struct { | ||
ID string `json:"log_group_id"` | ||
} | ||
err = extract.Into(raw.Body, &res) | ||
return res.ID, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package groups | ||
|
||
import "github.com/opentelekomcloud/gophertelekomcloud" | ||
|
||
// DeleteLogGroup a log group by id | ||
func DeleteLogGroup(client *golangsdk.ServiceClient, groupId string) (err error) { | ||
// DELETE /v2/{project_id}/groups/{log_group_id} | ||
_, err = client.Delete(client.ServiceURL("groups", groupId), &golangsdk.RequestOpts{ | ||
MoreHeaders: map[string]string{ | ||
"content-type": "application/json", | ||
}, | ||
}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package groups | ||
|
||
import ( | ||
"github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func ListLogGroups(client *golangsdk.ServiceClient) ([]LogGroup, error) { | ||
// GET /v2/{project_id}/groups | ||
raw, err := client.Get(client.ServiceURL("groups"), nil, &golangsdk.RequestOpts{ | ||
MoreHeaders: map[string]string{ | ||
"content-type": "application/json", | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res []LogGroup | ||
err = extract.IntoSlicePtr(raw.Body, &res, "log_groups") | ||
return res, err | ||
} | ||
|
||
type LogGroup struct { | ||
// Time when a log group was created. | ||
CreationTime int64 `json:"creation_time"` | ||
// Log group name. | ||
// Minimum length: 1 character | ||
// Maximum length: 64 characters | ||
LogGroupName string `json:"log_group_name"` | ||
// Log group ID. | ||
// Value length: 36 characters | ||
LogGroupId string `json:"log_group_id"` | ||
// Log retention duration, in days (fixed to 7 days). | ||
TTLInDays int `json:"ttl_in_days"` | ||
// Log group tag. | ||
Tag map[string]string `json:"tag,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package groups | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type UpdateLogGroupOpts struct { | ||
// Log group ID. For details about how to obtain a log group ID, see Obtaining the AccountID, Project ID, Log Group ID, and Log Stream ID. | ||
// Default value: None | ||
// Value length: 36 characters | ||
LogGroupId string `json:"-" required:"true"` | ||
// Log retention duration, in days (fixed to 7 days). | ||
TTLInDays int32 `json:"ttl_in_days" required:"true"` | ||
} | ||
|
||
func UpdateLogGroup(client *golangsdk.ServiceClient, opts UpdateLogGroupOpts) (*LogGroup, error) { | ||
b, err := build.RequestBody(opts, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// POST /v2/{project_id}/groups/{log_group_id} | ||
raw, err := client.Post(client.ServiceURL("groups", opts.LogGroupId), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res LogGroup | ||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.