Esempio n. 1
0
    def display(self, json_path):
        """Display a generated JSON in the web UI"""
        # Start the web server.

        data_path = os.path.dirname(json_path)
        report_name = os.path.basename(json_path)

        self._web_server_thread = web_app.WebServer(port=self.cfg.ui_port,
                                                    data_path=data_path,
                                                    report_name=report_name)

        self._web_server_thread.start()
        wait(
            self._web_server_thread.ready,
            self.cfg.web_server_startup_timeout,
            raise_on_timeout=True,
        )

        (host, port) = self._web_server_thread.server.bind_addr
        self._report_url = "http://localhost:{}/testplan/local".format(port)

        self.logger.exporter_info(
            "View the JSON report in the browser:\n%s",
            networking.format_access_urls(host, port, "/testplan/local"),
        )
Esempio n. 2
0
    def export(self, source):
        """Serve the web UI locally for our test report."""
        if self.cfg.ui_port is None:
            raise ValueError('`ui_port` cannot be None.')

        if not len(source):
            self.logger.exporter_info('Skipping starting web server'
                                      ' for empty report: {}'.format(
                                          source.name))
            return

        if not self._ui_installed:
            self.logger.warning(
                'Cannot display web UI for report locally since the Testplan '
                'UI is not installed.\n'
                'Install the UI by running `install-testplan-ui`')
            return

        test_plan_schema = TestReportSchema(strict=True)
        data = test_plan_schema.dump(source).data

        # Save the Testplan report as a JSON.
        with open(defaults.JSON_PATH, 'w') as json_file:
            json.dump(data, json_file)

        # Save any attachments.
        data_path = os.path.dirname(defaults.JSON_PATH)
        report_name = os.path.basename(defaults.JSON_PATH)
        attachments_dir = os.path.join(data_path, defaults.ATTACHMENTS)
        save_attachments(report=source, directory=attachments_dir)

        self.logger.exporter_info('JSON generated at {}'.format(
            defaults.JSON_PATH))

        # Start the web server.
        self._web_server_thread = web_app.WebServer(port=self.cfg.ui_port,
                                                    data_path=data_path,
                                                    report_name=report_name)

        self._web_server_thread.start()
        wait(self._web_server_thread.ready,
             self.cfg.web_server_startup_timeout,
             raise_on_timeout=True)

        (host, port) = self._web_server_thread.server.bind_addr

        # Check for an IPv6 address. Web browsers require IPv6 addresses to be
        # enclosed in [].
        try:
            if ipaddress.ip_address(host).version == 6:
                host = '[{}]'.format(host)
        except ValueError:
            # Expected if the host is a host name instead of an IP address.
            pass

        self.url = 'http://{host}:{port}/testplan/local'.format(host=host,
                                                                port=port)
        self.logger.exporter_info(
            'View the JSON report in the browser: {}'.format(self.url))
Esempio n. 3
0
    def export(self, source):
        """Serve the web UI locally for our test report."""
        if not len(source):
            self.logger.exporter_info(
                'Skipping starting web server for '
                'empty report: %s', source.name)
            return

        if not self._ui_installed:
            self.logger.warning(
                'Cannot display web UI for report locally since the Testplan '
                'UI is not installed.\n'
                'Install the UI by running `install-testplan-ui`')
            return

        test_plan_schema = TestReportSchema(strict=True)
        data = test_plan_schema.dump(source).data

        # Save the Testplan report as a JSON.
        with open(defaults.JSON_PATH, 'w') as json_file:
            json.dump(data, json_file)

        # Save any attachments.
        data_path = os.path.dirname(defaults.JSON_PATH)
        report_name = os.path.basename(defaults.JSON_PATH)
        attachments_dir = os.path.join(data_path, defaults.ATTACHMENTS)
        save_attachments(report=source, directory=attachments_dir)

        self.logger.exporter_info('JSON generated at %s', defaults.JSON_PATH)

        # Start the web server.
        self._web_server_thread = web_app.WebServer(port=self.cfg.ui_port,
                                                    data_path=data_path,
                                                    report_name=report_name)

        self._web_server_thread.start()
        wait(self._web_server_thread.ready,
             self.cfg.web_server_startup_timeout,
             raise_on_timeout=True)

        (host, port) = self._web_server_thread.server.bind_addr

        # Check if we are bound to the special (and default) 0.0.0.0 address -
        # in that case, the UI can be accessed both from localhost or from
        # any IP address this machine listens on.
        if host == "0.0.0.0":
            local_url = 'http://localhost:{}/testplan/local'.format(port)

            try:
                local_ip = socket.gethostbyname(socket.getfqdn())
                network_url = 'http://{host}:{port}/testplan/local'.format(
                    host=local_ip, port=port)
                self.logger.exporter_info(
                    'View the JSON report in the browser:\n\n'
                    '    Local: %(local)s\n'
                    '    On Your Network: %(network)s', {
                        'local': local_url,
                        'network': network_url
                    })
            except socket.gaierror:
                self.logger.exporter_info(
                    'View the JSON report in the browser: %s', local_url)
        else:
            # Check for an IPv6 address. Web browsers require IPv6 addresses
            # to be enclosed in [].
            try:
                if ipaddress.ip_address(host).version == 6:
                    host = '[{}]'.format(host)
            except ValueError:
                # Expected if the host is a host name instead of an IP address.
                pass

            url = 'http://{host}:{port}/testplan/local'.format(host=host,
                                                               port=port)
            self.logger.exporter_info(
                'View the JSON report in the browser: %s', url)