add log for logstash
Change-Id: Ifef5d27e702a13bab7817900f3870441a13732d6
This commit is contained in:
parent
5fbc516b2c
commit
c1c919ae33
@ -15,18 +15,14 @@
|
||||
|
||||
'''Module for Openstack compute operations'''
|
||||
|
||||
import log
|
||||
import os
|
||||
import time
|
||||
|
||||
import glanceclient.exc as glance_exception
|
||||
from log import LOG
|
||||
import novaclient
|
||||
import novaclient.exceptions as exceptions
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
class Compute(object):
|
||||
|
||||
def __init__(self, nova_client, config):
|
||||
@ -66,32 +62,32 @@ class Compute(object):
|
||||
while img.status in ['queued', 'saving'] and retry < retry_count:
|
||||
img = glance_client.images.find(name=img.name)
|
||||
retry = retry + 1
|
||||
CONLOG.debug("Image not yet active, retrying %s of %s..." % (retry, retry_count))
|
||||
LOG.debug("Image not yet active, retrying %s of %s..." % (retry, retry_count))
|
||||
time.sleep(2)
|
||||
if img.status != 'active':
|
||||
raise Exception
|
||||
except glance_exception.HTTPForbidden:
|
||||
CONLOG.error("Cannot upload image without admin access. Please make "
|
||||
"sure the image is uploaded and is either public or owned by you.")
|
||||
LOG.error("Cannot upload image without admin access. Please make "
|
||||
"sure the image is uploaded and is either public or owned by you.")
|
||||
return False
|
||||
except IOError:
|
||||
# catch the exception for file based errors.
|
||||
CONLOG.error("Failed while uploading the image. Please make sure the "
|
||||
"image at the specified location %s is correct." % image_url)
|
||||
LOG.error("Failed while uploading the image. Please make sure the "
|
||||
"image at the specified location %s is correct." % image_url)
|
||||
return False
|
||||
except Exception:
|
||||
CONLOG.error("Failed while uploading the image, please make sure the "
|
||||
"cloud under test has the access to URL: %s." % image_url)
|
||||
LOG.error("Failed while uploading the image, please make sure the "
|
||||
"cloud under test has the access to URL: %s." % image_url)
|
||||
return False
|
||||
return True
|
||||
|
||||
def delete_image(self, glance_client, img_name):
|
||||
try:
|
||||
CONLOG.log("Deleting image %s..." % img_name)
|
||||
LOG.log("Deleting image %s..." % img_name)
|
||||
img = glance_client.images.find(name=img_name)
|
||||
glance_client.images.delete(img.id)
|
||||
except Exception:
|
||||
CONLOG.error("Failed to delete the image %s." % img_name)
|
||||
LOG.error("Failed to delete the image %s." % img_name)
|
||||
return False
|
||||
|
||||
return True
|
||||
@ -102,7 +98,7 @@ class Compute(object):
|
||||
for key in keypair_list:
|
||||
if key.name == name:
|
||||
self.novaclient.keypairs.delete(name)
|
||||
CONLOG.info('Removed public key %s' % (name))
|
||||
LOG.info('Removed public key %s' % (name))
|
||||
break
|
||||
|
||||
# Test if keypair file is present if not create it
|
||||
@ -126,7 +122,7 @@ class Compute(object):
|
||||
with open(os.path.expanduser(public_key_file)) as pkf:
|
||||
public_key = pkf.read()
|
||||
except IOError as exc:
|
||||
CONLOG.error('Cannot open public key file %s: %s' % (public_key_file, exc))
|
||||
LOG.error('Cannot open public key file %s: %s' % (public_key_file, exc))
|
||||
return None
|
||||
keypair = self.novaclient.keypairs.create(name, public_key)
|
||||
return keypair
|
||||
@ -176,14 +172,14 @@ class Compute(object):
|
||||
if instance.status == 'ACTIVE':
|
||||
return instance
|
||||
if instance.status == 'ERROR':
|
||||
CONLOG.error('Instance creation error:' + instance.fault['message'])
|
||||
LOG.error('Instance creation error:' + instance.fault['message'])
|
||||
break
|
||||
CONLOG.debug("[%s] VM status=%s, retrying %s of %s..." %
|
||||
(vmname, instance.status, (retry_attempt + 1), retry_count))
|
||||
LOG.debug("[%s] VM status=%s, retrying %s of %s..." %
|
||||
(vmname, instance.status, (retry_attempt + 1), retry_count))
|
||||
time.sleep(2)
|
||||
|
||||
# instance not in ACTIVE state
|
||||
CONLOG.error('Instance failed status=' + instance.status)
|
||||
LOG.error('Instance failed status=' + instance.status)
|
||||
self.delete_server(instance)
|
||||
return None
|
||||
|
||||
@ -213,10 +209,10 @@ class Compute(object):
|
||||
if server.name == vmname and server.status == "ACTIVE":
|
||||
return True
|
||||
# Sleep between retries
|
||||
CONLOG.debug("[%s] VM not yet found, retrying %s of %s..." %
|
||||
(vmname, (retry_attempt + 1), retry_count))
|
||||
LOG.debug("[%s] VM not yet found, retrying %s of %s..." %
|
||||
(vmname, (retry_attempt + 1), retry_count))
|
||||
time.sleep(2)
|
||||
CONLOG.error("[%s] VM not found, after %s attempts" % (vmname, retry_count))
|
||||
LOG.error("[%s] VM not found, after %s attempts" % (vmname, retry_count))
|
||||
return False
|
||||
|
||||
# Returns True if server is found and deleted/False if not,
|
||||
@ -225,7 +221,7 @@ class Compute(object):
|
||||
servers_list = self.get_server_list()
|
||||
for server in servers_list:
|
||||
if server.name == vmname:
|
||||
CONLOG.info('Deleting server %s' % (server))
|
||||
LOG.info('Deleting server %s' % (server))
|
||||
self.novaclient.servers.delete(server)
|
||||
return True
|
||||
return False
|
||||
@ -253,11 +249,11 @@ class Compute(object):
|
||||
if hyp.host == host:
|
||||
return self.normalize_az_host(hyp.zone, host)
|
||||
# no match on host
|
||||
CONLOG.error('Passed host name does not exist: ' + host)
|
||||
LOG.error('Passed host name does not exist: ' + host)
|
||||
return None
|
||||
if self.config.availability_zone:
|
||||
return self.normalize_az_host(None, host)
|
||||
CONLOG.error('--hypervisor passed without an az and no az configured')
|
||||
LOG.error('--hypervisor passed without an az and no az configured')
|
||||
return None
|
||||
|
||||
def sanitize_az_host(self, host_list, az_host):
|
||||
@ -285,7 +281,7 @@ class Compute(object):
|
||||
return az_host
|
||||
# else continue - another zone with same host name?
|
||||
# no match
|
||||
CONLOG.error('No match for availability zone and host ' + az_host)
|
||||
LOG.error('No match for availability zone and host ' + az_host)
|
||||
return None
|
||||
else:
|
||||
return self.auto_fill_az(host_list, az_host)
|
||||
@ -318,8 +314,8 @@ class Compute(object):
|
||||
try:
|
||||
host_list = self.novaclient.services.list()
|
||||
except novaclient.exceptions.Forbidden:
|
||||
CONLOG.warning('Operation Forbidden: could not retrieve list of hosts'
|
||||
' (likely no permission)')
|
||||
LOG.warning('Operation Forbidden: could not retrieve list of hosts'
|
||||
' (likely no permission)')
|
||||
|
||||
# the user has specified a list of 1 or 2 hypervisors to use
|
||||
if self.config.hypervisors:
|
||||
@ -338,7 +334,7 @@ class Compute(object):
|
||||
# pick first 2 matches at most
|
||||
if len(avail_list) == 2:
|
||||
break
|
||||
CONLOG.info('Using hypervisors ' + ', '.join(avail_list))
|
||||
LOG.info('Using hypervisors ' + ', '.join(avail_list))
|
||||
else:
|
||||
for host in host_list:
|
||||
# this host must be a compute node
|
||||
@ -360,10 +356,10 @@ class Compute(object):
|
||||
if not avail_list:
|
||||
|
||||
if not self.config.availability_zone:
|
||||
CONLOG.error('Availability_zone must be configured')
|
||||
LOG.error('Availability_zone must be configured')
|
||||
elif host_list:
|
||||
CONLOG.error('No host matching the selection for availability zone: ' +
|
||||
self.config.availability_zone)
|
||||
LOG.error('No host matching the selection for availability zone: ' +
|
||||
self.config.availability_zone)
|
||||
avail_list = []
|
||||
else:
|
||||
avail_list = [self.config.availability_zone]
|
||||
@ -379,7 +375,7 @@ class Compute(object):
|
||||
else:
|
||||
return False
|
||||
except novaclient.exceptions:
|
||||
CONLOG.warning("Exception in retrieving the hostId of servers")
|
||||
LOG.warning("Exception in retrieving the hostId of servers")
|
||||
|
||||
# Create a new security group with appropriate rules
|
||||
def security_group_create(self):
|
||||
@ -407,7 +403,7 @@ class Compute(object):
|
||||
# Delete a security group
|
||||
def security_group_delete(self, group):
|
||||
if group:
|
||||
CONLOG.info("Deleting security group")
|
||||
LOG.info("Deleting security group")
|
||||
self.novaclient.security_groups.delete(group)
|
||||
|
||||
# Add rules to the security group
|
||||
|
@ -14,13 +14,8 @@
|
||||
#
|
||||
|
||||
from attrdict import AttrDict
|
||||
import log
|
||||
import yaml
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
def config_load(file_name, from_cfg=None):
|
||||
'''Load a yaml file into a config dict, merge with from_cfg if not None
|
||||
The config file content taking precedence in case of duplicate
|
||||
|
@ -15,13 +15,10 @@
|
||||
|
||||
# Module for credentials in Openstack
|
||||
import getpass
|
||||
import log
|
||||
import os
|
||||
import re
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
from log import LOG
|
||||
|
||||
class Credentials(object):
|
||||
|
||||
@ -90,7 +87,7 @@ class Credentials(object):
|
||||
elif name == "CACERT":
|
||||
self.rc_cacert = value
|
||||
else:
|
||||
CONLOG.error('Error: rc file does not exist %s' % (openrc_file))
|
||||
LOG.error('Error: rc file does not exist %s' % (openrc_file))
|
||||
success = False
|
||||
elif not no_env:
|
||||
# no openrc file passed - we assume the variables have been
|
||||
@ -98,7 +95,7 @@ class Credentials(object):
|
||||
# just check that they are present
|
||||
for varname in ['OS_USERNAME', 'OS_AUTH_URL', 'OS_TENANT_NAME']:
|
||||
if varname not in os.environ:
|
||||
CONLOG.warning('%s is missing' % (varname))
|
||||
LOG.warning('%s is missing' % (varname))
|
||||
success = False
|
||||
if success:
|
||||
self.rc_username = os.environ['OS_USERNAME']
|
||||
|
@ -15,14 +15,11 @@
|
||||
|
||||
import re
|
||||
|
||||
import log
|
||||
from log import LOG
|
||||
import monitor
|
||||
from netaddr import IPAddress
|
||||
import sshutils
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
# a dictionary of sequence number indexed by a name prefix
|
||||
prefix_seq = {}
|
||||
@ -178,11 +175,11 @@ class Instance(object):
|
||||
# Display a status message with the standard header that has the instance
|
||||
# name (e.g. [foo] some text)
|
||||
def display(self, fmt, *args):
|
||||
CONLOG.info(('[%s] ' + fmt) % ((self.name,) + args))
|
||||
LOG.info(('[%s] ' + fmt) % ((self.name,) + args))
|
||||
|
||||
# Debugging message, to be printed only in debug mode
|
||||
def buginf(self, fmt, *args):
|
||||
CONLOG.debug(('[%s] ' + fmt) % ((self.name,) + args))
|
||||
LOG.debug(('[%s] ' + fmt) % ((self.name,) + args))
|
||||
|
||||
# Ping an IP from this instance
|
||||
def ping_check(self, target_ip, ping_count, pass_threshold):
|
||||
|
@ -15,13 +15,9 @@
|
||||
|
||||
import re
|
||||
|
||||
import log
|
||||
from log import LOG
|
||||
from perf_tool import PerfTool
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
# The resulting unit should be in K
|
||||
MULTIPLIERS = {'K': 1,
|
||||
'M': 1.0e3,
|
||||
@ -33,7 +29,7 @@ def get_bdw_kbps(bdw, bdw_unit):
|
||||
return bdw / 1000
|
||||
if bdw_unit in MULTIPLIERS:
|
||||
return int(bdw * MULTIPLIERS[bdw_unit])
|
||||
CONLOG.error('Error: unknown multiplier: ' + bdw_unit)
|
||||
LOG.error('Error: unknown multiplier: ' + bdw_unit)
|
||||
return bdw
|
||||
|
||||
class IperfTool(PerfTool):
|
||||
|
10
vmtp/log.py
10
vmtp/log.py
@ -34,18 +34,22 @@ def setup(product_name, debug=False, logfile=None):
|
||||
console_logger.addHandler(console_handler)
|
||||
console_logger.setLevel(log_level)
|
||||
|
||||
logstash_logger = logging.getLogger(product_name + '_' + 'logstash')
|
||||
logstash_logger.setLevel(log_level)
|
||||
file_logger = logging.getLogger(product_name + '_' + 'file')
|
||||
file_logger.setLevel(log_level)
|
||||
|
||||
all_logger = logging.getLogger(product_name + '_' + 'all')
|
||||
all_logger.addHandler(console_handler)
|
||||
all_logger.setLevel(log_level)
|
||||
|
||||
if file_handler:
|
||||
logstash_logger.addHandler(file_handler)
|
||||
file_logger.addHandler(file_handler)
|
||||
all_logger.addHandler(file_handler)
|
||||
|
||||
def getLogger(product, target):
|
||||
logger = logging.getLogger(product + "_" + target)
|
||||
|
||||
return logger
|
||||
|
||||
CONLOG = getLogger('vmtp', 'console')
|
||||
LOG = getLogger('vmtp', 'all')
|
||||
FILELOG = getLogger('vmtp', 'file')
|
||||
|
@ -15,16 +15,12 @@
|
||||
|
||||
import time
|
||||
|
||||
import log
|
||||
from log import LOG
|
||||
# Module containing a helper class for operating on OpenStack networks
|
||||
from neutronclient.common.exceptions import NetworkInUseClient
|
||||
from neutronclient.common.exceptions import NeutronException
|
||||
import vmtp
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
class Network(object):
|
||||
|
||||
#
|
||||
@ -80,10 +76,10 @@ class Network(object):
|
||||
break
|
||||
|
||||
if not self.ext_net:
|
||||
CONLOG.error("No external network found.")
|
||||
LOG.error("No external network found.")
|
||||
return
|
||||
|
||||
CONLOG.info("Using external network: " + self.ext_net['name'])
|
||||
LOG.info("Using external network: " + self.ext_net['name'])
|
||||
|
||||
# Find or create the router to the external network
|
||||
ext_net_id = self.ext_net['id']
|
||||
@ -93,7 +89,7 @@ class Network(object):
|
||||
if external_gw_info:
|
||||
if external_gw_info['network_id'] == ext_net_id:
|
||||
self.ext_router = router
|
||||
CONLOG.info('Found external router: %s' % (self.ext_router['name']))
|
||||
LOG.info('Found external router: %s' % (self.ext_router['name']))
|
||||
break
|
||||
|
||||
# create a new external router if none found and a name was given
|
||||
@ -101,7 +97,7 @@ class Network(object):
|
||||
if (not self.ext_router) and self.ext_router_name:
|
||||
self.ext_router = self.create_router(self.ext_router_name,
|
||||
self.ext_net['id'])
|
||||
CONLOG.info('Created ext router %s.' % (self.ext_router_name))
|
||||
LOG.info('Created ext router %s.' % (self.ext_router_name))
|
||||
self.ext_router_created = True
|
||||
|
||||
if config.ipv6_mode:
|
||||
@ -146,7 +142,7 @@ class Network(object):
|
||||
|
||||
for network in self.networks:
|
||||
if network['name'] == network_name:
|
||||
CONLOG.info('Found existing internal network: %s' % (network_name))
|
||||
LOG.info('Found existing internal network: %s' % (network_name))
|
||||
return network
|
||||
|
||||
body = {
|
||||
@ -185,7 +181,7 @@ class Network(object):
|
||||
subnet = self.neutron_client.create_subnet(body)['subnet']
|
||||
# add the subnet id to the network dict
|
||||
network['subnets'].append(subnet['id'])
|
||||
CONLOG.info('Created internal network: %s.' % (network_name))
|
||||
LOG.info('Created internal network: %s.' % (network_name))
|
||||
return network
|
||||
|
||||
# Delete a network and associated subnet
|
||||
@ -196,7 +192,7 @@ class Network(object):
|
||||
for _ in range(1, 5):
|
||||
try:
|
||||
self.neutron_client.delete_network(network['id'])
|
||||
CONLOG.info('Network %s deleted.' % (name))
|
||||
LOG.info('Network %s deleted.' % (name))
|
||||
break
|
||||
except NetworkInUseClient:
|
||||
time.sleep(1)
|
||||
@ -220,7 +216,7 @@ class Network(object):
|
||||
port_ip = port['fixed_ips'][0]
|
||||
if (port['device_id'] == self.ext_router['id']) and \
|
||||
(port_ip['subnet_id'] == self.vm_int_net[0]['subnets'][0]):
|
||||
CONLOG.info('Ext router already associated to the internal network.')
|
||||
LOG.info('Ext router already associated to the internal network.')
|
||||
return
|
||||
|
||||
for int_net in self.vm_int_net:
|
||||
@ -228,7 +224,7 @@ class Network(object):
|
||||
'subnet_id': int_net['subnets'][0]
|
||||
}
|
||||
self.neutron_client.add_interface_router(self.ext_router['id'], body)
|
||||
CONLOG.debug('Ext router associated to ' + int_net['name'])
|
||||
LOG.debug('Ext router associated to ' + int_net['name'])
|
||||
# If ipv6 is enabled than add second subnet
|
||||
if self.ipv6_enabled:
|
||||
body = {
|
||||
@ -256,7 +252,7 @@ class Network(object):
|
||||
except NeutronException:
|
||||
# May fail with neutronclient.common.exceptions.Conflict
|
||||
# if there are floating IP in use - just ignore
|
||||
CONLOG.warning('Router interface may have floating IP in use: not deleted')
|
||||
LOG.warning('Router interface may have floating IP in use: not deleted')
|
||||
|
||||
# Lookup network given network name
|
||||
def lookup_network(self, network_name):
|
||||
@ -308,11 +304,11 @@ class Network(object):
|
||||
body['port']['binding:vnic_type'] = vnic_type
|
||||
port = self.neutron_client.create_port(body)
|
||||
if self.config.debug:
|
||||
CONLOG.info('Created port ' + port['port']['id'])
|
||||
LOG.info('Created port ' + port['port']['id'])
|
||||
return port['port']
|
||||
|
||||
def delete_port(self, port):
|
||||
CONLOG.debug('Deleting port ' + port['id'])
|
||||
LOG.debug('Deleting port ' + port['id'])
|
||||
self.neutron_client.delete_port(port['id'])
|
||||
|
||||
# Create a floating ip on the external network and return it
|
||||
@ -344,9 +340,9 @@ class Network(object):
|
||||
self.neutron_client.remove_gateway_router(
|
||||
self.ext_router['id'])
|
||||
self.neutron_client.delete_router(self.ext_router['id'])
|
||||
CONLOG.info('External router %s deleted' % (self.ext_router['name']))
|
||||
LOG.info('External router %s deleted' % (self.ext_router['name']))
|
||||
except TypeError:
|
||||
CONLOG.info("No external router set")
|
||||
LOG.info("No external router set")
|
||||
|
||||
def _get_l2agent_type(self):
|
||||
'''
|
||||
|
@ -15,14 +15,9 @@
|
||||
|
||||
import re
|
||||
|
||||
import log
|
||||
from perf_tool import PerfTool
|
||||
import sshutils
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
class NuttcpTool(PerfTool):
|
||||
|
||||
def __init__(self, instance):
|
||||
|
@ -14,13 +14,8 @@
|
||||
#
|
||||
|
||||
from instance import Instance as Instance
|
||||
import log
|
||||
from perf_tool import PingTool
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
class PerfInstance(Instance):
|
||||
'''An openstack instance to run performance tools
|
||||
'''
|
||||
|
@ -16,16 +16,11 @@
|
||||
import abc
|
||||
import re
|
||||
|
||||
import log
|
||||
from pkg_resources import resource_filename
|
||||
|
||||
# where to copy the tool on the target, must end with slash
|
||||
SCP_DEST_DIR = '/tmp/'
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
#
|
||||
# A base class for all tools that can be associated to an instance
|
||||
#
|
||||
@ -193,7 +188,7 @@ class PerfTool(object):
|
||||
min_kbps = int((max_kbps + min_kbps) / 2)
|
||||
|
||||
kbps = int((max_kbps + min_kbps) / 2)
|
||||
# CONLOG.debug(' undershot, min=%d kbps=%d max=%d' % (min_kbps, kbps, max_kbps))
|
||||
# LOG.debug(' undershot, min=%d kbps=%d max=%d' % (min_kbps, kbps, max_kbps))
|
||||
elif loss_rate > max_loss_rate:
|
||||
# overshot
|
||||
max_kbps = kbps
|
||||
@ -201,7 +196,7 @@ class PerfTool(object):
|
||||
kbps = measured_kbps
|
||||
else:
|
||||
kbps = int((max_kbps + min_kbps) / 2)
|
||||
# CONLOG.debug(' overshot, min=%d kbps=%d max=%d' % (min_kbps, kbps, max_kbps))
|
||||
# LOG.debug(' overshot, min=%d kbps=%d max=%d' % (min_kbps, kbps, max_kbps))
|
||||
else:
|
||||
# converged within loss rate bracket
|
||||
break
|
||||
|
@ -64,14 +64,10 @@ import StringIO
|
||||
import sys
|
||||
import time
|
||||
|
||||
import log
|
||||
from log import LOG
|
||||
import paramiko
|
||||
import scp
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
# from rally.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
@ -412,7 +408,7 @@ class SSH(object):
|
||||
if int(pkt_loss) < int(pass_threshold):
|
||||
return 1
|
||||
else:
|
||||
CONLOG.error('Ping to %s failed: %s' % (target_ip, cmd_output))
|
||||
LOG.error('Ping to %s failed: %s' % (target_ip, cmd_output))
|
||||
return 0
|
||||
|
||||
def get_file_from_host(self, from_path, to_path):
|
||||
@ -425,7 +421,7 @@ class SSH(object):
|
||||
try:
|
||||
scpcon.get(from_path, to_path)
|
||||
except scp.SCPException as exp:
|
||||
CONLOG.error("Receive failed: [%s]" % exp)
|
||||
LOG.error("Receive failed: [%s]" % exp)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
@ -439,7 +435,7 @@ class SSH(object):
|
||||
try:
|
||||
scpcon.put(from_path, remote_path=to_path)
|
||||
except scp.SCPException as exp:
|
||||
CONLOG.error("Send failed: [%s]" % exp)
|
||||
LOG.error("Send failed: [%s]" % exp)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
@ -465,7 +461,7 @@ class SSH(object):
|
||||
if self.stat(os_release_file):
|
||||
data = self.read_remote_file(os_release_file)
|
||||
if data is None:
|
||||
CONLOG.error("Failed to read file %s" % os_release_file)
|
||||
LOG.error("Failed to read file %s" % os_release_file)
|
||||
return None
|
||||
|
||||
for line in data.splitlines():
|
||||
@ -483,7 +479,7 @@ class SSH(object):
|
||||
if self.stat(sys_release_file):
|
||||
data = self.read_remote_file(sys_release_file)
|
||||
if data is None:
|
||||
CONLOG.error("Failed to read file %s" % sys_release_file)
|
||||
LOG.error("Failed to read file %s" % sys_release_file)
|
||||
return None
|
||||
|
||||
for line in data.splitlines():
|
||||
@ -512,7 +508,7 @@ class SSH(object):
|
||||
if mobj:
|
||||
return mobj.group(0)
|
||||
|
||||
CONLOG.info("%s pkg installed " % rpm_pkg)
|
||||
LOG.info("%s pkg installed " % rpm_pkg)
|
||||
|
||||
return None
|
||||
|
||||
|
96
vmtp/vmtp.py
96
vmtp/vmtp.py
@ -33,6 +33,9 @@ import credentials
|
||||
from glanceclient.v1 import client as glanceclient
|
||||
import iperf_tool
|
||||
from keystoneclient.v2_0 import client as keystoneclient
|
||||
from log import CONLOG
|
||||
from log import FILELOG
|
||||
from log import LOG
|
||||
import network
|
||||
from neutronclient.v2_0 import client as neutronclient
|
||||
from novaclient.client import Client
|
||||
@ -44,10 +47,6 @@ import pns_mongo
|
||||
from prettytable import PrettyTable
|
||||
import sshutils
|
||||
|
||||
CONLOG = log.getLogger('vmtp', 'console')
|
||||
LSLOG = log.getLogger('vmtp', 'logstash')
|
||||
LOG = log.getLogger('vmtp', 'all')
|
||||
|
||||
flow_num = 0
|
||||
class FlowPrinter(object):
|
||||
@staticmethod
|
||||
@ -55,7 +54,7 @@ class FlowPrinter(object):
|
||||
global flow_num
|
||||
flow_num = flow_num + 1
|
||||
CONLOG.info("=" * 60)
|
||||
CONLOG.info('Flow %d: %s' % (flow_num, desc))
|
||||
LOG.info('Flow %d: %s' % (flow_num, desc))
|
||||
|
||||
class ResultsCollector(object):
|
||||
|
||||
@ -105,7 +104,7 @@ class ResultsCollector(object):
|
||||
|
||||
def save_to_db(self, cfg):
|
||||
'''Save results to MongoDB database.'''
|
||||
CONLOG.info("Saving results to MongoDB database...")
|
||||
LOG.info("Saving results to MongoDB database...")
|
||||
post_id = pns_mongo.\
|
||||
pns_add_test_result_to_mongod(cfg.vmtp_mongod_ip,
|
||||
cfg.vmtp_mongod_port,
|
||||
@ -113,7 +112,7 @@ class ResultsCollector(object):
|
||||
cfg.vmtp_collection,
|
||||
self.results)
|
||||
if post_id is None:
|
||||
CONLOG.error("Failed to add result to DB")
|
||||
LOG.error("Failed to add result to DB")
|
||||
|
||||
class VmtpException(Exception):
|
||||
pass
|
||||
@ -184,14 +183,14 @@ class VmtpTest(object):
|
||||
self.instance_access.public_key_file = pub_key
|
||||
self.instance_access.private_key_file = priv_key
|
||||
else:
|
||||
CONLOG.error('Default keypair ~/.ssh/id_rsa[.pub] does not exist. Please '
|
||||
'either create one in your home directory, or specify your '
|
||||
'keypair information in the config file before running VMTP.')
|
||||
LOG.error('Default keypair ~/.ssh/id_rsa[.pub] does not exist. Please '
|
||||
'either create one in your home directory, or specify your '
|
||||
'keypair information in the config file before running VMTP.')
|
||||
sys.exit(1)
|
||||
|
||||
if self.config.debug and self.instance_access.public_key_file:
|
||||
CONLOG.info('VM public key: ' + self.instance_access.public_key_file)
|
||||
CONLOG.info('VM private key: ' + self.instance_access.private_key_file)
|
||||
LOG.info('VM public key: ' + self.instance_access.public_key_file)
|
||||
LOG.info('VM private key: ' + self.instance_access.private_key_file)
|
||||
|
||||
# If we need to reuse existing vms just return without setup
|
||||
if not self.config.reuse_existing_vm:
|
||||
@ -209,8 +208,8 @@ class VmtpTest(object):
|
||||
self.image_instance = self.comp.find_image(self.config.image_name)
|
||||
if self.image_instance is None:
|
||||
if self.config.vm_image_url != "":
|
||||
CONLOG.info('%s: image for VM not found, trying to upload it ...' %
|
||||
(self.config.image_name))
|
||||
LOG.info('%s: image for VM not found, trying to upload it ...' %
|
||||
(self.config.image_name))
|
||||
keystone = keystoneclient.Client(**creds)
|
||||
glance_endpoint = keystone.service_catalog.url_for(
|
||||
service_type='image', endpoint_type='publicURL')
|
||||
@ -225,24 +224,24 @@ class VmtpTest(object):
|
||||
self.image_uploaded = True
|
||||
else:
|
||||
# Exit the pogram
|
||||
CONLOG.error('%s: image to launch VM not found. ABORTING.' %
|
||||
(self.config.image_name))
|
||||
LOG.error('%s: image to launch VM not found. ABORTING.' %
|
||||
(self.config.image_name))
|
||||
sys.exit(1)
|
||||
|
||||
self.assert_true(self.image_instance)
|
||||
CONLOG.info('Found image %s to launch VM, will continue' % (self.config.image_name))
|
||||
LOG.info('Found image %s to launch VM, will continue' % (self.config.image_name))
|
||||
self.flavor_type = self.comp.find_flavor(self.config.flavor_type)
|
||||
self.net = network.Network(neutron, self.config)
|
||||
|
||||
self.rescol.add_property('l2agent_type', self.net.l2agent_type)
|
||||
CONLOG.info("OpenStack agent: " + self.net.l2agent_type)
|
||||
LOG.info("OpenStack agent: " + self.net.l2agent_type)
|
||||
try:
|
||||
network_type = self.net.vm_int_net[0]['provider:network_type']
|
||||
CONLOG.info("OpenStack network type: " + network_type)
|
||||
LOG.info("OpenStack network type: " + network_type)
|
||||
self.rescol.add_property('encapsulation', network_type)
|
||||
except KeyError as exp:
|
||||
network_type = 'Unknown'
|
||||
CONLOG.info("Provider network type not found: ", str(exp))
|
||||
LOG.info("Provider network type not found: ", str(exp))
|
||||
|
||||
# Create a new security group for the test
|
||||
self.sec_group = self.comp.security_group_create()
|
||||
@ -321,6 +320,7 @@ class VmtpTest(object):
|
||||
if res:
|
||||
self.rescol.add_flow_result(res)
|
||||
CONLOG.info(self.rescol.ppr.pformat(res))
|
||||
FILELOG.info(json.dumps(res, sort_keys=True))
|
||||
client.dispose()
|
||||
|
||||
def add_location(self, label):
|
||||
@ -356,12 +356,14 @@ class VmtpTest(object):
|
||||
results_list = perf_output['results']
|
||||
for res_dict in results_list:
|
||||
if 'error' in res_dict:
|
||||
CONLOG.error('Stopping execution on error, cleanup all VMs/networks manually')
|
||||
LOG.error('Stopping execution on error, cleanup all VMs/networks manually')
|
||||
CONLOG.info(self.rescol.ppr.pformat(perf_output))
|
||||
FILELOG.info(json.dumps(perf_output, sort_keys=True))
|
||||
sys.exit(2)
|
||||
|
||||
self.rescol.add_flow_result(perf_output)
|
||||
CONLOG.info(self.rescol.ppr.pformat(perf_output))
|
||||
FILELOG.info(json.dumps(perf_output, sort_keys=True))
|
||||
|
||||
def measure_vm_flows(self):
|
||||
# scenarios need to be tested for both inter and intra node
|
||||
@ -397,7 +399,7 @@ class VmtpTest(object):
|
||||
'''
|
||||
Clean up the floating ip and VMs
|
||||
'''
|
||||
CONLOG.info('Cleaning up...')
|
||||
LOG.info('Cleaning up...')
|
||||
if self.server:
|
||||
self.server.dispose()
|
||||
if self.client:
|
||||
@ -413,7 +415,7 @@ class VmtpTest(object):
|
||||
self.comp.security_group_delete(self.sec_group)
|
||||
except ClientException:
|
||||
# May throw novaclient.exceptions.BadRequest if in use
|
||||
CONLOG.warning('Security group in use: not deleted')
|
||||
LOG.warning('Security group in use: not deleted')
|
||||
if self.image_uploaded and self.config.delete_image_after_run:
|
||||
self.comp.delete_image(self.glance_client, self.config.image_name)
|
||||
|
||||
@ -426,11 +428,11 @@ class VmtpTest(object):
|
||||
except KeyboardInterrupt:
|
||||
traceback.format_exc()
|
||||
except (VmtpException, sshutils.SSHError, ClientException, Exception):
|
||||
CONLOG.error(traceback.print_exc())
|
||||
LOG.error(traceback.print_exc())
|
||||
error_flag = True
|
||||
|
||||
if self.config.stop_on_error and error_flag:
|
||||
CONLOG.error('Stopping execution on error, cleanup all VMs/networks manually')
|
||||
LOG.error('Stopping execution on error, cleanup all VMs/networks manually')
|
||||
sys.exit(2)
|
||||
else:
|
||||
self.teardown()
|
||||
@ -458,7 +460,7 @@ def test_native_tp(nhosts, ifname, config):
|
||||
# use the IP address configured on given interface
|
||||
server_ip = server.get_interface_ip(ifname)
|
||||
if not server_ip:
|
||||
CONLOG.error('Cannot get IP address for interface ' + ifname)
|
||||
LOG.error('Cannot get IP address for interface ' + ifname)
|
||||
else:
|
||||
server.display('Clients will use server IP address %s (%s)' %
|
||||
(server_ip, ifname))
|
||||
@ -492,10 +494,10 @@ def test_native_tp(nhosts, ifname, config):
|
||||
def get_controller_info(ssh_access, net, res_col, retry_count):
|
||||
if not ssh_access:
|
||||
return
|
||||
CONLOG.info('Fetching OpenStack deployment details...')
|
||||
LOG.info('Fetching OpenStack deployment details...')
|
||||
sshcon = sshutils.SSH(ssh_access, connect_retry_count=retry_count)
|
||||
if sshcon is None:
|
||||
CONLOG.error('Cannot connect to the controller node')
|
||||
LOG.error('Cannot connect to the controller node')
|
||||
return
|
||||
res = {}
|
||||
res['distro'] = sshcon.get_host_os_version()
|
||||
@ -511,6 +513,8 @@ def get_controller_info(ssh_access, net, res_col, retry_count):
|
||||
res['l2agent_version'] = sshcon.get_l2agent_version(l2type)
|
||||
# print results
|
||||
CONLOG.info(res_col.ppr.pformat(res))
|
||||
FILELOG.info(json.dumps(res, sort_keys=True))
|
||||
|
||||
res_col.add_properties(res)
|
||||
|
||||
def gen_report_data(proto, result):
|
||||
@ -639,6 +643,11 @@ def print_report(results):
|
||||
summary += str(ptable)
|
||||
|
||||
CONLOG.info(summary)
|
||||
ls_summary = {"Result": results, "Total Scenarios": (len(table) - 1),
|
||||
"Passed Scenarios": "%d [%.2f%%]" % (cnt_passed, passed_rate),
|
||||
"Failed Scenarios": "%d [%.2f%%]" % (cnt_failed, failed_rate),
|
||||
"Skipped Scenarios": "%d" % (cnt_skipped)}
|
||||
FILELOG.info(json.dumps(ls_summary, sort_keys=True))
|
||||
|
||||
def normalize_paths(cfg):
|
||||
'''
|
||||
@ -666,7 +675,7 @@ def get_ssh_access(opt_name, opt_value, config):
|
||||
host_access.private_key_file = config.private_key_file
|
||||
host_access.public_key_file = config.public_key_file
|
||||
if host_access.error:
|
||||
CONLOG.error('Error for --' + (opt_name + ':' + host_access.error))
|
||||
LOG.error('Error for --' + (opt_name + ':' + host_access.error))
|
||||
sys.exit(2)
|
||||
return host_access
|
||||
|
||||
@ -880,15 +889,15 @@ def merge_opts_to_configs(opts):
|
||||
config.same_network_only = opts.same_network_only
|
||||
|
||||
if config.public_key_file and not os.path.isfile(config.public_key_file):
|
||||
CONLOG.warning('Invalid public_key_file:' + config.public_key_file)
|
||||
LOG.warning('Invalid public_key_file:' + config.public_key_file)
|
||||
config.public_key_file = None
|
||||
if config.private_key_file and not os.path.isfile(config.private_key_file):
|
||||
CONLOG.warning('Invalid private_key_file:' + config.private_key_file)
|
||||
LOG.warning('Invalid private_key_file:' + config.private_key_file)
|
||||
config.private_key_file = None
|
||||
|
||||
# direct: use SR-IOV ports for all the test VMs
|
||||
if opts.vnic_type not in [None, 'direct', 'macvtap', 'normal']:
|
||||
CONLOG.error('Invalid vnic-type: ' + opts.vnic_type)
|
||||
LOG.error('Invalid vnic-type: ' + opts.vnic_type)
|
||||
sys.exit(1)
|
||||
config.vnic_type = opts.vnic_type
|
||||
config.hypervisors = opts.hypervisors
|
||||
@ -937,8 +946,8 @@ def merge_opts_to_configs(opts):
|
||||
raise ValueError
|
||||
val = int(opts.vm_bandwidth[0:-1])
|
||||
except ValueError:
|
||||
CONLOG.error('Invalid --bandwidth parameter. A valid input must '
|
||||
'specify only one unit (K|M|G).')
|
||||
LOG.error('Invalid --bandwidth parameter. A valid input must '
|
||||
'specify only one unit (K|M|G).')
|
||||
sys.exit(1)
|
||||
config.vm_bandwidth = int(val * (10 ** (ex_unit * 3)))
|
||||
|
||||
@ -950,8 +959,8 @@ def merge_opts_to_configs(opts):
|
||||
for i in xrange(len(config.tcp_pkt_sizes)):
|
||||
config.tcp_pkt_sizes[i] = int(config.tcp_pkt_sizes[i])
|
||||
except ValueError:
|
||||
CONLOG.error('Invalid --tcpbuf parameter. A valid input must be '
|
||||
'integers seperated by comma.')
|
||||
LOG.error('Invalid --tcpbuf parameter. A valid input must be '
|
||||
'integers seperated by comma.')
|
||||
sys.exit(1)
|
||||
|
||||
if opts.udp_pkt_sizes:
|
||||
@ -960,8 +969,8 @@ def merge_opts_to_configs(opts):
|
||||
for i in xrange(len(config.udp_pkt_sizes)):
|
||||
config.udp_pkt_sizes[i] = int(config.udp_pkt_sizes[i])
|
||||
except ValueError:
|
||||
CONLOG.error('Invalid --udpbuf parameter. A valid input must be '
|
||||
'integers seperated by comma.')
|
||||
LOG.error('Invalid --udpbuf parameter. A valid input must be '
|
||||
'integers seperated by comma.')
|
||||
sys.exit(1)
|
||||
|
||||
if opts.reuse_network_name:
|
||||
@ -987,12 +996,12 @@ def merge_opts_to_configs(opts):
|
||||
if mobj:
|
||||
config.gmond_svr_ip = mobj.group(1)
|
||||
config.gmond_svr_port = mobj.group(2)
|
||||
CONLOG.info("Ganglia monitoring enabled (%s:%s)" %
|
||||
(config.gmond_svr_ip, config.gmond_svr_port))
|
||||
LOG.info("Ganglia monitoring enabled (%s:%s)" %
|
||||
(config.gmond_svr_ip, config.gmond_svr_port))
|
||||
config.time = 30
|
||||
|
||||
else:
|
||||
CONLOG.warning('Invalid --monitor syntax: ' + opts.monitor)
|
||||
LOG.warning('Invalid --monitor syntax: ' + opts.monitor)
|
||||
|
||||
###################################################
|
||||
# Once we parse the config files, normalize
|
||||
@ -1017,7 +1026,7 @@ def merge_opts_to_configs(opts):
|
||||
elif opts.tp_tool.lower() == 'iperf':
|
||||
config.tp_tool = iperf_tool.IperfTool
|
||||
else:
|
||||
CONLOG.warning('Invalid transport tool: ' + opts.tp_tool)
|
||||
LOG.warning('Invalid transport tool: ' + opts.tp_tool)
|
||||
sys.exit(1)
|
||||
else:
|
||||
config.tp_tool = None
|
||||
@ -1068,12 +1077,13 @@ def run_vmtp(opts):
|
||||
for item in native_tp_results:
|
||||
rescol.add_flow_result(item)
|
||||
CONLOG.info(rescol.ppr.pformat(item))
|
||||
FILELOG.info(json.dumps(item, sort_keys=True))
|
||||
|
||||
# Parse the credentials of the OpenStack cloud, and run the benchmarking
|
||||
cred = credentials.Credentials(opts.rc, opts.passwd, opts.no_env)
|
||||
if cred.rc_auth_url:
|
||||
if config.debug:
|
||||
CONLOG.info('Using ' + cred.rc_auth_url)
|
||||
LOG.info('Using ' + cred.rc_auth_url)
|
||||
vmtp_instance = VmtpTest(config, cred, rescol)
|
||||
vmtp_instance.run()
|
||||
vmtp_net = vmtp_instance.net
|
||||
|
Loading…
Reference in New Issue
Block a user