-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: run ubuntu-bug
when error page is shown
#770
Draft
d-loose
wants to merge
7
commits into
canonical:main
Choose a base branch
from
d-loose:error-page-apport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f471aa
feat(provision): add apport service
d-loose d0a5c07
feat(provision): launch apport on error page if available
d-loose 8316be5
feat(bootstrap): register apport service for installer
d-loose 9ebb895
feat: add test exception
d-loose b46a7f6
feat(apport_service): log errors when failing to run ubuntu-bug
d-loose 86c2ae3
feat(provision): add preCommands to ApportService
d-loose 467d74d
feat(bootstrap): obtain read permissions for subiquity log files
d-loose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/ubuntu_provision/lib/src/services/apport_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:ubuntu_logger/ubuntu_logger.dart'; | ||
|
||
final _log = Logger('apport_service'); | ||
|
||
class ApportService { | ||
ApportService({ | ||
this.liveRun = true, | ||
this.preCommands, | ||
@visibleForTesting | ||
Future<ProcessResult> Function(String, List<String>)? runProcess, | ||
@visibleForTesting Map<String, String>? env, | ||
}) : runProcess = runProcess ?? Process.run, | ||
env = env ?? Platform.environment; | ||
|
||
static const String apport = 'ubuntu-bug'; | ||
|
||
final bool liveRun; | ||
final Future<ProcessResult> Function(String, List<String>) runProcess; | ||
final Map<String, String> env; | ||
final List<({String cmd, List<String> args})>? preCommands; | ||
|
||
Future<void> launch() async { | ||
final snapName = env['SNAP_NAME']; | ||
if (snapName == null) { | ||
_log.error('SNAP_NAME environment variable not set'); | ||
return; | ||
} | ||
if (liveRun) { | ||
if (preCommands != null) { | ||
for (final command in preCommands!) { | ||
_log.info( | ||
'Running pre-command ${command.cmd} ${command.args.join(' ')}'); | ||
final result = await runProcess(command.cmd, command.args); | ||
if (result.exitCode != 0) { | ||
_log.error('Failed to run ${command.cmd}: ${result.stderr}'); | ||
} | ||
} | ||
} | ||
_log.info('Running apport for $snapName'); | ||
final result = await runProcess(apport, [snapName]); | ||
if (result.exitCode != 0) { | ||
_log.error('Failed to run apport for $snapName: ${result.stderr}'); | ||
} | ||
} else { | ||
if (preCommands != null) { | ||
for (final command in preCommands!) { | ||
_log.info( | ||
'Dry-run: Running pre-command ${command.cmd} ${command.args.join(' ')}'); | ||
} | ||
} | ||
_log.info('Dry-run: Running apport for $snapName'); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/ubuntu_provision/test/services/apport_service_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:ubuntu_provision/ubuntu_provision.dart'; | ||
|
||
void main() { | ||
test('run ubuntu-bug', () async { | ||
final mockProcess = MockProcess(); | ||
when(mockProcess.run(any, any)) | ||
.thenAnswer((_) async => ProcessResult(0, 0, '', '')); | ||
final mockEnv = <String, String>{'SNAP_NAME': 'snap-name'}; | ||
final service = ApportService(runProcess: mockProcess.run, env: mockEnv); | ||
|
||
await service.launch(); | ||
verify(mockProcess.run('ubuntu-bug', ['snap-name'])).called(1); | ||
}); | ||
|
||
test('pre commands', () async { | ||
final mockProcess = MockProcess(); | ||
when(mockProcess.run(any, any)) | ||
.thenAnswer((_) async => ProcessResult(0, 0, '', '')); | ||
final mockEnv = <String, String>{'SNAP_NAME': 'snap-name'}; | ||
final service = ApportService( | ||
runProcess: mockProcess.run, | ||
env: mockEnv, | ||
preCommands: [ | ||
(cmd: 'echo', args: ['foo']), | ||
], | ||
); | ||
|
||
await service.launch(); | ||
verify(mockProcess.run('echo', ['foo'])).called(1); | ||
}); | ||
} | ||
|
||
abstract class _Process { | ||
Future<ProcessResult> run(String? executable, List<String>? arguments); | ||
} | ||
|
||
class MockProcess extends Mock implements _Process { | ||
@override | ||
Future<ProcessResult> run(String? executable, List<String>? arguments) => | ||
super.noSuchMethod( | ||
Invocation.method(#run, [executable, arguments]), | ||
returnValue: Future.value(ProcessResult(0, 0, '', '')), | ||
) as Future<ProcessResult>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing purposes this exception is thrown when the language selection page is loaded.