Beispiel #1
0
class UPnPServer:

    """This class implements an extensible UPnP Server."""

    def __init__(self, task_runner, product_name,
                 root_device_config=None, logger=None):
        
        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)
        
        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr, self._ssdp_server,
                                  self._http_server, self._ed, device,
                                  product_name, logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids
        
        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)

    def get_presentation_url(self):
        root = self.get_root_device()
        return root.base_url + root.get_presentation_url()

    def announce(self):
        """Causes underlying SSDPServer to re-announce itself."""
        self._tr.add_task(self._ssdp_server.announce)

    def close(self):
        """Close the UPnP server."""
        self._sm.close()
        self._ssdp_server.close()
        self._http_server.close()
        self._ed.close()
Beispiel #2
0
class GracieServer(object):
    """ Server for Gracie OpenID provider service """
    def __init__(self, socket_params, opts):
        """ Set up a new instance """
        self.version = __version__
        self.opts = opts
        self._setup_logging()
        server_address = (opts.host, opts.port)
        self.httpserver = HTTPServer(server_address, HTTPRequestHandler, self)
        self._setup_openid()
        self.auth_service = AuthService()
        self.sess_manager = SessionManager()
        self.consumer_auth_store = ConsumerAuthStore()

    def _setup_openid(self):
        """ Set up OpenID parameters """
        store = OpenIDStore(self.opts.datadir)
        self.openid_server = OpenIDServer(store)

    def __del__(self):
        _logger.info("Exiting Gracie server")

    def _setup_logging(self):
        """ Set up logging for this server """
        server_version = self.version
        _logger.info("Starting Gracie server (version %(server_version)s)" %
                     vars())

    def serve_forever(self):
        """ Begin serving requests indefinitely """
        self.httpserver.serve_forever()
Beispiel #3
0
class UPnPServer:

    """This class implements an extensible UPnP Server."""

    def __init__(self, task_runner, product_name,
                 root_device_config=None, logger=None):
        
        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)
        
        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr, self._ssdp_server,
                                  self._http_server, self._ed, device,
                                  product_name, logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids
        
        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)

    def get_presentation_url(self):
        root = self.get_root_device()
        return root.base_url + root.get_presentation_url()

    def announce(self):
        """Causes underlying SSDPServer to re-announce itself."""
        self._tr.add_task(self._ssdp_server.announce)

    def close(self):
        """Close the UPnP server."""
        self._sm.close()
        self._ssdp_server.close()
        self._http_server.close()
        self._ed.close()
Beispiel #4
0
    def setUp(self):
        # Start the server in a thread
        self.server = HTTPServer(SERVER_HOST, SERVER_PORT)
        self.server_thread = threading.Thread(target=self.server.start)
        self.server_thread.start()

        # Defines the base url
        self.url = 'http://127.0.0.1:8000/'
Beispiel #5
0
 def __init__(self, socket_params, opts):
     """ Set up a new instance """
     self.version = __version__
     self.opts = opts
     self._setup_logging()
     server_address = (opts.host, opts.port)
     self.httpserver = HTTPServer(server_address, HTTPRequestHandler, self)
     self._setup_openid()
     self.auth_service = AuthService()
     self.sess_manager = SessionManager()
     self.consumer_auth_store = ConsumerAuthStore()
Beispiel #6
0
    def __init__(self,
                 task_runner,
                 product_name,
                 root_device_config=None,
                 logger=None):

        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)

        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr,
                                  self._ssdp_server,
                                  self._http_server,
                                  self._ed,
                                  device,
                                  product_name,
                                  logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids

        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)
Beispiel #7
0
class TestBase(unittest.TestCase):
    """Base for all tests."""
    def setUp(self):
        # Start the server in a thread
        self.server = HTTPServer(SERVER_HOST, SERVER_PORT)
        self.server_thread = threading.Thread(target=self.server.start)
        self.server_thread.start()

        # Defines the base url
        self.url = 'http://127.0.0.1:8000/'

    def tearDown(self):
        # Stops the server thread
        self.server.stop()
        self.server_thread.join()
        time.sleep(0.1)
Beispiel #8
0
 def __init__(self, socket_params, opts):
     """ Set up a new instance """
     self.version = __version__
     self.opts = opts
     self._setup_logging()
     server_address = (opts.host, opts.port)
     self.httpserver = HTTPServer(
         server_address, HTTPRequestHandler, self
         )
     self._setup_openid()
     self.auth_service = AuthService()
     self.sess_manager = SessionManager()
     self.consumer_auth_store = ConsumerAuthStore()
Beispiel #9
0
class GracieServer(object):
    """ Server for Gracie OpenID provider service """

    def __init__(self, socket_params, opts):
        """ Set up a new instance """
        self.version = __version__
        self.opts = opts
        self._setup_logging()
        server_address = (opts.host, opts.port)
        self.httpserver = HTTPServer(
            server_address, HTTPRequestHandler, self
            )
        self._setup_openid()
        self.auth_service = AuthService()
        self.sess_manager = SessionManager()
        self.consumer_auth_store = ConsumerAuthStore()

    def _setup_openid(self):
        """ Set up OpenID parameters """
        store = OpenIDStore(self.opts.datadir)
        self.openid_server = OpenIDServer(store)

    def __del__(self):
        _logger.info("Exiting Gracie server")

    def _setup_logging(self):
        """ Set up logging for this server """
        server_version = self.version
        _logger.info(
            "Starting Gracie server (version %(server_version)s)"
            % vars()
            )

    def serve_forever(self):
        """ Begin serving requests indefinitely """
        self.httpserver.serve_forever()
Beispiel #10
0
    def __init__(self, task_runner, product_name,
                 root_device_config=None, logger=None):
        
        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)
        
        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr, self._ssdp_server,
                                  self._http_server, self._ed, device,
                                  product_name, logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids
        
        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)
Beispiel #11
0
    if os.path.commonprefix([www_dir_path, requested_file_path
                             ]) != www_dir_path:
        # bad address
        return HTTPResponder.generate_HTTP_response(404, "Not found")

    if not os.path.isfile(requested_file_path):
        # check if directory
        if os.path.isdir(requested_file_path):
            return fetch_page(os.path.join(path, "index.html"))

        # file not found
        return HTTPResponder.generate_HTTP_response(404, "Not found")

    log("File accessed: {}".format(path))
    with open(requested_file_path, "rb") as file:
        content_type, encoding = mimetypes.guess_type(requested_file_path)
        return HTTPResponder.generate_HTTP_response(
            200, file.read(), {
                "Content-Type": content_type,
                "Content-Encoding": encoding
            })


routes = (HTTPRoute(r"^/socket$", type="websocket"),
          HTTPRoute(
              r"^/.*$",
              content_handler=lambda content: fetch_page(content["path"][1:])))

with HTTPServer(HOST, PORT, routes) as server:
    server.start()
Beispiel #12
0
# An example showing the use of HTTPServer
# If you pass a folder location, it serves that directory
# Or serves the current working directory

import sys

# Import httpserver in the python import path
sys.path.insert(0, "./httpserver")

from httpserver import HTTPServer

if __name__ == '__main__':

    # Check if a directory is passed from the command line
    try:
        directory = sys.argv[1]
    except IndexError:
        directory = None

    httpserver = HTTPServer('127.0.0.1', 8000, directory=directory)
    httpserver.start()
    httpserver.run()

Beispiel #13
0
def main(libsdir):
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        prog='gst-validate-launcher', description=HELP)
    parser.add_argument('testsuites', metavar='N', nargs='*',
                        help="""Lets you specify a file where the testsuite to execute is defined.

In the module if you want to work with a specific test manager(s) (for example,
'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names)

In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This
function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is
avalaible. You should configure it using:

   * test_manager.add_scenarios: which allows you to register a list of scenario names to be run
   * test_manager.set_default_blacklist: Lets you set a list of tuple of the form:
         (@regex_defining_blacklister_test_names, @reason_for_the_blacklisting)
   * test_manager.add_generators: which allows you to register a list of #GstValidateTestsGenerator
     to be used to generate tests
   * test_manager.add_encoding_formats:: which allows you to register a list #MediaFormatCombination to be used for transcoding tests

You can also set default values with:
    * test_manager.register_defaults: Sets default values for all parametters
    * test_manager.register_default_test_generators: Sets default values for the TestsGenerators to be used
    * test_manager.register_default_scenarios: Sets default values for the scenarios to be executed
    * test_manager.register_default_encoding_formats: Sets default values for the encoding formats to be tested

Note that all testsuite should be inside python modules, so the directory should contain a __init__.py file
""",
                        default=["validate", "ges"])
    parser.add_argument("-d", "--debug", dest="debug",
                        action="store_true",
                        help="Let user debug the process on timeout")
    parser.add_argument("-f", "--forever", dest="forever",
                        action="store_true",
                        help="Keep running tests until one fails")
    parser.add_argument("-F", "--fatal-error", dest="fatal_error",
                        action="store_true",
                        help="Stop on first fail")
    parser.add_argument("-t", "--wanted-tests", dest="wanted_tests",
                        action="append",
                        help="Define the tests to execute, it can be a regex."
                        " If it contains defaults_only, only default scenarios"
                        " will be executed")
    parser.add_argument("-b", "--blacklisted-tests", dest="blacklisted_tests",
                        action="append",
                        help="Define the tests not to execute, it can be a regex.")
    parser.add_argument("-L", "--list-tests",
                        dest="list_tests",
                        action="store_true",
                        help="List tests and exit")
    parser.add_argument("-m", "--mute", dest="mute",
                        action="store_true",
                        help="Mute playback output, which means that we use "
                        "a fakesink")
    parser.add_argument("-n", "--no-color", dest="no_color",
                        action="store_true",
                        help="Set it to output no colored text in the terminal")
    parser.add_argument("-g", "--generate-media-info", dest="generate_info",
                        action="store_true",
                        help="Set it in order to generate the missing .media_infos files")
    parser.add_argument("--update-media-info", dest="update_media_info",
                        action="store_true",
                        help="Set it in order to update exising .media_infos files")
    parser.add_argument(
        "-G", "--generate-media-info-with-frame-detection", dest="generate_info_full",
        action="store_true",
        help="Set it in order to generate the missing .media_infos files. "
        "It implies --generate-media-info but enabling frame detection")
    parser.add_argument("-lt", "--long-test-limit", dest="long_limit",
                        action='store',
                        help="Defines the limite from which a test is concidered as long (in seconds)"
                             " not that 0 will enable all tests", type=int),
    parser.add_argument("-c", "--config", dest="config",
                        help="This is DEPRECATED, prefer using the testsuite format"
                        " to configure testsuites")
    dir_group = parser.add_argument_group(
        "Directories and files to be used by the launcher")
    parser.add_argument('--xunit-file', action='store',
                        dest='xunit_file', metavar="FILE",
                        help=("Path to xml file to store the xunit report in. "
                              "Default is LOGSDIR/xunit.xml"))
    dir_group.add_argument("-M", "--main-dir", dest="main_dir",
                           help="Main directory where to put files. Default is %s" % DEFAULT_MAIN_DIR)
    dir_group.add_argument("--testsuites-dir", dest="testsuites_dir",
                           help="Directory where to look for testsuites. Default is %s"
                           " Note that GstValidate expect testsuite file to have .testsuite"
                           " as an extension in this folder." % DEFAULT_TESTSUITES_DIR)
    dir_group.add_argument("-o", "--output-dir", dest="output_dir",
                           help="Directory where to store logs and rendered files. Default is MAIN_DIR")
    dir_group.add_argument("-l", "--logs-dir", dest="logsdir",
                           help="Directory where to store logs, default is OUTPUT_DIR/logs.")
    dir_group.add_argument("-R", "--render-path", dest="dest",
                           help="Set the path to which projects should be rendered, default is OUTPUT_DIR/rendered")
    dir_group.add_argument("-p", "--medias-paths", dest="paths", action="append",
                           help="Paths in which to look for media files")
    dir_group.add_argument("-a", "--clone-dir", dest="clone_dir",
                           help="Paths where to clone the testuite to run "
                           " default is MAIN_DIR/gst-integration-testsuites")
    dir_group.add_argument("-rl", "--redirect-logs", dest="redirect_logs",
                           help="Redirect logs to 'stdout' or 'sdterr'.")
    dir_group.add_argument("-j", "--jobs", dest="num_jobs",
                           help="Number of tests to execute simultaneously",
                           type=int)

    http_server_group = parser.add_argument_group(
        "Handle the HTTP server to be created")
    http_server_group.add_argument(
        "--http-server-port", dest="http_server_port",
        help="Port on which to run the http server on localhost")
    http_server_group.add_argument(
        "--http-bandwith-limitation", dest="http_bandwith",
        help="The artificial bandwith limitation to introduce to the local server (in Bytes/sec) (default: 1 MBps)")
    http_server_group.add_argument(
        "-s", "--folder-for-http-server", dest="http_server_dir",
        help="Folder in which to create an http server on localhost. Default is PATHS")
    http_server_group.add_argument("--http-only", dest="httponly",
                                   action='store_true',
                                   help="Start the http server and quit")

    assets_group = parser.add_argument_group("Handle remote assets")
    assets_group.add_argument(
        "-u", "--update-assets-command", dest="update_assets_command",
        help="Command to update assets")
    assets_group.add_argument(
        "--get-assets-command", dest="get_assets_command",
        help="Command to get assets")
    assets_group.add_argument("--remote-assets-url", dest="remote_assets_url",
                              help="Url to the remote assets (default:%s)" % DEFAULT_GST_QA_ASSETS_REPO)
    assets_group.add_argument("-S", "--sync", dest="sync", action="store_true",
                              help="Synchronize asset repository")
    assets_group.add_argument("--sync-all", dest="sync_all", action="store_true",
                              help="Synchronize asset repository,"
                              " including big media files")
    assets_group.add_argument("--usage", action=PrintUsage,
                              help="Print usage documentation")

    loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)

    tests_launcher = _TestsLauncher(libsdir)
    tests_launcher.add_options(parser)

    options = LauncherConfig()
    parser.parse_args(namespace=options)
    if not options.cleanup():
        exit(1)

    if options.remote_assets_url and options.sync:
        if os.path.exists(options.clone_dir):
            if not update_assets(options):
                exit(1)
        else:
            if not download_assets(options):
                exit(1)

            if not update_assets(options):
                exit(1)

    tests_launcher.set_settings(options, [])

    # Ensure that the scenario manager singleton is ready to be used
    ScenarioManager().config = options
    tests_launcher.list_tests()

    if options.list_tests:
        l = tests_launcher.tests
        for test in l:
            printc(test)

        printc("\nNumber of tests: %d" % len(l), Colors.OKGREEN)
        return 0

    httpsrv = HTTPServer(options)
    if tests_launcher.needs_http_server() or options.httponly is True:
        httpsrv.start()

    if options.httponly is True:
        print "Running HTTP server only"
        return

    e = None
    try:
        tests_launcher.run_tests()
    except Exception as e:
        pass
    finally:
        tests_launcher.final_report()
        httpsrv.stop()
        if e is not None:
            raise

    return 0
Beispiel #14
0
def main():
    parser = argparse.ArgumentParser(formatter_class=Formatter, prog='gst-validate-launcher',
                                     description=HELP)
    parser.add_argument("-d", "--debug", dest="debug",
                      action="store_true",
                      default=False,
                      help="Let user debug the process on timeout")
    parser.add_argument("-f", "--forever", dest="forever",
                      action="store_true", default=False,
                      help="Keep running tests until one fails")
    parser.add_argument("-F", "--fatal-error", dest="fatal_error",
                      action="store_true", default=False,
                      help="Stop on first fail")
    parser.add_argument("-t", "--wanted-tests", dest="wanted_tests",
                      default=[],
                      action="append",
                      help="Define the tests to execute, it can be a regex"
                           " if it contains defaults_only, only default scenarios"
                           " will be executed")
    parser.add_argument("-b", "--blacklisted-tests", dest="blacklisted_tests",
                      default=[],
                      action="append",
                      help="Define the tests not to execute, it can be a regex.")
    parser.add_argument("-L", "--list-tests",
                      dest="list_tests",
                      action="store_true",
                      default=False,
                      help="List tests and exit")
    parser.add_argument("-m", "--mute", dest="mute",
                      action="store_true", default=False,
                      help="Mute playback output, which mean that we use "
                      "a fakesink")
    parser.add_argument("-n", "--no-color", dest="no_color",
                     action="store_true", default=False,
                     help="Set it to output no colored text in the terminal")
    parser.add_argument("-g", "--generate-media-info", dest="generate_info",
                     action="store_true", default=False,
                     help="Set it in order to generate the missing .media_infos files")
    parser.add_argument("-lt", "--long-test-limit", dest="long_limit",
                     default=utils.LONG_TEST, action='store',
                     help="Defines the limite from which a test is concidered as long (is seconds)"),
    dir_group = parser.add_argument_group("Directories and files to be used by the launcher")
    parser.add_argument('--xunit-file', action='store',
                      dest='xunit_file', metavar="FILE",
                      default=None,
                      help=("Path to xml file to store the xunit report in. "
                      "Default is LOGSDIR/xunit.xml"))
    dir_group.add_argument("-M", "--main-dir", dest="main_dir",
                      default=DEFAULT_MAIN_DIR,
                         help="Main directory where to put files. Default is %s" % DEFAULT_MAIN_DIR)
    dir_group.add_argument("-o", "--output-dir", dest="output_dir",
                         default=None,
                         help="Directory where to store logs and rendered files. Default is MAIN_DIR")
    dir_group.add_argument("-l", "--logs-dir", dest="logsdir",
                      default=None,
                      help="Directory where to store logs, default is OUTPUT_DIR/logs")
    dir_group.add_argument("-R", "--render-path", dest="dest",
                     default=None,
                     help="Set the path to which projects should be rendered, default is OUTPUT_DIR/rendered")
    dir_group.add_argument("-p", "--medias-paths", dest="paths", action="append",
                      default=None,
                      help="Paths in which to look for media files, default is MAIN_DIR/gst-qa-assets/media")
    dir_group.add_argument("-a", "--clone-dir", dest="clone_dir",
                      default=None,
                      help="Paths in which to look for media files, default is MAIN_DIR/gst-qa-assets")

    http_server_group = parser.add_argument_group("Handle the HTTP server to be created")
    http_server_group.add_argument("--http-server-port", dest="http_server_port",
                      default=8079,
                      help="Port on which to run the http server on localhost")
    http_server_group.add_argument("-s", "--folder-for-http-server", dest="http_server_dir",
                      default=None,
                      help="Folder in which to create an http server on localhost. Default is PATHS")
    http_server_group.add_argument("--http-only", dest="httponly",
                      default=False, action='store_true',
                      help="Start the http server and quit")

    assets_group = parser.add_argument_group("Handle remote assets")
    assets_group.add_argument("-u", "--update-assets-command", dest="update_assets_command",
                      default="git fetch %s && git checkout FETCH_HEAD && git annex get ."
                            % (DEFAULT_GST_QA_ASSETS_REPO, ),
                      help="Command to update assets")
    assets_group.add_argument("--get-assets-command", dest="get_assets_command",
                      default="git clone",
                      help="Command to get assets")
    assets_group.add_argument("--remote-assets-url", dest="remote_assets_url",
                      default=DEFAULT_GST_QA_ASSETS_REPO,
                            help="Url to the remote assets (default:%s)" % DEFAULT_GST_QA_ASSETS_REPO)
    assets_group.add_argument("-S", "--sync", dest="sync", action="store_true",
                            default=False, help="Synchronize asset repository")
    assets_group.add_argument("--usage", dest="sync", action=PrintUsage,
                            help="Print usage documentation")

    loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)

    tests_launcher = _TestsLauncher()
    tests_launcher.add_options(parser)

    (options, args) = parser.parse_known_args()

    # Get absolute path for main_dir and base everything on that
    options.main_dir = os.path.abspath(options.main_dir)

    # default for output_dir is MAINDIR
    if not options.output_dir:
        options.output_dir = options.main_dir
    else:
        options.output_dir = os.path.abspath(options.output_dir)

    # other output directories
    if options.logsdir is None:
        options.logsdir = os.path.join(options.output_dir, "logs")
    if options.xunit_file is None:
        options.xunit_file = os.path.join(options.logsdir, "xunit.xml")
    if options.dest is None:
        options.dest = os.path.join(options.output_dir, "rendered")

    if not os.path.exists(options.dest):
        os.makedirs(options.dest)
    if urlparse.urlparse(options.dest).scheme == "":
        options.dest = path2url(options.dest)

    if options.no_color:
        utils.desactivate_colors()
    if options.clone_dir is None:
        options.clone_dir = os.path.join(options.main_dir, QA_ASSETS)
    if options.paths is None:
        options.paths = os.path.join(options.clone_dir, MEDIAS_FOLDER)

    if options.http_server_dir is None:
        options.http_server_dir = options.paths

    if not options.sync and not os.path.exists(options.clone_dir) and \
            options.clone_dir == os.path.join(options.clone_dir, MEDIAS_FOLDER):
        printc("Media path (%s) does not exists. Forgot to run --sync ?"
               % options.clone_dir, Colors.FAIL, True)
        return -1

    blacklisted = tests_launcher.get_blacklisted()
    if blacklisted:
        msg = "Currently 'hardcoded' blacklisted tests:\n"
        for name, bug in blacklisted:
            options.blacklisted_tests.append(name)
            msg += "  + %s \n   --> bug: %s\n\n" % (name, bug)

        printc(msg, Colors.FAIL, True)

    tests_launcher.set_settings(options, args)

    if options.remote_assets_url and options.sync:
        if os.path.exists(options.clone_dir):
            launch_command("cd %s && %s" % (options.clone_dir,
                                            options.update_assets_command),
                           fails=True)
        else:
            launch_command("%s %s %s" % (options.get_assets_command,
                                         options.remote_assets_url,
                                         options.clone_dir),
                           fails=True)
            launch_command("cd %s && %s" % (options.clone_dir,
                                            options.update_assets_command),
                           fails=True)

    # Ensure that the scenario manager singleton is ready to be used
    ScenarioManager().config = options
    tests_launcher.list_tests()

    if options.list_tests:
        l = tests_launcher.tests
        l.sort()
        for test in l:
            printc(test)

        printc("\nNumber of tests: %d" % len (l), Colors.OKGREEN)
        return 0

    httpsrv = HTTPServer(options)
    if tests_launcher.needs_http_server() or options.httponly is True:
        httpsrv.start()

    if options.httponly is True:
        print "Running HTTP server only"
        return

    e = None
    try:
        tests_launcher.run_tests()
        tests_launcher.final_report()
    except Exception as e:
        pass
    finally:
        httpsrv.stop()
        if e is not None:
            raise

    return 0
Beispiel #15
0
def main(libsdir):
    if "--help" in sys.argv:
        _help_message = HELP
    else:
        _help_message = "Use --help for the full help"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        prog='gst-validate-launcher', description=_help_message)

    parser.add_argument('testsuites', metavar='N', nargs='*',
                        help="""Lets you specify a file where the testsuite to execute is defined.

In the module if you want to work with a specific test manager(s) (for example,
'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names)

In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This
function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is
available. You should configure it using:

   * test_manager.add_scenarios: which allows you to register a list of scenario names to be run
   * test_manager.set_default_blacklist: Lets you set a list of tuple of the form:
         (@regex_defining_blacklister_test_names, @reason_for_the_blacklisting)
   * test_manager.add_generators: which allows you to register a list of #GstValidateTestsGenerator
     to be used to generate tests
   * test_manager.add_encoding_formats:: which allows you to register a list #MediaFormatCombination to be used for transcoding tests

You can also set default values with:
    * test_manager.register_defaults: Sets default values for all parametters
    * test_manager.register_default_test_generators: Sets default values for the TestsGenerators to be used
    * test_manager.register_default_scenarios: Sets default values for the scenarios to be executed
    * test_manager.register_default_encoding_formats: Sets default values for the encoding formats to be tested

Note that all testsuite should be inside python modules, so the directory should contain a __init__.py file
""",
                        default=["validate"])
    parser.add_argument("-d", "--debug", dest="debug",
                        action="store_true",
                        help="Let user debug the process on timeout")
    parser.add_argument("-f", "--forever", dest="forever",
                        action="store_true",
                        help="Keep running tests until one fails")
    parser.add_argument("-F", "--fatal-error", dest="fatal_error",
                        action="store_true",
                        help="Stop on first fail")
    parser.add_argument("--fail-on-testlist-change",
                        dest="fail_on_testlist_change",
                        action="store_true",
                        help="Fail the testsuite if a test has been added"
                        " or removed without being explicitely added/removed "
                        "from the testlist file.")
    parser.add_argument("-t", "--wanted-tests", dest="wanted_tests",
                        action="append",
                        help="Define the tests to execute, it can be a regex."
                        " If it contains defaults_only, only default scenarios"
                        " will be executed")
    parser.add_argument("-b", "--blacklisted-tests", dest="blacklisted_tests",
                        action="append",
                        help="Define the tests not to execute, it can be a regex.")
    parser.add_argument("-L", "--list-tests",
                        dest="list_tests",
                        action="store_true",
                        help="List tests and exit")
    parser.add_argument("-m", "--mute", dest="mute",
                        action="store_true",
                        help="Mute playback output, which means that we use "
                        "a fakesink")
    parser.add_argument("-n", "--no-color", dest="no_color",
                        action="store_true",
                        help="Set it to output no colored text in the terminal")
    parser.add_argument("-g", "--generate-media-info", dest="generate_info",
                        action="store_true",
                        help="Set it in order to generate the missing .media_infos files")
    parser.add_argument("--update-media-info", dest="update_media_info",
                        action="store_true",
                        help="Set it in order to update exising .media_infos files")
    parser.add_argument(
        "-G", "--generate-media-info-with-frame-detection", dest="generate_info_full",
        action="store_true",
        help="Set it in order to generate the missing .media_infos files. "
        "It implies --generate-media-info but enabling frame detection")
    parser.add_argument("-lt", "--long-test-limit", dest="long_limit",
                        action='store',
                        help="Defines the limit for which a test is considered as long (in seconds)."
                             " Note that 0 will enable all tests", type=int),
    parser.add_argument("--dump-on-failure", dest="dump_on_failure",
                        action="store_true", default=False,
                        help="Dump logs to stdout when a test fails")
    parser.add_argument("-c", "--config", dest="config",
                        help="This is DEPRECATED, prefer using the testsuite format"
                        " to configure testsuites")
    parser.add_argument("-vg", "--valgrind", dest="valgrind",
                        action="store_true",
                        help="Run the tests inside Valgrind")
    parser.add_argument("--gdb", dest="gdb",
                        action="store_true",
                        help="Run the tests inside gdb (implies"
                        " --output-dir=stdout and --jobs=1)")
    parser.add_argument("-nd", "--no-display", dest="no_display",
                        action="store_true",
                        help="Run the tests without outputting graphics"
                             " on any display. It tries to run all graphical operation"
                             " in a virtual framebuffer."
                             " Note that it is currently implemented only"
                             " for the X  server thanks to Xvfb (which is requeried in that case)")
    dir_group = parser.add_argument_group(
        "Directories and files to be used by the launcher")
    parser.add_argument('--xunit-file', action='store',
                        dest='xunit_file', metavar="FILE",
                        help=("Path to xml file to store the xunit report in."))
    dir_group.add_argument("-M", "--main-dir", dest="main_dir",
                           help="Main directory where to put files. Default is %s" % DEFAULT_MAIN_DIR)
    dir_group.add_argument("--testsuites-dir", dest="testsuites_dir",
                           help="Directory where to look for testsuites. Default is %s"
                           " Note that GstValidate expect testsuite file to have .testsuite"
                           " as an extension in this folder." % DEFAULT_TESTSUITES_DIR)
    dir_group.add_argument("-o", "--output-dir", dest="output_dir",
                           help="Directory where to store logs and rendered files. Default is MAIN_DIR")
    dir_group.add_argument("-l", "--logs-dir", dest="logsdir",
                           help="Directory where to store logs, default is OUTPUT_DIR/logs.")
    dir_group.add_argument("-R", "--render-path", dest="dest",
                           help="Set the path to which projects should be rendered, default is OUTPUT_DIR/rendered")
    dir_group.add_argument("-p", "--medias-paths", dest="user_paths", action="append",
                           help="Paths in which to look for media files")
    dir_group.add_argument("-a", "--clone-dir", dest="clone_dir",
                           help="Paths where to clone the testuite to run "
                           " default is MAIN_DIR/gst-integration-testsuites")
    dir_group.add_argument("-rl", "--redirect-logs", dest="redirect_logs",
                           help="Redirect logs to 'stdout' or 'sdterr'.")
    dir_group.add_argument("-j", "--jobs", dest="num_jobs",
                           help="Number of tests to execute simultaneously",
                           type=int)

    http_server_group = parser.add_argument_group(
        "Handle the HTTP server to be created")
    http_server_group.add_argument(
        "--http-server-port", dest="http_server_port",
        help="Port on which to run the http server on localhost", type=int)
    http_server_group.add_argument(
        "--http-bandwith-limitation", dest="http_bandwith",
        help="The artificial bandwith limitation to introduce to the local server (in Bytes/sec) (default: 1 MBps)")
    http_server_group.add_argument(
        "-s", "--folder-for-http-server", dest="http_server_dir",
        help="Folder in which to create an http server on localhost. Default is PATHS")
    http_server_group.add_argument("--http-only", dest="httponly",
                                   action='store_true',
                                   help="Start the http server and quit")

    assets_group = parser.add_argument_group("Handle remote assets")
    assets_group.add_argument(
        "--get-assets-command", dest="get_assets_command",
        help="Command to get assets")
    assets_group.add_argument("--remote-assets-url", dest="remote_assets_url",
                              help="Url to the remote assets (default:%s)" % DEFAULT_GST_QA_ASSETS_REPO)
    assets_group.add_argument("-S", "--sync", dest="sync", action="store_true",
                              help="Synchronize asset repository")
    assets_group.add_argument("-fs", "--force-sync", dest="force_sync", action="store_true",
                              help="Synchronize asset repository reseting any change that might have"
                              " happened in the testsuite")
    assets_group.add_argument("--sync-all", dest="sync_all", action="store_true",
                              help="Synchronize asset repository,"
                              " including big media files")
    assets_group.add_argument("--usage", action=PrintUsage,
                              help="Print usage documentation")

    loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)

    tests_launcher = _TestsLauncher(libsdir)
    tests_launcher.add_options(parser)

    if _help_message == HELP and which(LESS):
        tmpf = tempfile.NamedTemporaryFile()

        parser.print_help(file=tmpf)
        exit(os.system("%s %s" % (LESS, tmpf.name)))

    options = LauncherConfig()
    parser.parse_args(namespace=options)
    if not options.cleanup():
        exit(1)

    if options.remote_assets_url and options.sync and not os.path.exists(options.clone_dir):
        if not download_assets(options):
            exit(1)

    # Ensure that the scenario manager singleton is ready to be used
    ScenarioManager().config = options
    if not tests_launcher.set_settings(options, []):
        exit(1)
    if tests_launcher.list_tests() == -1:
        printc("\nFailling as tests have been removed/added "
               " (--fail-on-testlist-change)", Colors.FAIL)
        exit(1)

    if options.list_tests:
        l = tests_launcher.tests
        for test in l:
            printc(test)

        printc("\nNumber of tests: %d" % len(l), Colors.OKGREEN)
        return 0

    httpsrv = HTTPServer(options)
    if tests_launcher.needs_http_server() or options.httponly is True:
        httpsrv.start()

    vfb_server = get_virual_frame_buffer_server(options)
    if options.no_display:
        res = vfb_server.start()
        if res[0] is False:
            printc("Could not start virtual frame server: %s" % res[1],
                   Colors.FAIL)
            exit(1)
        os.environ["DISPLAY"] = vfb_server.display_id

    if options.httponly is True:
        print("Running HTTP server only")
        return

    # There seems to be some issue with forking, dconf and some gtype
    # initialization that deadlocks occasionally, setting the
    # GSettings backend make it go away.
    # Also happened here: https://cgit.freedesktop.org/gstreamer/gst-plugins-good/commit/tests/check/Makefile.am?id=8e2c1d1de56bddbff22170f8b17473882e0e63f9
    os.environ['GSETTINGS_BACKEND'] = "memory"

    e = None
    try:
        tests_launcher.run_tests()
    except Exception as e:
        pass
    finally:
        tests_launcher.final_report()
        tests_launcher.clean_tests()
        httpsrv.stop()
        vfb_server.stop()
        if e is not None:
            raise

    return 0
Beispiel #16
0
def main(libsdir):
    if "--help" in sys.argv:
        _help_message = HELP
    else:
        _help_message = "Use --help for the full help"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        prog='gst-validate-launcher', description=_help_message)

    parser.add_argument('testsuites', metavar='N', nargs='*',
                        help="""Lets you specify a file where the testsuite to execute is defined.

In the module if you want to work with a specific test manager(s) (for example,
'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names)

In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This
function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is
avalaible. You should configure it using:

   * test_manager.add_scenarios: which allows you to register a list of scenario names to be run
   * test_manager.set_default_blacklist: Lets you set a list of tuple of the form:
         (@regex_defining_blacklister_test_names, @reason_for_the_blacklisting)
   * test_manager.add_generators: which allows you to register a list of #GstValidateTestsGenerator
     to be used to generate tests
   * test_manager.add_encoding_formats:: which allows you to register a list #MediaFormatCombination to be used for transcoding tests

You can also set default values with:
    * test_manager.register_defaults: Sets default values for all parametters
    * test_manager.register_default_test_generators: Sets default values for the TestsGenerators to be used
    * test_manager.register_default_scenarios: Sets default values for the scenarios to be executed
    * test_manager.register_default_encoding_formats: Sets default values for the encoding formats to be tested

Note that all testsuite should be inside python modules, so the directory should contain a __init__.py file
""",
                        default=["validate"])
    parser.add_argument("-d", "--debug", dest="debug",
                        action="store_true",
                        help="Let user debug the process on timeout")
    parser.add_argument("-f", "--forever", dest="forever",
                        action="store_true",
                        help="Keep running tests until one fails")
    parser.add_argument("-F", "--fatal-error", dest="fatal_error",
                        action="store_true",
                        help="Stop on first fail")
    parser.add_argument("-t", "--wanted-tests", dest="wanted_tests",
                        action="append",
                        help="Define the tests to execute, it can be a regex."
                        " If it contains defaults_only, only default scenarios"
                        " will be executed")
    parser.add_argument("-b", "--blacklisted-tests", dest="blacklisted_tests",
                        action="append",
                        help="Define the tests not to execute, it can be a regex.")
    parser.add_argument("-L", "--list-tests",
                        dest="list_tests",
                        action="store_true",
                        help="List tests and exit")
    parser.add_argument("-m", "--mute", dest="mute",
                        action="store_true",
                        help="Mute playback output, which means that we use "
                        "a fakesink")
    parser.add_argument("-n", "--no-color", dest="no_color",
                        action="store_true",
                        help="Set it to output no colored text in the terminal")
    parser.add_argument("-g", "--generate-media-info", dest="generate_info",
                        action="store_true",
                        help="Set it in order to generate the missing .media_infos files")
    parser.add_argument("--update-media-info", dest="update_media_info",
                        action="store_true",
                        help="Set it in order to update exising .media_infos files")
    parser.add_argument(
        "-G", "--generate-media-info-with-frame-detection", dest="generate_info_full",
        action="store_true",
        help="Set it in order to generate the missing .media_infos files. "
        "It implies --generate-media-info but enabling frame detection")
    parser.add_argument("-lt", "--long-test-limit", dest="long_limit",
                        action='store',
                        help="Defines the limit for which a test is considered as long (in seconds)."
                             " Note that 0 will enable all tests", type=int),
    parser.add_argument("-c", "--config", dest="config",
                        help="This is DEPRECATED, prefer using the testsuite format"
                        " to configure testsuites")
    parser.add_argument("-vg", "--valgrind", dest="valgrind",
                        action="store_true",
                        help="Run the tests inside Valgrind")
    parser.add_argument("--gdb", dest="gdb",
                        action="store_true",
                        help="Run the tests inside gdb (implies"
                        " --output-dir=stdout and --jobs=1)")
    parser.add_argument("-nd", "--no-display", dest="no_display",
                        action="store_true",
                        help="Run the tests without outputting graphics"
                             " on any display. It tries to run all graphical operation"
                             " in a virtual framebuffer."
                             " Note that it is currently implemented only"
                             " for the X  server thanks to Xvfb (which is requeried in that case)")
    dir_group = parser.add_argument_group(
        "Directories and files to be used by the launcher")
    parser.add_argument('--xunit-file', action='store',
                        dest='xunit_file', metavar="FILE",
                        help=("Path to xml file to store the xunit report in. "
                              "Default is LOGSDIR/xunit.xml"))
    dir_group.add_argument("-M", "--main-dir", dest="main_dir",
                           help="Main directory where to put files. Default is %s" % DEFAULT_MAIN_DIR)
    dir_group.add_argument("--testsuites-dir", dest="testsuites_dir",
                           help="Directory where to look for testsuites. Default is %s"
                           " Note that GstValidate expect testsuite file to have .testsuite"
                           " as an extension in this folder." % DEFAULT_TESTSUITES_DIR)
    dir_group.add_argument("-o", "--output-dir", dest="output_dir",
                           help="Directory where to store logs and rendered files. Default is MAIN_DIR")
    dir_group.add_argument("-l", "--logs-dir", dest="logsdir",
                           help="Directory where to store logs, default is OUTPUT_DIR/logs.")
    dir_group.add_argument("-R", "--render-path", dest="dest",
                           help="Set the path to which projects should be rendered, default is OUTPUT_DIR/rendered")
    dir_group.add_argument("-p", "--medias-paths", dest="paths", action="append",
                           help="Paths in which to look for media files")
    dir_group.add_argument("-a", "--clone-dir", dest="clone_dir",
                           help="Paths where to clone the testuite to run "
                           " default is MAIN_DIR/gst-integration-testsuites")
    dir_group.add_argument("-rl", "--redirect-logs", dest="redirect_logs",
                           help="Redirect logs to 'stdout' or 'sdterr'.")
    dir_group.add_argument("-j", "--jobs", dest="num_jobs",
                           help="Number of tests to execute simultaneously",
                           type=int)

    http_server_group = parser.add_argument_group(
        "Handle the HTTP server to be created")
    http_server_group.add_argument(
        "--http-server-port", dest="http_server_port",
        help="Port on which to run the http server on localhost")
    http_server_group.add_argument(
        "--http-bandwith-limitation", dest="http_bandwith",
        help="The artificial bandwith limitation to introduce to the local server (in Bytes/sec) (default: 1 MBps)")
    http_server_group.add_argument(
        "-s", "--folder-for-http-server", dest="http_server_dir",
        help="Folder in which to create an http server on localhost. Default is PATHS")
    http_server_group.add_argument("--http-only", dest="httponly",
                                   action='store_true',
                                   help="Start the http server and quit")

    assets_group = parser.add_argument_group("Handle remote assets")
    assets_group.add_argument(
        "--get-assets-command", dest="get_assets_command",
        help="Command to get assets")
    assets_group.add_argument("--remote-assets-url", dest="remote_assets_url",
                              help="Url to the remote assets (default:%s)" % DEFAULT_GST_QA_ASSETS_REPO)
    assets_group.add_argument("-S", "--sync", dest="sync", action="store_true",
                              help="Synchronize asset repository")
    assets_group.add_argument("-fs", "--force-sync", dest="force_sync", action="store_true",
                              help="Synchronize asset repository reseting any change that might have"
                              " happened in the testsuite")
    assets_group.add_argument("--sync-all", dest="sync_all", action="store_true",
                              help="Synchronize asset repository,"
                              " including big media files")
    assets_group.add_argument("--usage", action=PrintUsage,
                              help="Print usage documentation")

    loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)

    tests_launcher = _TestsLauncher(libsdir)
    tests_launcher.add_options(parser)

    if _help_message == HELP and which(LESS):
        tmpf = tempfile.NamedTemporaryFile()

        parser.print_help(file=tmpf)
        exit(os.system("%s %s" % (LESS, tmpf.name)))

    options = LauncherConfig()
    parser.parse_args(namespace=options)
    if not options.cleanup():
        exit(1)

    if options.remote_assets_url and options.sync and not os.path.exists(options.clone_dir):
        if not download_assets(options):
            exit(1)

    # Ensure that the scenario manager singleton is ready to be used
    ScenarioManager().config = options
    tests_launcher.set_settings(options, [])
    tests_launcher.list_tests()

    if options.list_tests:
        l = tests_launcher.tests
        for test in l:
            printc(test)

        printc("\nNumber of tests: %d" % len(l), Colors.OKGREEN)
        return 0

    httpsrv = HTTPServer(options)
    if tests_launcher.needs_http_server() or options.httponly is True:
        httpsrv.start()

    vfb_server = get_virual_frame_buffer_server(options)
    if options.no_display:
        res = vfb_server.start()
        if res[0] is False:
            printc("Could not start virtual frame server: %s" % res[1],
                   Colors.FAIL)
            exit(1)
        os.environ["DISPLAY"] = vfb_server.display_id

    if options.httponly is True:
        print("Running HTTP server only")
        return

    e = None
    try:
        tests_launcher.run_tests()
    except Exception as e:
        pass
    finally:
        tests_launcher.final_report()
        httpsrv.stop()
        vfb_server.stop()
        if e is not None:
            raise

    return 0
Beispiel #17
0
config = Configuration()
templates = Template(config)

logLevel = logging.ERROR
if(config['debug']):
  try:
    logLevel = {'WARNING':logging.WARNING,'INFO':logging.INFO,'DEBUG':logging.DEBUG}[config['debug']]
  except:
    logLevel = logging.ERROR

logger.setLevel(logLevel)
logger.debug("log level: %d"%logLevel)
database = Database.getDatabase(config['database'])

tftpserver = TFTPServer(database=database,**config['binding']['tftp'])
httpserver = HTTPServer(database=database,**config['binding']['http'])

tftpserver.start()
httpserver.start()
time.sleep(1)

stop_services = False


while tftpserver.running and httpserver.running and not stop_services:
  time.sleep(1)

logger.info("HTTP server running" if httpserver.running else "HTTP server has stopped")
logger.info("TFTP server running" if tftpserver.running else "TFTP server has stopped")
logger.info('Stopping all services')
def main():
    server = HTTPServer(port=5000,
                        backlog_size=1,
                        request_handler_cls=BaseHTTPRequestHandler)
    server.serve_forever()