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')
    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'
        )
    def test_clc_set_credentials_w_creds(self):
        with patch.dict('os.environ', {'CLC_V2_API_USERNAME': '******', '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='******', api_passwd='falcon')
    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)
    def test_clc_set_credentials_w_creds(self):
        with patch.dict('os.environ', {'CLC_V2_API_USERNAME': '******', '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='******', api_passwd='falcon')
Esempio n. 6
0
 def test_modify_aa_policy(self, mock_clc_sdk):
     mock_clc_sdk.v2.API.Call.side_effect = 'OK'
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     ret = under_test._modify_aa_policy(self.clc, self.module, 'alias',
                                        'server1', 'aa_id')
     self.assertTrue(ret, 'OK')
    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')
    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)
    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')
    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'
        )
 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)
    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)
 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')
 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')
    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)
 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)
Esempio n. 17
0
 def test_remove_alert_policy(self, mock_clc_sdk, mock_ansible_module):
     mock_clc_sdk.v2.API.Call.side_effect = {'success'}
     mock_ansible_module.check_mode = False
     under_test = ClcModifyServer(mock_ansible_module)
     res = under_test._remove_alert_policy_to_server(
         mock_clc_sdk, mock_ansible_module, 'alias', 'server_id',
         'alert_pol_id')
     self.assertEqual(res, 'success')
 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)
    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')
    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)
 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')
 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')
 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')
 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')
 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')
 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')
    def test_modify_add_nic_looks_up_datacenter_by_location(
            self, mock_network):
        self.module.clc = self.clc
        self.module.params = {'location': 'cybertron'}
        under_test = ClcModifyServer(self.module)
        under_test._modify_add_nic(self.clc, self.module, 'server_id')

        self.clc.v2.Datacenter.assert_called_once_with('cybertron')
 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')
 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')
 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)
 def test_ensure_nic_present_no_change(self, add_nic):
     add_nic.return_value = False
     mock_server = mock.MagicMock()
     mock_server_params = {'additional_network': 'test'}
     under_test = ClcModifyServer(self.module)
     changed = under_test._ensure_nic_present(mock_server,
                                              mock_server_params)
     self.assertEqual(changed, False)
 def test_get_aa_policy_id_of_server_exception_501(self, mock_clc_sdk):
     error = APIFailedResponse()
     error.response_text = 'Mock failure message'
     error.response_status_code = 501
     mock_clc_sdk.v2.API.Call.side_effect = error
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     under_test._get_aa_policy_id_of_server(mock_clc_sdk, self.module, 'alias', 'dummy_server')
     self.module.fail_json.assert_called_once_with(msg='Unable to fetch anti affinity policy for server "dummy_server". Mock failure message')
 def test_ensure_nic_present_no_change(self, add_nic):
     add_nic.return_value = False
     mock_server = mock.MagicMock()
     mock_server_params = {
         'additional_network': 'test'
     }
     under_test = ClcModifyServer(self.module)
     changed = under_test._ensure_nic_present(mock_server, mock_server_params)
     self.assertEqual(changed, False)
    def test_modify_add_nic_looks_up_datacenter_by_location(self, mock_network):
        self.module.clc = self.clc
        self.module.params = {
            'location': 'cybertron'
        }
        under_test = ClcModifyServer(self.module)
        under_test._modify_add_nic(self.clc, self.module, 'server_id')

        self.clc.v2.Datacenter.assert_called_once_with('cybertron')
 def test_get_aa_policy_id_of_server_exception_501(self, mock_clc_sdk):
     error = APIFailedResponse()
     error.response_text = 'Mock failure message'
     error.response_status_code = 501
     mock_clc_sdk.v2.API.Call.side_effect = error
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     under_test._get_aa_policy_id_of_server(mock_clc_sdk, self.module, 'alias', 'dummy_server')
     self.module.fail_json.assert_called_once_with(msg='Unable to fetch anti affinity policy for server "dummy_server". Mock failure message')
    def test_ensure_nic_absent_calls_modify_remove_nic(self, mock_remove_nic):
        self.module.clc = self.clc
        mock_server = mock.MagicMock
        mock_server.id = 'test_id'

        under_test = ClcModifyServer(self.module)
        under_test._ensure_nic_absent(mock_server, {'additional_network': 'beer'})

        mock_remove_nic.assert_called_once_with(under_test.clc, under_test.module, 'test_id')
 def test_add_second_nic(self, mock_modify_server):
     mock_modify_server.retrun_value = 'OK'
     mock_server = mock.MagicMock()
     server_params = {'network_id': 'Test Network'}
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     changed, res = under_test._ensure_server_config(
         mock_server, server_params)
     self.assertEqual(changed, False)
     self.assertEqual(res, None)
 def test_refresh_servers_fail(self):
     error = CLCException()
     error.message = 'Mock fail message'
     under_test = ClcModifyServer(self.module)
     mock_server = mock.MagicMock()
     mock_server.id = 'mock_server_id'
     mock_server.Refresh.side_effect = error
     mock_servers = [mock_server]
     under_test._refresh_servers(self.module, mock_servers)
     self.module.fail_json.assert_called_with(msg='Unable to refresh the server mock_server_id. Mock fail message')
 def test_get_aa_policy_id_of_server_exception_404(self, mock_clc_sdk):
     error = APIFailedResponse()
     error.response_text = 'Mock failure message'
     error.response_status_code = 404
     mock_clc_sdk.v2.API.Call.side_effect = error
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     res = under_test._get_aa_policy_id_of_server(mock_clc_sdk, self.module, 'alias', 'dummy_server')
     self.assertEqual(self.module.fail_json.called, False)
     self.assertEqual(res, None)
 def test_get_aa_policy_id_of_server_exception_404(self, mock_clc_sdk):
     error = APIFailedResponse()
     error.response_text = 'Mock failure message'
     error.response_status_code = 404
     mock_clc_sdk.v2.API.Call.side_effect = error
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     res = under_test._get_aa_policy_id_of_server(mock_clc_sdk, self.module, 'alias', 'dummy_server')
     self.assertEqual(self.module.fail_json.called, False)
     self.assertEqual(res, None)
 def test_remove_alert_policy(self, mock_clc_sdk, mock_ansible_module):
     mock_clc_sdk.v2.API.Call.side_effect = {'success'}
     mock_ansible_module.check_mode = False
     under_test = ClcModifyServer(mock_ansible_module)
     res = under_test._remove_alert_policy_to_server(mock_clc_sdk,
                                                     mock_ansible_module,
                                                     'alias',
                                                     'server_id',
                                                     'alert_pol_id')
     self.assertEqual(res, 'success')
 def test_refresh_servers_fail(self):
     error = CLCException()
     error.message = 'Mock fail message'
     under_test = ClcModifyServer(self.module)
     mock_server = mock.MagicMock()
     mock_server.id = 'mock_server_id'
     mock_server.Refresh.side_effect = error
     mock_servers = [mock_server]
     under_test._refresh_servers(self.module, mock_servers)
     self.module.fail_json.assert_called_with(msg='Unable to refresh the server mock_server_id. Mock fail message')
 def test_add_second_nic(self, mock_modify_server):
     mock_modify_server.retrun_value = 'OK'
     mock_server = mock.MagicMock()
     server_params = {
         'network_id': 'Test Network'
     }
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     changed, res = under_test._ensure_server_config(mock_server, server_params)
     self.assertEqual(changed, False)
     self.assertEqual(res, None)
    def test_modify_remove_nic_handles_exception(self, mock_sdk):
        mock_sdk.v2.Account.GetAlias.return_value = 'alias'
        exception = CLCException()
        exception.message = "get wrekd"
        mock_sdk.v2.Server.side_effect = exception

        under_test = ClcModifyServer(self.module)
        result = under_test._modify_remove_nic(mock_sdk, self.module, 'test_id')

        self.assertFalse(result)
        self.module.fail_json.assert_called_with(msg='Unable to remove NIC from server : "test_id". get wrekd')
    def test_get_anti_affinity_policy_id_by_name_no_match(self, mock_clc_sdk, mock_ansible_module):
        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_aa_policy_id_by_name(mock_clc_sdk,
                                                              mock_ansible_module,
                                                              'alias',
                                                              'testnone')
        mock_ansible_module.fail_json.assert_called_with(
            msg='No anti affinity policy was found with policy name : testnone')
 def test_get_aalert_policy_id_by_name_duplicate_match(self, mock_clc_sdk, mock_ansible_module):
     mock_clc_sdk.v2.API.Call.side_effect = [{'items' :
                                             [{'name' : 'test1', 'id' : '111'},
                                              {'name' : 'test2', 'id' : '222'},
                                              {'name' : 'test1', 'id' : '111'}]}]
     under_test = ClcModifyServer(self.module)
     policy_id = under_test._get_alert_policy_id_by_name(mock_clc_sdk,
                                                           mock_ansible_module,
                                                           'alias',
                                                           'test1')
     mock_ansible_module.fail_json.assert_called_with(
         msg='multiple alert policies were found with policy name : test1')
Esempio n. 47
0
 def test_ensure_server_config_no_change(self, mock_modify_server):
     mock_modify_server.return_value = 'OK'
     mock_server = mock.MagicMock()
     mock_server.cpu = 2
     mock_server.memory = 2
     server_params = {'cpu': 2, 'memory': 2}
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     changed, res = under_test._ensure_server_config(
         mock_server, server_params)
     self.assertEqual(changed, False)
     self.assertEqual(res, None)
    def test_get_anti_affinity_policy_id_by_name_no_match(self, mock_clc_sdk, mock_ansible_module):
        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_aa_policy_id_by_name(mock_clc_sdk,
                                                              mock_ansible_module,
                                                              'alias',
                                                              'testnone')
        mock_ansible_module.fail_json.assert_called_with(
            msg='No anti affinity policy was found with policy name : testnone')
Esempio n. 49
0
 def test_ensure_alert_policy_absent(self, mock_remove_pol, mock_pol_exists,
                                     mock_get_pol):
     mock_remove_pol.return_value = 'OK'
     mock_pol_exists.return_value = True
     mock_get_pol.return_value = '123'
     under_test = ClcModifyServer(self.module)
     under_test.clc = self.clc
     server_params = {'alert_policy_name': 'test'}
     server = mock.MagicMock()
     server.id = 'server1'
     changed = under_test._ensure_alert_policy_absent(server, server_params)
     self.assertEqual(changed, True)
 def test_get_aalert_policy_id_by_name_duplicate_match(self, mock_clc_sdk, mock_ansible_module):
     mock_clc_sdk.v2.API.Call.side_effect = [{'items' :
                                             [{'name' : 'test1', 'id' : '111'},
                                              {'name' : 'test2', 'id' : '222'},
                                              {'name' : 'test1', 'id' : '111'}]}]
     under_test = ClcModifyServer(self.module)
     policy_id = under_test._get_alert_policy_id_by_name(mock_clc_sdk,
                                                           mock_ansible_module,
                                                           'alias',
                                                           'test1')
     mock_ansible_module.fail_json.assert_called_with(
         msg='multiple alert policies were found with policy name : test1')
    def test_modify_remove_nic_calls_remove_nic_on_server_without_wait(self, mock_sdk, mock_net, mock_dc):
        mock_sdk.v2.Account.GetAlias.return_value = 'alias'
        mock_dc.return_value = 'test-dc'
        mock_net.return_value = 'testnet'

        under_test = ClcModifyServer(self.module)
        result = under_test._modify_remove_nic(mock_sdk, self.module, 'test_id')

        mock_sdk.v2.Server.return_value.RemoveNIC.assert_called_once_with(network_id='testnet')
        self.assertEqual(0, mock_sdk.v2.Server.return_value.RemoveNIC.return_value.WaitUntilComplete.call_count)
        mock_net.assert_called_once_with(self.module, 'test-dc')
        self.assertTrue(result)
    def test_override_v2_api_url_from_environment(self):
        original_url = clc_sdk.defaults.ENDPOINT_URL_V2
        under_test = ClcModifyServer(self.module)

        under_test._set_clc_credentials_from_env()
        self.assertEqual(clc_sdk.defaults.ENDPOINT_URL_V2, original_url)

        with patch.dict('os.environ', {'CLC_V2_API_URL': 'http://unittest.example.com/'}):
            under_test._set_clc_credentials_from_env()

        self.assertEqual(clc_sdk.defaults.ENDPOINT_URL_V2, 'http://unittest.example.com/')

        clc_sdk.defaults.ENDPOINT_URL_V2 = original_url
 def test_ensure_server_config_change_memory(self, mock_modify_server):
     mock_modify_server.return_value = 'OK'
     mock_server = mock.MagicMock()
     mock_server.cpu = 1
     mock_server.memory = 1
     server_params = {
         'memory': 2
     }
     self.module.check_mode = False
     under_test = ClcModifyServer(self.module)
     changed, res = under_test._ensure_server_config(mock_server, server_params)
     self.assertEqual(changed, True)
     self.assertEqual(res, 'OK')
 def test_find_network_id_no_network(self):
     params = {
         'additional_network': 'test1'
     }
     self.module.params = params
     mock_datacenter = mock.MagicMock()
     mock_datacenter.id = 'DC1'
     mock_network1 = mock.MagicMock()
     mock_network1.id = 'test1'
     mock_network2 = mock.MagicMock()
     mock_network2.id = 'test2'
     mock_datacenter.Networks().Get.return_value = None
     ClcModifyServer._find_network_id(self.module, mock_datacenter)
     self.module.fail_json.assert_called_with(msg='Unable to find a network with name/id "test1" at location: DC1')