def add_keys_to_zbi(fuchsia_resources_dir, initrd_path, fuchsia_zbi): """Adds keys to the ZBI so we can SSH into it. See: fuchsia.googlesource.com/fuchsia/+/refs/heads/master/sdk/docs/ssh.md""" zbi_tool = os.path.join(fuchsia_resources_dir, 'build', 'out', 'default.zircon', 'tools', 'zbi') os.chmod(zbi_tool, 0o500) authorized_keys_path = os.path.join(fuchsia_resources_dir, '.ssh', 'authorized_keys') process = new_process.ProcessRunner(zbi_tool, [ '-o', initrd_path, fuchsia_zbi, '-e', 'data/ssh/authorized_keys=' + authorized_keys_path ]) result = process.run_and_wait() if result.return_code or result.timed_out: raise errors.FuchsiaSdkError('Failed to add keys to Fuchsia ZBI: ' + result.output) os.chmod(initrd_path, 0o644)
def initialize_resources_dir(): """Download Fuchsia QEMU resources from GCS bucket.""" # This module depends on multiprocessing, which is not available in # appengine, and since appengine *imports* this file (but does not run this # function!), we import it here. from google_cloud_utils import gsutil resources_dir = environment.get_value('RESOURCES_DIR') if not resources_dir: raise errors.FuchsiaConfigError('Could not find RESOURCES_DIR') fuchsia_resources_dir = os.path.join(resources_dir, 'fuchsia') shell.create_directory(fuchsia_resources_dir, create_intermediates=True, recreate=True) # Bucket for QEMU resources. fuchsia_resources_url = environment.get_value('FUCHSIA_BUILD_URL') if not fuchsia_resources_url: raise errors.FuchsiaConfigError( 'Could not find path for remote' 'Fuchsia resources bucket (FUCHSIA_BUILD_URL') gsutil_command_arguments = [ '-m', 'cp', '-r', fuchsia_resources_url, fuchsia_resources_dir ] logs.log("Fetching Fuchsia build.") result = gsutil.GSUtilRunner().run_gsutil(gsutil_command_arguments) if result.return_code or result.timed_out: raise errors.FuchsiaSdkError('Failed to download Fuchsia ' 'resources: ' + result.output) # Chmod the symbolizers so they can be used easily. symbolizer_path = os.path.join(fuchsia_resources_dir, 'build', 'zircon', 'prebuilt', 'downloads', 'symbolize', 'linux-x64', 'symbolize') llvm_symbolizer_path = os.path.join(fuchsia_resources_dir, 'build', 'buildtools', 'linux-x64', 'clang', 'bin', 'llvm-symbolizer') os.chmod(symbolizer_path, 0o111) os.chmod(llvm_symbolizer_path, 0o111) logs.log("Fuchsia build download complete.") return fuchsia_resources_dir
def extend_fvm(fuchsia_resources_dir, orig_drive_path, drive_path): """The FVM is minimally sized to begin with; make an extended copy of it to make room for ephemeral packages etc.""" fvm_tool_path = os.path.join(fuchsia_resources_dir, 'build', 'out', 'default.zircon', 'tools', 'fvm') os.chmod(fvm_tool_path, 0o500) # Since the fvm tool modifies the image in place, make a copy so the build # isn't mutated (required for running undercoat on a cached build previously # affected by this legacy codepath) shutil.copy(orig_drive_path, drive_path) process = new_process.ProcessRunner( fvm_tool_path, [drive_path, 'extend', '--length', '3G']) result = process.run_and_wait() if result.return_code or result.timed_out: raise errors.FuchsiaSdkError('Failed to extend FVM: ' + result.output) os.chmod(drive_path, 0o644)
def add_keys_to_zbi(fuchsia_resources_dir, initrd_path, fuchsia_zbi): """Adds keys to the ZBI so we can SSH into it. See: fuchsia.googlesource.com/fuchsia/+/refs/heads/master/sdk/docs/ssh.md""" zbi_tool = os.path.join(fuchsia_resources_dir, "build", "out", "default.zircon", "tools", "zbi") os.chmod(zbi_tool, 0o500) authorized_keys_path = os.path.join(fuchsia_resources_dir, ".ssh", "authorized_keys") process = new_process.ProcessRunner( zbi_tool, [ "-o", initrd_path, fuchsia_zbi, "-e", "data/ssh/authorized_keys=" + authorized_keys_path, ], ) result = process.run_and_wait() if result.return_code or result.timed_out: raise errors.FuchsiaSdkError("Failed to add keys to Fuchsia ZBI: " + result.output) os.chmod(initrd_path, 0o644)