create_bwc_index_with_conficting_mappings.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import create_bwc_index
  2. import logging
  3. import os
  4. import random
  5. import shutil
  6. import subprocess
  7. import sys
  8. import tempfile
  9. def fetch_version(version):
  10. logging.info('fetching ES version %s' % version)
  11. if subprocess.call([sys.executable, os.path.join(os.path.split(sys.argv[0])[0], 'get-bwc-version.py'), version]) != 0:
  12. raise RuntimeError('failed to download ES version %s' % version)
  13. def main():
  14. '''
  15. Creates a static back compat index (.zip) with conflicting mappings.
  16. '''
  17. logging.basicConfig(format='[%(levelname)s] [%(asctime)s] %(message)s', level=logging.INFO,
  18. datefmt='%Y-%m-%d %I:%M:%S %p')
  19. logging.getLogger('elasticsearch').setLevel(logging.ERROR)
  20. logging.getLogger('urllib3').setLevel(logging.WARN)
  21. tmp_dir = tempfile.mkdtemp()
  22. try:
  23. data_dir = os.path.join(tmp_dir, 'data')
  24. repo_dir = os.path.join(tmp_dir, 'repo')
  25. logging.info('Temp data dir: %s' % data_dir)
  26. logging.info('Temp repo dir: %s' % repo_dir)
  27. version = '1.7.0'
  28. classifier = 'conflicting-mappings-%s' % version
  29. index_name = 'index-%s' % classifier
  30. # Download old ES releases if necessary:
  31. release_dir = os.path.join('backwards', 'elasticsearch-%s' % version)
  32. if not os.path.exists(release_dir):
  33. fetch_version(version)
  34. node = create_bwc_index.start_node(version, release_dir, data_dir, repo_dir, cluster_name=index_name)
  35. client = create_bwc_index.create_client()
  36. put_conflicting_mappings(client, index_name)
  37. create_bwc_index.shutdown_node(node)
  38. print('%s server output:\n%s' % (version, node.stdout.read().decode('utf-8')))
  39. node = None
  40. create_bwc_index.compress_index(classifier, tmp_dir, 'core/src/test/resources/org/elasticsearch/action/admin/indices/upgrade')
  41. finally:
  42. if node is not None:
  43. create_bwc_index.shutdown_node(node)
  44. shutil.rmtree(tmp_dir)
  45. def put_conflicting_mappings(client, index_name):
  46. client.indices.delete(index=index_name, ignore=404)
  47. logging.info('Create single shard test index')
  48. mappings = {}
  49. # backwardcompat test for conflicting mappings, see #11857
  50. mappings['x'] = {
  51. 'analyzer': 'standard',
  52. "properties": {
  53. "foo": {
  54. "type": "string"
  55. }
  56. }
  57. }
  58. mappings['y'] = {
  59. 'analyzer': 'standard',
  60. "properties": {
  61. "foo": {
  62. "type": "date"
  63. }
  64. }
  65. }
  66. client.indices.create(index=index_name, body={
  67. 'settings': {
  68. 'number_of_shards': 1,
  69. 'number_of_replicas': 0
  70. },
  71. 'mappings': mappings
  72. })
  73. health = client.cluster.health(wait_for_status='green', wait_for_relocating_shards=0)
  74. assert health['timed_out'] == False, 'cluster health timed out %s' % health
  75. num_docs = random.randint(2000, 3000)
  76. create_bwc_index.index_documents(client, index_name, 'doc', num_docs)
  77. logging.info('Running basic asserts on the data added')
  78. create_bwc_index.run_basic_asserts(client, index_name, 'doc', num_docs)
  79. if __name__ == '__main__':
  80. main()