Skip to content

Commit 02d5900

Browse files
committed
Add tests back
Signed-off-by: Ian Hoang <ianhoang16@gmail.com>
1 parent f2b858f commit 02d5900

6 files changed

+363
-0
lines changed

it/distribution_test.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import it
26+
27+
28+
@it.random_benchmark_config
29+
def test_tar_distributions(cfg):
30+
port = 19200
31+
for dist in it.DISTRIBUTIONS:
32+
for workload in it.WORKLOADS:
33+
it.wait_until_port_is_free(port_number=port)
34+
assert it.execute_test(cfg, f"--distribution-version=\"{dist}\" --workload=\"{workload}\" "
35+
f"--test-mode --provision-config-instance=4gheap --target-hosts=127.0.0.1:{port}") == 0
36+
37+
38+
@it.random_benchmark_config
39+
def test_docker_distribution(cfg):
40+
port = 19200
41+
# only test the most recent Docker distribution
42+
dist = it.DISTRIBUTIONS[-1]
43+
it.wait_until_port_is_free(port_number=port)
44+
assert it.execute_test(cfg, f"--pipeline=\"docker\" --distribution-version=\"{dist}\" "
45+
f"--workload=\"geonames\" --test-procedure=\"append-no-conflicts-index-only\" --test-mode "
46+
f"--provision-config-instance=4gheap --target-hosts=127.0.0.1:{port}") == 0

it/download_test.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import it
26+
27+
28+
@it.random_benchmark_config
29+
def test_download_distribution(cfg):
30+
for d in it.DISTRIBUTIONS:
31+
assert it.osbenchmark(cfg, f"download --distribution-version=\"{d}\" --quiet") == 0
32+
33+
34+
@it.random_benchmark_config
35+
def test_does_not_download_unsupported_distribution(cfg):
36+
assert it.osbenchmark(cfg, "download --distribution-version=\"1.7.6\" --quiet") != 0

it/info_test.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import it
26+
from osbenchmark.utils import process
27+
28+
29+
@it.benchmark_in_mem
30+
def test_workload_info_with_test_procedure(cfg):
31+
assert it.osbenchmark(cfg, "info --workload=geonames --test-procedure=append-no-conflicts") == 0
32+
33+
34+
@it.benchmark_in_mem
35+
def test_workload_info_with_workload_repo(cfg):
36+
assert it.osbenchmark(cfg, "info --workload-repository=default --workload=geonames") == 0
37+
38+
39+
@it.benchmark_in_mem
40+
def test_workload_info_with_task_filter(cfg):
41+
assert it.osbenchmark(cfg, "info --workload=geonames --test-procedure=append-no-conflicts --include-tasks=\"type:search\"") == 0
42+
43+
44+
@it.benchmark_in_mem
45+
def test_workload_info_fails_with_wrong_workload_params(cfg):
46+
# simulate a typo in workload parameter
47+
cmd = it.osbenchmark_command_line_for(cfg, "info --workload=geonames --workload-params='conflict_probability:5,number-of-replicas:1'")
48+
output = process.run_subprocess_with_output(cmd)
49+
expected = "Some of your workload parameter(s) \"number-of-replicas\" are not used by this workload; " \
50+
"perhaps you intend to use \"number_of_replicas\" instead.\n\nAll workload parameters you " \
51+
"provided are:\n- conflict_probability\n- number-of-replicas\n\nAll parameters exposed by this workload"
52+
53+
assert expected in "\n".join(output)

it/list_test.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import it
26+
27+
28+
@it.all_benchmark_configs
29+
def test_list_test_executions(cfg):
30+
assert it.osbenchmark(cfg, "list test_executions") == 0
31+
32+
33+
@it.benchmark_in_mem
34+
def test_list_provision_config_instances(cfg):
35+
assert it.osbenchmark(cfg, "list provision_config_instances") == 0
36+
assert it.osbenchmark(cfg, "list provision_config_instances --provision-config-repository=default") == 0
37+
38+
39+
@it.benchmark_in_mem
40+
def test_list_opensearch_plugins(cfg):
41+
assert it.osbenchmark(cfg, "list opensearch-plugins") == 0
42+
43+
44+
@it.benchmark_in_mem
45+
def test_list_workloads(cfg):
46+
assert it.osbenchmark(cfg, "list workloads") == 0
47+
assert it.osbenchmark(cfg, "list workloads --workload-repository=default "
48+
"--workload-revision=cba4e45dda37ac03abbd3c9dd4532475dac355e9") == 0
49+
50+
51+
@it.benchmark_in_mem
52+
def test_list_telemetry(cfg):
53+
assert it.osbenchmark(cfg, "list telemetry") == 0

it/proxy_test.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import collections
26+
import os
27+
import shutil
28+
import tempfile
29+
30+
import pytest
31+
32+
import it
33+
from osbenchmark.utils import process
34+
35+
HttpProxy = collections.namedtuple("HttpProxy", ["authenticated_url", "anonymous_url"])
36+
37+
38+
@pytest.fixture(scope="module")
39+
def http_proxy():
40+
config_dir = os.path.join(os.path.dirname(__file__), "resources", "squid")
41+
42+
lines = process.run_subprocess_with_output(f"docker run --rm --name squid -d "
43+
f"-v {config_dir}/squidpasswords:/etc/squid/squidpasswords "
44+
f"-v {config_dir}/squid.conf:/etc/squid/squid.conf "
45+
f"-p 3128:3128 ubuntu/squid")
46+
proxy_container_id = lines[0].strip()
47+
proxy = HttpProxy(authenticated_url="http://testuser:testuser@127.0.0.1:3128",
48+
anonymous_url="http://127.0.0.1:3128")
49+
yield proxy
50+
process.run_subprocess(f"docker stop {proxy_container_id}")
51+
52+
53+
# ensures that a fresh log file is available
54+
@pytest.fixture(scope="function")
55+
def fresh_log_file():
56+
cfg = it.ConfigFile(config_name=None)
57+
log_file = os.path.join(cfg.benchmark_home, "logs", "benchmark.log")
58+
59+
if os.path.exists(log_file):
60+
bak = os.path.join(tempfile.mkdtemp(), "benchmark.log")
61+
shutil.move(log_file, bak)
62+
yield log_file
63+
# append log lines to the original file and move it back to its original
64+
with open(log_file, "r") as src:
65+
with open(bak, "a") as dst:
66+
dst.write(src.read())
67+
shutil.move(bak, log_file)
68+
else:
69+
yield log_file
70+
71+
72+
def assert_log_line_present(log_file, text):
73+
with open(log_file, "r") as f:
74+
assert any(text in line for line in f), f"Could not find [{text}] in [{log_file}]."
75+
76+
77+
@it.benchmark_in_mem
78+
def test_run_with_direct_internet_connection(cfg, http_proxy, fresh_log_file):
79+
assert it.osbenchmark(cfg, "list workloads") == 0
80+
assert_log_line_present(fresh_log_file, "Connecting directly to the Internet")
81+
82+
83+
@it.benchmark_in_mem
84+
def test_anonymous_proxy_no_connection(cfg, http_proxy, fresh_log_file):
85+
env = dict(os.environ)
86+
env["http_proxy"] = http_proxy.anonymous_url
87+
assert process.run_subprocess_with_logging(it.osbenchmark_command_line_for(cfg, "list workloads"), env=env) == 0
88+
assert_log_line_present(fresh_log_file, f"Connecting via proxy URL [{http_proxy.anonymous_url}] to the Internet")
89+
# unauthenticated proxy access is prevented
90+
assert_log_line_present(fresh_log_file, "No Internet connection detected")
91+
92+
93+
@it.benchmark_in_mem
94+
def test_authenticated_proxy_user_can_connect(cfg, http_proxy, fresh_log_file):
95+
env = dict(os.environ)
96+
env["http_proxy"] = http_proxy.authenticated_url
97+
assert process.run_subprocess_with_logging(it.osbenchmark_command_line_for(cfg, "list workloads"), env=env) == 0
98+
assert_log_line_present(fresh_log_file,
99+
f"Connecting via proxy URL [{http_proxy.authenticated_url}] to the Internet")
100+
# authenticated proxy access is allowed
101+
assert_log_line_present(fresh_log_file, "Detected a working Internet connection")

it/tracker_test.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.
6+
# Modifications Copyright OpenSearch Contributors. See
7+
# GitHub history for details.
8+
# Licensed to Elasticsearch B.V. under one or more contributor
9+
# license agreements. See the NOTICE file distributed with
10+
# this work for additional information regarding copyright
11+
# ownership. Elasticsearch B.V. licenses this file to you under
12+
# the Apache License, Version 2.0 (the "License"); you may
13+
# not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing,
19+
# software distributed under the License is distributed on an
20+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
# KIND, either express or implied. See the License for the
22+
# specific language governing permissions and limitations
23+
# under the License.
24+
25+
import uuid
26+
27+
import pytest
28+
29+
import it
30+
31+
32+
@pytest.fixture(scope="module")
33+
def test_cluster():
34+
cluster = it.TestCluster("in-memory-it")
35+
# test with a recent distribution
36+
dist = it.DISTRIBUTIONS[-1]
37+
port = 19200
38+
test_execution_id = str(uuid.uuid4())
39+
40+
it.wait_until_port_is_free(port_number=port)
41+
cluster.install(distribution_version=dist, node_name="benchmark-node", provision_config_instance="4gheap", http_port=port)
42+
cluster.start(test_execution_id=test_execution_id)
43+
yield cluster
44+
cluster.stop()
45+
46+
47+
@it.benchmark_in_mem
48+
def test_create_workload(cfg, tmp_path, test_cluster):
49+
# prepare some data
50+
cmd = f"--test-mode --pipeline=benchmark-only --target-hosts=127.0.0.1:{test_cluster.http_port} " \
51+
f" --workload=geonames --test-procedure=append-no-conflicts-index-only --quiet"
52+
assert it.execute_test(cfg, cmd) == 0
53+
54+
# create the workload
55+
workload_name = f"test-workload-{uuid.uuid4()}"
56+
workload_path = tmp_path / workload_name
57+
58+
assert it.osbenchmark(cfg, f"create-workload --target-hosts=127.0.0.1:{test_cluster.http_port} --indices=geonames "
59+
f"--workload={workload_name} --output-path={tmp_path}") == 0
60+
61+
expected_files = ["workload.json",
62+
"geonames.json",
63+
"geonames-documents-1k.json",
64+
"geonames-documents.json",
65+
"geonames-documents-1k.json.bz2",
66+
"geonames-documents.json.bz2"]
67+
68+
for f in expected_files:
69+
full_path = workload_path / f
70+
assert full_path.exists(), f"Expected file to exist at path [{full_path}]"
71+
72+
# run a benchmark with the created workload
73+
cmd = f"--test-mode --pipeline=benchmark-only --target-hosts=127.0.0.1:{test_cluster.http_port} --workload-path={workload_path}"
74+
assert it.execute_test(cfg, cmd) == 0

0 commit comments

Comments
 (0)