|
7 | 7 | import json |
8 | 8 |
|
9 | 9 | from SoftLayer import testing |
10 | | - |
| 10 | +from SoftLayer.CLI import formatting |
11 | 11 |
|
12 | 12 | class EventLogTests(testing.TestCase): |
13 | 13 | def test_get_event_log_with_metadata(self): |
@@ -188,6 +188,136 @@ def test_get_event_log_without_metadata(self): |
188 | 188 | self.assert_no_fail(result) |
189 | 189 | self.assertEqual(expected, json.loads(result.output)) |
190 | 190 |
|
| 191 | + def test_get_event_table(self): |
| 192 | + table_fix = formatting.Table(['event', 'object', 'type', 'date', 'username', 'metadata']) |
| 193 | + table_fix.align['metadata'] = "l" |
| 194 | + expected = [ |
| 195 | + { |
| 196 | + 'date': '2017-10-23T14:22:36.221541-05:00', |
| 197 | + 'event': 'Disable Port', |
| 198 | + 'object': 'test.softlayer.com', |
| 199 | + 'username': 'SYSTEM', |
| 200 | + 'type': 'CCI', |
| 201 | + 'metadata': '' |
| 202 | + }, |
| 203 | + { |
| 204 | + 'date': '2017-10-18T09:40:41.830338-05:00', |
| 205 | + 'event': 'Security Group Rule Added', |
| 206 | + 'object': 'test.softlayer.com', |
| 207 | + 'username': 'SL12345-test', |
| 208 | + 'type': 'CCI', |
| 209 | + 'metadata': json.dumps(json.loads( |
| 210 | + '{"networkComponentId":"100",' |
| 211 | + '"networkInterfaceType":"public",' |
| 212 | + '"requestId":"53d0b91d392864e062f4958",' |
| 213 | + '"rules":[{"direction":"ingress",' |
| 214 | + '"ethertype":"IPv4",' |
| 215 | + '"portRangeMax":2001,"portRangeMin":2000,"protocol":"tcp",' |
| 216 | + '"remoteGroupId":null,"remoteIp":null,"ruleId":"100"}],"securityGroupId":"200",' |
| 217 | + '"securityGroupName":"test_SG"}' |
| 218 | + ), |
| 219 | + indent=4, |
| 220 | + sort_keys=True |
| 221 | + ) |
| 222 | + }, |
| 223 | + { |
| 224 | + 'date': '2017-10-18T09:40:32.238869-05:00', |
| 225 | + 'event': 'Security Group Added', |
| 226 | + 'object': 'test.softlayer.com', |
| 227 | + 'username': 'SL12345-test', |
| 228 | + 'type': 'CCI', |
| 229 | + 'metadata': json.dumps(json.loads( |
| 230 | + '{"networkComponentId":"100",' |
| 231 | + '"networkInterfaceType":"public",' |
| 232 | + '"requestId":"96c9b47b9e102d2e1d81fba",' |
| 233 | + '"securityGroupId":"200",' |
| 234 | + '"securityGroupName":"test_SG"}' |
| 235 | + ), |
| 236 | + indent=4, |
| 237 | + sort_keys=True |
| 238 | + ) |
| 239 | + }, |
| 240 | + { |
| 241 | + 'date': '2017-10-18T10:42:13.089536-05:00', |
| 242 | + 'event': 'Security Group Rule(s) Removed', |
| 243 | + 'object': 'test_SG', |
| 244 | + 'username': 'SL12345-test', |
| 245 | + 'type': 'Security Group', |
| 246 | + 'metadata': json.dumps(json.loads( |
| 247 | + '{"requestId":"2abda7ca97e5a1444cae0b9",' |
| 248 | + '"rules":[{"direction":"ingress",' |
| 249 | + '"ethertype":"IPv4",' |
| 250 | + '"portRangeMax":2001,"portRangeMin":2000,"protocol":"tcp",' |
| 251 | + '"remoteGroupId":null,"remoteIp":null,"ruleId":"800"}]}' |
| 252 | + ), |
| 253 | + indent=4, |
| 254 | + sort_keys=True |
| 255 | + ) |
| 256 | + }, |
| 257 | + { |
| 258 | + 'date': '2017-10-18T10:42:11.679736-05:00', |
| 259 | + 'event': 'Network Component Removed from Security Group', |
| 260 | + 'object': 'test_SG', |
| 261 | + 'username': 'SL12345-test', |
| 262 | + 'type': 'Security Group', |
| 263 | + 'metadata': json.dumps(json.loads( |
| 264 | + '{"fullyQualifiedDomainName":"test.softlayer.com",' |
| 265 | + '"networkComponentId":"100",' |
| 266 | + '"networkInterfaceType":"public",' |
| 267 | + '"requestId":"6b9a87a9ab8ac9a22e87a00"}' |
| 268 | + ), |
| 269 | + indent=4, |
| 270 | + sort_keys=True |
| 271 | + ) |
| 272 | + }, |
| 273 | + { |
| 274 | + 'date': '2017-10-18T10:41:49.802498-05:00', |
| 275 | + 'event': 'Security Group Rule(s) Added', |
| 276 | + 'object': 'test_SG', |
| 277 | + 'username': 'SL12345-test', |
| 278 | + 'type': 'Security Group', |
| 279 | + 'metadata': json.dumps(json.loads( |
| 280 | + '{"requestId":"0a293c1c3e59e4471da6495",' |
| 281 | + '"rules":[{"direction":"ingress",' |
| 282 | + '"ethertype":"IPv4",' |
| 283 | + '"portRangeMax":2001,"portRangeMin":2000,"protocol":"tcp",' |
| 284 | + '"remoteGroupId":null,"remoteIp":null,"ruleId":"800"}]}' |
| 285 | + ), |
| 286 | + indent=4, |
| 287 | + sort_keys=True |
| 288 | + ) |
| 289 | + }, |
| 290 | + { |
| 291 | + 'date': '2017-10-18T10:41:42.176328-05:00', |
| 292 | + 'event': 'Network Component Added to Security Group', |
| 293 | + 'object': 'test_SG', |
| 294 | + 'username': 'SL12345-test', |
| 295 | + 'type': 'Security Group', |
| 296 | + 'metadata': json.dumps(json.loads( |
| 297 | + '{"fullyQualifiedDomainName":"test.softlayer.com",' |
| 298 | + '"networkComponentId":"100",' |
| 299 | + '"networkInterfaceType":"public",' |
| 300 | + '"requestId":"4709e02ad42c83f80345904"}' |
| 301 | + ), |
| 302 | + indent=4, |
| 303 | + sort_keys=True |
| 304 | + ) |
| 305 | + } |
| 306 | + ] |
| 307 | + |
| 308 | + for log in expected: |
| 309 | + table_fix.add_row([log['event'], log['object'], log['type'], log['date'], log['username'], log['metadata'].strip("{}\n\t")]) |
| 310 | + expected_output = formatting.format_output(table_fix) + '\n' |
| 311 | + |
| 312 | + #print("Output: " + expected_output) |
| 313 | + |
| 314 | + result = self.run_command(args=['event-log', 'get', '--metadata'], fmt='table') |
| 315 | + |
| 316 | + #print("Result: " + result.output) |
| 317 | + |
| 318 | + self.assert_no_fail(result) |
| 319 | + self.assertEqual(expected_output, result.output) |
| 320 | + |
191 | 321 | def test_get_event_log_empty(self): |
192 | 322 | mock = self.set_mock('SoftLayer_Event_Log', 'getAllObjects') |
193 | 323 | mock.return_value = None |
|
0 commit comments