Skip to content

Commit cab2895

Browse files
committed
Fix OpenSearch index creation in CI
- Remove cluster.blocks.create_index setting before creating indices to fix 403 errors in CI - Fix AttributeError by serializing e.info dict to JSON string before writing to stdout
1 parent 25e2038 commit cab2895

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

backend/dataroom/management/commands/setup_opensearch.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from django.core.management.base import BaseCommand
24
from opensearchpy import TransportError
35

@@ -16,6 +18,18 @@ def handle(self, *args, **options):
1618
confirm = options['confirm']
1719
index_name = options['index'] or OSImage.INDEX
1820

21+
# Ensure cluster is writable (remove read-only block if present)
22+
try:
23+
OS.client.cluster.put_settings(
24+
body={
25+
"persistent": {
26+
"cluster.blocks.create_index": None
27+
}
28+
}
29+
)
30+
except TransportError as e:
31+
self.stdout.write(self.style.WARNING(f'Could not remove cluster block: {json.dumps(e.info)}'))
32+
1933
exists = OS.client.indices.exists(index=index_name)
2034
if exists:
2135
self.stdout.write(f'Index "{index_name}" already exists. Mappings will be updated.')
@@ -33,7 +47,7 @@ def handle(self, *args, **options):
3347
body=OSImage.INDEX_SETTINGS['mappings'],
3448
)
3549
except TransportError as e:
36-
self.stdout.write(self.style.ERROR(e.info))
50+
self.stdout.write(self.style.ERROR(json.dumps(e.info)))
3751
raise e
3852
else:
3953
try:
@@ -42,7 +56,7 @@ def handle(self, *args, **options):
4256
body=OSImage.INDEX_SETTINGS,
4357
)
4458
except TransportError as e:
45-
self.stdout.write(self.style.ERROR(e.info))
59+
self.stdout.write(self.style.ERROR(json.dumps(e.info)))
4660
raise e
4761

4862
self.stdout.write(self.style.SUCCESS('Done!'))

0 commit comments

Comments
 (0)