本文整理汇总了Python中clc_ansible_module.clc_modify_server.ClcModifyServer类的典型用法代码示例。如果您正苦于以下问题:Python ClcModifyServer类的具体用法?Python ClcModifyServer怎么用?Python ClcModifyServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClcModifyServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_modify_clc_server_mock_server
def test_modify_clc_server_mock_server(self,
mock_clc_sdk):
# Setup Test
self.module.params = {
'state': 'present',
'server_ids': ['TEST_SERVER'],
'cpu': 2,
'memory': 4,
'wait': True
}
mock_server = mock.MagicMock()
mock_server.id = 'TEST_SERVER'
mock_server.cpu = 2
mock_server.memory= 4
mock_clc_sdk.v2.Server = [mock_server]
# Test
self.module.check_mode = False
under_test = ClcModifyServer(self.module)
result = under_test._modify_clc_server(self.clc, self.module, 'TEST_SERVER', 2, 4)
# Assert
self.assertFalse(self.module.fail_json.called)
self.assertIsNotNone(result)
示例2: test_process_request_state_present_cpu_memory
def test_process_request_state_present_cpu_memory(self,
mock_clc_sdk,
mock_set_clc_creds):
# Setup Test
self.module.params = {
'state': 'present',
'server_ids': ['TEST_SERVER'],
'cpu': 2,
'memory': 4,
'wait': True
}
mock_server = mock.MagicMock()
mock_server.id = 'TEST_SERVER'
mock_server.cpu = 2
mock_server.memory= 2
mock_clc_sdk.v2.Servers().Servers.return_value = [mock_server]
# Test
under_test = ClcModifyServer(self.module)
under_test.process_request()
# Assert
self.assertTrue(self.module.exit_json.called)
self.assertFalse(self.module.fail_json.called)
示例3: test_process_request_state_present_empty_server_list
def test_process_request_state_present_empty_server_list(self,
mock_clc_sdk,
mock_set_clc_creds):
# Setup Test
self.module.params = {
'state': 'present',
'server_ids': None,
'cpu': 2,
'memory': 4,
'wait': True
}
mock_server = mock.MagicMock()
mock_server.id = 'TEST_SERVER'
mock_server.cpu = 2
mock_server.memory= 2
#mock_clc_sdk.v2.Servers().Servers.return_value = [mock_server]
# Test
under_test = ClcModifyServer(self.module)
under_test.process_request()
# Assert
self.assertFalse(self.module.exit_json.called)
self.assertTrue(self.module.fail_json.called)
self.module.fail_json.assert_called_once_with(
msg='server_ids needs to be a list of instances to modify: None'
)
示例4: test_get_servers_from_clc_exception
def test_get_servers_from_clc_exception(self, mock_clc_sdk):
error = CLCException()
error.message = 'Mock failure message'
mock_clc_sdk.v2.Servers.side_effect = error
under_test = ClcModifyServer(self.module)
under_test._get_servers_from_clc(['dummy_server1', 'dummy_server2'], 'Unable to fetch test servers')
self.module.fail_json.assert_called_once_with(msg='Unable to fetch test servers: Mock failure message')
示例5: test_clc_set_credentials_w_creds
def test_clc_set_credentials_w_creds(self):
with patch.dict('os.environ', {'CLC_V2_API_USERNAME': 'hansolo', 'CLC_V2_API_PASSWD': 'falcon'}):
with patch.object(clc_modify_server, 'clc_sdk') as mock_clc_sdk:
under_test = ClcModifyServer(self.module)
under_test._set_clc_credentials_from_env()
mock_clc_sdk.v2.SetCredentials.assert_called_once_with(api_username='hansolo', api_passwd='falcon')
示例6: test_wait_for_requests_fail
def test_wait_for_requests_fail(self):
self.module.params = {'wait': True}
under_test = ClcModifyServer(self.module)
mock_request = mock.MagicMock()
mock_request.WaitUntilComplete.return_value = 1
under_test._wait_for_requests(self.module, [mock_request])
self.module.fail_json.assert_called_with(msg='Unable to process modify server request')
示例7: test_process_request_state_absent_alertpolicy_error
def test_process_request_state_absent_alertpolicy_error(self,
mock_clc_sdk,
mock_set_clc_creds):
# Setup Test
self.module.params = {
'state': 'absent',
'server_ids': ['TEST_SERVER'],
'alert_policy_name': 'test',
'cpu': 2,
'wait': True
}
mock_server = mock.MagicMock()
mock_server.id = 'TEST_SERVER'
mock_server.cpu = 2
mock_server.memory= 2
mock_clc_sdk.v2.Servers().Servers.return_value = [mock_server]
# Test
under_test = ClcModifyServer(self.module)
under_test.process_request()
# Assert
self.assertFalse(self.module.exit_json.called)
self.assertTrue(self.module.fail_json.called)
self.module.fail_json.assert_called_with(
msg='\'absent\' state is not supported for \'cpu\' and \'memory\' arguments')
示例8: test_get_alert_policy_id_by_name_singe_match
def test_get_alert_policy_id_by_name_singe_match(self, mock_clc_sdk):
mock_clc_sdk.v2.API.Call.side_effect = [{'items' :
[{'name' : 'test1', 'id' : '111'},
{'name' : 'test2', 'id' : '222'}]}]
under_test = ClcModifyServer(self.module)
policy_id = under_test._get_alert_policy_id_by_name(mock_clc_sdk, None, 'alias', 'test1')
self.assertEqual('111', policy_id)
示例9: test_ensure_nic_absent_returns_false_if_network_not_provided
def test_ensure_nic_absent_returns_false_if_network_not_provided(self, mock_remove_nic):
mock_remove_nic.return_value = 'Purple'
self.module.clc = self.clc
under_test = ClcModifyServer(self.module)
result = under_test._ensure_nic_absent(None, {})
self.assertEqual(False, result)
示例10: test_set_clc_credentials_from_env
def test_set_clc_credentials_from_env(self, mock_clc_sdk):
with patch.dict('os.environ', {'CLC_V2_API_TOKEN': 'dummyToken',
'CLC_ACCT_ALIAS': 'TEST'}):
under_test = ClcModifyServer(self.module)
under_test._set_clc_credentials_from_env()
self.assertEqual(under_test.clc._LOGIN_TOKEN_V2, 'dummyToken')
self.assertFalse(mock_clc_sdk.v2.SetCredentials.called)
self.assertEqual(self.module.fail_json.called, False)
示例11: test_modify_clc_server_exception
def test_modify_clc_server_exception(self, mock_clc_sdk):
error = APIFailedResponse()
error.response_text = 'Mock failure message'
mock_clc_sdk.v2.API.Call.side_effect = error
self.module.check_mode = False
under_test = ClcModifyServer(self.module)
under_test._modify_clc_server(mock_clc_sdk, self.module, 'dummy_server',1,2)
self.module.fail_json.assert_called_once_with(msg='Unable to update the server configuration for server : "dummy_server". Mock failure message')
示例12: test_delete_aa_policy_exception
def test_delete_aa_policy_exception(self, mock_clc_sdk):
error = APIFailedResponse()
error.response_text = 'Mock failure message'
mock_clc_sdk.v2.API.Call.side_effect = error
self.module.check_mode = False
under_test = ClcModifyServer(self.module)
under_test._delete_aa_policy(mock_clc_sdk, self.module, 'alias', 'dummy_server')
self.module.fail_json.assert_called_once_with(msg='Unable to delete anti affinity policy to server : "dummy_server". Mock failure message')
示例13: test_remove_alert_policy_to_server_exception
def test_remove_alert_policy_to_server_exception(self, mock_clc_sdk):
error = APIFailedResponse()
error.response_text = 'Mock failure message'
mock_clc_sdk.v2.API.Call.side_effect = error
self.module.check_mode = False
under_test = ClcModifyServer(self.module)
under_test._remove_alert_policy_to_server(mock_clc_sdk, self.module, 'alias', 'server_id', 'alert_id')
self.module.fail_json.assert_called_once_with(msg='Unable to remove alert policy from the server : "server_id". Mock failure message')
示例14: test_get_alert_policy_id_by_name_exception
def test_get_alert_policy_id_by_name_exception(self, mock_clc_sdk):
error = APIFailedResponse()
error.response_text = 'Mock failure message'
mock_clc_sdk.v2.API.Call.side_effect = error
self.module.check_mode = False
under_test = ClcModifyServer(self.module)
under_test._get_alert_policy_id_by_name(mock_clc_sdk, self.module, 'alias', 'name')
self.module.fail_json.assert_called_once_with(msg='Unable to fetch alert policies for account : "alias". Mock failure message')
示例15: test_modify_remove_nic_looks_up_server
def test_modify_remove_nic_looks_up_server(self, mock_sdk):
mock_sdk.v2.Account.GetAlias.return_value = 'alias'
under_test = ClcModifyServer(self.module)
result = under_test._modify_remove_nic(mock_sdk, self.module, 'test_id')
self.assertEqual(1, mock_sdk.v2.Account.GetAlias.call_count)
mock_sdk.v2.Server.assert_called_once_with(alias='alias', id='test_id')