Skip to content

Commit e072ba1

Browse files
authored
Added additional test cases with running binary nuzzle (#226)
1 parent 826fe51 commit e072ba1

File tree

9 files changed

+177
-55
lines changed

9 files changed

+177
-55
lines changed

.circleci/config.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ jobs:
9292
name: Executing tests
9393
command: |
9494
.circleci/functional-test.sh
95-
96-
teardown:
97-
docker:
98-
- image: circleci/golang:1.12
99-
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
100-
steps:
101-
- attach_workspace:
102-
at: /tmp
103-
- checkout
104-
- run:
105-
name: Install dependencies
106-
command: |
107-
curl https://glide.sh/get | sh
108-
go get -t ./...
109-
cp -R /tmp/splunk-firehose-nozzle .
110-
.circleci/pre-req.sh
11195
- run:
11296
name: Teardown
11397
command: |
@@ -146,13 +130,3 @@ workflows:
146130
only:
147131
- develop
148132
- master
149-
- teardown:
150-
requires:
151-
- build
152-
- deploy-nozzle
153-
- execute_tests
154-
filters:
155-
branches:
156-
only:
157-
- develop
158-
- master

.circleci/functional-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
cd testing/integration
44
. venv/bin/activate
5-
pytest -rfps --durations=10
5+
pytest

testing/integration/conftest.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import pytest
66
import configparser
77
from os.path import join
8+
import subprocess
9+
import time
810

911

1012
from lib.helper import get_config_folder, get_project_folder
1113

1214
_current_dir = os.path.dirname(os.path.realpath(__file__))
1315
sys.path.insert(0, get_project_folder())
16+
_env_var = os.environ
1417

1518

1619
@pytest.fixture(scope="session", autouse=True)
@@ -32,17 +35,30 @@ def pytest_addoption(parser):
3235
"""
3336
This function is sued to add command line parameters to test suite
3437
"""
35-
env_var = os.environ
3638
parser.addoption("--splunk-url", help="splunk url used to send test data to.",
37-
default=env_var.get('SPLUNK_URL'))
39+
default=_env_var.get('SPLUNK_URL'))
3840
parser.addoption("--splunk-user", help="splunk username",
39-
default=env_var.get('SPLUNK_USER'))
41+
default=_env_var.get('SPLUNK_USER'))
4042
parser.addoption("--splunk-password", help="splunk user password",
41-
default=env_var.get('SPLUNK_PASSWORD'))
43+
default=_env_var.get('SPLUNK_PASSWORD'))
4244
parser.addoption("--api-endpoint", help="pleasanton cf api endpoint.",
43-
default=env_var.get('API_ENDPOINT'))
45+
default=_env_var.get('API_ENDPOINT'))
4446
parser.addoption("--splunk-index", help="splunk index on hec setting.",
45-
default=env_var.get('SPLUNK_INDEX'))
47+
default=_env_var.get('SPLUNK_INDEX'))
48+
49+
50+
@pytest.fixture(scope="class")
51+
def test_setup(request, nozzle_logger):
52+
nozzle_logger.info("Stopping nozzle...")
53+
cmd = "cf login --skip-ssl-validation -a {0} -u {1} -p {2} -o system -s system; " \
54+
"cf stop splunk-firehose-nozzle".format(_env_var['API_ENDPOINT'],
55+
_env_var['API_USER'],
56+
_env_var['API_PASSWORD'])
57+
58+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
59+
stderr=subprocess.STDOUT)
60+
output, error = proc.communicate()
61+
time.sleep(5)
4662

4763

4864
@pytest.fixture(scope="class")

testing/integration/lib/helper.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44

55

6-
def get_project_folder():
6+
def get_integration_folder():
77
"""
8-
returns the project root folder
8+
returns the integration test folder
99
"""
1010
return os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
1111

@@ -14,7 +14,14 @@ def get_config_folder():
1414
"""
1515
returns the config folder
1616
"""
17-
return os.path.join(get_project_folder(), "config")
17+
return os.path.join(get_integration_folder(), "config")
18+
19+
20+
def get_project_folder():
21+
"""
22+
returns the project root folder
23+
"""
24+
return get_integration_folder().replace("/testing/integration", "/")
1825

1926

2027

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/env python
2+
3+
from .helper import *
4+
_env_var = os.environ
5+
import time
6+
_path = get_project_folder()
7+
8+
9+
def update_environment_variables(input_dict=None):
10+
default_dict = \
11+
{
12+
'ADD_APP_INFO': 'true',
13+
'EVENTS': 'ValueMetric,CounterEvent,Error,LogMessage,HttpStartStop,ContainerMetric',
14+
'SPLUNK_TOKEN': _env_var.get('SPLUNK_TOKEN'),
15+
'SPLUNK_HOST': _env_var.get('SPLUNK_HOST'),
16+
'SPLUNK_INDEX': _env_var.get('SPLUNK_INDEX'),
17+
'FIREHOSE_SUBSCRIPTION_ID': 'splunk-ci',
18+
'CLIENT_ID': _env_var.get('CLIENT_ID'),
19+
'CLIENT_SECRET': _env_var.get('CLIENT_SECRET'),
20+
'ENABLE_EVENT_TRACING': 'true',
21+
'SKIP_SSL_VALIDATION_CF': 'true',
22+
'SKIP_SSL_VALIDATION_SPLUNK': 'true',
23+
'EXTRA_FIELDS': 'name:update-ci-test'
24+
}
25+
26+
if input_dict:
27+
default_dict.update(input_dict)
28+
29+
path = os.path.join(get_project_folder(), "env.sh")
30+
with open(path, 'w') as file:
31+
file.write('''#! /bin/bash''')
32+
for key, value in default_dict.items():
33+
file.write("\nexport {0}={1}".format(key, value))
34+
time.sleep(2)

testing/integration/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
addopts = --durations=10
2+
addopts = -rfps --durations=10 --disable-pytest-warnings --continue-on-collection-errors
33

44
markers =
55
Critical: mark a test as a critical test case.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
FILE_PATH=$1
4+
TIME_INTERVAL=$2
5+
6+
cd $FILE_PATH
7+
source env.sh
8+
./splunk-firehose-nozzle & sleep $TIME_INTERVAL ; kill $!

testing/integration/testcases/test_nozzle_configurations.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,10 @@ def test_search_by_incorrect_splunk_index(self, test_env, splunk_logger, query_i
4848

4949
@pytest.mark.Critical
5050
@pytest.mark.parametrize("query_input", [
51-
"index={} cf_app_name=data_gen", # when add_app_info is true, cf_app_name is searchable
52-
"index={} cf_org_name=splunk-ci-org", # when add_app_info is true, cf_org_name is searchable
53-
"index={} cf_space_name=splunk-ci-space" # when add_app_info is true, cf_space_name is searchable
54-
])
55-
def test_add_app_info_is_true(self, test_env, splunk_logger, query_input):
56-
self.splunk_api = SplunkApi(test_env, splunk_logger)
57-
58-
search_results = self.splunk_api.check_events_from_splunk(
59-
query=query_input.format(test_env['splunk_index']),
60-
start_time="-15m@m")
61-
assert len(search_results) > 0, \
62-
'\nNumber of events from Splunk should not be {}, however the result is {}'.format(0, len(search_results))
63-
64-
@pytest.mark.Critical
65-
@pytest.mark.parametrize("query_input", [
66-
"index={} cf_app_name=data_gen", # when add_app_info is true, cf_app_name is searchable
67-
"index={} cf_org_name=splunk-ci-org", # when add_app_info is true, cf_org_name is searchable
68-
"index={} cf_space_name=splunk-ci-space" # when add_app_info is true, cf_space_name is searchable
51+
"index={0} cf_space_id=*", # when cf_space_id is true, cf_org_name is searchable
52+
"index={0} cf_org_id=*", # cf_org_id add_app_info is true, cf_org_name is searchable
53+
"index={0} cf_org_name=*", # when add_app_info is true, cf_org_name is searchable
54+
"index={0} cf_space_name=*" # when add_app_info is true, cf_space_name is searchable
6955
])
7056
def test_add_app_info_is_true(self, test_env, splunk_logger, query_input):
7157
self.splunk_api = SplunkApi(test_env, splunk_logger)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import pytest
2+
from lib.update_env import *
3+
from lib.splunk_api import *
4+
import string
5+
import random
6+
_tag = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
7+
8+
9+
class TestSplunkNozzleLocal():
10+
@pytest.fixture(scope='class', autouse=True)
11+
def setup_class(self, test_env, splunk_logger, nozzle_logger, test_setup):
12+
update_environment_variables(input_dict={'EVENTS': 'LogMessage',
13+
'EXTRA_FIELDS': 'test_tag:{},test2.0:nozzle2.0'.format(_tag),
14+
'ENABLE_EVENT_TRACING': False,
15+
'ADD_APP_INFO': False}
16+
)
17+
18+
path = os.path.join(get_integration_folder(), "scripts")
19+
env_path = get_project_folder()
20+
time_interval = 20
21+
cmd = "cd {0}; ./start_nozzle.sh {1} {2}".format(path, env_path, time_interval)
22+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
23+
stderr=subprocess.STDOUT)
24+
proc.communicate()
25+
26+
@pytest.mark.Critical
27+
@pytest.mark.parametrize("query_input, is_result_empty", [
28+
("index={0} test_tag::{1} event_type=ValueMetric", True),
29+
("index={0} test_tag::{1} event_type=CounterEvent", True),
30+
("index={0} test_tag::{1} event_type=LogMessage", False),
31+
("index={0} test_tag::{1} event_type=HttpStartStop", True),
32+
("index={0} test_tag::{1} event_type=ContainerMetric", True)
33+
])
34+
def test_search_event_on_splunk_is_not_empty(self, query_input, is_result_empty, test_env, splunk_logger, nozzle_logger):
35+
self.splunk_api = SplunkApi(test_env, splunk_logger)
36+
search_results = self.splunk_api.check_events_from_splunk(
37+
query=query_input.format(test_env['splunk_index'], _tag),
38+
start_time="-10m@m")
39+
40+
if is_result_empty:
41+
assert len(search_results) == 0, \
42+
'\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results))
43+
else:
44+
assert len(search_results) > 0, \
45+
'\nNumber of events from Splunk should not be {}, however the result is {}'\
46+
.format(0, len(search_results))
47+
48+
@pytest.mark.Critical
49+
@pytest.mark.parametrize("query_input, is_result_empty", [
50+
("index={0} test_tag::{1} test2.0::nozzle2.0", False),
51+
("index={0} test_tag::{1} test::nozzle2.0", True),
52+
("index={0} test_tag::{1} test2.0::nozzle", True)
53+
])
54+
def test_search_by_extra_fields(self, query_input, is_result_empty, test_env, splunk_logger):
55+
self.splunk_api = SplunkApi(test_env, splunk_logger)
56+
search_results = self.splunk_api.check_events_from_splunk(
57+
query=query_input.format(test_env['splunk_index'], _tag),
58+
start_time="-10m@m")
59+
60+
if is_result_empty:
61+
assert len(search_results) == 0, \
62+
'\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results))
63+
else:
64+
assert len(search_results) > 0, \
65+
'\nNumber of events from Splunk should not be {}, however the result is {}'\
66+
.format(0, len(search_results))
67+
68+
@pytest.mark.Critical
69+
@pytest.mark.parametrize("query_input", [
70+
"index={0} test_tag::{1} nozzle-event-counter>0", # nozzle-event-counter should not be searchable
71+
"index={0} test_tag::{1} subscription-id::splunk-ci", # subscription-id should not be searchable
72+
"index={0} test_tag::{1} uuid::*" # uuid should not be searchable
73+
])
74+
def test_enable_event_tracing_is_false(self, test_env, query_input, splunk_logger):
75+
self.splunk_api = SplunkApi(test_env, splunk_logger)
76+
search_results = self.splunk_api.check_events_from_splunk(
77+
query=query_input.format(test_env['splunk_index'], _tag),
78+
start_time="-10m@m")
79+
80+
assert len(search_results) == 0, \
81+
'\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results))
82+
83+
@pytest.mark.Critical
84+
@pytest.mark.parametrize("query_input", [
85+
"index={0} test_tag::{1} cf_space_id=*", # when cf_space_id is false, cf_org_name is not searchable
86+
"index={0} test_tag::{1} cf_org_id=*", # cf_org_id add_app_info is false, cf_org_name is not searchable
87+
"index={0} test_tag::{1} cf_org_name=*", # when add_app_info is false, cf_org_name is not searchable
88+
"index={0} test_tag::{1} cf_space_name=*" # when add_app_info is false, cf_space_name is not searchable
89+
])
90+
def test_add_app_info_is_false(self, test_env, query_input, splunk_logger):
91+
self.splunk_api = SplunkApi(test_env, splunk_logger)
92+
search_results = self.splunk_api.check_events_from_splunk(
93+
query=query_input.format(test_env['splunk_index'], _tag),
94+
start_time="-10m@m")
95+
96+
assert len(search_results) == 0, \
97+
'\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results))

0 commit comments

Comments
 (0)