本文整理汇总了Python中clc_ansible_module.clc_publicip.ClcPublicIp类的典型用法代码示例。如果您正苦于以下问题:Python ClcPublicIp类的具体用法?Python ClcPublicIp怎么用?Python ClcPublicIp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClcPublicIp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_ports_returns_expected_error_for_invalid_protocol
def test_valid_ports_returns_expected_error_for_invalid_protocol(self):
under_test = ClcPublicIp(self.module)
under_test._validate_ports([{'protocol': 'ICP', 'port': 'Faygo'}])
self.module.fail_json.assert_called_once_with(
msg="Valid protocols for this module are: [TCP, UDP]: You specified 'ICP'"
)
示例2: test_valid_ports_skips_and_removes_blank_entry
def test_valid_ports_skips_and_removes_blank_entry(self):
expected = [{'protocol': 'TCP', 'port': 456}]
under_test = ClcPublicIp(self.module)
actual = under_test._validate_ports([{'protocol': 'TCP', 'port': 456}, {}])
self.assertEqual(expected, actual)
self.assertFalse(self.module.fail_json.called)
示例3: test_process_request_calls_ensure_public_ip_present_with_expected_args
def test_process_request_calls_ensure_public_ip_present_with_expected_args(self, mock_set_clc_creds, mock_public_ip):
test_params = {
'server_id': 'TESTSVR1'
,'private_ip': '10.11.12.13'
,'source_restrictions': ['no']
,'ports': [
{'port': 80},
{'port': 90, 'protocol': 'TCP'}
]
,'wait': True
,'state': 'present'
}
mock_public_ip.return_value = True, 'TESTSVR1', mock.MagicMock()
self.module.params = test_params
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.process_request()
mock_public_ip.assert_called_once_with(
server_id='TESTSVR1'
, private_ip="10.11.12.13"
, ports=[
{'port': 80, 'protocol': 'TCP'},
{'port': 90, 'protocol': 'TCP'}
]
, source_restrictions=['no']
)
self.assertFalse(self.module.fail_json.called)
示例4: test_wait_for_request_w_mock_request
def test_wait_for_request_w_mock_request(self):
mock_r1 = mock.MagicMock()
mock_r1.WaitUntilComplete.return_value = True
self.module.wait = True
under_test = ClcPublicIp(self.module)
under_test._wait_for_request_to_complete(mock_r1)
self.assertFalse(self.module.fail_json.called)
示例5: test_ensure_server_publicip_present_w_mock_server
def test_ensure_server_publicip_present_w_mock_server(self,mock_get_servers):
server_ids = ['TESTSVR1']
mock_get_servers.return_value=[mock.MagicMock()]
protocol = 'TCP'
ports = [80]
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.ensure_public_ip_present(server_ids, protocol, ports)
self.assertFalse(self.module.fail_json.called)
示例6: test_set_clc_credentials_w_token
def test_set_clc_credentials_w_token(self):
with patch.dict('os.environ', {'CLC_V2_API_TOKEN': 'Token12345',
'CLC_ACCT_ALIAS': 'TEST' }):
with patch.object(ClcPublicIp, 'clc') as mock_clc_sdk:
under_test = ClcPublicIp(self.module)
under_test._set_clc_credentials_from_env()
self.assertEqual(mock_clc_sdk._LOGIN_TOKEN_V2, 'Token12345')
self.assertFalse(mock_clc_sdk.v2.SetCredentials.called)
self.assertEqual(self.module.fail_json.called, False)
示例7: test_wait_for_requests_no_wait
def test_wait_for_requests_no_wait(self):
mock_request = mock.MagicMock()
mock_request.WaitUntilComplete.return_value = True
self.module.params = {
'wait': False
}
under_test = ClcPublicIp(self.module)
under_test._wait_for_requests_to_complete([mock_request])
self.assertFalse(self.module.fail_json.called)
示例8: test_add_publicip_to_server_exception
def test_add_publicip_to_server_exception(self, mock_clc_sdk):
error = CLCException("Failed")
error.response_text = 'Mock failure message'
mock_server = mock.MagicMock()
mock_server.id = 'TESTSVR1'
mock_server.data = {'details': {'ipAddresses': [{'internal': '1.2.3.4'}]}}
mock_server.PublicIPs().Add.side_effect = error
under_test = ClcPublicIp(self.module)
under_test._add_publicip_to_server(mock_server, 'ports')
self.module.fail_json.assert_called_once_with(
msg='Failed to add public ip to the server : TESTSVR1. Mock failure message')
示例9: test_wait_for_request_w_mock_request_fail
def test_wait_for_request_w_mock_request_fail(self):
mock_request = mock.MagicMock()
mock_request.WaitUntilComplete.return_value = True
mock_response = mock.MagicMock()
mock_response.Status.return_value = 'Failed'
mock_request.requests = [mock_response]
self.module.wait = True
under_test = ClcPublicIp(self.module)
under_test._wait_for_request_to_complete(mock_request)
self.assertTrue(self.module.fail_json.called)
示例10: test_ensure_server_publicip_present_w_mock_server
def test_ensure_server_publicip_present_w_mock_server(self,mock_get_server):
server_id = 'TESTSVR1'
mock_get_server.return_value=mock.MagicMock()
ports = [
{'port': 80},
{'port': 90, 'protocol': 'TCP'}
]
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.ensure_public_ip_present(server_id, ports)
self.assertFalse(self.module.fail_json.called)
示例11: test_ensure_server_publicip_present_w_mock_server_restrictions
def test_ensure_server_publicip_present_w_mock_server_restrictions(self,mock_get_servers):
server_ids = ['TESTSVR1']
mock_get_servers.return_value=[mock.MagicMock()]
protocol = 'TCP'
ports = [80]
restrictions = ['1.1.1.1/24', '2.2.2.0/36']
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.ensure_public_ip_present(server_ids=server_ids,
protocol=protocol,
ports=ports,
source_restrictions=restrictions)
self.assertFalse(self.module.fail_json.called)
示例12: test_remove_publicip_from_server_exception
def test_remove_publicip_from_server_exception(self, mock_clc_sdk):
error = CLCException("Failed")
error.response_text = 'Mock failure message'
mock_server = mock.MagicMock()
mock_server.id = 'TESTSVR1'
ip = mock.MagicMock()
ip.ipAddresses = [{'internal': '1.2.3.4'}]
ip.Delete.side_effect = error
mock_server.data = {'details': ip}
mock_server.PublicIPs().public_ips = [ip]
under_test = ClcPublicIp(self.module)
under_test._remove_publicip_from_server(mock_server)
self.module.fail_json.assert_called_once_with(
msg='Failed to remove public ip from the server : TESTSVR1. Mock failure message')
示例13: test_ensure_server_publicip_present_w_mock_server_restrictions
def test_ensure_server_publicip_present_w_mock_server_restrictions(self,mock_get_server):
server_id = 'TESTSVR1'
mock_get_server.return_value=mock.MagicMock()
ports = [
{'port': 80},
{'port': 1290, 'protocol': 'UDP'}
]
restrictions = ['1.1.1.1/24', '2.2.2.0/36']
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.ensure_public_ip_present(server_id=server_id,
ports=ports,
source_restrictions=restrictions)
self.assertFalse(self.module.fail_json.called)
示例14: test_process_request_state_invalid
def test_process_request_state_invalid(self, mock_set_clc_creds, mock_public_ip):
test_params = {
'server_ids': ['TESTSVR1', 'TESTSVR2']
,'protocol': 'TCP'
,'ports': [80, 90]
,'wait': True
, 'state': 'INVALID'
}
self.module.params = test_params
under_test = ClcPublicIp(self.module)
under_test.process_request()
self.assertFalse(mock_public_ip.called)
self.module.fail_json.assert_called_once_with(msg='Unknown State: INVALID')
self.assertFalse(self.module.exit_json.called)
示例15: test_process_request_state_absent
def test_process_request_state_absent(self, mock_set_clc_creds, mock_public_ip):
test_params = {
'server_ids': ['TESTSVR1', 'TESTSVR2']
,'protocol': 'TCP'
,'ports': [80, 90]
,'wait': True
, 'state': 'absent'
}
mock_public_ip.return_value = True, ['TESTSVR1','TESTSVR2'], mock.MagicMock()
self.module.params = test_params
self.module.check_mode = False
under_test = ClcPublicIp(self.module)
under_test.process_request()
self.module.exit_json.assert_called_once_with(changed=True, server_ids=['TESTSVR1', 'TESTSVR2'])
self.assertFalse(self.module.fail_json.called)