예제 #1
0
    def test_backup_already_running(self):
        """ Don't snapshot if there's already a snapshot running """
        self.node.consul = Consul(envs=get_environ())
        self.node.consul.client = mock.MagicMock()
        self.node.consul.client.session.create.return_value = 'xyzzy'

        with mock.patch('manage.write_snapshot') as ws:
            lockfile_name = '/tmp/' + BACKUP_LOCK_KEY
            try:
                backup_lock = open(lockfile_name, 'w')
                fcntl.flock(backup_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
                manage.snapshot_task(self.node)
            finally:
                fcntl.flock(backup_lock, fcntl.LOCK_UN)
                backup_lock.close()
            self.assertFalse(ws.called)
예제 #2
0
    def test_backup_already_running(self):
        """ Don't snapshot if there's already a snapshot running """
        self.node.consul = Consul(envs=get_environ())
        self.node.consul.client = mock.MagicMock()
        self.node.consul.client.session.create.return_value = 'xyzzy'

        with mock.patch('manage.write_snapshot') as ws:
            lockfile_name = '/tmp/' + BACKUP_LOCK_KEY
            try:
                backup_lock = open(lockfile_name, 'w')
                fcntl.flock(backup_lock, fcntl.LOCK_EX|fcntl.LOCK_NB)
                manage.snapshot_task(self.node)
            finally:
                fcntl.flock(backup_lock, fcntl.LOCK_UN)
                backup_lock.close()
            self.assertFalse(ws.called)
예제 #3
0
 def test_backup_unlocked(self):
     """
     Make sure that if a snapshot has run that we unlock correctly.
     """
     self.node.consul = Consul(envs=get_environ())
     self.node.consul.client = mock.MagicMock()
     self.node.consul.client.session.create.return_value = 'xyzzy'
     with mock.patch('manage.write_snapshot') as ws:
         lockfile_name = '/tmp/' + BACKUP_LOCK_KEY
         try:
             backup_lock = open(lockfile_name, 'w')
             fcntl.flock(backup_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
             manage.snapshot_task(self.node)
         finally:
             fcntl.flock(backup_lock, fcntl.LOCK_UN)
             backup_lock.close()
         manage.snapshot_task(self.node)
         self.assertTrue(ws.called)
예제 #4
0
 def test_backup_unlocked(self):
     """
     Make sure that if a snapshot has run that we unlock correctly.
     """
     self.node.consul = Consul(envs=get_environ())
     self.node.consul.client = mock.MagicMock()
     self.node.consul.client.session.create.return_value = 'xyzzy'
     with mock.patch('manage.write_snapshot') as ws:
         lockfile_name = '/tmp/' + BACKUP_LOCK_KEY
         try:
             backup_lock = open(lockfile_name, 'w')
             fcntl.flock(backup_lock, fcntl.LOCK_EX|fcntl.LOCK_NB)
             manage.snapshot_task(self.node)
         finally:
             fcntl.flock(backup_lock, fcntl.LOCK_UN)
             backup_lock.close()
         manage.snapshot_task(self.node)
         self.assertTrue(ws.called)
예제 #5
0
 def test_not_snapshot_node(self):
     """ Don't snapshot if this isn't the snapshot node """
     # TODO update when this logic changes
     self.node.cp.state = REPLICA
     manage.snapshot_task(self.node)
     self.assertFalse(self.node.mysql.query.called)
예제 #6
0
 def test_not_snapshot_node(self):
     """ Don't snapshot if this isn't the snapshot node """
     # TODO update when this logic changes
     self.node.cp.state = REPLICA
     manage.snapshot_task(self.node)
     self.assertFalse(self.node.mysql.query.called)