Ejemplo n.º 1
0
def _conn(commit=False):
    '''
    Return an postgres cursor
    '''
    defaults = {'host': 'localhost',
                'user': '******',
                'password': '******',
                'dbname': 'salt',
                'port': 5432}

    conn_kwargs = {}
    for key, value in defaults.items():
        conn_kwargs[key] = __opts__.get('queue.{0}.{1}'.format(__virtualname__, key), value)
    try:
        conn = psycopg2.connect(**conn_kwargs)
    except psycopg2.OperationalError as exc:
        raise SaltMasterError('pgjsonb returner could not connect to database: {exc}'.format(exc=exc))

    cursor = conn.cursor()

    try:
        yield cursor
    except psycopg2.DatabaseError as err:
        error = err.args
        sys.stderr.write(six.text_type(error))
        cursor.execute("ROLLBACK")
        six.reraise(*sys.exc_info())
    else:
        if commit:
            cursor.execute("COMMIT")
        else:
            cursor.execute("ROLLBACK")
    finally:
        conn.close()
Ejemplo n.º 2
0
 def _visit(self, node, marked_nodes, root):
     if marked_nodes[node] == 1:
         msg = 'found a loop node={0} dfs_root={1}'.format(node, root)
         log.error(msg)
         raise SaltMasterError(msg)
     if marked_nodes[node] == 2:
         return
     marked_nodes[node] = 1
     if node in self.data:
         for child in self.data[node]:
             self._visit(child, marked_nodes, root)
         self.sorted.append(node)
     marked_nodes[node] = 2
Ejemplo n.º 3
0
def fileserver_update(fileserver):
    '''
    Update the fileserver backends, requires that a built fileserver object
    be passed in
    '''
    try:
        if not fileserver.servers:
            log.error('No fileservers loaded, the master will not be able to '
                      'serve files to minions')
            raise SaltMasterError('No fileserver backends available')
        fileserver.update()
    except Exception as exc:
        log.error('Exception {0} occurred in file server update'.format(exc),
                  exc_info_on_loglevel=logging.DEBUG)
Ejemplo n.º 4
0
def _conn(commit=False):
    """
    Return an postgres cursor
    """
    defaults = {
        "host": "localhost",
        "user": "******",
        "password": "******",
        "dbname": "salt",
        "port": 5432,
    }

    conn_kwargs = {}
    for key, value in defaults.items():
        conn_kwargs[key] = __opts__.get(
            "queue.{}.{}".format(__virtualname__, key), value)
    try:
        conn = psycopg2.connect(**conn_kwargs)
    except psycopg2.OperationalError as exc:
        raise SaltMasterError(
            "pgjsonb returner could not connect to database: {exc}".format(
                exc=exc))

    cursor = conn.cursor()

    try:
        yield cursor
    except psycopg2.DatabaseError as err:
        error = err.args
        sys.stderr.write(str(error))
        cursor.execute("ROLLBACK")
        raise
    else:
        if commit:
            cursor.execute("COMMIT")
        else:
            cursor.execute("ROLLBACK")
    finally:
        conn.close()