Beispiel #1
0
    def test_timeout(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        self.called = False

        def urlopen_timeout(request, **kwargs):
            self.called = True
            raise socket.timeout('TIMEOUT')

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen_timeout):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assert_(self.called)
Beispiel #2
0
    def test_suspects(self):

        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        available = self.create('AVAILABLE', datetime(2000, 01, 01, 1, 1, 1))
        not_expected = self.create('BUILDING',
                                   datetime(2000, 01, 01, 1, 1, 25))

        restore = RestoreSuspects(self.conf, self.db)
        # Query the backup suspects for backups older than 10 seconds ago
        results = restore.suspects(
            timedelta(seconds=10), datetime(2000, 01, 01, 1, 1, 30)).all()

        # Assert the correct backups are in the results
        self.assertIn(expected, results)
        self.assertNotIn(available, results)
        self.assertNotIn(not_expected, results)
Beispiel #3
0
    def test_timeout(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        self.called = False

        def urlopen_timeout(request, **kwargs):
            self.called = True
            raise socket.timeout('TIMEOUT')

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen_timeout):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assert_(self.called)
Beispiel #4
0
    def test_run(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        available = self.create('AVAILABLE', datetime(2000, 01, 01, 1, 1, 1))
        not_expected = self.create('BUILDING',
                                   datetime(2000, 01, 01, 1, 1, 25))
        self.count = 0

        def urlopen(request, **kwargs):
            self.assert_(kwargs.get('timeout'))
            self.assertEquals(kwargs['timeout'], self.timeout)
            self.count += 1
            data = parse_qs(request.get_data())
            self.assertIn('backup_source_volume_id', data)
            self.assertEquals(data['backup_id'][0], expected.restore_of)
            self.assertEquals(data['size'][0], '0')
            return MockResponse('{}', 200)

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assertEquals(self.count, 1)
Beispiel #5
0
    def test_suspects(self):

        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        available = self.create('AVAILABLE', datetime(2000, 01, 01, 1, 1, 1))
        not_expected = self.create('BUILDING',
                                   datetime(2000, 01, 01, 1, 1, 25))

        restore = RestoreSuspects(self.conf, self.db)
        # Query the backup suspects for backups older than 10 seconds ago
        results = restore.suspects(timedelta(seconds=10),
                                   datetime(2000, 01, 01, 1, 1, 30)).all()

        # Assert the correct backups are in the results
        self.assertIn(expected, results)
        self.assertNotIn(available, results)
        self.assertNotIn(not_expected, results)
Beispiel #6
0
    def test_run(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        available = self.create('AVAILABLE', datetime(2000, 01, 01, 1, 1, 1))
        not_expected = self.create('BUILDING',
                                   datetime(2000, 01, 01, 1, 1, 25))
        self.count = 0

        def urlopen(request, **kwargs):
            self.assert_(kwargs.get('timeout'))
            self.assertEquals(kwargs['timeout'], self.timeout)
            self.count += 1
            data = parse_qs(request.get_data())
            self.assertIn('backup_source_volume_id', data)
            self.assertEquals(data['backup_id'][0], expected.restore_of)
            self.assertEquals(data['size'][0], '0')
            return MockResponse('{}', 200)

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assertEquals(self.count, 1)
Beispiel #7
0
            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


if __name__ == "__main__":
    sys.exit(main())