Skip to content

Commit 6f498f8

Browse files
authored
Merge pull request #247 from splunk/bugfix/upgrade-test
Bugfix/upgrade test
2 parents 1ec369f + 68f23b7 commit 6f498f8

File tree

2 files changed

+36
-59
lines changed

2 files changed

+36
-59
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ jobs:
5050
command: |
5151
make test_setup
5252
- run:
53-
name: Build a Debian 10 Container
53+
name: Build Debian 10 Splunk
5454
command: |
5555
make splunk-debian-10
5656
- run:
57-
name: Build a Debian 10 UF Container
57+
name: Build Debian 10 UF
5858
command: |
5959
make uf-debian-10
6060
- run:
6161
name: Test if image size increase
6262
command: make test_debian10_image_size
6363
- run:
64-
name: Running debian10 CI Tests
64+
name: Run Debian 10 image tests
6565
command: make run_tests_debian10
6666
no_output_timeout: 20m
6767
- store_artifacts:
@@ -87,15 +87,15 @@ jobs:
8787
command: |
8888
make test_setup
8989
- run:
90-
name: Build a Debian 10 Container
90+
name: Build Redhat 8 Splunk
9191
command: |
9292
make splunk-redhat-8
9393
- run:
94-
name: Build a Debian 10 UF Container
94+
name: Build Redhat 8 UF
9595
command: |
9696
make uf-redhat-8
9797
- run:
98-
name: Running debian10 CI Tests
98+
name: Run Redhat 8 image tests
9999
command: make run_tests_redhat8
100100
no_output_timeout: 20m
101101
- store_artifacts:

tests/test_docker_splunk.py

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ def extract_json(self, container_name):
243243
self.logger.error(e)
244244
return None
245245

246-
def search_internal_distinct_hosts(self, container_id, username="admin", password="password"):
247-
query = "search index=_internal earliest=-1m | stats dc(host) as distinct_hosts"
246+
def _run_splunk_query(self, container_id, query, username="admin", password="password"):
248247
splunkd_port = self.client.port(container_id, 8089)[0]["HostPort"]
249248
url = "https://localhost:{}/services/search/jobs?output_mode=json".format(splunkd_port)
250249
kwargs = {
@@ -258,30 +257,36 @@ def search_internal_distinct_hosts(self, container_id, username="admin", passwor
258257
assert sid
259258
self.logger.info("Search job {} created against on {}".format(sid, container_id))
260259
# Wait for search to finish
261-
# TODO: implement polling mechanism here
262260
job_status = None
261+
url = "https://localhost:{}/services/search/jobs/{}?output_mode=json".format(splunkd_port, sid)
262+
kwargs = {
263+
"auth": (username, password),
264+
"verify": False
265+
}
263266
for _ in range(10):
264-
url = "https://localhost:{}/services/search/jobs/{}?output_mode=json".format(splunkd_port, sid)
265-
kwargs = {"auth": (username, password), "verify": False}
266267
job_status = requests.get(url, **kwargs)
267268
done = json.loads(job_status.content)["entry"][0]["content"]["isDone"]
268269
self.logger.info("Search job {} done status is {}".format(sid, done))
269270
if done:
270271
break
271272
time.sleep(3)
272-
# Check searchProviders - use the latest job_status check from the polling
273-
assert job_status.status_code == 200
274-
search_providers = json.loads(job_status.content)["entry"][0]["content"]["searchProviders"]
275-
assert search_providers
273+
assert job_status and job_status.status_code == 200
274+
# Get job metadata
275+
job_metadata = json.loads(job_status.content)
276276
# Check search results
277277
url = "https://localhost:{}/services/search/jobs/{}/results?output_mode=json".format(splunkd_port, sid)
278-
kwargs = {"auth": (username, password), "verify": False}
279-
resp = requests.get(url, **kwargs)
280-
assert resp.status_code == 200
281-
distinct_hosts = int(json.loads(resp.content)["results"][0]["distinct_hosts"])
282-
assert distinct_hosts
278+
job_results = requests.get(url, **kwargs)
279+
assert job_results.status_code == 200
280+
job_results = json.loads(job_results.content)
281+
return job_metadata, job_results
282+
283+
def search_internal_distinct_hosts(self, container_id, username="admin", password="password"):
284+
query = "search index=_internal earliest=-1m | stats dc(host) as distinct_hosts"
285+
meta, results = self._run_splunk_query(container_id, query, username, password)
286+
search_providers = meta["entry"][0]["content"]["searchProviders"]
287+
distinct_hosts = int(results["results"][0]["distinct_hosts"])
283288
return search_providers, distinct_hosts
284-
289+
285290
def check_common_keys(self, log_output, role):
286291
try:
287292
assert log_output["all"]["vars"]["ansible_ssh_user"] == "splunk"
@@ -1207,7 +1212,6 @@ def test_adhoc_1so_web_ssl(self):
12071212
except OSError:
12081213
pass
12091214

1210-
@pytest.mark.skip(reason="Ask Nelson")
12111215
def test_adhoc_1so_upgrade(self):
12121216
# Pull the old image
12131217
for line in self.client.pull("splunk/splunk:{}".format(OLD_SPLUNK_VERSION), stream=True, decode=True):
@@ -1216,7 +1220,7 @@ def test_adhoc_1so_upgrade(self):
12161220
try:
12171221
cid = None
12181222
splunk_container_name = generate_random_string()
1219-
password = generate_random_string()
1223+
user, password = "admin", generate_random_string()
12201224
cid = self.client.create_container("splunk/splunk:{}".format(OLD_SPLUNK_VERSION), tty=True, ports=[8089, 8088], hostname="splunk",
12211225
name=splunk_container_name, environment={"DEBUG": "true", "SPLUNK_HEC_TOKEN": "qwerty", "SPLUNK_PASSWORD": password, "SPLUNK_START_ARGS": "--accept-license"},
12221226
host_config=self.client.create_host_config(mounts=[Mount("/opt/splunk/etc", "opt-splunk-etc"), Mount("/opt/splunk/var", "opt-splunk-var")],
@@ -1227,13 +1231,15 @@ def test_adhoc_1so_upgrade(self):
12271231
# Poll for the container to be ready
12281232
assert self.wait_for_containers(1, name=splunk_container_name)
12291233
# Check splunkd
1230-
assert self.check_splunkd("admin", password)
1234+
assert self.check_splunkd(user, password)
12311235
# Add some data via HEC
12321236
splunk_hec_port = self.client.port(cid, 8088)[0]["HostPort"]
12331237
url = "https://localhost:{}/services/collector/event".format(splunk_hec_port)
12341238
kwargs = {"json": {"event": "world never says hello back"}, "verify": False, "headers": {"Authorization": "Splunk qwerty"}}
12351239
status, content = self.handle_request_retry("POST", url, kwargs)
12361240
assert status == 200
1241+
# Sleep to let the data index
1242+
time.sleep(3)
12371243
# Remove the "splunk-old" container
12381244
self.client.remove_container(cid, v=False, force=True)
12391245
# Create the "splunk-new" container re-using volumes
@@ -1248,41 +1254,12 @@ def test_adhoc_1so_upgrade(self):
12481254
# Poll for the container to be ready
12491255
assert self.wait_for_containers(1, name=splunk_container_name)
12501256
# Check splunkd
1251-
assert self.check_splunkd("admin", password)
1252-
# Run a search - we should be getting 2 hosts because the hostnames were different in the two containers created above
1253-
query = "search index=main earliest=-3m"
1254-
splunkd_port = self.client.port(cid, 8089)[0]["HostPort"]
1255-
url = "https://localhost:{}/services/search/jobs?output_mode=json".format(splunkd_port)
1256-
kwargs = {
1257-
"auth": ("admin", password),
1258-
"data": "search={}".format(urllib.quote_plus(query)),
1259-
"verify": False
1260-
}
1261-
resp = requests.post(url, **kwargs)
1262-
assert resp.status_code == 201
1263-
sid = json.loads(resp.content)["sid"]
1264-
assert sid
1265-
self.logger.info("Search job {} created against on {}".format(sid, cid))
1266-
# Wait for search to finish
1267-
# TODO: implement polling mechanism here
1268-
job_status = None
1269-
for _ in range(10):
1270-
url = "https://localhost:{}/services/search/jobs/{}?output_mode=json".format(splunkd_port, sid)
1271-
kwargs = {"auth": ("admin", password), "verify": False}
1272-
job_status = requests.get(url, **kwargs)
1273-
done = json.loads(job_status.content)["entry"][0]["content"]["isDone"]
1274-
self.logger.info("Search job {} done status is {}".format(sid, done))
1275-
if done:
1276-
break
1277-
time.sleep(3)
1278-
# Check searchProviders - use the latest job_status check from the polling
1279-
assert job_status.status_code == 200
1280-
# Check search results
1281-
url = "https://localhost:{}/services/search/jobs/{}/results?output_mode=json".format(splunkd_port, sid)
1282-
kwargs = {"auth": ("admin", password), "verify": False}
1283-
resp = requests.get(url, **kwargs)
1284-
assert resp.status_code == 200
1285-
results = json.loads(resp.content)["results"]
1257+
assert self.check_splunkd(user, password)
1258+
# Run a search
1259+
time.sleep(3)
1260+
query = "search index=main earliest=-10m"
1261+
meta, results = self._run_splunk_query(cid, query, user, password)
1262+
results = results["results"]
12861263
assert len(results) == 1
12871264
assert results[0]["_raw"] == "world never says hello back"
12881265
except Exception as e:

0 commit comments

Comments
 (0)