Exemplo n.º 1
0
    def test_is_snapshot_stale_invalid(self):
        """ Snapshot if the timer has elapsed even if the binlog isn't stale"""
        consul = Consul(envs=get_environ())
        binlog_file = 'mysql.001'

        consul_values = {
            LAST_BACKUP_KEY: '{"id": "xxxx", "dt": "yyyyy"}',
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        try:
            self.assertTrue(consul.is_snapshot_stale(binlog_file))
            self.fail('Expected ValueError with invalid data in Consul')
        except ValueError:
            pass

        # not stale
        now = datetime.utcnow().isoformat()
        consul_values = {
            LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(now),
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        self.assertFalse(consul.is_snapshot_stale(binlog_file))

        # stale
        then = (datetime.utcnow() - timedelta(hours=25)).isoformat()
        consul_values = {
            LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(then),
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        self.assertTrue(consul.is_snapshot_stale(binlog_file))
Exemplo n.º 2
0
    def test_is_snapshot_stale_invalid(self):
        """ Snapshot if the timer has elapsed even if the binlog isn't stale"""
        consul = Consul(envs=get_environ())
        binlog_file = 'mysql.001'

        consul_values = {
            LAST_BACKUP_KEY: '{"id": "xxxx", "dt": "yyyyy"}',
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        try:
            self.assertTrue(consul.is_snapshot_stale(binlog_file))
            self.fail('Expected ValueError with invalid data in Consul')
        except ValueError:
            pass

        # not stale
        now = datetime.utcnow().isoformat()
        consul_values = {
            LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(now),
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        self.assertFalse(consul.is_snapshot_stale(binlog_file))

        # stale
        then = (datetime.utcnow() - timedelta(hours=25)).isoformat()
        consul_values = {
            LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(then),
            LAST_BINLOG_KEY: 'mysql.001',
        }
        consul.get = consul_values.__getitem__
        self.assertTrue(consul.is_snapshot_stale(binlog_file))
Exemplo n.º 3
0
 def test_binlog_stale(self):
     """ Snapshot if the binlog is stale even if its not time to do so """
     consul = Consul(envs=get_environ())
     binlog_file = 'mysql.002'
     now = datetime.utcnow().isoformat()
     consul_values = {
         LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(now),
         LAST_BINLOG_KEY: 'mysql.001',
     }
     consul.get = consul_values.__getitem__
     self.assertTrue(consul.is_snapshot_stale(binlog_file))
Exemplo n.º 4
0
 def test_binlog_stale(self):
     """ Snapshot if the binlog is stale even if its not time to do so """
     consul = Consul(envs=get_environ())
     binlog_file = 'mysql.002'
     now = datetime.utcnow().isoformat()
     consul_values = {
         LAST_BACKUP_KEY: '{{"id": "xxxx", "dt": "{}"}}'.format(now),
         LAST_BINLOG_KEY: 'mysql.001',
     }
     consul.get = consul_values.__getitem__
     self.assertTrue(consul.is_snapshot_stale(binlog_file))