|
68 | 68 | SECURITY_GROUP_RULE_REMOTE_GROUP], |
69 | 69 | } |
70 | 70 |
|
| 71 | +security_group_2_id = '12' |
| 72 | +security_group_2_name = 'he-shoots' |
| 73 | +security_group_2_description = 'he scores' |
| 74 | + |
| 75 | +SECURITY_GROUP_2_RULE = { |
| 76 | + 'id': '2', |
| 77 | + 'group': {}, |
| 78 | + 'ip_protocol': 'tcp', |
| 79 | + 'ip_range': {}, |
| 80 | + 'parent_group_id': security_group_2_id, |
| 81 | + 'from_port': 80, |
| 82 | + 'to_port': 80, |
| 83 | +} |
| 84 | + |
| 85 | +SECURITY_GROUP_2 = { |
| 86 | + 'id': security_group_2_id, |
| 87 | + 'name': security_group_2_name, |
| 88 | + 'description': security_group_2_description, |
| 89 | + 'tenant_id': identity_fakes.project_id, |
| 90 | + 'rules': [SECURITY_GROUP_2_RULE], |
| 91 | +} |
| 92 | + |
71 | 93 |
|
72 | 94 | class FakeSecurityGroupRuleResource(fakes.FakeResource): |
73 | 95 |
|
@@ -383,12 +405,22 @@ class TestSecurityGroupRuleList(TestSecurityGroupRule): |
383 | 405 | def setUp(self): |
384 | 406 | super(TestSecurityGroupRuleList, self).setUp() |
385 | 407 |
|
386 | | - self.secgroups_mock.get.return_value = FakeSecurityGroupRuleResource( |
| 408 | + security_group_mock = FakeSecurityGroupRuleResource( |
387 | 409 | None, |
388 | 410 | copy.deepcopy(SECURITY_GROUP), |
389 | 411 | loaded=True, |
390 | 412 | ) |
391 | 413 |
|
| 414 | + security_group_2_mock = FakeSecurityGroupRuleResource( |
| 415 | + None, |
| 416 | + copy.deepcopy(SECURITY_GROUP_2), |
| 417 | + loaded=True, |
| 418 | + ) |
| 419 | + |
| 420 | + self.secgroups_mock.get.return_value = security_group_mock |
| 421 | + self.secgroups_mock.list.return_value = [security_group_mock, |
| 422 | + security_group_2_mock] |
| 423 | + |
392 | 424 | # Get the command object to test |
393 | 425 | self.cmd = security_group.ListSecurityGroupRule(self.app, None) |
394 | 426 |
|
@@ -420,18 +452,64 @@ def test_security_group_rule_list(self): |
420 | 452 | security_group_rule_cidr, |
421 | 453 | '0:0', |
422 | 454 | '', |
423 | | - ), ( |
| 455 | + ), ( |
424 | 456 | security_group_rule_id, |
425 | 457 | 'icmp', |
426 | 458 | security_group_rule_cidr, |
427 | 459 | '', |
428 | 460 | '', |
429 | | - ), ( |
| 461 | + ), ( |
430 | 462 | security_group_rule_id, |
431 | 463 | 'tcp', |
432 | 464 | '', |
433 | 465 | '80:80', |
434 | 466 | 'default', |
435 | | - ), |
| 467 | + ),) |
| 468 | + self.assertEqual(datalist, tuple(data)) |
| 469 | + |
| 470 | + def test_security_group_rule_list_no_group(self): |
| 471 | + |
| 472 | + parsed_args = self.check_parser(self.cmd, [], []) |
| 473 | + |
| 474 | + # DisplayCommandBase.take_action() returns two tuples |
| 475 | + columns, data = self.cmd.take_action(parsed_args) |
| 476 | + |
| 477 | + collist = ( |
| 478 | + 'ID', |
| 479 | + 'IP Protocol', |
| 480 | + 'IP Range', |
| 481 | + 'Port Range', |
| 482 | + 'Remote Security Group', |
| 483 | + 'Security Group', |
436 | 484 | ) |
| 485 | + self.assertEqual(collist, columns) |
| 486 | + datalist = (( |
| 487 | + security_group_rule_id, |
| 488 | + 'tcp', |
| 489 | + security_group_rule_cidr, |
| 490 | + '0:0', |
| 491 | + '', |
| 492 | + security_group_id, |
| 493 | + ), ( |
| 494 | + security_group_rule_id, |
| 495 | + 'icmp', |
| 496 | + security_group_rule_cidr, |
| 497 | + '', |
| 498 | + '', |
| 499 | + security_group_id, |
| 500 | + ), ( |
| 501 | + security_group_rule_id, |
| 502 | + 'tcp', |
| 503 | + '', |
| 504 | + '80:80', |
| 505 | + 'default', |
| 506 | + security_group_id, |
| 507 | + ), ( |
| 508 | + '2', |
| 509 | + 'tcp', |
| 510 | + '', |
| 511 | + '80:80', |
| 512 | + '', |
| 513 | + security_group_2_id, |
| 514 | + ),) |
437 | 515 | self.assertEqual(datalist, tuple(data)) |
0 commit comments