1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
"""Test the Create Index action"""
# pylint: disable=C0115, C0116, invalid-name
import os
from curator import IndexList
from curator.helpers.date_ops import parse_date_pattern
from curator.helpers.getters import get_indices
from . import CuratorTestCase
from . import testvars
HOST = os.environ.get('TEST_ES_SERVER', 'http://127.0.0.1:9200')
class TestCLICreateIndex(CuratorTestCase):
def test_plain(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'], testvars.create_index.format('testing')
)
assert not get_indices(self.client)
self.invoke_runner()
self.assertEqual(['testing'], get_indices(self.client))
assert ['testing'] == get_indices(self.client)
def test_with_extra_settings(self):
idx = 'testing'
alias = 'aliasname'
mapkey1 = 'meep'
mapval1 = 'integer'
mapkey2 = 'beep'
mapval2 = 'keyword'
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'],
testvars.create_index_with_extra_settings.format(
idx, alias, mapkey1, mapval1, mapkey2, mapval2
),
)
assert not get_indices(self.client)
self.invoke_runner()
ilo = IndexList(self.client)
ilo.get_index_settings()
aliases = self.client.indices.get_alias(name=alias)
mapping = self.client.indices.get_mapping(index=idx)
assert [idx] == ilo.indices
assert '1' == ilo.index_info[idx]['number_of_shards']
assert '0' == ilo.index_info[idx]['number_of_replicas']
assert mapping[idx]['mappings']['properties'][mapkey1] == {'type': mapval1}
assert mapping[idx]['mappings']['properties'][mapkey2] == {'type': mapval2}
assert aliases[idx]['aliases'] == {alias: {'is_write_index': True}}
def test_with_strftime(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'], testvars.create_index.format('testing-%Y.%m.%d')
)
assert not get_indices(self.client)
idx = parse_date_pattern('testing-%Y.%m.%d')
self.invoke_runner()
assert [idx] == get_indices(self.client)
def test_with_date_math(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'], testvars.create_index.format('<testing-{now/d}>')
)
assert not get_indices(self.client)
idx = parse_date_pattern('testing-%Y.%m.%d')
self.invoke_runner()
assert [idx] == get_indices(self.client)
def test_extra_option(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'],
testvars.bad_option_proto_test.format('create_index'),
)
self.invoke_runner()
assert not get_indices(self.client)
assert 1 == self.result.exit_code
def test_already_existing_fail(self):
idx = 'testing'
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(self.args['actionfile'], testvars.create_index.format(idx))
self.create_index(idx)
self.invoke_runner()
assert [idx] == get_indices(self.client)
assert 1 == self.result.exit_code
def test_already_existing_pass(self):
config = (
'---\n'
'actions:\n'
' 1:\n'
' description: "Create index as named"\n'
' action: create_index\n'
' options:\n'
' name: {0}\n'
' ignore_existing: true\n'
)
idx = 'testing'
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(self.args['actionfile'], config.format(idx))
self.create_index(idx)
self.invoke_runner()
assert [idx] == get_indices(self.client)
assert 0 == self.result.exit_code
def test_incorrect_mapping_fail_with_propper_error(self):
config = (
'---\n'
'actions:\n'
' 1:\n'
' description: "Create index as named"\n'
' action: create_index\n'
' options:\n'
' name: {0}\n'
' extra_settings:\n'
' mappings:\n'
' properties:\n'
' name: ["test"]\n'
)
idx = 'testing'
self.write_config(
self.args['configfile'], testvars.none_logging_config.format(HOST)
)
self.write_config(self.args['actionfile'], config.format(idx))
self.invoke_runner()
assert not get_indices(self.client)
assert 'mapper_parsing_exception' in self.result.stdout
assert 1 == self.result.exit_code
|