Пример #1
0
 def _configure_report(self):
     """Configure transport and exporter."""
     if self.ctx.args.output_format == '?':
         print_objs('exporter', self.ctx.sa)
         raise SystemExit(0)
     if self.ctx.args.transport == '?':
         print(', '.join(get_all_transports()))
         raise SystemExit(0)
     if not self.ctx.args.transport:
         if self.ctx.args.transport_where:
             _logger.error(
                 _("--transport-where is useless without --transport"))
             raise SystemExit(1)
         if self.ctx.args.transport_options:
             _logger.error(
                 _("--transport-options is useless without --transport"))
             raise SystemExit(1)
         if self.ctx.args.output_file != '-':
             self.transport = 'file'
             self.transport_where = self.ctx.args.output_file
             self.transport_options = ''
         else:
             self.transport = 'stream'
             self.transport_where = 'stdout'
             self.transport_options = ''
     else:
         if self.ctx.args.transport not in get_all_transports():
             _logger.error("The selected transport %r is not available",
                           self.ctx.args.transport)
             raise SystemExit(1)
         self.transport = self.ctx.args.transport
         self.transport_where = self.ctx.args.transport_where
         self.transport_options = self.ctx.args.transport_options
     self.exporter = self.ctx.args.output_format
     self.exporter_opts = self.ctx.args.output_options
Пример #2
0
 def _prepare_transport(self, ns):
     if ns.transport not in get_all_transports():
         return None
     transport_cls = get_all_transports()[ns.transport]
     try:
         return transport_cls(ns.transport_where, ns.transport_options)
     except ValueError as exc:
         raise SystemExit(str(exc))
Пример #3
0
 def _prepare_transport(self, ns):
     if ns.transport not in get_all_transports():
         return None
     transport_cls = get_all_transports()[ns.transport]
     try:
         return transport_cls(ns.transport_where, ns.transport_options)
     except ValueError as exc:
         raise SystemExit(str(exc))
Пример #4
0
 def _print_results(self):
     all_transports = get_all_transports()
     transport = get_all_transports()[self.transport](
         self.transport_where, self.transport_options)
     print(self.C.header(_("Results")))
     if self.transport == 'file':
         print(_("Saving results to {}").format(self.transport_where))
     elif self.transport == 'certification':
         print(_("Sending results to {}").format(self.transport_where))
     self.sa.export_to_transport(self.exporter, transport,
                                 self.exporter_opts)
Пример #5
0
 def submit_launchpad_results(self):
     transport_cls = get_all_transports().get('launchpad')
     options_string = "field.emailaddress={}".format(
         self.config.email_address)
     transport = transport_cls(self.config.lp_url, options_string)
     # TRANSLATORS: Do not translate the {} format markers.
     print(
         _("Submitting results to {0} for email_address {1}").format(
             self.config.lp_url, self.config.email_address))
     with open(self.submission_file, encoding='utf-8') as stream:
         try:
             # NOTE: don't pass the file-like object to this transport
             json = transport.send(stream.read(),
                                   self.config,
                                   session_state=self.manager.state)
             if json.get('url'):
                 # TRANSLATORS: Do not translate the {} format marker.
                 print(_("Submission uploaded to: {0}".format(json['url'])))
             elif json.get('status'):
                 print(json['status'])
             else:
                 # TRANSLATORS: Do not translate the {} format marker.
                 print(
                     _("Bad response from {0} transport".format(transport)))
         except TransportError as exc:
             print(str(exc))
Пример #6
0
 def submit_certification_results(self):
     from checkbox_ng.certification import InvalidSecureIDError
     transport_cls = get_all_transports().get('certification')
     # TRANSLATORS: Do not translate the {} format markers.
     print(
         _("Submitting results to {0} for secure_id {1}").format(
             self.config.c3_url, self.config.secure_id))
     option_chunks = []
     option_chunks.append("secure_id={0}".format(self.config.secure_id))
     if self.config.submit_to_hexr:
         option_chunks.append("submit_to_hexr=1")
     # Assemble the option string
     options_string = ",".join(option_chunks)
     # Create the transport object
     try:
         transport = transport_cls(self.config.c3_url, options_string)
     except InvalidSecureIDError as exc:
         print(exc)
         return False
     with open(self.submission_file, "r", encoding='utf-8') as stream:
         try:
             # Send the data, reading from the fallback file
             result = transport.send(stream, self.config)
             if 'url' in result:
                 # TRANSLATORS: Do not translate the {} format marker.
                 print(
                     _("Successfully sent, submission status"
                       " at {0}").format(result['url']))
             else:
                 # TRANSLATORS: Do not translate the {} format marker.
                 print(
                     _("Successfully sent, server response"
                       ": {0}").format(result))
         except TransportError as exc:
             print(str(exc))
Пример #7
0
 def _prepare_transports(self):
     self.base_dir = os.path.join(
         os.getenv(
             'XDG_DATA_HOME', os.path.expanduser("~/.local/share/")),
         "checkbox-ng")
     self._available_transports = get_all_transports()
     self.transports = dict()
    def create_transport(self):
        """
        Create the ISessionStateTransport based on the command line options

        This sets the attr:`_transport`.
        """
        if self.ns.transport is None:
            return
        # XXX: perhaps we should be more vocal about it?
        if self.ns.transport not in get_all_transports():
            logger.error("The selected transport %r is not available",
                         self.ns.transport)
            return
        transport_cls = get_all_transports()[self.ns.transport]
        try:
            self._transport = transport_cls(self.ns.transport_where,
                                            self.ns.transport_options)
        except ValueError as exc:
            raise SystemExit(str(exc))
Пример #9
0
 def register_parser(self, subparsers):
     parser = subparsers.add_parser("run", help="run a test job")
     parser.set_defaults(command=self)
     group = parser.add_argument_group(title="user interface options")
     group.add_argument('--not-interactive',
                        action='store_true',
                        help="Skip tests that require interactivity")
     group.add_argument('-n',
                        '--dry-run',
                        action='store_true',
                        help="Don't actually run any jobs")
     group = parser.add_argument_group("output options")
     assert 'text' in get_all_exporters()
     group.add_argument('-f',
                        '--output-format',
                        default='text',
                        metavar='FORMAT',
                        choices=['?'] + list(get_all_exporters().keys()),
                        help=('Save test results in the specified FORMAT'
                              ' (pass ? for a list of choices)'))
     group.add_argument(
         '-p',
         '--output-options',
         default='',
         metavar='OPTIONS',
         help=('Comma-separated list of options for the export mechanism'
               ' (pass ? for a list of choices)'))
     group.add_argument('-o',
                        '--output-file',
                        default='-',
                        metavar='FILE',
                        type=FileType("wb"),
                        help=('Save test results to the specified FILE'
                              ' (or to stdout if FILE is -)'))
     group.add_argument('-t',
                        '--transport',
                        metavar='TRANSPORT',
                        choices=['?'] + list(get_all_transports().keys()),
                        help=('use TRANSPORT to send results somewhere'
                              ' (pass ? for a list of choices)'))
     group.add_argument(
         '--transport-where',
         metavar='WHERE',
         help=('Where to send data using the selected transport.'
               ' This is passed as-is and is transport-dependent.'))
     group.add_argument(
         '--transport-options',
         metavar='OPTIONS',
         help=('Comma-separated list of key-value options (k=v) to '
               ' be passed to the transport.'))
     # Call enhance_parser from CheckBoxCommandMixIn
     self.enhance_parser(parser)
Пример #10
0
 def register_arguments(self, parser):
     parser.add_argument(
         'PATTERN',
         nargs="*",
         help=_("run jobs matching the given regular expression"))
     parser.add_argument('--non-interactive',
                         action='store_true',
                         help=_("skip tests that require interactivity"))
     parser.add_argument('-f',
                         '--output-format',
                         default='com.canonical.plainbox::text',
                         metavar=_('FORMAT'),
                         help=_('save test results in the specified FORMAT'
                                ' (pass ? for a list of choices)'))
     parser.add_argument(
         '-p',
         '--output-options',
         default='',
         metavar=_('OPTIONS'),
         help=_('comma-separated list of options for the export mechanism'
                ' (pass ? for a list of choices)'))
     parser.add_argument(
         '-o',
         '--output-file',
         default='-',
         metavar=_('FILE'),  # type=FileType("wb"),
         help=_('save test results to the specified FILE'
                ' (or to stdout if FILE is -)'))
     parser.add_argument('-t',
                         '--transport',
                         metavar=_('TRANSPORT'),
                         choices=[_('?')] +
                         list(get_all_transports().keys()),
                         help=_('use TRANSPORT to send results somewhere'
                                ' (pass ? for a list of choices)'))
     parser.add_argument(
         '--transport-where',
         metavar=_('WHERE'),
         help=_('where to send data using the selected transport'))
     parser.add_argument(
         '--transport-options',
         metavar=_('OPTIONS'),
         help=_('comma-separated list of key-value options (k=v) to '
                'be passed to the transport'))
     parser.add_argument('--title',
                         action='store',
                         metavar='SESSION_NAME',
                         help=_('title of the session to use'))
     parser.add_argument("-m",
                         "--message",
                         help=_("submission description"))
Пример #11
0
 def send_data_via_transport(self, transport, where, options, data):
     transport_cls = get_all_transports().get(transport)
     if transport is None:
         return "No transport with name '{}' was found".format(transport)
     try:
         transport = transport_cls(where, options)
         json = transport.send(data)
         return "Submission uploaded to: {}".format(json['url'])
     except Timeout as error:
         return "Request to {} timed out: {}".format(where, error)
     except ConnectionError as error:
         return "Unable to connect to {}: {}".format(where, error)
     except HTTPError as error:
         return "HTTP error"
Пример #12
0
 def send_data_via_transport(self, transport, where, options, data):
     transport_cls = get_all_transports().get(transport)
     if transport is None:
         return "No transport with name '{}' was found".format(transport)
     try:
         transport = transport_cls(where, options)
         json = transport.send(data)
         return "Submission uploaded to: {}".format(json['url'])
     except Timeout as error:
         return "Request to {} timed out: {}".format(where, error)
     except ConnectionError as error:
         return "Unable to connect to {}: {}".format(where, error)
     except HTTPError as error:
         return "HTTP error"
Пример #13
0
    def register_parser(self, subparsers):
        parser = subparsers.add_parser("run", help="run a test job")
        parser.set_defaults(command=self)
        group = parser.add_argument_group(title="user interface options")
        group.add_argument(
            '--not-interactive', action='store_true',
            help="Skip tests that require interactivity")
        group.add_argument(
            '-n', '--dry-run', action='store_true',
            help="Don't actually run any jobs")
        group = parser.add_argument_group("output options")
        assert 'text' in get_all_exporters()
        group.add_argument(
            '-f', '--output-format', default='text',
            metavar='FORMAT', choices=['?'] + list(
                get_all_exporters().keys()),
            help=('Save test results in the specified FORMAT'
                  ' (pass ? for a list of choices)'))
        group.add_argument(
            '-p', '--output-options', default='',
            metavar='OPTIONS',
            help=('Comma-separated list of options for the export mechanism'
                  ' (pass ? for a list of choices)'))
        group.add_argument(
            '-o', '--output-file', default='-',
            metavar='FILE', type=FileType("wb"),
            help=('Save test results to the specified FILE'
                  ' (or to stdout if FILE is -)'))
        group.add_argument(
            '-t', '--transport',
            metavar='TRANSPORT', choices=['?'] + list(
                get_all_transports().keys()),
            help=('use TRANSPORT to send results somewhere'
                  ' (pass ? for a list of choices)'))
        group.add_argument(
            '--transport-where',
            metavar='WHERE',
            help=('Where to send data using the selected transport.'
                  ' This is passed as-is and is transport-dependent.'))
        group.add_argument(
            '--transport-options',
            metavar='OPTIONS',
            help=('Comma-separated list of key-value options (k=v) to '
                  ' be passed to the transport.'))

        # Call enhance_parser from CheckBoxCommandMixIn
        self.enhance_parser(parser)
Пример #14
0
 def get_all_transports(self):
     return [transport for transport in get_all_transports()]
 def _print_transport_list(self, ns):
     print(
         _("Available transports: {}").format(', '.join(
             get_all_transports())))
Пример #16
0
class LauncherDefinitionLegacy(LauncherDefinition):
    """
    Launcher definition class for 'unversioned' launchers.

    This definition is used for launchers that do not specify
    'launcher_version' in their [launcher] section.
    """

    api_flags = config.Variable(
        section='launcher',
        kind=list,
        default=[],
        help_text=_('List of feature-flags the application requires'))

    api_version = config.Variable(
        section='launcher',
        default='0.99',
        help_text=_('Version of API the launcher uses'))

    title = config.Variable(
        section="welcome",
        help_text=_("Application Title"))

    text = config.Variable(
        section="welcome",
        help_text=_("Welcome Message"))

    dont_suppress_output = config.Variable(
        section="ui", kind=bool, default=False,
        help_text=_("Don't suppress the output of certain job plugin types."))

    whitelist_filter = config.Variable(
        section="suite",
        # TODO: valid regexp text validator
        help_text=_("Pattern that whitelists need to match to be displayed"))

    whitelist_selection = config.Variable(
        section="suite",
        # TODO: valid regexp text validator
        help_text=_("Pattern that whitelists need to match to be selected"))

    skip_whitelist_selection = config.Variable(
        section="suite",
        kind=bool,
        default=False,
        help_text=_("If enabled then suite selection screen is not displayed"))

    skip_test_selection = config.Variable(
        section="suite",
        kind=bool,
        default=False,
        help_text=_("If enabled then test selection screen is not displayed"))

    input_type = config.Variable(
        section="submission",
        # TODO: probably a choice validator
        help_text=_("Type of the input field?"))

    ok_btn_text = config.Variable(
        section="submission",
        help_text=_("Label on the 'send' button"))

    submit_to_hexr = config.Variable(
        section="submission",
        kind=bool,
        # TODO: default?
        help_text=_("If enabled then test results will be also sent to HEXR"))

    submit_to = config.Variable(
        section="transport",
        validator_list=[config.ChoiceValidator(get_all_transports().keys())],
        help_text=_("Where to submit the test results to"))

    # TODO: Add a validator to ensure it looks like a valid URL
    submit_url = config.Variable(
        section="transport",
        help_text=_("HTTP endpoint to submit data to, using the"
                    " transport specified with submit_to."))

    secure_id = config.Variable(
        section="submission",
        validator_list=[config.PatternValidator(SECURE_ID_PATTERN)],
        help_text=_("Secure ID to identify the system this"
                    " submission belongs to."))

    exporter = config.Section(
        help_text=_("Section with only exported unit ids as keys (no values)"))
 def register_parser(self, subparsers):
     parser = subparsers.add_parser("run",
                                    help=_("run a test job"),
                                    prog="plainbox run")
     parser.set_defaults(command=self)
     group = parser.add_argument_group(title=_("user interface options"))
     parser.set_defaults(color=None)
     group.add_argument('--no-color',
                        dest='color',
                        action='store_false',
                        help=SUPPRESS)
     group.add_argument('--non-interactive',
                        action='store_true',
                        help=_("skip tests that require interactivity"))
     group.add_argument('-n',
                        '--dry-run',
                        action='store_true',
                        help=_("don't really run most jobs"))
     group.add_argument(
         '--dont-suppress-output',
         action="store_true",
         default=False,
         help=_("don't suppress the output of certain job plugin types"))
     group = parser.add_argument_group(_("output options"))
     group.add_argument('-f',
                        '--output-format',
                        default='com.canonical.plainbox::text',
                        metavar=_('FORMAT'),
                        help=_('save test results in the specified FORMAT'
                               ' (pass ? for a list of choices)'))
     group.add_argument(
         '-p',
         '--output-options',
         default='',
         metavar=_('OPTIONS'),
         help=_('comma-separated list of options for the export mechanism'
                ' (pass ? for a list of choices)'))
     group.add_argument('-o',
                        '--output-file',
                        default='-',
                        metavar=_('FILE'),
                        type=FileType("wb"),
                        help=_('save test results to the specified FILE'
                               ' (or to stdout if FILE is -)'))
     group.add_argument('-t',
                        '--transport',
                        metavar=_('TRANSPORT'),
                        choices=[_('?')] +
                        list(get_all_transports().keys()),
                        help=_('use TRANSPORT to send results somewhere'
                               ' (pass ? for a list of choices)'))
     group.add_argument(
         '--transport-where',
         metavar=_('WHERE'),
         help=_('where to send data using the selected transport'))
     group.add_argument(
         '--transport-options',
         metavar=_('OPTIONS'),
         help=_('comma-separated list of key-value options (k=v) to '
                'be passed to the transport'))
     # Call enhance_parser from CheckBoxCommandMixIn
     self.enhance_parser(parser)
Пример #18
0
class LauncherDefinition(config.Config):
    """
    Launcher definition.

    Launchers are small executables using one of the available user interfaces
    as the interpreter. This class contains all the available options that can
    be set inside the launcher, that will affect the user interface at runtime.
    """

    title = config.Variable(section="welcome",
                            help_text=_("Application Title"))

    text = config.Variable(section="welcome", help_text=_("Welcome Message"))

    whitelist_filter = config.Variable(
        section="suite",
        # TODO: valid regexp text validator
        help_text=_("Pattern that whitelists need to match to be displayed"))

    whitelist_selection = config.Variable(
        section="suite",
        # TODO: valid regexp text validator
        help_text=_("Pattern that whitelists need to match to be selected"))

    skip_whitelist_selection = config.Variable(
        section="suite",
        kind=bool,
        default=False,
        help_text=_("If enabled then suite selection screen is not displayed"))

    skip_test_selection = config.Variable(
        section="suite",
        kind=bool,
        default=False,
        help_text=_("If enabled then test selection screen is not displayed"))

    input_type = config.Variable(
        section="submission",
        # TODO: probably a choice validator
        help_text=_("Type of the input field?"))

    ok_btn_text = config.Variable(section="submission",
                                  help_text=_("Label on the 'send' button"))

    submit_to_hexr = config.Variable(
        section="submission",
        kind=bool,
        # TODO: default?
        help_text=_("If enabled then test results will be also sent to HEXR"))

    submit_to = config.Variable(
        section="transport",
        validator_list=[config.ChoiceValidator(get_all_transports().keys())],
        help_text=_("Where to submit the test results to"))

    # TODO: Add a validator to ensure it looks like a valid URL
    submit_url = config.Variable(
        section="transport",
        help_text=_("HTTP endpoint to submit data to, using the"
                    " transport specified with submit_to."))

    secure_id = config.Variable(
        section="submission",
        validator_list=[config.PatternValidator(SECURE_ID_PATTERN)],
        help_text=_("Secure ID to identify the system this"
                    " submission belongs to."))

    config_filename = config.Variable(
        section="config", help_text=_("Name of custom configuration file"))

    dont_suppress_output = config.Variable(
        section="ui",
        kind=bool,
        default=False,
        help_text=_("Don't suppress the output of certain job plugin types."))

    exporter = config.Section(
        help_text=_("Section with only exported unit ids as keys (no values)"))
Пример #19
0
 def _print_transport_list(self, ns):
     print("Available transports: {}".format(
         ', '.join(get_all_transports())))
Пример #20
0
 def _prepare_transports(self):
     self._available_transports = get_all_transports()
     self.transports = dict()
Пример #21
0
 def get_all_transports(self):
     return [transport for transport in get_all_transports()]