Esempio n. 1
0
 def test_certificate_logic(self):
     client = Mock()
     kwargs = { 'use_ssl' : True, 'certificate' : 'mycert.pem' }
     with self.assertRaises(SystemExit) as cm:
         curator.get_client(**kwargs)
         self.assertEqual(sys.stdout.getvalue(),'ERROR: Connection failure.\n')
     self.assertEqual(cm.exception.code, 1)
Esempio n. 2
0
 def test_client_key_logic(self):
     client = Mock()
     kwargs = {'use_ssl': True, 'client_key': 'myclientkey.pem'}
     with self.assertRaises(SystemExit) as cm:
         curator.get_client(**kwargs)
         self.assertEqual(sys.stdout.getvalue(),
                          'ERROR: Connection failure.\n')
     self.assertEqual(cm.exception.code, 1)
Esempio n. 3
0
    def test_reindex_migrate_from_remote_with_pre_suf_fixes(self):
        wait_interval = 1
        max_wait = 3
        source1 = 'my_source1'
        source2 = 'my_source2'
        prefix = 'my_'
        dest = 'MIGRATION'
        expected = 3
        mpfx = 'pre-'
        msfx = '-fix'

        # Build remote client
        try:
            rclient = curator.get_client(host=rhost,
                                         port=rport,
                                         skip_version_test=True)
            rclient.info()
        except:
            raise SkipTest('Unable to connect to host at {0}:{1}'.format(
                rhost, rport))
        # Build indices remotely.
        counter = 0
        for rindex in [source1, source2]:
            rclient.indices.create(index=rindex)
            for i in range(0, 3):
                rclient.create(
                    index=rindex,
                    doc_type='log',
                    id=str(counter + 1),
                    body={"doc" + str(counter + i): 'TEST DOCUMENT'},
                )
                counter += 1
                # Decorators make this pylint exception necessary
                # pylint: disable=E1123
                rclient.indices.flush(index=rindex, force=True)
        self.write_config(self.args['configfile'],
                          testvars.client_config.format(host, port))
        self.write_config(
            self.args['actionfile'],
            testvars.migration_reindex.format(
                wait_interval, max_wait, mpfx, msfx,
                'http://{0}:{1}'.format(rhost, rport), 'REINDEX_SELECTION',
                dest, prefix))
        test = clicktest.CliRunner()
        _ = test.invoke(
            curator.cli,
            ['--config', self.args['configfile'], self.args['actionfile']],
        )
        # Do our own cleanup here.
        rclient.indices.delete(index='{0},{1}'.format(source1, source2))
        # And now the neat trick of verifying that the reindex worked to both
        # indices, and they preserved their names
        self.assertEqual(
            expected,
            self.client.count(
                index='{0}{1}{2}'.format(mpfx, source1, msfx))['count'])
        self.assertEqual(
            expected,
            self.client.count(
                index='{0}{1}{2}'.format(mpfx, source1, msfx))['count'])
Esempio n. 4
0
    def test_reindex_migrate_from_remote_with_pre_suf_fixes(self):
        wait_interval = 1
        max_wait = 3
        source1 = 'my_source1'
        source2 = 'my_source2'
        prefix = 'my_'
        dest = 'MIGRATION'
        expected = 3
        mpfx = 'pre-'
        msfx = '-fix'


        # Build remote client
        try:
            rclient = curator.get_client(
                host=rhost, port=rport, skip_version_test=True)
            rclient.info()
        except:
            raise SkipTest(
                'Unable to connect to host at {0}:{1}'.format(rhost, rport))
        # Build indices remotely.
        counter = 0
        for rindex in [source1, source2]:
            rclient.indices.create(index=rindex)
            for i in range(0, 3):
                rclient.create(
                    index=rindex, doc_type='log', id=str(counter+1),
                    body={"doc" + str(counter+i) :'TEST DOCUMENT'},
                )
                counter += 1
                rclient.indices.flush(index=rindex, force=True)
        self.write_config(
            self.args['configfile'], testvars.client_config.format(host, port))
        self.write_config(self.args['actionfile'],
            testvars.migration_reindex.format(
                wait_interval, 
                max_wait,
                mpfx,
                msfx,
                'http://{0}:{1}'.format(rhost, rport),
                'REINDEX_SELECTION', 
                dest,
                prefix
            )
        )
        test = clicktest.CliRunner()
        result = test.invoke(
                    curator.cli,
                    [
                        '--config', self.args['configfile'],
                        self.args['actionfile']
                    ],
                    )
        # Do our own cleanup here.
        rclient.indices.delete(index='{0},{1}'.format(source1, source2))
        # And now the neat trick of verifying that the reindex worked to both 
        # indices, and they preserved their names
        self.assertEqual(expected, self.client.count(index='{0}{1}{2}'.format(mpfx,source1,msfx))['count'])
        self.assertEqual(expected, self.client.count(index='{0}{1}{2}'.format(mpfx,source1,msfx))['count'])
Esempio n. 5
0
    def test_reindex_from_remote_no_indices(self):
        wait_interval = 1
        max_wait = 3
        source1 = 'wrong1'
        source2 = 'wrong2'
        prefix = 'my_'
        dest = 'my_dest'
        expected = 1

        # Build remote client
        try:
            rclient = curator.get_client(
                host=rhost, port=rport, skip_version_test=True)
            rclient.info()
        except:
            raise SkipTest(
                'Unable to connect to host at {0}:{1}'.format(rhost, rport))
        # Build indices remotely.
        counter = 0
        for rindex in [source1, source2]:
            rclient.indices.create(index=rindex)
            for i in range(0, 3):
                rclient.create(
                    index=rindex, doc_type='log', id=str(counter+1),
                    body={"doc" + str(counter+i) :'TEST DOCUMENT'},
                )
                counter += 1
                rclient.indices.flush(index=rindex, force=True)        
        self.write_config(
            self.args['configfile'], testvars.client_config.format(host, port))
        self.write_config(self.args['actionfile'],
            testvars.remote_reindex.format(
                wait_interval, 
                max_wait, 
                'http://{0}:{1}'.format(rhost, rport),
                'REINDEX_SELECTION', 
                dest,
                prefix
            )
        )
        test = clicktest.CliRunner()
        result = test.invoke(
                    curator.cli,
                    [
                        '--config', self.args['configfile'],
                        self.args['actionfile']
                    ],
                    )
        # Do our own cleanup here.
        rclient.indices.delete(index='{0},{1}'.format(source1, source2))
        self.assertEqual(expected, result.exit_code)
Esempio n. 6
0
    def test_reindex_from_remote_no_indices(self):
        wait_interval = 1
        max_wait = 3
        source1 = 'wrong1'
        source2 = 'wrong2'
        prefix = 'my_'
        dest = 'my_dest'
        expected = 1

        # Build remote client
        try:
            rclient = curator.get_client(
                host=rhost, port=rport, skip_version_test=True)
            rclient.info()
        except:
            raise SkipTest(
                'Unable to connect to host at {0}:{1}'.format(rhost, rport))
        # Build indices remotely.
        counter = 0
        for rindex in [source1, source2]:
            rclient.indices.create(index=rindex)
            for i in range(0, 3):
                rclient.create(
                    index=rindex, doc_type='log', id=str(counter+1),
                    body={"doc" + str(counter+i) :'TEST DOCUMENT'},
                )
                counter += 1
                rclient.indices.flush(index=rindex, force=True)        
        self.write_config(
            self.args['configfile'], testvars.client_config.format(host, port))
        self.write_config(self.args['actionfile'],
            testvars.remote_reindex.format(
                wait_interval, 
                max_wait, 
                'http://{0}:{1}'.format(rhost, rport),
                'REINDEX_SELECTION', 
                dest,
                prefix
            )
        )
        test = clicktest.CliRunner()
        result = test.invoke(
                    curator.cli,
                    [
                        '--config', self.args['configfile'],
                        self.args['actionfile']
                    ],
                    )
        # Do our own cleanup here.
        rclient.indices.delete(index='{0},{1}'.format(source1, source2))
        self.assertEqual(expected, result.exit_code)
Esempio n. 7
0
 def test_get_client_negative_connection_fail(self):
     client_args = {"host": host, "port": 54321}
     with self.assertRaises(SystemExit) as cm:
         curator.get_client(**client_args)
     self.assertEqual(cm.exception.code, 1)
Esempio n. 8
0
 def test_get_client_positive(self):
     client_args = {"host": host, "port": port}
     client = curator.get_client(**client_args)
     self.assertTrue(isinstance(client, elasticsearch.client.Elasticsearch))
Esempio n. 9
0
 def test_get_client_negative_connection_fail(self):
     client_args = {"host":host, "port":54321}
     with self.assertRaises(SystemExit) as cm:
         curator.get_client(**client_args)
     self.assertEqual(cm.exception.code, 1)
Esempio n. 10
0
 def test_get_client_positive(self):
     client_args = {"host":host, "port":port}
     client = curator.get_client(**client_args)
     self.assertTrue(isinstance(client, elasticsearch.client.Elasticsearch))