Skip to content

Commit 36fd3b1

Browse files
authored
Sample Data Tooling Refactor (#70)
* Refactored file structure and modified sys.path Signed-off-by: Huy Nguyen <wronghuy@amazon.com> * Added another directory level for Dockerfile Signed-off-by: Huy Nguyen <wronghuy@amazon.com> * Removed a directory structure layer Signed-off-by: Huy Nguyen <wronghuy@amazon.com> * Added license headers to unit tests Signed-off-by: Huy Nguyen <wronghuy@amazon.com> * Removed unnecessary comments from Dockerfile Signed-off-by: Huy Nguyen <wronghuy@amazon.com> Signed-off-by: Huy Nguyen <wronghuy@amazon.com>
1 parent a576197 commit 36fd3b1

File tree

12 files changed

+38
-27
lines changed

12 files changed

+38
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# syntax=docker/dockerfile:1
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# The OpenSearch Contributors require contributions made to
4+
# this file be licensed under the Apache-2.0 license or a
5+
# compatible open source license.
26

37
FROM python:3
48

59
COPY requirements.txt requirements.txt
610

711
RUN pip install -r requirements.txt
812

9-
COPY . .
13+
RUN mkdir sample_data_tooling
14+
15+
COPY . sample_data_tooling

src/playground/sample_data_tooling/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ In order to deploy this tooling to Playground, first ensure that [`kubectl`](htt
6060
Once `kubectl` is installed and the Kubernetes cluster is running, first configure secrets so the container can pull credentials from the cluster.
6161

6262
```
63-
kubectl create secret generic sample-data-secret --from-literal='username=<admin username>' --from-literal='password=<admin password>' --from-literal='host=opensearch-cluster-leader'
63+
kubectl create secret generic sample-data-secret --from-literal='SAMPLE_DATA_USERNAME=<username>' --from-literal='SAMPLE_DATA_PASSWORD=<password>' --from-literal='SAMPLE_DATA_HOST=opensearch-cluster-leader'
6464
```
6565

6666
Then, from this directory, change directory into the job and cronjob deployment files and deploy them.

src/playground/sample_data_tooling/sample_data_authentication/sample_data_basic_authentication.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import sys
99

1010
# Adds parent directory "/sample_data_tooling" to sys.path
11-
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
12-
from sample_data_authentication.sample_data_authentication import Authentication
11+
sys.path.append(path.abspath(__file__).split("sample_data_tooling")[0])
12+
from sample_data_tooling.sample_data_authentication.sample_data_authentication import Authentication
1313

1414

1515
class BasicAuthentication(Authentication):

src/playground/sample_data_tooling/sample_data_indices/sample_data_indices.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import sys
1111

1212
# Adds parent directory "/sample_data_tooling" to sys.path
13-
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
14-
from sample_data_ingestor.sample_data_ingestor import ingest
13+
sys.path.append(path.abspath(__file__).split("sample_data_tooling")[0])
14+
from sample_data_tooling.sample_data_ingestor.sample_data_ingestor import ingest
1515

1616

1717
class SampleDataIndex:

src/playground/sample_data_tooling/sample_data_plugins/ad_plugin_class.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import sys
1212

1313
# Adds parent directory "/sample_data_tooling" to sys.path
14-
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
15-
from sample_data_authentication.sample_data_authentication import Authentication
16-
from sample_data_plugins.sample_data_plugin import Plugin
14+
sys.path.append(path.abspath(__file__).split("sample_data_tooling")[0])
15+
from sample_data_tooling.sample_data_authentication.sample_data_authentication import Authentication
16+
from sample_data_tooling.sample_data_plugins.sample_data_plugin import Plugin
1717

1818

1919
class AnomalyDetection(Plugin):

src/playground/sample_data_tooling/sample_data_plugins/sample_data_plugin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import sys
1111

1212
# Adds parent directory "/sample_data_tooling" to sys.path
13-
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
14-
from sample_data_authentication.sample_data_authentication import Authentication
15-
from sample_data_commons.utils import validate_filename
13+
sys.path.append(path.abspath(__file__).split("sample_data_tooling")[0])
14+
from sample_data_tooling.sample_data_authentication.sample_data_authentication import Authentication
15+
from sample_data_tooling.sample_data_commons.utils import validate_filename
1616

1717

1818
class Plugin:

src/playground/sample_data_tooling/sample_data_tests/sample_data_authentication_tests/unit-test/sample_data_authentication_unit_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import os
99

1010
# Adds parent directory sample_data_tooling to sys.path
11-
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
12-
from sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
11+
sys.path.append(os.path.abspath(__file__).split("sample_data_tooling")[0])
12+
from sample_data_tooling.sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
1313

1414

1515
# Test that basic authentication works and returns as expected

src/playground/sample_data_tooling/sample_data_tests/sample_data_generator_tests/unit-test/sample_data_generator_unit_test.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Copyright OpenSearch Contributors
3+
SPDX-License-Identifier: Apache-2.0
4+
"""
5+
16
# Test functions
27
import os
38
import sys
@@ -7,8 +12,8 @@
712
from types import NoneType
813

914
# Adds parent directory sample_data_tooling to sys.path
10-
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
11-
import sample_data_generator.sample_data_generator as generator
15+
sys.path.append(os.path.abspath(__file__).split("sample_data_tooling")[0])
16+
import sample_data_tooling.sample_data_generator.sample_data_generator as generator
1217

1318

1419
# This path is for getting the parent directory sample_data_generator_tests
@@ -78,7 +83,7 @@ def test_valid_choose_field():
7883
assert type(generator.choose_field("keyword", ["email"])) is str
7984
assert "@" in generator.choose_field("keyword", ["email"])
8085
assert type(generator.choose_field("date detection string")) is bool
81-
assert type(generator.choose_field("numeric detection string")) is bool
86+
assert type(generator.choose_field("numeric detection string")) is bool
8287
# One of Faker's standard providers
8388
ssn = generator.choose_field("ssn")
8489
assert type(ssn) is str and "-" == ssn[3] and "-" == ssn[6]
@@ -158,7 +163,7 @@ def test_valid_generate_data():
158163
test_2 = json.loads(generator.generate_data(valid_json_mapping))
159164
assert len(test_2) == 3
160165
for field in test_2:
161-
assert test_2[field] != None
166+
assert test_2[field] != None
162167

163168
test_3 = json.loads(generator.generate_data(valid_json_string_shorthand, False))
164169
assert len(test_3) == 3

src/playground/sample_data_tooling/sample_data_tests/sample_data_indices_tests/unit-test/sample_data_indices_unit_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import os
1111

1212
# Adds the directory "/sample_data_tooling" to sys.path
13-
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
14-
from sample_data_indices.sample_data_indices import SampleDataIndex
13+
sys.path.append(os.path.abspath(__file__).split("sample_data_tooling")[0])
14+
from sample_data_tooling.sample_data_indices.sample_data_indices import SampleDataIndex
1515

1616

1717
# Constants

src/playground/sample_data_tooling/sample_data_tests/sample_data_plugin_tests/unit-test/ad_plugin_class_unit_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import os
99

1010
# Adds the directory "/sample_data_tooling" to sys.path
11-
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
12-
from sample_data_plugins.ad_plugin_class import AnomalyDetection
13-
from sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
11+
sys.path.append(os.path.abspath(__file__).split("sample_data_tooling")[0])
12+
from sample_data_tooling.sample_data_plugins.ad_plugin_class import AnomalyDetection
13+
from sample_data_tooling.sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
1414

1515

1616
# Constants

src/playground/sample_data_tooling/sample_data_tests/sample_data_plugin_tests/unit-test/sample_data_plugin_unit_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import os
99

1010
# Adds the directory "/sample_data_tooling" to sys.path
11-
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
12-
from sample_data_plugins.sample_data_plugin import Plugin
13-
from sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
11+
sys.path.append(os.path.abspath(__file__).split("sample_data_tooling")[0])
12+
from sample_data_tooling.sample_data_plugins.sample_data_plugin import Plugin
13+
from sample_data_tooling.sample_data_authentication.sample_data_basic_authentication import BasicAuthentication
1414

1515

1616
# Constants

0 commit comments

Comments
 (0)