def testFailingJailedCommand(self): with self.assertRaises(subprocess.CalledProcessError): nsjail.run(nsjail_bin='/bin/false', chroot='/chroot', source_dir='/source_dir', command=['/bin/bash'], android_target='target_name')
def build(android_target, variant, nsjail_bin, chroot, dist_dir, build_id, max_cpus): """Builds an Android target on a Busytown build host. Args: android_target: A string with the name of the android target to build. variant: A string with the build variant. nsjail_bin: A string with the path to the nsjail binary. chroot: A string with the path to the chroot of the NsJail sandbox. dist_dir: A string with the path to the Android dist directory. build_id: A string with the Android build identifier. max_cpus: An integer with maximum number of CPUs. Returns: A list of commands that were executed. Each command is a list of strings. """ # All busytown builds run with the root of the # Android source tree as the current directory. source_dir = os.getcwd() command = [ '/src/development/keystone/build_keystone.sh', '%s-%s' % (android_target, variant), '/src', 'make', '-j', 'droid', 'showcommands', 'dist', 'platform_tests' ] return nsjail.run(nsjail_bin=nsjail_bin, chroot=chroot, source_dir=source_dir, command=command, android_target=android_target, dist_dir=dist_dir, build_id=build_id, max_cpus=max_cpus)
def testUserGroupID(self): nsjail.GROUPADD_COMMAND = '/bin/true' nsjail.USERADD_COMMAND = '/bin/true' commands = nsjail.run(nsjail_bin='/bin/true', chroot='/chroot', source_dir='/source_dir', command=['/bin/bash'], android_target='target_name', user_id=os.getuid(), group_id=os.getgid()) self.assertEqual( commands, [[ '/bin/true', 'android-build', '--gid', str(os.getgid()), ], [ '/bin/true', '--gid', 'android-build', '--groups', 'sudo', '--uid', str(os.getuid()), '--create-home', 'android-build' ], [ '/bin/true', '--bindmount', '/source_dir:/src', '--chroot', '/chroot', '--env', 'USER=android-build', '--config', '/nsjail.cfg', '--', '/bin/bash' ]])
def testMinimalParameters(self): commands = nsjail.run(nsjail_bin='/bin/true', chroot='/chroot', source_dir='/source_dir', command=['/bin/bash'], android_target='target_name') self.assertEqual(commands, [[ '/bin/true', '--bindmount', '/source_dir:/src', '--chroot', '/chroot', '--env', 'USER=android-build', '--config', '/nsjail.cfg', '--', '/bin/bash' ]])
def testBuildID(self): commands = nsjail.run(nsjail_bin='/bin/true', chroot='/chroot', source_dir='/source_dir', command=['/bin/bash'], android_target='target_name', build_id='0') self.assertEqual(commands, [[ '/bin/true', '--bindmount', '/source_dir:/src', '--chroot', '/chroot', '--env', 'USER=android-build', '--config', '/nsjail.cfg', '--env', 'BUILD_NUMBER=0', '--', '/bin/bash' ]])