Unverified Commit 75c853c8 authored by omerlevran46's avatar omerlevran46 Committed by GitHub

[fuchsia] - update getting local host address logic (#75981)

parent 894fdea8
...@@ -68,12 +68,9 @@ class FuchsiaDevFinder { ...@@ -68,12 +68,9 @@ class FuchsiaDevFinder {
/// Returns the address of the named device. /// Returns the address of the named device.
/// ///
/// If local is true, then gives the address by which the device reaches the
/// host.
///
/// The string [deviceName] should be the name of the device from the /// The string [deviceName] should be the name of the device from the
/// 'list' command, e.g. 'scare-cable-skip-joy'. /// 'list' command, e.g. 'scare-cable-skip-joy'.
Future<String> resolve(String deviceName, {bool local = false}) async { Future<String> resolve(String deviceName) async {
if (_fuchsiaArtifacts.devFinder == null || if (_fuchsiaArtifacts.devFinder == null ||
!_fuchsiaArtifacts.devFinder.existsSync()) { !_fuchsiaArtifacts.devFinder.existsSync()) {
throwToolExit('Fuchsia device-finder tool not found.'); throwToolExit('Fuchsia device-finder tool not found.');
...@@ -81,7 +78,6 @@ class FuchsiaDevFinder { ...@@ -81,7 +78,6 @@ class FuchsiaDevFinder {
final List<String> command = <String>[ final List<String> command = <String>[
_fuchsiaArtifacts.devFinder.path, _fuchsiaArtifacts.devFinder.path,
'resolve', 'resolve',
if (local) '-local',
'-device-limit', '1', '-device-limit', '1',
deviceName, deviceName,
]; ];
......
...@@ -211,7 +211,6 @@ class FuchsiaDevices extends PollingDeviceDiscovery { ...@@ -211,7 +211,6 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
final String name = words[1]; final String name = words[1];
final String resolvedHost = await _fuchsiaSdk.fuchsiaDevFinder.resolve( final String resolvedHost = await _fuchsiaSdk.fuchsiaDevFinder.resolve(
name, name,
local: false,
); );
if (resolvedHost == null) { if (resolvedHost == null) {
_logger.printError('Failed to resolve host for Fuchsia device `$name`'); _logger.printError('Failed to resolve host for Fuchsia device `$name`');
...@@ -297,14 +296,7 @@ class FuchsiaDevice extends Device { ...@@ -297,14 +296,7 @@ class FuchsiaDevice extends Device {
} }
// Stop the app if it's currently running. // Stop the app if it's currently running.
await stopApp(package); await stopApp(package);
final String host = await fuchsiaSdk.fuchsiaDevFinder.resolve( final String host = await hostAddress;
name,
local: true,
);
if (host == null) {
globals.printError('Failed to resolve host for Fuchsia device');
return LaunchResult.failed();
}
// Find out who the device thinks we are. // Find out who the device thinks we are.
final int port = await globals.os.findFreePort(); final int port = await globals.os.findFreePort();
if (port == 0) { if (port == 0) {
......
...@@ -876,16 +876,17 @@ void main() { ...@@ -876,16 +876,17 @@ void main() {
FakeOperatingSystemUtils osUtils; FakeOperatingSystemUtils osUtils;
FakeFuchsiaDeviceTools fuchsiaDeviceTools; FakeFuchsiaDeviceTools fuchsiaDeviceTools;
MockFuchsiaSdk fuchsiaSdk; MockFuchsiaSdk fuchsiaSdk;
MockFuchsiaArtifacts fuchsiaArtifacts;
Artifacts artifacts; Artifacts artifacts;
FakeProcessManager fakeSuccessfulProcessManager;
FakeProcessManager fakeFailedProcessManager;
File sshConfig;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
osUtils = FakeOperatingSystemUtils(); osUtils = FakeOperatingSystemUtils();
fuchsiaDeviceTools = FakeFuchsiaDeviceTools(); fuchsiaDeviceTools = FakeFuchsiaDeviceTools();
fuchsiaSdk = MockFuchsiaSdk(); fuchsiaSdk = MockFuchsiaSdk();
fuchsiaArtifacts = MockFuchsiaArtifacts(); sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n');
artifacts = Artifacts.test(); artifacts = Artifacts.test();
for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) { for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) {
memoryFileSystem.file( memoryFileSystem.file(
...@@ -908,6 +909,20 @@ void main() { ...@@ -908,6 +909,20 @@ void main() {
platform: TargetPlatform.fuchsia_arm64, mode: mode), platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync(); ).createSync();
} }
fakeSuccessfulProcessManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]);
fakeFailedProcessManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: '',
stderr: '',
exitCode: 1,
),
]);
}); });
Future<LaunchResult> setupAndStartApp({ Future<LaunchResult> setupAndStartApp({
...@@ -949,9 +964,9 @@ void main() { ...@@ -949,9 +964,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -976,9 +991,9 @@ void main() { ...@@ -976,9 +991,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -991,9 +1006,9 @@ void main() { ...@@ -991,9 +1006,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1006,9 +1021,23 @@ void main() { ...@@ -1006,9 +1021,23 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'Artifact.genSnapshot.TargetPlatform.fuchsia_arm64.release',
'--deterministic',
'--snapshot_kind=app-aot-elf',
'--elf=build/fuchsia/elf.aotsnapshot',
'build/fuchsia/app_name.dil'
],
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]),
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1021,25 +1050,37 @@ void main() { ...@@ -1021,25 +1050,37 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
testUsingContext('fail with correct LaunchResult when device-finder fails', () async { testUsingContext('fail when cant get ssh config', () async {
final LaunchResult launchResult = expect(() async =>
await setupAndStartApp(prebuilt: true, mode: BuildMode.release); await setupAndStartApp(prebuilt: true, mode: BuildMode.release),
expect(launchResult.started, isFalse); throwsToolExit(message: 'Cannot interact with device. No ssh config.\n'
expect(launchResult.hasObservatory, isFalse); 'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: null),
FuchsiaSdk: () => MockFuchsiaSdk(devFinder: FailingDevFinder()), OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail when cant get host address', () async {
expect(() async =>
await setupAndStartApp(prebuilt: true, mode: BuildMode.release),
throwsToolExit(message: 'Failed to get local address, aborting.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeFailedProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1051,9 +1092,9 @@ void main() { ...@@ -1051,9 +1092,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => MockFuchsiaSdk(pm: FailingPM()), FuchsiaSdk: () => MockFuchsiaSdk(pm: FailingPM()),
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1066,9 +1107,9 @@ void main() { ...@@ -1066,9 +1107,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(amber: FailingAmberCtl()), FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(amber: FailingAmberCtl()),
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1081,9 +1122,9 @@ void main() { ...@@ -1081,9 +1122,9 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => artifacts, Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(tiles: FailingTilesCtl()), FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(tiles: FailingTilesCtl()),
FuchsiaArtifacts: () => fuchsiaArtifacts, FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk, FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -1548,23 +1589,11 @@ class FakeFuchsiaDevFinder implements FuchsiaDevFinder { ...@@ -1548,23 +1589,11 @@ class FakeFuchsiaDevFinder implements FuchsiaDevFinder {
} }
@override @override
Future<String> resolve(String deviceName, {bool local = false}) async { Future<String> resolve(String deviceName) async {
return '192.168.42.10'; return '192.168.42.10';
} }
} }
class FailingDevFinder implements FuchsiaDevFinder {
@override
Future<List<String>> list({ Duration timeout }) async {
return null;
}
@override
Future<String> resolve(String deviceName, {bool local = false}) async {
return null;
}
}
class MockFuchsiaSdk extends Mock implements FuchsiaSdk { class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
MockFuchsiaSdk({ MockFuchsiaSdk({
FuchsiaPM pm, FuchsiaPM pm,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment