Exemplo n.º 1
0
    def _execute_stmt(self, stmt, stmt_args_list):
        """Helper for "self.execute_queued_items".

        Execute a statement. If this is the public database, return True on
        success and False on failure. If this is the private database, return
        True on success, and raise on failure.
        """
        try:
            self.connect()
            self.conn.executemany(stmt, stmt_args_list)
        except sqlite3.Error:
            if not self.is_public:
                raise
            if cylc.flags.debug:
                traceback.print_exc()
            err_log = ("cannot execute database statement:\n" +
                       "file=%(file)s:\nstmt=%(stmt)s") % {
                           "file": self.db_file_name,
                           "stmt": stmt
                       }
            for i, stmt_args in enumerate(stmt_args_list):
                err_log += ("\nstmt_args[%(i)d]=%(stmt_args)s" % {
                    "i": i,
                    "stmt_args": stmt_args
                })
            ERR.warning(err_log)
            raise
Exemplo n.º 2
0
    def unlink_suite_contact_files(self, reg):
        """Remove suite contact files from initialised hosts.

        This is called on shutdown, so we don't want anything to hang.
        Terminate any incomplete SSH commands after 10 seconds.
        """
        # Issue all SSH commands in parallel
        procs = {}
        for user_at_host, should_unlink in self.initialised_hosts.items():
            if not should_unlink:
                continue
            if "@" in user_at_host:
                owner, host = user_at_host.split("@", 1)
            else:
                owner, host = None, user_at_host
            ssh_tmpl = GLOBAL_CFG.get_host_item("remote shell template", host, owner)
            r_suite_contact_file = os.path.join(
                GLOBAL_CFG.get_derived_host_item(reg, "suite run directory", host, owner),
                SuiteSrvFilesManager.DIR_BASE_SRV,
                SuiteSrvFilesManager.FILE_BASE_CONTACT,
            )
            cmd = shlex.split(ssh_tmpl) + ["-n", user_at_host, "rm", "-f", r_suite_contact_file]
            procs[user_at_host] = (cmd, Popen(cmd, stdout=PIPE, stderr=PIPE))
        # Wait for commands to complete for a max of 10 seconds
        timeout = time() + 10.0
        while procs and time() < timeout:
            for user_at_host, (cmd, proc) in procs.items():
                if not proc.poll():
                    continue
                del procs[user_at_host]
                out, err = proc.communicate()
                if proc.wait():
                    ERR.warning(
                        RemoteJobHostInitError(
                            RemoteJobHostInitError.MSG_TIDY,
                            user_at_host,
                            " ".join([quote(item) for item in cmd]),
                            proc.returncode,
                            out,
                            err,
                        )
                    )
        # Terminate any remaining commands
        for user_at_host, (cmd, proc) in procs.items():
            try:
                proc.terminate()
            except OSError:
                pass
            out, err = proc.communicate()
            proc.wait()
            ERR.warning(
                RemoteJobHostInitError(
                    RemoteJobHostInitError.MSG_TIDY,
                    user_at_host,
                    " ".join([quote(item) for item in cmd]),
                    proc.returncode,
                    out,
                    err,
                )
            )
Exemplo n.º 3
0
    def unlink_suite_contact_files(self, reg):
        """Remove suite contact files from initialised hosts.

        This is called on shutdown, so we don't want anything to hang.
        Terminate any incomplete SSH commands after 10 seconds.
        """
        # Issue all SSH commands in parallel
        procs = {}
        for (host, owner), should_unlink in self.initialised.items():
            if not should_unlink:
                continue
            user_at_host = host
            if owner:
                user_at_host = owner + '@' + host
            ssh_tmpl = GLOBAL_CFG.get_host_item('remote shell template', host,
                                                owner)
            r_suite_contact_file = os.path.join(
                GLOBAL_CFG.get_derived_host_item(reg, 'suite run directory',
                                                 host, owner),
                SuiteSrvFilesManager.DIR_BASE_SRV,
                SuiteSrvFilesManager.FILE_BASE_CONTACT)
            cmd = shlex.split(ssh_tmpl) + [
                '-n', user_at_host, 'rm', '-f', r_suite_contact_file
            ]
            procs[user_at_host] = (cmd, Popen(cmd, stdout=PIPE, stderr=PIPE))
        # Wait for commands to complete for a max of 10 seconds
        timeout = time() + 10.0
        while procs and time() < timeout:
            for user_at_host, (cmd, proc) in procs.copy().items():
                if proc.poll() is None:
                    continue
                del procs[user_at_host]
                out, err = proc.communicate()
                if proc.wait():
                    ERR.warning(
                        RemoteJobHostInitError(
                            RemoteJobHostInitError.MSG_TIDY, user_at_host,
                            ' '.join([quote(item) for item in cmd]),
                            proc.returncode, out, err))
        # Terminate any remaining commands
        for user_at_host, (cmd, proc) in procs.items():
            try:
                proc.terminate()
            except OSError:
                pass
            out, err = proc.communicate()
            if proc.wait():
                ERR.warning(
                    RemoteJobHostInitError(
                        RemoteJobHostInitError.MSG_TIDY, user_at_host,
                        ' '.join([quote(item) for item in cmd]),
                        proc.returncode, out, err))
Exemplo n.º 4
0
    def unlink_hosts_contacts(self, reg):
        """Remove suite contact files from initialised hosts.

        This is called on shutdown, so we don't want anything to hang.
        Terminate any incomplete SSH commands after 10 seconds.
        """
        # Issue all SSH commands in parallel
        procs = {}
        for (host, owner), should_unlink in self.init_host_map.items():
            if not should_unlink:
                continue
            user_at_host = host
            if owner:
                user_at_host = owner + '@' + host
            ssh_tmpl = GLOBAL_CFG.get_host_item('ssh command', host, owner)
            r_suite_contact_file = os.path.join(
                GLOBAL_CFG.get_derived_host_item(
                    reg, 'suite run directory', host, owner),
                self.suite_srv_files_mgr.DIR_BASE_SRV,
                self.suite_srv_files_mgr.FILE_BASE_CONTACT)
            cmd = shlex.split(ssh_tmpl) + [
                '-n', user_at_host, 'rm', '-f', r_suite_contact_file]
            procs[user_at_host] = (cmd, Popen(cmd, stdout=PIPE, stderr=PIPE))
        # Wait for commands to complete for a max of 10 seconds
        timeout = time() + 10.0
        while procs and time() < timeout:
            for user_at_host, (cmd, proc) in procs.copy().items():
                if proc.poll() is None:
                    continue
                del procs[user_at_host]
                out, err = proc.communicate()
                if proc.wait():
                    ERR.warning(RemoteJobHostInitError(
                        RemoteJobHostInitError.MSG_TIDY,
                        user_at_host, ' '.join([quote(item) for item in cmd]),
                        proc.returncode, out, err))
        # Terminate any remaining commands
        for user_at_host, (cmd, proc) in procs.items():
            try:
                proc.terminate()
            except OSError:
                pass
            out, err = proc.communicate()
            if proc.wait():
                ERR.warning(RemoteJobHostInitError(
                    RemoteJobHostInitError.MSG_TIDY,
                    user_at_host, ' '.join([quote(item) for item in cmd]),
                    proc.returncode, out, err))
Exemplo n.º 5
0
 def start(self):
     """Start quick web service."""
     # cherrypy.config["tools.encode.on"] = True
     # cherrypy.config["tools.encode.encoding"] = "utf-8"
     cherrypy.config["server.socket_host"] = '0.0.0.0'
     cherrypy.config["engine.autoreload.on"] = False
     try:
         from OpenSSL import SSL, crypto
         cherrypy.config['server.ssl_module'] = 'pyopenSSL'
         cherrypy.config['server.ssl_certificate'] = self.cert
         cherrypy.config['server.ssl_private_key'] = self.pkey
     except ImportError:
         ERR.warning("no HTTPS/OpenSSL support")
     cherrypy.config['log.screen'] = None
     key = binascii.hexlify(os.urandom(16))
     cherrypy.config.update({
         'tools.auth_digest.on':
         True,
         'tools.auth_digest.realm':
         self.suite,
         'tools.auth_digest.get_ha1':
         self.get_ha1,
         'tools.auth_digest.key':
         key,
         'tools.auth_digest.algorithm':
         self.hash_algorithm
     })
     cherrypy.tools.connect_log = cherrypy.Tool(
         'on_end_resource', self.report_connection_if_denied)
     cherrypy.config['tools.connect_log.on'] = True
     self.engine = cherrypy.engine
     for port in self.ok_ports:
         cherrypy.config["server.socket_port"] = port
         try:
             cherrypy.engine.start()
             cherrypy.engine.wait(cherrypy.engine.states.STARTED)
         except Exception:
             if cylc.flags.debug:
                 traceback.print_exc()
             # We need to reinitialise the httpserver for each port attempt.
             cherrypy.server.httpserver = None
         else:
             if cherrypy.engine.state == cherrypy.engine.states.STARTED:
                 self.port = port
                 return
     raise Exception("No available ports")
Exemplo n.º 6
0
 def start(self):
     """Start quick web service."""
     # cherrypy.config["tools.encode.on"] = True
     # cherrypy.config["tools.encode.encoding"] = "utf-8"
     cherrypy.config["server.socket_host"] = '0.0.0.0'
     cherrypy.config["engine.autoreload.on"] = False
     try:
         from OpenSSL import SSL, crypto
         cherrypy.config['server.ssl_module'] = 'pyopenSSL'
         cherrypy.config['server.ssl_certificate'] = self.cert
         cherrypy.config['server.ssl_private_key'] = self.pkey
     except ImportError:
         ERR.warning("no HTTPS/OpenSSL support")
     cherrypy.config['log.screen'] = None
     key = binascii.hexlify(os.urandom(16))
     cherrypy.config.update({
         'tools.auth_digest.on': True,
         'tools.auth_digest.realm': self.suite,
         'tools.auth_digest.get_ha1': self.get_ha1,
         'tools.auth_digest.key': key,
         'tools.auth_digest.algorithm': self.hash_algorithm
     })
     cherrypy.tools.connect_log = cherrypy.Tool(
         'on_end_resource', self.report_connection_if_denied)
     cherrypy.config['tools.connect_log.on'] = True
     self.engine = cherrypy.engine
     for port in self.ok_ports:
         cherrypy.config["server.socket_port"] = port
         try:
             cherrypy.engine.start()
             cherrypy.engine.wait(cherrypy.engine.states.STARTED)
         except Exception:
             if cylc.flags.debug:
                 traceback.print_exc()
             # We need to reinitialise the httpserver for each port attempt.
             cherrypy.server.httpserver = None
         else:
             if cherrypy.engine.state == cherrypy.engine.states.STARTED:
                 self.port = port
                 return
     raise Exception("No available ports")
Exemplo n.º 7
0
    def _execute_stmt(self, stmt, stmt_args_list):
        """Helper for "self.execute_queued_items".

        Execute a statement. If this is the public database, return True on
        success and False on failure. If this is the private database, return
        True on success, and raise on failure.
        """
        try:
            self.connect()
            self.conn.executemany(stmt, stmt_args_list)
        except sqlite3.Error:
            if not self.is_public:
                raise
            if cylc.flags.debug:
                traceback.print_exc()
            err_log = ("cannot execute database statement:\n" + "file=%(file)s:\nstmt=%(stmt)s") % {
                "file": self.db_file_name,
                "stmt": stmt,
            }
            for i, stmt_args in enumerate(stmt_args_list):
                err_log += "\nstmt_args[%(i)d]=%(stmt_args)s" % {"i": i, "stmt_args": stmt_args}
            ERR.warning(err_log)
            raise