Skip to content

Commit 701926b

Browse files
[Fix] CES alarm rule v2 resources tag (#934)
1 parent 10bb47f commit 701926b

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

acceptance/openstack/ces/v2/alarms_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
7+
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
78
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ces/v2/alarms"
89
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto"
910
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
@@ -83,3 +84,67 @@ func TestAlarmsCRUD(t *testing.T) {
8384
})
8485
th.AssertNoErr(t, err)
8586
}
87+
88+
func TestAlarmsCreateEventSysWithEmptyResources(t *testing.T) {
89+
client, err := clients.NewCesV2Client()
90+
th.AssertNoErr(t, err)
91+
92+
alarmName := tools.RandomString("test-alarm-event-sys-", 4)
93+
94+
t.Log("Attempting to create EVENT.SYS alarm rule with empty resources")
95+
createOpts := alarms.CreateOpts{
96+
Name: alarmName,
97+
Namespace: "SYS.ECS",
98+
Type: "EVENT.SYS",
99+
Resources: [][]alarms.Dimension{},
100+
Policies: []alarms.Policy{
101+
{
102+
MetricName: "stopServer",
103+
Period: 0,
104+
Filter: "average",
105+
ComparisonOperator: ">=",
106+
Value: 1,
107+
Unit: "count",
108+
Count: 1,
109+
SuppressDuration: 0,
110+
Level: 2,
111+
},
112+
},
113+
NotificationEnabled: pointerto.Bool(false),
114+
Enabled: pointerto.Bool(true),
115+
}
116+
117+
alarmId, err := alarms.Create(client, createOpts)
118+
th.AssertNoErr(t, err)
119+
120+
t.Cleanup(func() {
121+
t.Log("Attempting to delete EVENT.SYS alarm rule")
122+
_, err := alarms.Delete(client, alarms.DeleteOpts{
123+
AlarmIds: []string{alarmId},
124+
})
125+
th.AssertNoErr(t, err)
126+
})
127+
128+
t.Log("Attempting to verify EVENT.SYS alarm rule")
129+
listResp, err := alarms.List(client, alarms.ListOpts{
130+
AlarmId: alarmId,
131+
})
132+
th.AssertNoErr(t, err)
133+
th.AssertEquals(t, listResp.Count, 1)
134+
th.AssertEquals(t, listResp.Alarms[0].Name, alarmName)
135+
th.AssertEquals(t, listResp.Alarms[0].Namespace, "SYS.ECS")
136+
th.AssertEquals(t, listResp.Alarms[0].Type, "EVENT.SYS")
137+
th.AssertEquals(t, listResp.Alarms[0].Enabled, true)
138+
th.AssertEquals(t, listResp.Alarms[0].NotificationEnabled, false)
139+
th.AssertEquals(t, len(listResp.Alarms[0].Resources), 1)
140+
th.AssertEquals(t, len(listResp.Alarms[0].Policies), 1)
141+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].MetricName, "stopServer")
142+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Period, 0)
143+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Filter, "average")
144+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].ComparisonOperator, ">=")
145+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Value, float64(1))
146+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Unit, "count")
147+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Count, 1)
148+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].SuppressDuration, 0)
149+
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Level, 2)
150+
}

openstack/ces/v2/alarms/Create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type CreateOpts struct {
2121
ResourceGroupId string `json:"resource_group_id,omitempty"`
2222
// Specifies the resource list. This parameter is mandatory when type is set to MULTI_INSTANCE.
2323
// A maximum of 1000 resources are supported.
24-
Resources [][]Dimension `json:"resources,omitempty"`
24+
Resources [][]Dimension `json:"resources"`
2525
// Specifies the alarm policies.
2626
// Either policies or alarm_template_id must be configured.
2727
Policies []Policy `json:"policies,omitempty"`

0 commit comments

Comments
 (0)