diff --git a/vmtp/compute.py b/vmtp/compute.py index 14cf99d..7b6ab86 100644 --- a/vmtp/compute.py +++ b/vmtp/compute.py @@ -62,7 +62,7 @@ class Compute(object): while img.status in ['queued', 'saving'] and retry < retry_count: img = glance_client.images.find(name=img.name) retry = retry + 1 - LOG.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 @@ -73,21 +73,21 @@ class Compute(object): except IOError: # catch the exception for file based errors. LOG.error("Failed while uploading the image. Please make sure the " - "image at the specified location %s is correct." % image_url) + "image at the specified location %s is correct.", image_url) return False except Exception: LOG.error("Failed while uploading the image, please make sure the " - "cloud under test has the access to URL: %s." % image_url) + "cloud under test has the access to URL: %s.", image_url) return False return True def delete_image(self, glance_client, img_name): try: - LOG.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: - LOG.error("Failed to delete the image %s." % img_name) + LOG.error("Failed to delete the image %s.", img_name) return False return True @@ -98,7 +98,7 @@ class Compute(object): for key in keypair_list: if key.name == name: self.novaclient.keypairs.delete(name) - LOG.info('Removed public key %s' % (name)) + LOG.info('Removed public key %s', name) break # Test if keypair file is present if not create it @@ -122,7 +122,7 @@ class Compute(object): with open(os.path.expanduser(public_key_file)) as pkf: public_key = pkf.read() except IOError as exc: - LOG.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 @@ -173,14 +173,14 @@ class Compute(object): if instance.status == 'ACTIVE': return instance if instance.status == 'ERROR': - LOG.error('Instance creation error:' + instance.fault['message']) + LOG.error('Instance creation error: %s', instance.fault['message']) break - LOG.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 - LOG.error('Instance failed status=' + instance.status) + LOG.error('Instance failed status=%s', instance.status) self.delete_server(instance) return None @@ -210,10 +210,10 @@ class Compute(object): if server.name == vmname and server.status == "ACTIVE": return True # Sleep between retries - LOG.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) - LOG.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, @@ -222,7 +222,7 @@ class Compute(object): servers_list = self.get_server_list() for server in servers_list: if server.name == vmname: - LOG.info('Deleting server %s' % (server)) + LOG.info('Deleting server %s', server) self.novaclient.servers.delete(server) return True return False diff --git a/vmtp/credentials.py b/vmtp/credentials.py index 189e161..b873827 100644 --- a/vmtp/credentials.py +++ b/vmtp/credentials.py @@ -87,7 +87,7 @@ class Credentials(object): elif name == "CACERT": self.rc_cacert = value else: - LOG.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 @@ -95,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: - LOG.warning('%s is missing' % (varname)) + LOG.warning('%s is missing', varname) success = False if success: self.rc_username = os.environ['OS_USERNAME'] diff --git a/vmtp/network.py b/vmtp/network.py index 91fa95d..25d2545 100644 --- a/vmtp/network.py +++ b/vmtp/network.py @@ -76,7 +76,7 @@ class Network(object): break if self.ext_net: - LOG.info("Using external network: " + self.ext_net['name']) + LOG.info("Using external network: %s.", self.ext_net['name']) # Find or create the router to the external network ext_net_id = self.ext_net['id'] routers = neutron_client.list_routers()['routers'] @@ -85,7 +85,7 @@ class Network(object): if external_gw_info: if external_gw_info['network_id'] == ext_net_id: self.ext_router = router - LOG.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 @@ -93,7 +93,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']) - LOG.info('Created ext router %s.' % (self.ext_router_name)) + LOG.info('Created ext router %s.', self.ext_router_name) self.ext_router_created = True else: LOG.warning("No external network found.") @@ -145,7 +145,7 @@ class Network(object): for network in self.networks: if network['name'] == network_name: - LOG.info('Found existing internal network: %s' % (network_name)) + LOG.info('Found existing internal network: %s', network_name) return network body = { @@ -189,7 +189,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']) - LOG.info('Created internal network: %s.' % (network_name)) + LOG.info('Created internal network: %s.', network_name) return network # Delete a network and associated subnet @@ -200,7 +200,7 @@ class Network(object): for _ in range(1, 5): try: self.neutron_client.delete_network(network['id']) - LOG.info('Network %s deleted.' % (name)) + LOG.info('Network %s deleted.', name) break except NetworkInUseClient: time.sleep(1) @@ -351,7 +351,7 @@ class Network(object): self.neutron_client.remove_gateway_router( self.ext_router['id']) self.neutron_client.delete_router(self.ext_router['id']) - LOG.info('External router %s deleted' % (self.ext_router['name'])) + LOG.info('External router %s deleted.', self.ext_router['name']) except TypeError: LOG.info("No external router set") diff --git a/vmtp/perf_tool.py b/vmtp/perf_tool.py index e466c2f..aa9cbeb 100644 --- a/vmtp/perf_tool.py +++ b/vmtp/perf_tool.py @@ -16,6 +16,7 @@ import abc import re +from log import LOG from pkg_resources import resource_filename # where to copy the tool on the target, must end with slash @@ -188,7 +189,7 @@ class PerfTool(object): min_kbps = int((max_kbps + min_kbps) / 2) kbps = int((max_kbps + min_kbps) / 2) - # LOG.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 @@ -196,7 +197,7 @@ class PerfTool(object): kbps = measured_kbps else: kbps = int((max_kbps + min_kbps) / 2) - # LOG.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 diff --git a/vmtp/sshutils.py b/vmtp/sshutils.py index fa64826..7d3642b 100644 --- a/vmtp/sshutils.py +++ b/vmtp/sshutils.py @@ -408,7 +408,7 @@ class SSH(object): if int(pkt_loss) < int(pass_threshold): return 1 else: - LOG.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): @@ -421,7 +421,7 @@ class SSH(object): try: scpcon.get(from_path, to_path) except scp.SCPException as exp: - LOG.error("Receive failed: [%s]" % exp) + LOG.error("Receive failed: [%s]", exp) return 0 return 1 @@ -435,7 +435,7 @@ class SSH(object): try: scpcon.put(from_path, remote_path=to_path) except scp.SCPException as exp: - LOG.error("Send failed: [%s]" % exp) + LOG.error("Send failed: [%s]", exp) return 0 return 1 @@ -461,7 +461,7 @@ class SSH(object): if self.stat(os_release_file): data = self.read_remote_file(os_release_file) if data is None: - LOG.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(): @@ -479,7 +479,7 @@ class SSH(object): if self.stat(sys_release_file): data = self.read_remote_file(sys_release_file) if data is None: - LOG.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(): @@ -508,7 +508,7 @@ class SSH(object): if mobj: return mobj.group(0) - LOG.info("%s pkg installed " % rpm_pkg) + LOG.info("%s pkg installed ", rpm_pkg) return None diff --git a/vmtp/vmtp.py b/vmtp/vmtp.py index f7bf0e9..ac75cf1 100755 --- a/vmtp/vmtp.py +++ b/vmtp/vmtp.py @@ -54,7 +54,7 @@ class FlowPrinter(object): global flow_num flow_num = flow_num + 1 CONLOG.info("=" * 60) - LOG.info('Flow %d: %s' % (flow_num, desc)) + LOG.info('Flow %d: %s', flow_num, desc) class ResultsCollector(object): @@ -208,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 != "": - LOG.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') @@ -224,12 +224,12 @@ class VmtpTest(object): self.image_uploaded = True else: # Exit the pogram - LOG.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) - LOG.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) @@ -1015,8 +1015,8 @@ def merge_opts_to_configs(opts): if mobj: config.gmond_svr_ip = mobj.group(1) config.gmond_svr_port = mobj.group(2) - LOG.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: