Hai Shi 60c687e9cd Avoid shell=True in subprocess
'shell=True' has a potential security danger, so
we need avoid this usage.

Refs:
[1] https://security.openstack.org/guidelines/dg_avoid-shell-true.html

Change-Id: I095e69c70f82467211a63323530a0b1753c5b952
Closes-Bug: #1508103
2017-03-23 13:26:57 +00:00

60 lines
1.7 KiB
Python

#!/usr/bin/env python
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Run HTTP benchmark by runcommand_heat scenario."""
import json
import re
import subprocess
import sys
import tempfile
SIEGE_RE = re.compile(r"^(Throughput|Transaction rate):\s+(\d+\.\d+)\s+.*")
def get_instances():
outputs = json.load(sys.stdin)
for output in outputs:
if output["output_key"] == "wp_nodes":
for node in output["output_value"].values():
yield node["wordpress-network"][0]
def generate_urls_list(instances):
urls = tempfile.NamedTemporaryFile(delete=False)
with urls:
for inst in instances:
for i in range(1, 1000):
urls.write("http://%s/wordpress/index.php/%d/\n" % (inst, i))
return urls.name
def run():
instances = list(get_instances())
urls = generate_urls_list(instances)
out = subprocess.check_output(
["siege", "-q", "-t", "60S", "-b", "-f", urls],
stderr=subprocess.STDOUT)
for line in out.splitlines():
m = SIEGE_RE.match(line)
if m:
sys.stdout.write("%s:%s\n" % m.groups())
if __name__ == "__main__":
sys.exit(run())