|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" |
| 7 | + "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" |
7 | 8 | "github.com/opentelekomcloud/gophertelekomcloud/openstack/ces/v2/alarms" |
8 | 9 | "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" |
9 | 10 | th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" |
@@ -83,3 +84,67 @@ func TestAlarmsCRUD(t *testing.T) { |
83 | 84 | }) |
84 | 85 | th.AssertNoErr(t, err) |
85 | 86 | } |
| 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 | +} |
0 commit comments