Ejemplo n.º 1
0
 def testCreateInsideFails(self):
     """Test Create raises an error when called inside the chroot."""
     # Make sure it fails inside the chroot.
     self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True)
     arguments = sdk.CreateArguments()
     with self.assertRaises(cros_build_lib.DieSystemExit):
         sdk.Create(arguments)
Ejemplo n.º 2
0
    def testCreate(self):
        """Test the create function builds the command correctly."""
        arguments = sdk.CreateArguments(replace=True)
        arguments.paths.chroot_path = os.path.join(self.tempdir, 'chroot')
        expected_args = ['--arg', '--other', '--with-value', 'value']
        expected_version = 1

        self.PatchObject(arguments, 'GetArgList', return_value=expected_args)
        self.PatchObject(sdk,
                         'GetChrootVersion',
                         return_value=expected_version)
        self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=False)

        version = sdk.Create(arguments)

        self.assertCommandContains(expected_args)
        self.assertEqual(expected_version, version)
Ejemplo n.º 3
0
def Create(input_proto, output_proto, config):
    """Chroot creation, includes support for replacing an existing chroot.

  Args:
    input_proto (CreateRequest): The input proto.
    output_proto (CreateResponse): The output proto.
    config (api_config.ApiConfig): The API call config.
  """
    replace = not input_proto.flags.no_replace
    bootstrap = input_proto.flags.bootstrap
    use_image = not input_proto.flags.no_use_image

    chroot_path = input_proto.chroot.path
    cache_dir = input_proto.chroot.cache_dir

    if chroot_path and not os.path.isabs(chroot_path):
        cros_build_lib.Die('The chroot path must be absolute.')

    if config.validate_only:
        return controller.RETURN_CODE_VALID_INPUT

    paths = sdk.ChrootPaths(cache_dir=cache_dir, chroot_path=chroot_path)
    args = sdk.CreateArguments(replace=replace,
                               bootstrap=bootstrap,
                               use_image=use_image,
                               paths=paths)

    version = sdk.Create(args)

    if version:
        output_proto.version.version = version
    else:
        # This should be very rare, if ever used, but worth noting.
        cros_build_lib.Die(
            'No chroot version could be found. There was likely an'
            'error creating the chroot that was not detected.')