Skip to content

Commit 670afc5

Browse files
authored
Merge pull request #231 from cloudfoundry-community/dev/pcf-performance-testing
Add pcf performance testing
2 parents 406dc21 + 0c549c8 commit 670afc5

File tree

12 files changed

+338
-26
lines changed

12 files changed

+338
-26
lines changed

.circleci/config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,37 @@ jobs:
102102
when:
103103
always
104104

105+
execute_perf_tests:
106+
docker:
107+
- image: circleci/golang:1.12
108+
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
109+
steps:
110+
- attach_workspace:
111+
at: /tmp
112+
- checkout
113+
- run:
114+
name: Install dependencies
115+
command: |
116+
curl https://glide.sh/get | sh
117+
go get -t ./...
118+
cp -R /tmp/splunk-firehose-nozzle .
119+
- run:
120+
name: Prepare test environment
121+
command: |
122+
.circleci/pre-req.sh
123+
.circleci/pre-functional-test.sh
124+
- run:
125+
name: Executing perf tests
126+
command: |
127+
.circleci/performance-test.sh
128+
- run:
129+
name: Teardown
130+
command: |
131+
echo "Teardown deployment env"
132+
cf delete-org splunk-ci-org -f
133+
when:
134+
always
135+
105136
workflows:
106137
version: 2
107138
build-and-deploy-nozzle:
@@ -129,3 +160,23 @@ workflows:
129160
only:
130161
- develop
131162
- master
163+
# - execute_perf_tests:
164+
# requires:
165+
# - build
166+
# filters:
167+
# branches:
168+
# only:
169+
# - dev/pcf-performance-testing
170+
# nightly:
171+
# triggers:
172+
# - schedule:
173+
# cron: "0 7 * * *"
174+
# filters:
175+
# branches:
176+
# only:
177+
# - dev/pcf-performance-testing
178+
# jobs:
179+
# - build
180+
# - execute_perf_tests:
181+
# requires:
182+
# - build

.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
5+
pytest -v -m Critical

.circleci/performance-test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
cd testing/integration
4+
. venv/bin/activate
5+
pytest -v -m Perf_Binary
6+
pytest -v -m Perf_Romote

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ vendor/github.com/cloudfoundry/sonde-go/definitions/
1717
testing/integration/venv/
1818
testing/integration/config/local.ini
1919
*.pyc
20+
testing/integration/config/env.json

testing/integration/config/config.ini

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
[DEFAULT]
2-
splunk_url =
3-
splunk_user =
4-
splunk_password =
2+
53
go_package_name = main
6-
api_endpoint =
7-
client_id =
8-
client_secret =
9-
splunk_host =
10-
splunk_token =
11-
splunk_index =
124
job_name = splunk-nozzle
135
add_app_info = true
146
bolted_path = cache.db

testing/integration/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ def test_env(request):
7272
"""
7373
config_folder = get_config_folder()
7474
parser = configparser.ConfigParser()
75-
76-
if os.path.exists(join(config_folder, 'local.ini')):
77-
parser.read([join(config_folder, 'config.ini'),
78-
join(config_folder, 'local.ini')])
79-
else:
80-
parser.read(join(config_folder, 'config.ini'))
75+
parser.read(join(config_folder, 'config.ini'))
8176

8277
cfg = parser.items('DEFAULT')
8378
conf = dict(cfg)
@@ -93,4 +88,9 @@ def test_env(request):
9388
if request.config.getoption("--splunk-index"):
9489
conf["splunk_index"] = request.config.getoption("--splunk-index")
9590

91+
if os.path.exists(join(config_folder, 'local.ini')):
92+
parser.read(join(config_folder, 'local.ini'))
93+
94+
conf.update(parser.items('LOCAL'))
95+
9696
return conf

testing/integration/lib/runner.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from .helper import *
2+
import subprocess
3+
import time
4+
import logging
5+
6+
_env_var = os.environ
7+
_env_path = get_project_folder()
8+
logging.config.fileConfig(os.path.join(get_integration_folder(), "logging.conf"))
9+
nozzle_logger = logging.getLogger("nozzle")
10+
11+
12+
def login_pcf(nozzle_logger):
13+
path = os.path.join(get_integration_folder(), "scripts")
14+
cmd = "cd {0}; ./pre_perf.sh".format(path, _env_path)
15+
try:
16+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
17+
stderr=subprocess.STDOUT)
18+
output, error = proc.communicate()
19+
if error:
20+
nozzle_logger.error(error.strip())
21+
except OSError as e:
22+
nozzle_logger.error(e)
23+
24+
25+
def start_local_nozzle_binary(time_interval=20):
26+
path = os.path.join(get_integration_folder(), "scripts")
27+
cmd = "cd {0}; ./start_nozzle.sh {1} {2}".format(path, _env_path, time_interval)
28+
try:
29+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
30+
stderr=subprocess.STDOUT)
31+
output, error = proc.communicate()
32+
if error:
33+
nozzle_logger.error(error.strip())
34+
except OSError as e:
35+
nozzle_logger.error(e)
36+
37+
38+
def deploy_nozzle_to_pcf():
39+
cmd = "cd {}; make deploy-nozzle".format(_env_path)
40+
try:
41+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
42+
stderr=subprocess.STDOUT)
43+
output, error = proc.communicate()
44+
if error:
45+
nozzle_logger.error(error.strip())
46+
except OSError as e:
47+
nozzle_logger.error(e)
48+
49+
50+
def deploy_date_gen_to_pcf():
51+
cmd = "cd {}; make deploy-data-gen".format(_env_path)
52+
try:
53+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
54+
stderr=subprocess.STDOUT)
55+
output, error = proc.communicate()
56+
if error:
57+
nozzle_logger.error(error.strip())
58+
except OSError as e:
59+
nozzle_logger.error(e)
60+
61+
62+
def delete_data_gen(name='data_gen'):
63+
cmd = "cf delete {} -f".format(name)
64+
65+
try:
66+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
67+
stderr=subprocess.STDOUT)
68+
output, error = proc.communicate()
69+
if error:
70+
nozzle_logger.error(error.strip())
71+
except OSError as e:
72+
nozzle_logger.error(e)
73+
74+
75+
def delete_pcf_org():
76+
nozzle_logger.info("Deleting pcf org...")
77+
cmd = "cf delete-org splunk-ci-org -f"
78+
79+
try:
80+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
81+
stderr=subprocess.STDOUT)
82+
output, error = proc.communicate()
83+
if error:
84+
nozzle_logger.error(error.strip())
85+
except OSError as e:
86+
nozzle_logger.error(e)
87+
88+
89+
def wait_until_date_gen_done(name=None):
90+
cmd = "cf logs {} --recent".format(name)
91+
try:
92+
while True:
93+
time.sleep(10)
94+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
95+
stderr=subprocess.STDOUT)
96+
output, error = proc.communicate()
97+
if 'data generation done' in str(output):
98+
break
99+
except OSError as e:
100+
nozzle_logger.error(e)
Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,82 @@
11
#! /usr/bin/env python
22

33
from .helper import *
4-
_env_var = os.environ
54
import time
5+
import yaml
6+
import json
7+
from os.path import join
8+
9+
_env_var = os.environ
610
_path = get_project_folder()
711

812

9-
def update_environment_variables(input_dict=None):
13+
def get_default_env():
1014
default_dict = \
1115
{
12-
'ADD_APP_INFO': 'true',
16+
'ADD_APP_INFO': True,
17+
'API_ENDPOINT': _env_var.get('API_ENDPOINT'),
1318
'EVENTS': 'ValueMetric,CounterEvent,Error,LogMessage,HttpStartStop,ContainerMetric',
1419
'SPLUNK_TOKEN': _env_var.get('SPLUNK_TOKEN'),
1520
'SPLUNK_HOST': _env_var.get('SPLUNK_HOST'),
1621
'SPLUNK_INDEX': _env_var.get('SPLUNK_INDEX'),
1722
'FIREHOSE_SUBSCRIPTION_ID': 'splunk-ci',
1823
'CLIENT_ID': _env_var.get('CLIENT_ID'),
1924
'CLIENT_SECRET': _env_var.get('CLIENT_SECRET'),
20-
'ENABLE_EVENT_TRACING': 'true',
21-
'SKIP_SSL_VALIDATION_CF': 'true',
22-
'SKIP_SSL_VALIDATION_SPLUNK': 'true',
25+
'ENABLE_EVENT_TRACING': True,
26+
'SKIP_SSL_VALIDATION_CF': True,
27+
'SKIP_SSL_VALIDATION_SPLUNK': True,
2328
'EXTRA_FIELDS': 'name:update-ci-test'
2429
}
30+
config_folder = get_config_folder()
31+
if os.path.exists(join(config_folder, 'env.json')):
32+
with open(join(config_folder, 'env.json')) as json_file:
33+
local_env = json.load(json_file)
2534

35+
default_dict.update(local_env)
36+
return default_dict
37+
38+
39+
def update_environment_variables(input_dict=None):
40+
default_env = get_default_env()
2641
if input_dict:
27-
default_dict.update(input_dict)
42+
default_env.update(input_dict)
2843

2944
path = os.path.join(get_project_folder(), "env.sh")
3045
with open(path, 'w') as file:
3146
file.write('''#! /bin/bash''')
32-
for key, value in default_dict.items():
47+
for key, value in default_env.items():
3348
file.write("\nexport {0}={1}".format(key, value))
3449
time.sleep(2)
50+
51+
52+
def update_nozzle_manifest(nozzle_name=None, instances=None, input_dict=None):
53+
default_env = get_default_env()
54+
file_name = os.path.join(_path, ".circleci/ci_nozzle_manifest.yml")
55+
stream = open(file_name, 'r')
56+
config = yaml.load(stream)
57+
if instances:
58+
config['applications'][0].update({'instances': instances})
59+
if nozzle_name:
60+
config['applications'][0].update({'name': nozzle_name})
61+
62+
env_var = config['applications'][0]['env']
63+
env_var.update(default_env)
64+
if input_dict:
65+
env_var.update(input_dict)
66+
67+
with open(file_name, 'w') as yaml_file:
68+
yaml_file.write(yaml.dump(config, default_flow_style=False))
69+
time.sleep(0.5)
70+
71+
72+
def update_data_gen_manifest(input_dict=None):
73+
file_name = os.path.join(_path, ".circleci/data_gen_manifest.yml")
74+
stream = open(file_name, 'r')
75+
config = yaml.load(stream)
76+
77+
env_var = config['applications'][0]
78+
env_var.update(input_dict)
79+
80+
with open(file_name, 'w') as yaml_file:
81+
yaml_file.write(yaml.dump(config, default_flow_style=False))
82+
time.sleep(0.5)

testing/integration/pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
addopts = -rfps --durations=10 --disable-pytest-warnings --continue-on-collection-errors
33

44
markers =
5-
Critical: mark a test as a critical test case.
5+
Critical: mark a test as a critical test case.
6+
Perf_Binary: mark a test as a performance test case that use local binary nozzle.
7+
Perf_Romote: mark a test as a performance test case that use remote nozzle deployed on pcf.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest
22
requests
3-
json_delta
3+
json_delta
4+
pyyaml

0 commit comments

Comments
 (0)