예제 #1
0
    def testExecuteDockerNotInstalled(self):
        self.call_mock.side_effect = OSError(errno.ENOENT,
                                             'No such file or directory',
                                             'foo')

        with self.assertRaisesRegex(exceptions.Error, 'not installed'):
            client_lib.Execute(['ps', '-a'])

        self.assertTrue(self.call_mock.called)
    def Run(self, args):
        """Executes the given docker command, after refreshing our credentials.

    Args:
      args: An argparse.Namespace that contains the values for
         the arguments specified in the .Args() method.

    Raises:
      exceptions.ExitCodeNoError: The docker command execution failed.
    """
        if args.account:
            # Since the docker binary invokes `gcloud auth docker-helper` through
            # `docker-credential-gcloud`, it cannot forward the command line
            # arguments. Subsequently, we are unable to set the account (or any
            # flag for that matter) used by `docker-credential-gcloud` with
            # the global `--account` flag.
            log.warning('Docker uses the account from the gcloud config.'
                        'To set the account in the gcloud config, run '
                        '`gcloud config set account <account_name>`.')

        with base.WithLegacyQuota():
            force_refresh = True
            for server in args.server:
                if server not in _DEFAULT_REGISTRIES:
                    log.warning(
                        'Authenticating to a non-default server: {server}.'.
                        format(server=server))
                docker.UpdateDockerCredentials(server, refresh=force_refresh)
                # Only force a refresh for the first server we authorize
                force_refresh = False

            if args.authorize_only:
                # NOTE: We don't know at this point how long the access token we have
                # placed in the docker configuration will last.  More information needs
                # to be exposed from all credential kinds in order for us to have an
                # accurate awareness of lifetime here.
                log.err.Print(
                    'Short-lived access for {server} configured.'.format(
                        server=args.server))
                return

            docker_args = args.docker_args or []
            docker_args = (docker_args if not args.docker_host else
                           ['-H', args.docker_host] + docker_args)

            result = docker_client_utils.Execute(docker_args)
            # Explicitly avoid displaying an error message that might
            # distract from the docker error message already displayed.
            if result:
                raise exceptions.ExitCodeNoError(exit_code=result)
            return
예제 #3
0
    def Run(self, args):
        """Executes the given docker command, after refreshing our credentials.

    Args:
      args: An argparse.Namespace that contains the values for
         the arguments specified in the .Args() method.

    Raises:
      exceptions.ExitCodeNoError: The docker command execution failed.
    """
        base.DisableUserProjectQuota()
        force_refresh = True
        for server in args.server:
            if server not in _DEFAULT_REGISTRIES:
                log.warning(
                    'Authenticating to a non-default server: {server}.'.format(
                        server=server))
            docker.UpdateDockerCredentials(server, refresh=force_refresh)
            # Only force a refresh for the first server we authorize
            force_refresh = False

        if args.authorize_only:
            # NOTE: We don't know at this point how long the access token we have
            # placed in the docker configuration will last.  More information needs
            # to be exposed from all credential kinds in order for us to have an
            # accurate awareness of lifetime here.
            log.err.Print('Short-lived access for {server} configured.'.format(
                server=args.server))
            return

        docker_args = args.docker_args or []
        docker_args = (docker_args if not args.docker_host else
                       ['-H', args.docker_host] + docker_args)

        result = docker_client_utils.Execute(docker_args)
        # Explicitly avoid displaying an error message that might
        # distract from the docker error message already displayed.
        if result:
            raise exceptions.ExitCodeNoError(exit_code=result)
        return
예제 #4
0
 def testExecuteSuccess(self):
     self.call_mock.return_value = 1
     result = client_lib.Execute(['help'])
     self.assertTrue(self.call_mock.called)
     self.assertEqual(result, 1)