diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2017-04-07 20:59:58 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2017-04-11 02:08:57 -0500 |
| commit | 1bf6706ad1628dcf18a515f13a7b4ba01a38b758 (patch) | |
| tree | 8870698bb3e3790c5175ba456330250fe99b0e11 /openstackclient/tests/unit/api | |
| parent | 4289ddd47a9c92eb3033eccf39966915caae05db (diff) | |
| download | python-openstackclient-1bf6706ad1628dcf18a515f13a7b4ba01a38b758.tar.gz | |
Low-level Compute v2 API: security group rules
api.compute.APIv2 security group rule functions.
novaclient 8.0 is now released without support for the previously
deprecated nova-net functions, so include a new low-level REST
implementation of the removed APIs.
Change-Id: Ieabd61113bc6d3562738686f52bb06aa84fca765
Diffstat (limited to 'openstackclient/tests/unit/api')
| -rw-r--r-- | openstackclient/tests/unit/api/test_compute_v2.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/api/test_compute_v2.py b/openstackclient/tests/unit/api/test_compute_v2.py index f443e810..949205fd 100644 --- a/openstackclient/tests/unit/api/test_compute_v2.py +++ b/openstackclient/tests/unit/api/test_compute_v2.py @@ -226,3 +226,84 @@ class TestSecurityGroup(TestComputeAPIv2): security_group='sg2', description='desc2') self.assertEqual(self.FAKE_SECURITY_GROUP_RESP_2, ret) + + +class TestSecurityGroupRule(TestComputeAPIv2): + + FAKE_SECURITY_GROUP_RULE_RESP = { + 'id': '1', + 'name': 'sgr1', + 'tenant_id': 'proj-1', + 'ip_protocol': 'TCP', + 'from_port': 1, + 'to_port': 22, + 'group': {}, + # 'ip_range': , + # 'cidr': , + # 'parent_group_id': , + } + + def test_security_group_create_no_options(self): + self.requests_mock.register_uri( + 'POST', + FAKE_URL + '/os-security-group-rules', + json={'security_group_rule': self.FAKE_SECURITY_GROUP_RULE_RESP}, + status_code=200, + ) + ret = self.api.security_group_rule_create( + security_group_id='1', + ip_protocol='tcp', + ) + self.assertEqual(self.FAKE_SECURITY_GROUP_RULE_RESP, ret) + + def test_security_group_create_options(self): + self.requests_mock.register_uri( + 'POST', + FAKE_URL + '/os-security-group-rules', + json={'security_group_rule': self.FAKE_SECURITY_GROUP_RULE_RESP}, + status_code=200, + ) + ret = self.api.security_group_rule_create( + security_group_id='1', + ip_protocol='tcp', + from_port=22, + to_port=22, + remote_ip='1.2.3.4/24', + ) + self.assertEqual(self.FAKE_SECURITY_GROUP_RULE_RESP, ret) + + def test_security_group_create_port_errors(self): + self.requests_mock.register_uri( + 'POST', + FAKE_URL + '/os-security-group-rules', + json={'security_group_rule': self.FAKE_SECURITY_GROUP_RULE_RESP}, + status_code=200, + ) + self.assertRaises( + compute.InvalidValue, + self.api.security_group_rule_create, + security_group_id='1', + ip_protocol='tcp', + from_port='', + to_port=22, + remote_ip='1.2.3.4/24', + ) + self.assertRaises( + compute.InvalidValue, + self.api.security_group_rule_create, + security_group_id='1', + ip_protocol='tcp', + from_port=0, + to_port=[], + remote_ip='1.2.3.4/24', + ) + + def test_security_group_rule_delete(self): + self.requests_mock.register_uri( + 'DELETE', + FAKE_URL + '/os-security-group-rules/1', + status_code=202, + ) + ret = self.api.security_group_rule_delete('1') + self.assertEqual(202, ret.status_code) + self.assertEqual("", ret.text) |
