def handle(self, *args, **options):
     if options['delete']:
         Snapshot.delete_repository(options['repo'])
     else:
         if not options['dir']:
             raise CommandError("the following arguments are required: dir")
         Snapshot.create_repository(options['repo'], options['dir'])
Ejemplo n.º 2
0
 def test_show(self):
     self.assertTrue(
         Snapshot.show(ElasticSettings.getattr('REPOSITORY'), '_all',
                       False))
     self.assertTrue(
         Snapshot.show(ElasticSettings.getattr('REPOSITORY'), '_all', True))
     self.assertFalse(Snapshot.show('xyzabc', '_all', False))
Ejemplo n.º 3
0
 def wait_for_running_snapshot(self):
     ''' Wait for a running snapshot to complete. '''
     for _ in range(10):
         if not Snapshot.is_running():
             return
         time.sleep(2)
     logger.warn('Long running snapshot')
     self.assertTrue(False, 'Long running snapshot')
Ejemplo n.º 4
0
    def test_create_delete_repository(self):
        self.wait_for_running_snapshot()
        repo = SnapshotTest.TEST_REPO
        self.assertTrue(Snapshot.exists(repo, ''),
                        'Repository ' + repo + ' created')

        self.assertFalse(
            Snapshot.create_repository(repo, SnapshotTest.TEST_REPO_DIR),
            'Repository already exists.')

        call_command('repository', repo, delete=True)
        self.assertFalse(Snapshot.exists(repo, ''),
                         'Repository ' + repo + ' deleted')
        self.assertFalse(Snapshot.delete_repository(repo),
                         'Repository ' + repo + ' deleted')
        call_command('repository', repo, dir=SnapshotTest.TEST_REPO_DIR)
        self.assertTrue(Snapshot.exists(repo, ''),
                        'Repository ' + repo + ' created')
Ejemplo n.º 5
0
    def test_create_restore_delete_snapshot(self):
        self.wait_for_running_snapshot()
        snapshot = 'test_' + ElasticSettings.getattr('TEST')
        repo = SnapshotTest.TEST_REPO

        # create a snapshot
        call_command('snapshot',
                     snapshot,
                     indices=IDX['MARKER']['indexName'],
                     repo=repo)
        Snapshot.wait_for_snapshot(repo, snapshot)
        self.assertTrue(Snapshot.exists(repo, snapshot),
                        "Created snapshot " + snapshot)
        # snapshot already exist so return false
        self.assertFalse(
            Snapshot.create_snapshot(repo, snapshot,
                                     IDX['MARKER']['indexName']))

        # delete index
        requests.delete(ElasticSettings.url() + '/' +
                        IDX['MARKER']['indexName'])
        self.assertFalse(Search.index_exists(IDX['MARKER']['indexName']),
                         "Removed index")
        # restore from snapshot
        call_command('restore_snapshot',
                     snapshot,
                     repo=repo,
                     indices=IDX['MARKER']['indexName'])
        Search.index_refresh(IDX['MARKER']['indexName'])
        self.assertTrue(Search.index_exists(IDX['MARKER']['indexName']),
                        "Restored index exists")

        # remove snapshot
        call_command('snapshot', snapshot, delete=True, repo=repo)
        Snapshot.wait_for_snapshot(repo, snapshot, delete=True, count=10)
        self.assertFalse(Snapshot.exists(repo, snapshot),
                         "Deleted snapshot " + snapshot)
Ejemplo n.º 6
0
 def handle(self, *args, **options):
     Snapshot.show(options['repo'], options['snapshot'], options['all'])
Ejemplo n.º 7
0
 def handle(self, *args, **options):
     Snapshot.restore_snapshot(options['repo'], options['snapshot'],
                               options['url'], options['indices'])
Ejemplo n.º 8
0
 def handle(self, *args, **options):
     if options['delete']:
         Snapshot.delete_snapshot(options['repo'], options['snapshot'])
     else:
         Snapshot.create_snapshot(options['repo'], options['snapshot'],
                                  options['indices'])