Ejemplo n.º 1
0
 def get_conn(self):
     """
     Returns a DB API connection instance to the auth server's SQLite
     database. This is a contextmanager call to be use with the 'with'
     statement. It takes no parameters.
     """
     if not self.conn:
         # We go ahead and make another db connection even if this is a
         # reentry call; just in case we had an error that caused self.conn
         # to become None. Even if we make an extra conn, we'll only keep
         # one after the 'with' block.
         self.conn = get_db_connection(self.db_file)
     conn = self.conn
     self.conn = None
     try:
         yield conn
         conn.rollback()
         self.conn = conn
     except Exception, err:
         try:
             conn.close()
         except Exception:
             pass
         self.conn = get_db_connection(self.db_file)
         raise err
Ejemplo n.º 2
0
 def get_conn(self):
     """
     Returns a DB API connection instance to the auth server's SQLite
     database. This is a contextmanager call to be use with the 'with'
     statement. It takes no parameters.
     """
     if not self.conn:
         # We go ahead and make another db connection even if this is a
         # reentry call; just in case we had an error that caused self.conn
         # to become None. Even if we make an extra conn, we'll only keep
         # one after the 'with' block.
         self.conn = get_db_connection(self.db_file)
     conn = self.conn
     self.conn = None
     try:
         yield conn
         conn.rollback()
         self.conn = conn
     except Exception, err:
         try:
             conn.close()
         except Exception:
             pass
         self.conn = get_db_connection(self.db_file)
         raise err
Ejemplo n.º 3
0
 def test_upgrading_from_db2(self):
     swift_dir = '/tmp/swift_test_auth_%s' % uuid4().hex
     os.mkdir(swift_dir)
     try:
         # Create db1
         db_file = os.path.join(swift_dir, 'auth.db')
         conn = get_db_connection(db_file, okay_to_create=True)
         conn.execute('''CREATE TABLE IF NOT EXISTS account (
                            account TEXT, url TEXT, cfaccount TEXT,
                            user TEXT, password TEXT, admin TEXT)''')
         conn.execute('''CREATE INDEX IF NOT EXISTS ix_account_account
                         ON account (account)''')
         conn.execute('''CREATE TABLE IF NOT EXISTS token (
                            token TEXT, created FLOAT,
                            account TEXT, user TEXT, cfaccount TEXT)''')
         conn.execute('''CREATE INDEX IF NOT EXISTS ix_token_token
                         ON token (token)''')
         conn.execute('''CREATE INDEX IF NOT EXISTS ix_token_created
                         ON token (created)''')
         conn.execute('''CREATE INDEX IF NOT EXISTS ix_token_account
                         ON token (account)''')
         conn.execute('''INSERT INTO account
                         (account, url, cfaccount, user, password, admin)
                         VALUES ('act', 'url', 'cfa', 'us1', 'pas', '')''')
         conn.execute('''INSERT INTO account
                         (account, url, cfaccount, user, password, admin)
                         VALUES ('act', 'url', 'cfa', 'us2', 'pas', 't')''')
         conn.execute('''INSERT INTO token
                         (token, created, account, user, cfaccount)
                         VALUES ('tok', '1', 'act', 'us1', 'cfa')''')
         conn.commit()
         conn.close()
         # Upgrade to current db
         conf = {'swift_dir': swift_dir, 'super_admin_key': 'testkey'}
         exc = None
         try:
             auth_server.AuthController(conf)
         except Exception, err:
             exc = err
         self.assert_(str(err).strip().startswith('THERE ARE ACCOUNTS IN '
             'YOUR auth.db THAT DO NOT BEGIN WITH YOUR NEW RESELLER'), err)
         # Check new items exist and are correct
         conn = get_db_connection(db_file)
         row = conn.execute('''SELECT admin, reseller_admin
                             FROM account WHERE user = '******' ''').fetchone()
         self.assert_(not row[0], row[0])
         self.assert_(not row[1], row[1])
         row = conn.execute('''SELECT admin, reseller_admin
                             FROM account WHERE user = '******' ''').fetchone()
         self.assertEquals(row[0], 't')
         self.assert_(not row[1], row[1])
         row = conn.execute('SELECT user FROM token').fetchone()
         self.assert_(row)
Ejemplo n.º 4
0
 def __init__(self, conf):
     self.logger = get_logger(conf)
     self.super_admin_key = conf.get('super_admin_key')
     if not self.super_admin_key:
         msg = _('No super_admin_key set in conf file! Exiting.')
         try:
             self.logger.critical(msg)
         except Exception:
             pass
         raise ValueError(msg)
     self.swift_dir = conf.get('swift_dir', '/etc/swift')
     self.reseller_prefix = conf.get('reseller_prefix', 'AUTH').strip()
     if self.reseller_prefix and self.reseller_prefix[-1] != '_':
         self.reseller_prefix += '_'
     self.default_cluster_url = conf.get('default_cluster_url',
                                 'http://127.0.0.1:8080/v1').rstrip('/')
     self.token_life = int(conf.get('token_life', 86400))
     self.log_headers = conf.get('log_headers') == 'True'
     self.db_file = os.path.join(self.swift_dir, 'auth.db')
     self.conn = get_db_connection(self.db_file, okay_to_create=True)
     try:
         self.conn.execute('SELECT admin FROM account LIMIT 1')
     except sqlite3.OperationalError, err:
         if str(err) == 'no such column: admin':
             self.conn.execute("ALTER TABLE account ADD COLUMN admin TEXT")
             self.conn.execute("UPDATE account SET admin = 't'")
Ejemplo n.º 5
0
 def __init__(self, conf):
     self.logger = get_logger(conf)
     self.super_admin_key = conf.get('super_admin_key')
     if not self.super_admin_key:
         msg = _('No super_admin_key set in conf file! Exiting.')
         try:
             self.logger.critical(msg)
         except Exception:
             pass
         raise ValueError(msg)
     self.swift_dir = conf.get('swift_dir', '/etc/swift')
     self.reseller_prefix = conf.get('reseller_prefix', 'AUTH').strip()
     if self.reseller_prefix and self.reseller_prefix[-1] != '_':
         self.reseller_prefix += '_'
     self.default_cluster_url = conf.get(
         'default_cluster_url', 'http://127.0.0.1:8080/v1').rstrip('/')
     self.token_life = int(conf.get('token_life', 86400))
     self.log_headers = conf.get('log_headers') == 'True'
     self.db_file = os.path.join(self.swift_dir, 'auth.db')
     self.conn = get_db_connection(self.db_file, okay_to_create=True)
     try:
         self.conn.execute('SELECT admin FROM account LIMIT 1')
     except sqlite3.OperationalError, err:
         if str(err) == 'no such column: admin':
             self.conn.execute("ALTER TABLE account ADD COLUMN admin TEXT")
             self.conn.execute("UPDATE account SET admin = 't'")
Ejemplo n.º 6
0
 def test_normal_case(self):
     conn = get_db_connection(':memory:')
     self.assert_(hasattr(conn, 'execute'))
Ejemplo n.º 7
0
 def test_normal_case(self):
     conn = get_db_connection(':memory:')
     self.assert_(hasattr(conn, 'execute'))