Exemple #1
0
    def test_auto_create_false(self):
        class FakeLogger(object):
            def __init__(self):
                self.warned = False

            def warn(self, msg):
                self.warned = True
                self.msg = msg

        logger = FakeLogger()
        temp = mkdtemp()
        try:
            conf = LunrConfig({
                'default': {
                    'lunr_dir': temp
                },
                'db': {
                    'auto_create': False
                },
            })
            with patch(db, 'logger', logger):
                db.configure(conf)
            self.assert_(logger.warned)
            self.assert_('not version controlled' in logger.msg)
        finally:
            rmtree(temp)
Exemple #2
0
 def test_echo_false(self):
     db.configure(
         LunrConfig({
             'db': {
                 'auto_create': True,
                 'url': 'sqlite://',
                 'echo': 'false'
             }
         }))
     self.assertFalse(db.Session.bind.echo)
Exemple #3
0
 def test_non_default_poolclass(self):
     db.configure(
         LunrConfig({
             'db': {
                 'auto_create': True,
                 'url': 'sqlite://',
                 'poolclass': 'StaticPool'
             }
         }))
     self.assert_(isinstance(db.Session.bind.pool, pool.StaticPool))
Exemple #4
0
 def test_create_default_file_db(self):
     temp = mkdtemp()
     try:
         conf = LunrConfig(
             {'default': {'lunr_dir': temp}, 'db': {'auto_create': True}})
         db.configure(conf)
         self.assertEquals(str(db.Session.bind.url),
                           'sqlite:///' + temp + '/lunr.db')
         self.assert_(isinstance(db.Session.bind.pool, pool.NullPool))
     finally:
         rmtree(temp)
Exemple #5
0
 def __init__(self):
     self.conf = LunrConfig(
         {'db': {'auto_create': True, 'url': 'sqlite://'}})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
     self.node_timeout = None
Exemple #6
0
def main():
    parser = OptionParser('%prog [options] [DB_URL]')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      help='make sqlalchemy noisy')
    parser.add_option('-C', '--config', help="override config file")
    parser.add_option('-c', '--command', help="execute command and quit")
    options, args = parser.parse_args()

    logger.configure(log_to_console=True, capture_stdio=False)
    # Attempt to load a config
    conf = load_conf(options, args)
    # Create the session used to connect to the database
    session = db.configure(conf)

    banner = "session object 'db' connected to %s" % session.bind.url
    share = {
        'db': session,
        'func': func,
        'Query': Query,
        'helpers': helpers,
    }
    # add all models
    for model in models.ModelBase.__subclasses__():
        share[model.__name__] = model

    if options.command:
        exec options.command in globals(), share
    else:
        c = DBConsole(banner=banner, locals=share)
        return c()
Exemple #7
0
def main():
    parser = OptionParser('%prog [options] [DB_URL]')
    parser.add_option('-v', '--verbose', action='store_true',
                      help='make sqlalchemy noisy')
    parser.add_option('-C', '--config', help="override config file")
    parser.add_option('-c', '--command', help="execute command and quit")
    options, args = parser.parse_args()

    logger.configure(log_to_console=True, capture_stdio=False)
    # Attempt to load a config
    conf = load_conf(options, args)
    # Create the session used to connect to the database
    session = db.configure(conf)

    banner = "session object 'db' connected to %s" % session.bind.url
    share = {
        'db': session,
        'func': func,
        'Query': Query,
        'helpers': helpers,
    }
    # add all models
    for model in models.ModelBase.__subclasses__():
        share[model.__name__] = model

    if options.command:
        exec options.command in globals(), share
    else:
        c = DBConsole(banner=banner, locals=share)
        return c()
Exemple #8
0
 def __init__(self):
     self.conf = LunrConfig(
         {'db': {'auto_create': True, 'url': 'sqlite://'}})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
     self.node_timeout = None
     self.backups_per_volume = 10
Exemple #9
0
 def __init__(self):
     self.conf = LunrConfig(
         {'db': {'auto_create': True, 'url': 'sqlite://', 'echo': False}})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
     self.fill_strategy = 'broad_fill'
     self.node_timeout = None
     self.image_convert_limit = 3
Exemple #10
0
 def __init__(self):
     self.conf = LunrConfig(
         {'db': {'auto_create': True, 'url': 'sqlite://', 'echo': False}})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
     self.fill_strategy = 'broad_fill'
     self.node_timeout = None
     self.image_convert_limit = 3
Exemple #11
0
 def __init__(self):
     self.conf = LunrConfig(
         {'db': {
             'auto_create': True,
             'url': 'sqlite://'
         }})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
Exemple #12
0
 def setUpClass(cls):
     conf = LunrConfig.from_api_conf()
     sess = db.configure(conf)
     # Change the min_size to 0, so we can
     # create volumes smaller than a gig
     query = sess.query(VolumeType).filter_by(name='vtype')
     # Save the original value
     cls._min_size = query.one().min_size
     # Set min_size to 0
     query.update({'min_size': 0})
     sess.commit()
Exemple #13
0
 def setUpClass(cls):
     conf = LunrConfig.from_api_conf()
     sess = db.configure(conf)
     # Change the min_size to 0, so we can
     # create volumes smaller than a gig
     query = sess.query(VolumeType).filter_by(name='vtype')
     # Save the original value
     cls._min_size = query.one().min_size
     # Set min_size to 0
     query.update({'min_size': 0})
     sess.commit()
Exemple #14
0
    def setUp(self):
        self.conf = LunrConfig({'db': {'auto_create': True,
                                       'url': 'sqlite://'}})
        self.sess = db.configure(self.conf)

        vtype = VolumeType('vtype')
        node = Node('node1', volume_type=vtype,
                    hostname='10.127.0.1', port=8080)
        account_id = self.sess.get_or_create_account('test_account').id
        self.volume = Volume(1, 'vtype', node=node, account_id=account_id)
        self.sess.add_all([vtype, node, self.volume])
        self.sess.commit()
Exemple #15
0
    def setUp(self):
        self.conf = LunrConfig({'db': {'auto_create': True,
                                       'url': 'sqlite://'}})
        self.sess = db.configure(self.conf)

        vtype = VolumeType('vtype')
        node = Node('node1', volume_type=vtype,
                    hostname='10.127.0.1', port=8080)
        account_id = self.sess.get_or_create_account('test_account').id
        self.volume = Volume(1, 'vtype', node=node, account_id=account_id)
        self.sess.add_all([vtype, node, self.volume])
        self.sess.commit()
Exemple #16
0
    def test_auto_create_false(self):
        class FakeLogger(object):
            def __init__(self):
                self.warned = False

            def warn(self, msg):
                self.warned = True
                self.msg = msg

        logger = FakeLogger()
        temp = mkdtemp()
        try:
            conf = LunrConfig({
                'default': {'lunr_dir': temp},
                'db': {'auto_create': False},
            })
            with patch(db, 'logger', logger):
                db.configure(conf)
            self.assert_(logger.warned)
            self.assert_('not version controlled' in logger.msg)
        finally:
            rmtree(temp)
Exemple #17
0
    def setUp(self):
        self.timeout = 42
        self.conf = LunrConfig({
            'db': {'auto_create': True, 'url': 'sqlite://'},
            'restore-suspects': {'span': 'seconds=10'},
            'orbit': {'timeout': self.timeout},
        })
        self.db = db.configure(self.conf)

        self.account = Account()
        vtype = VolumeType('vtype')
        self.node = Node('node', 10, volume_type=vtype,
                         hostname='10.127.0.1', port=8080)
        self.db.add_all([vtype, self.node])
Exemple #18
0
    def setUp(self):
        self.timeout = 42
        self.conf = LunrConfig({
            'db': {'auto_create': True, 'url': 'sqlite://'},
            'restore-suspects': {'span': 'seconds=10'},
            'orbit': {'timeout': self.timeout},
        })
        self.db = db.configure(self.conf)

        self.account = Account()
        vtype = VolumeType('vtype')
        self.node = Node('node', 10, volume_type=vtype,
                         hostname='10.127.0.1', port=8080)
        self.db.add_all([vtype, self.node])
Exemple #19
0
    def setUp(self):
        self.conf = LunrConfig({
            'db': {'auto_create': True, 'url': 'sqlite://'},
            'scrub-suspects': {'span': 'seconds=10'},
        })
        self.db = db.configure(self.conf)

        self.account = Account()
        vtype = VolumeType('vtype')
        self.node = Node('node', 10, volume_type=vtype,
                         hostname='10.127.0.1', port=8080)
        self.db.add_all([vtype, self.node])
        volume = Volume(0, 'vtype', status='AVAILABLE', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETED', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETING', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        self.db.add(volume)
        self.db.commit()
Exemple #20
0
    def setUp(self):
        self.conf = LunrConfig({
            'db': {'auto_create': True, 'url': 'sqlite://'},
            'scrub-suspects': {'span': 'seconds=10'},
        })
        self.db = db.configure(self.conf)

        self.account = Account()
        vtype = VolumeType('vtype')
        self.node = Node('node', 10, volume_type=vtype,
                         hostname='10.127.0.1', port=8080)
        self.db.add_all([vtype, self.node])
        volume = Volume(0, 'vtype', status='AVAILABLE', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETED', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETING', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        self.db.add(volume)
        self.db.commit()
Exemple #21
0
 def _get_helper(self, conf):
     return db.configure(conf)
Exemple #22
0
 def setUp(self):
     self.db = db.configure(
         LunrConfig({'db': {'auto_create': True, 'url': 'sqlite://'}}))
Exemple #23
0
 def setUp(self):
     self.db = db.configure(LunrConfig({"db": {"auto_create": True, "url": "sqlite://"}}))
Exemple #24
0
 def __init__(self):
     self.conf = LunrConfig({"db": {"auto_create": True, "url": "sqlite://"}})
     # self.urlmap = urlmap
     self.helper = db.configure(self.conf)
     self.fill_percentage_limit = 0.5
Exemple #25
0
    if not re.match('(start|foreground)', options.command):
        return parser.print_help()

    if options.command == 'start':
        if daemon.alive():
            print "-- Orbit Already running"
            return 1

    try:
        log.info("Starting Orbit..")
        with daemon:
            # load the logging config and get our log handle
            detach = conf.bool('orbit', 'foreground', False)
            logger.configure(conf.file, log_to_console=detach)
            # Connect to the database
            session = db.configure(conf)
            # TODO(thrawn): make this configurable
            # Pass in a list of jobs cron should run
            cron = Cron([
                AuditSuspects(conf, session),
                BackupSuspects(conf, session),
                RestoreSuspects(conf, session),
                ScrubSuspects(conf, session),
                PruneSuspects(conf, session),
                Detach(conf, session)
            ])
            # Run the cron
            return cron.run()
    except (DaemonError, CronError), e:
        log.error(str(e))
        return 1
Exemple #26
0
    if not re.match('(start|foreground)', options.command):
        return parser.print_help()

    if options.command == 'start':
        if daemon.alive():
            print "-- Orbit Already running"
            return 1

    try:
        log.info("Starting Orbit..")
        with daemon:
            # load the logging config and get our log handle
            detach = conf.bool('orbit', 'foreground', False)
            logger.configure(conf.file, log_to_console=detach)
            # Connect to the database
            session = db.configure(conf)
            # TODO(thrawn): make this configurable
            # Pass in a list of jobs cron should run
            cron = Cron([AuditSuspects(conf, session),
                         BackupSuspects(conf, session),
                         RestoreSuspects(conf, session),
                         ScrubSuspects(conf, session),
                         PruneSuspects(conf, session),
                         Detach(conf, session)])
            # Run the cron
            return cron.run()
    except (DaemonError, CronError), e:
        log.error(str(e))
        return 1

Exemple #27
0
 def setUp(self):
     self.db = db.configure(
         LunrConfig({'db': {
             'auto_create': True,
             'url': 'sqlite://'
         }}))
Exemple #28
0
 def test_create_in_memory_sqlite(self):
     db.configure(LunrConfig({'db': {'url': 'sqlite://'}}))
     self.assertEquals(str(db.Session.bind.url), 'sqlite://')
     self.assert_(isinstance(db.Session.bind.pool,
                             pool.SingletonThreadPool))
Exemple #29
0
 def test_create_in_memory_sqlite(self):
     db.configure(LunrConfig({'db': {'url': 'sqlite://'}}))
     self.assertEquals(str(db.Session.bind.url), 'sqlite://')
     self.assert_(isinstance(db.Session.bind.pool,
                             pool.SingletonThreadPool))
Exemple #30
0
 def test_non_default_poolclass(self):
     db.configure(LunrConfig({'db': {'auto_create': True,
                                     'url': 'sqlite://',
                                     'poolclass': 'StaticPool'}}))
     self.assert_(isinstance(db.Session.bind.pool, pool.StaticPool))
Exemple #31
0
 def test_echo_false(self):
     db.configure(LunrConfig({'db': {'auto_create': True,
                                     'url': 'sqlite://',
                                     'echo': 'false'}}))
     self.assertFalse(db.Session.bind.echo)