mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Tests: Make sure snapshots created with old version of elasticsearch can be restored
Closes #8968
This commit is contained in:
parent
3c0d2081cf
commit
fcb0186d2e
29 changed files with 212 additions and 4 deletions
|
@ -113,7 +113,7 @@ def start_node(version, release_dir, data_dir, tcp_port, http_port):
|
|||
'-Des.transport.tcp.port=%s' % tcp_port,
|
||||
'-Des.http.port=%s' % http_port
|
||||
]
|
||||
if version.startswith('0.') or version == '1.0.0.Beta1':
|
||||
if version.startswith('0.') or version.startswith('1.0.0.Beta') :
|
||||
cmd.append('-f') # version before 1.0 start in background automatically
|
||||
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
@ -150,17 +150,60 @@ def generate_index(client):
|
|||
logging.info('Running basic asserts on the data added')
|
||||
run_basic_asserts(client, 'test', 'doc', num_docs)
|
||||
|
||||
def snapshot_index(client, cfg):
|
||||
# Add bogus persistent settings to make sure they can be restored
|
||||
client.cluster.put_settings(body = {
|
||||
'persistent': {
|
||||
'cluster.routing.allocation.exclude.version_attr' : cfg.version
|
||||
}
|
||||
})
|
||||
client.indices.put_template(name = 'template_' + cfg.version.lower(), order = 0, body = {
|
||||
"template" : "te*",
|
||||
"settings" : {
|
||||
"number_of_shards" : 1
|
||||
},
|
||||
"mappings" : {
|
||||
"type1" : {
|
||||
"_source" : { "enabled" : False }
|
||||
}
|
||||
},
|
||||
"aliases" : {
|
||||
"alias1" : {},
|
||||
"alias2" : {
|
||||
"filter" : {
|
||||
"term" : {"version" : cfg.version }
|
||||
},
|
||||
"routing" : "kimchy"
|
||||
},
|
||||
"{index}-alias" : {}
|
||||
}
|
||||
});
|
||||
client.snapshot.create_repository(repository='test_repo', body={
|
||||
'type': 'fs',
|
||||
'settings': {
|
||||
'location': cfg.repo_dir
|
||||
}
|
||||
})
|
||||
client.snapshot.create(repository='test_repo', snapshot='test_1', wait_for_completion=True)
|
||||
|
||||
def compress_index(version, tmp_dir, output_dir):
|
||||
compress(tmp_dir, output_dir, 'index-%s.zip' % version, 'data')
|
||||
|
||||
def compress_repo(version, tmp_dir, output_dir):
|
||||
compress(tmp_dir, output_dir, 'repo-%s.zip' % version, 'repo')
|
||||
|
||||
def compress(tmp_dir, output_dir, zipfile, directory):
|
||||
abs_output_dir = os.path.abspath(output_dir)
|
||||
zipfile = os.path.join(abs_output_dir, 'index-%s.zip' % version)
|
||||
zipfile = os.path.join(abs_output_dir, zipfile)
|
||||
if os.path.exists(zipfile):
|
||||
os.remove(zipfile)
|
||||
logging.info('Compressing index into %s', zipfile)
|
||||
olddir = os.getcwd()
|
||||
os.chdir(tmp_dir)
|
||||
subprocess.check_call('zip -r %s *' % zipfile, shell=True)
|
||||
subprocess.check_call('zip -r %s %s' % (zipfile, directory), shell=True)
|
||||
os.chdir(olddir)
|
||||
|
||||
|
||||
def parse_config():
|
||||
parser = argparse.ArgumentParser(description='Builds an elasticsearch index for backwards compatibility tests')
|
||||
parser.add_argument('version', metavar='X.Y.Z',
|
||||
|
@ -184,7 +227,10 @@ def parse_config():
|
|||
|
||||
cfg.tmp_dir = tempfile.mkdtemp()
|
||||
cfg.data_dir = os.path.join(cfg.tmp_dir, 'data')
|
||||
cfg.repo_dir = os.path.join(cfg.tmp_dir, 'repo')
|
||||
logging.info('Temp data dir: %s' % cfg.data_dir)
|
||||
logging.info('Temp repo dir: %s' % cfg.repo_dir)
|
||||
cfg.snapshot_supported = not (cfg.version.startswith('0.') or cfg.version == '1.0.0.Beta1')
|
||||
|
||||
return cfg
|
||||
|
||||
|
@ -193,17 +239,21 @@ def main():
|
|||
datefmt='%Y-%m-%d %I:%M:%S %p')
|
||||
logging.getLogger('elasticsearch').setLevel(logging.ERROR)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARN)
|
||||
|
||||
cfg = parse_config()
|
||||
try:
|
||||
node = start_node(cfg.version, cfg.release_dir, cfg.data_dir, cfg.tcp_port, cfg.http_port)
|
||||
client = create_client(cfg.http_port)
|
||||
generate_index(client)
|
||||
if cfg.snapshot_supported:
|
||||
snapshot_index(client, cfg)
|
||||
finally:
|
||||
if 'node' in vars():
|
||||
logging.info('Shutting down node with pid %d', node.pid)
|
||||
node.terminate()
|
||||
time.sleep(1) # some nodes take time to terminate
|
||||
compress_index(cfg.version, cfg.tmp_dir, cfg.output_dir)
|
||||
if cfg.snapshot_supported:
|
||||
compress_repo(cfg.version, cfg.tmp_dir, cfg.output_dir)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue