Skip to content

Commit

Permalink
Merge pull request kubernetes#1587 from mm4tt/dns_python3
Browse files Browse the repository at this point in the history
Fix dns benchmark failing after python 2->3 migration
  • Loading branch information
k8s-ci-robot committed Nov 23, 2020
2 parents f001b44 + d97ed73 commit e3bd829
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dns/py/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Parser(object):
Parses dnsperf output file.
"""
def __init__(self, out):
self.lines = [x.strip() for x in out.decode().split('\n')]
self.lines = [x.strip() for x in out.split('\n')]
self.results = {}
self.histogram = []

Expand Down
19 changes: 9 additions & 10 deletions dns/py/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
MAX_TEST_SVC = 20

def add_prefix(prefix, text):
return '\n'.join([prefix + l for l in text.decode().split('\n')])
decoded_text = isinstance(text, str) and str or text.decode()
return '\n'.join([prefix + l for l in decoded_text.split('\n')])


class Runner(object):
Expand Down Expand Up @@ -161,8 +162,6 @@ def _kubectl(self, stdin, *args):
"""
cmdline = [self.args.kubectl_exec] + list(args)
_log.debug('kubectl %s', cmdline)
if stdin:
_log.debug('kubectl stdin\n%s', add_prefix('in | ', stdin))
proc = subprocess.Popen(cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate(stdin)
ret = proc.wait()
Expand All @@ -171,11 +170,11 @@ def _kubectl(self, stdin, *args):
_log.debug('kubectl stdout\n%s', add_prefix('out | ', out))
_log.debug('kubectl stderr\n%s', add_prefix('err | ', err))

return proc.wait(), out, err
return proc.wait(), out.decode(), err.decode()

def _create(self, yaml_obj):
_log.debug('applying yaml: %s', yaml.dump(yaml_obj))
ret, out, err = self._kubectl(yaml.dump(yaml_obj), 'create', '-f', '-')
ret, out, err = self._kubectl(yaml.dump(yaml_obj, encoding='utf-8'), 'create', '-f', '-')
if ret != 0:
_log.error('Could not create dns: %d\nstdout:\n%s\nstderr:%s\n',
ret, out, err)
Expand Down Expand Up @@ -260,8 +259,8 @@ def _run_perf(self, test_case, inputs, podname):
results = {}
results['params'] = test_case.to_yaml()
results['code'] = code
results['stdout'] = out.decode().split('\n')
results['stderr'] = err.decode().split('\n')
results['stdout'] = out.split('\n')
results['stderr'] = err.split('\n')
results['data'] = {}

try:
Expand All @@ -280,8 +279,8 @@ def _run_perf(self, test_case, inputs, podname):
results['data']['max_kubedns_cpu'] = res_usage.get()
results['data']['max_kubedns_memory'] = res_usage.get()
results['data']['histogram'] = parser.histogram
except Exception as exc:
_log.error('Error parsing results: %s', exc)
except Exception:
_log.exception('Error parsing results.')
results['data']['ok'] = False
results['data']['msg'] = 'parsing error:\n%s' % traceback.format_exc()

Expand Down Expand Up @@ -370,7 +369,7 @@ def _reset_client(self):
if code != 0:
_log.error('Error: stderr\n%s', add_prefix('err | ', err))
raise Exception('error getting pod information: %d', code)
client_pods=client_pods.rstrip().decode().split('\n')
client_pods=client_pods.rstrip().split('\n')
_log.info('got client pods "%s"', client_pods)
if len(client_pods) > 0:
break
Expand Down

0 comments on commit e3bd829

Please sign in to comment.