-# Copyright 2015-2016 Intel Corporation.
+# Copyright 2015-2017 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
import subprocess
import locale
import re
+import distro
from conf import settings as S
+from tools.version import Version
def match_line(file_name, pattern):
""" loops through given file and returns first line matching given pattern
:returns: Return distro name as a string
"""
- return ' '.join(platform.dist())
+ return ' '.join(distro.linux_distribution())
def get_kernel():
"""Get kernel version.
:returns: version string or None
"""
try:
- output = subprocess.check_output(binary, shell=True).decode().rstrip('\n')
+ output = str(subprocess.check_output(
+ binary, stderr=subprocess.STDOUT, shell=True).decode().rstrip('\n'))
except subprocess.CalledProcessError:
return None
return None
# This function uses long switch per purpose, so let us suppress pylint warning too-many-branches
-# pylint: disable=R0912
+# pylint: disable=too-many-branches, too-many-statements
def get_version(app_name):
""" Get version of given application and its git tag
'testpmd' : r'RTE Version: \'\S+ ([0-9.]+)',
'qemu' : r'QEMU emulator version ([0-9.]+)',
'loopback_l2fwd' : os.path.join(S.getValue('ROOT_DIR'), 'src/l2fwd/l2fwd.c'),
- 'loopback_testpmd' : os.path.join(S.getValue('TOOLS')['dpdk_src'],
- 'lib/librte_eal/common/include/rte_version.h'),
'ixnet' : os.path.join(S.getValue('TRAFFICGEN_IXNET_LIB_PATH'), 'pkgIndex.tcl'),
'ixia' : os.path.join(S.getValue('TRAFFICGEN_IXIA_ROOT_DIR'), 'lib/ixTcl1.0/ixTclHal.tcl'),
+ 'trex' : os.path.join(S.getValue('ROOT_DIR'), 'src/trex/trex'),
}
# stored at TOOS['dpdk_src'] directory
tmp_ver = ['', '', '']
dpdk_16 = False
- with open(app_version_file['loopback_testpmd']) as file_:
+ # TOOLS dictionary is created during runtime and it is not
+ # available in some vsperf modes (e.g. -m trafficgen), thus
+ # following definition can't be part of app_version_file dict above
+ app_file = os.path.join(S.getValue('TOOLS')['dpdk_src'],
+ 'lib/librte_eal/common/include/rte_version.h')
+ with open(app_file) as file_:
for line in file_:
if not line.strip():
continue
app_version = match_line(app_version_file['ixia'], 'package provide IxTclHal')
if app_version:
app_version = app_version.split(' ')[3]
+ elif app_name.lower() == 'trex':
+ app_version = match_line(os.path.join(app_version_file['trex'], 'VERSION'), 'v')
+ app_git_tag = get_git_tag(app_version_file['trex'])
elif app_name.lower() == 'xena':
try:
app_version = S.getValue('XENA_VERSION')
app_version = 'NA'
app_git_tag = 'NA'
- return {'name' : app_name, 'version' : app_version, 'git_tag' : app_git_tag}
+ return Version(app_name, app_version, app_git_tag)
def get_loopback_version(loopback_app_name):
""" Get version of given guest loopback application and its git tag
version or git tag are not known or not applicaple, than None is returned for any unknown value
"""
version = get_version("loopback_{}".format(loopback_app_name))
- version['name'] = loopback_app_name
+ version.set_value('name', loopback_app_name)
return version