def test_cloud_bad_connect_soft_reboot( self, mock_soft_reboot, mock_get_host_key, mock_get_ssh_client, mock_start_instance, mock_set_image_id, mock_set_instance_ip ): """Test exception when connection not established after hard reboot.""" mock_soft_reboot.return_value = None mock_get_host_key.return_value = b'04820482' mock_get_ssh_client.side_effect = [ None, None, IpaSSHException('ERROR!') ] mock_start_instance.return_value = None mock_set_image_id.return_value = None mock_set_instance_ip.return_value = None self.kwargs['running_instance_id'] = 'fakeinstance' self.kwargs['test_files'] = ['test_soft_reboot'] cloud = IpaCloud(**self.kwargs) cloud.ssh_private_key_file = 'tests/data/ida_test' cloud.ssh_user = '******' cloud.logger = MagicMock() cloud.test_image() cloud.logger.error.assert_called_once_with( 'Unable to connect to instance after soft reboot: ERROR!' ) cloud.logger.error.reset_mock() assert mock_get_ssh_client.call_count > 0 assert mock_soft_reboot.call_count == 1 mock_soft_reboot.reset_mock() cloud.results_dir = self.results_dir.name mock_get_ssh_client.side_effect = [None, None, Exception('ERROR!')] cloud.test_image() cloud.logger.error.assert_called_once_with( 'Instance failed soft reboot: ERROR!' ) assert mock_get_ssh_client.call_count > 0 assert mock_soft_reboot.call_count == 1 mock_soft_reboot.reset_mock()
def test_cloud_break_if_test_failure( self, mock_run_test, mock_get_host_key, mock_get_ssh_client, mock_start_instance, mock_set_image_id, mock_set_instance_ip ): """Test exception raised when invalid test item provided.""" mock_run_test.return_value = 1 mock_get_host_key.return_value = b'04820482' mock_get_ssh_client.return_value = None mock_start_instance.return_value = None mock_set_image_id.return_value = None mock_set_instance_ip.return_value = None self.kwargs['running_instance_id'] = 'fakeinstance' self.kwargs['early_exit'] = True cloud = IpaCloud(**self.kwargs) cloud.ssh_private_key_file = 'tests/data/ida_test' cloud.ssh_user = '******' status, results = cloud.test_image() assert status == 1 assert mock_run_test.call_count == 1
def test_cloud_distro_refresh( self, mock_distro_refresh, mock_get_host_key, mock_terminate_instance, mock_get_ssh_client, mock_start_instance, mock_set_image_id, mock_set_instance_ip ): """Test exception raised when invalid test item provided.""" mock_distro_refresh.return_value = 'Refreshed!' mock_get_host_key.return_value = b'04820482' mock_terminate_instance.return_value = None mock_get_ssh_client.return_value = None mock_start_instance.return_value = None mock_set_image_id.return_value = None mock_set_instance_ip.return_value = None self.kwargs['running_instance_id'] = 'fakeinstance' self.kwargs['test_files'] = ['test_refresh'] self.kwargs['cleanup'] = True cloud = IpaCloud(**self.kwargs) cloud.ssh_private_key_file = 'tests/data/ida_test' cloud.ssh_user = '******' status, results = cloud.test_image() assert status == 0 assert mock_distro_refresh.call_count == 1 self.kwargs['cleanup'] = None
def test_cloud_unable_connect_instance(self, mock_get_ssh_client, mock_start_instance, mock_set_image_id, mock_set_instance_ip, mock_get_console_log): """Test exception raised when connection cannot be established.""" mock_get_ssh_client.side_effect = IpaSSHException('ERROR!') mock_start_instance.return_value = None mock_set_image_id.return_value = None mock_set_instance_ip.return_value = None mock_get_console_log.return_value = 'Console log output...' self.kwargs['running_instance_id'] = 'fakeinstance' cloud = IpaCloud(*args, **self.kwargs) with pytest.raises(IpaCloudException) as error: cloud.test_image() assert str(error.value) == 'Unable to connect to instance: ERROR!' assert mock_get_ssh_client.call_count == 1