Skip to content

Commit

Permalink
Merge pull request #185 from DeliZhangX/private/deliz/CP-33853
Browse files Browse the repository at this point in the history
Private/deliz/cp 33853
  • Loading branch information
DeliZhangX authored Jun 28, 2020
2 parents 32599fe + ecd22c5 commit 3866570
Show file tree
Hide file tree
Showing 17 changed files with 703 additions and 810 deletions.
2 changes: 1 addition & 1 deletion acktools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def make_local_call(call):
"""Function wrapper for making a simple call to shell"""
process = subprocess.Popen(call, stdout=subprocess.PIPE)
process = subprocess.Popen(call, stdout=subprocess.PIPE) # NOSONAR
stdout, stderr = process.communicate()
if process.returncode == 0:
return str(stdout).strip()
Expand Down
8 changes: 4 additions & 4 deletions acktools/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def configure_log(name, path, to_stdout=True):
fileh.setFormatter(formatter)
log.addHandler(fileh)
except IOError, e:
print "Error writing to file handler. Ignoring."
print str(e)
print("Error writing to file handler. Ignoring.")
print(str(e))

if to_stdout:
try:
sth = logging.StreamHandler(sys.__stdout__)
sth.setLevel(logging.DEBUG)
log.addHandler(sth)
except IOError, e:
print "Error writing to stdout handler. Ignoring."
print str(e)
print("Error writing to stdout handler. Ignoring.")
print(str(e))

return log

Expand Down
6 changes: 3 additions & 3 deletions acktools/net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def generate_mac():
Care should be taken to ensure duplicates are not used.
"""
mac = [0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff)]
random.randint(0x00, 0x7f), # NOSONAR
random.randint(0x00, 0xff), # NOSONAR
random.randint(0x00, 0xff)] # NOSONAR
return ':'.join(map(lambda x: "%02x" % x, mac))
175 changes: 95 additions & 80 deletions autocertkit/ack_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def get_xapi_session(config):


def parse_cmd_args():
parser = OptionParser(
usage="%prog [options]", version="%prog @KIT_VERSION@")
parser = OptionParser( # NOSONAR
usage="%prog [options]", version="%prog @KIT_VERSION@") # NOSONAR

parser.add_option("-d", "--debug",
dest="debug",
Expand Down Expand Up @@ -142,6 +142,12 @@ def parse_cmd_args():
for k, v in kvp_rec.iteritems():
config[k] = v

check_files(config)

return config


def check_files(config):
# Check if files exist
file_opts = [("vpx_dlvm_file", "VPX DLVM file")]
for opt, label in file_opts:
Expand All @@ -155,8 +161,6 @@ def parse_cmd_args():
assert_file_exists(os.path.join(
INSTALL_DIR, vf_driver_pkg), "VF driver rpm package")

return config


def kvp_string_to_rec(string):
"""Take an input string 'a=b,c=d,e=f' and return the record
Expand Down Expand Up @@ -196,85 +200,93 @@ def parse_netconf_file(filename):
rec = {}
for section in cp.sections():
if section.startswith('eth'):
# Ethernet Interface
utils.log.debug("Ethernet Interface: '%s'" % section)

# Network ID is a label of the physical network the adapter has been connected to
# and should be uniform across all adapters.
network_id = cp.get(section, 'network_id')
utils.log.debug("Network IDs: '%s'" % network_id)
try:
network_id = int(network_id)
except:
raise utils.InvalidArgument('Network IDs for %s' % section, network_id,
'should be integer')

# Parse VLAN IDs
vlan_ids = ""
if cp.has_option(section, 'vlan_ids'):
vlan_ids = cp.get(section, 'vlan_ids')
utils.log.debug("VLAN IDs: '%s'" % vlan_ids)
try:
vlan_ids = [int(id.strip()) for id in vlan_ids.split(',')]
except:
raise utils.InvalidArgument('VLAN IDs for %s' % section, vlan_ids,
'should be integer with comma as delimiter if multiple')
# Ensure that the specified VLAN is valid
for vlan_id in vlan_ids:
if vlan_id > MAX_VLAN or vlan_id < MIN_VLAN:
raise utils.InvalidArgument('VLAN ID for %s' % section, vlan_id, '%d < x < %d' %
(MIN_VLAN, MAX_VLAN))

# VF driver info for SR-IOV test
vf_driver_name = ""
if cp.has_option(section, 'vf_driver_name'):
vf_driver_name = cp.get(section, 'vf_driver_name')
vf_driver_pkg = ""
if cp.has_option(section, 'vf_driver_pkg'):
vf_driver_pkg = cp.get(section, 'vf_driver_pkg')
utils.log.debug("VF Driver Name: '%s'" % vf_driver_name)
utils.log.debug("VF Driver Pkg: '%s'" % vf_driver_pkg)

# User is able to specify maxinum VF number per PF to test
max_vf_num = ""
if cp.has_option(section, 'max_vf_num'):
max_vf_num = cp.get(section, 'max_vf_num')
if max_vf_num:
try:
max_vf_num = int(max_vf_num)
except:
raise utils.InvalidArgument('Maxinum VF number for %s' % section, max_vf_num,
'should be integer')
if max_vf_num <= 1:
raise utils.InvalidArgument('Maxinum VF number for %s' % section, max_vf_num,
'should be greater than 1')
max_vf_num = str(max_vf_num)
utils.log.debug(
"Maxinum VF number per PF to test: '%s'" % max_vf_num)

rec[section] = {'network_id': network_id, 'vlan_ids': vlan_ids,
'vf_driver_name': vf_driver_name, 'vf_driver_pkg': vf_driver_pkg,
'max_vf_num': max_vf_num}
parse_section_iface(cp, rec, section)
elif section == "static_management":
rec[section] = parse_static_config(cp, section)
elif section.startswith('static'):
# Definition of network properties (e.g. dhcp/static)
arr = section.split('_')
if len(arr) != 3:
raise utils.InvalidArgument('static addressing section', section,
'should be in format of "static_<network_id>_<vlan_id>"')
net = arr[1]
vlan = arr[2]
if not unicode(net.strip()).isdecimal() or not unicode(vlan.strip()).isdecimal():
raise utils.InvalidArgument('static addressing section', section,
'should be valid network and/or vlan to determine')
rec[section] = parse_static_config(cp, section)
parse_section_static_net(cp, rec, section)
else:
raise Exception("Error: Unknown section: '%s'" % section)

return rec


def parse_section_iface(cp, rec, section):
# Ethernet Interface
utils.log.debug("Ethernet Interface: '%s'" % section)

# Network ID is a label of the physical network the adapter has been connected to
# and should be uniform across all adapters.
network_id = cp.get(section, 'network_id')
utils.log.debug("Network IDs: '%s'" % network_id)
try:
network_id = int(network_id)
except:
raise utils.InvalidArgument('Network IDs for %s' % section, network_id,
'should be integer')

# Parse VLAN IDs
vlan_ids = ""
if cp.has_option(section, 'vlan_ids'):
vlan_ids = cp.get(section, 'vlan_ids')
utils.log.debug("VLAN IDs: '%s'" % vlan_ids)
try:
vlan_ids = [int(id.strip()) for id in vlan_ids.split(',')]
except:
raise utils.InvalidArgument('VLAN IDs for %s' % section, vlan_ids,
'should be integer with comma as delimiter if multiple')
# Ensure that the specified VLAN is valid
for vlan_id in vlan_ids:
if vlan_id > MAX_VLAN or vlan_id < MIN_VLAN:
raise utils.InvalidArgument('VLAN ID for %s' % section, vlan_id, '%d < x < %d' %
(MIN_VLAN, MAX_VLAN))

# VF driver info for SR-IOV test
vf_driver_name = ""
if cp.has_option(section, 'vf_driver_name'):
vf_driver_name = cp.get(section, 'vf_driver_name')
vf_driver_pkg = ""
if cp.has_option(section, 'vf_driver_pkg'):
vf_driver_pkg = cp.get(section, 'vf_driver_pkg')
utils.log.debug("VF Driver Name: '%s'" % vf_driver_name)
utils.log.debug("VF Driver Pkg: '%s'" % vf_driver_pkg)

# User is able to specify maxinum VF number per PF to test
max_vf_num = ""
if cp.has_option(section, 'max_vf_num'):
max_vf_num = cp.get(section, 'max_vf_num')
if max_vf_num:
try:
max_vf_num = int(max_vf_num)
except:
raise utils.InvalidArgument('Maxinum VF number for %s' % section, max_vf_num,
'should be integer')
if max_vf_num <= 1:
raise utils.InvalidArgument('Maxinum VF number for %s' % section, max_vf_num,
'should be greater than 1')
max_vf_num = str(max_vf_num)
utils.log.debug(
"Maxinum VF number per PF to test: '%s'" % max_vf_num)

rec[section] = {'network_id': network_id, 'vlan_ids': vlan_ids,
'vf_driver_name': vf_driver_name, 'vf_driver_pkg': vf_driver_pkg,
'max_vf_num': max_vf_num}


def parse_section_static_net(cp, rec, section):
# Definition of network properties (e.g. dhcp/static)
arr = section.split('_')
if len(arr) != 3:
raise utils.InvalidArgument('static addressing section', section,
'should be in format of "static_<network_id>_<vlan_id>"')
net = arr[1]
vlan = arr[2]
if not unicode(net.strip()).isdecimal() or not unicode(vlan.strip()).isdecimal():
raise utils.InvalidArgument('static addressing section', section,
'should be valid network and/or vlan to determine')
rec[section] = parse_static_config(cp, section)


def assert_file_exists(file_name, label):
"""Check whether a file exists, if it doesn't, raise an exception"""
if not os.path.isfile(file_name):
Expand All @@ -287,12 +299,12 @@ def validate_param(value, possibles, arg_name):
raise utils.InvalidArgument(arg_name, value, possibles)


def parse_static_config(configParser, section):
def parse_static_config(config_parser, section):
"""Parse a ini section specifying static networking config for droid VMs to use."""
utils.log.debug("Read section '%s'" % section)
config = {}
for option in ['ip_start', 'ip_end', 'netmask', 'gw']:
config[option] = configParser.get(section, option)
config[option] = config_parser.get(section, option)
utils.log.debug("Get option %s = '%s'" % (option, config[option]))
if not config[option]:
raise utils.InvalidArgument(
Expand Down Expand Up @@ -415,10 +427,7 @@ def generate_test_config(session, config, test_run_file):
fh.close()


@utils.log_exceptions
def pre_flight_checks(session, config):
"""Check for some of the common problems"""

def pre_flight_check_host(session):
# Check for a run in progress
if check_for_process():
raise Exception(
Expand All @@ -442,6 +451,12 @@ def pre_flight_checks(session, config):
if not avail_storage:
raise Exception("Error: host '%s' has no available storage.")


@utils.log_exceptions
def pre_flight_checks(session, config):
"""Check for some of the common problems"""
pre_flight_check_host(session)

# Check that we have at least two network adaptors, on the same network
recs = config['netconf']
ifaces = {}
Expand Down
72 changes: 0 additions & 72 deletions autocertkit/cpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ class PerfTestClass(testbase.CPUTestClass):
"""A somewhat generic test class for CPU performance tests
that could be expanded to include additional plugin-based tasks"""

# Deine the test timeout in seconds and the number of test VMs
timeout = 3600
vm_count = 3

# SSH command variables
username = 'root'
password = DEFAULT_PASSWORD

# Class variables
test = ''
cmd_str = ''

def _setup_vms(self, session):
"""Create vm_count VMs on the master host and
return a list of VM ref objects"""
Expand All @@ -61,66 +49,6 @@ def _setup_vms(self, session):
self.vm_count,
{net_ref: self.get_static_manager(net_ref)})[host_ref]

def _call_plugin(self, session, vm_ref_list, call):
"""Generic plugin call modified for this test class"""
res = []
for vm_ref in vm_ref_list:
res.append(call_ack_plugin(self.session, call,
{'vm_ref': vm_ref,
'mip': get_context_vm_mip(vm_ref),
'username': self.username,
'password': self.password}))
return res

def _create_test_threads(self, session, vm_ref_list):
"""Spawns a new non-blocking test thread for each VM and
returns a reference object to these threads. Each thread is
a timeout function of function self.cmd_str which is run on
the master host by the XenAPI plugin"""
threads = []
for vm_ref in vm_ref_list:
threads.append(create_test_thread(lambda vm=vm_ref: TimeoutFunction(ssh_command(get_context_vm_mip(vm),
self.username,
self.password,
self.cmd_str,
timeout=self.timeout)["stdout"],
self.timeout, '%s test timed out %d' % (self.test, self.timeout))))
return threads

def _run_test(self, session):
"""Main run fuction. Sets up the VMs, deploys the test,
spawns the test threads, and tracks the threads until they
all complete"""
# setup vms
vm_ref_list = self._setup_vms(session)

# Make certain the VMs are available
for vm_ref in vm_ref_list:
check_vm_ping_response(session, vm_ref, get_context_vm_mip(vm_ref))

# deploy test rpms
log.debug("Deploying test RPMs")
self._call_plugin(session, vm_ref_list, 'deploy_' + self.test)

# create and start test threads, wait until complete
log.debug("About to run %s test..." % self.test)
threads = self._create_test_threads(session, vm_ref_list)

# Wait for the threads to finish running or timeout
start = time.time()
while check_test_thread_status(threads):
time.sleep(1)
if should_timeout(start, self.timeout):
raise Exception("%s test timed out %s" %
(self.test, self.timeout))

# retrieve the logs
log.debug("%s test is complete, retrieving logs" % self.test)
res = self._call_plugin(session, vm_ref_list,
'retrieve_' + self.test + '_logs')

return {'info': 'Test ran successfully'}

def test_lmbench(self, session):
"""Perform the LMBench CPU benchmark"""
self.test = 'lmbench'
Expand Down
Loading

0 comments on commit 3866570

Please sign in to comment.