Commit be74286b by Marco Mariani

removed dead code, petty cleanup

1 parent 8b829033
......@@ -27,8 +27,6 @@
#
##############################################################################
import textwrap
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, do_console, ClientConfig
......
......@@ -34,8 +34,6 @@ from slapos.cli.command import check_root_user
from slapos.cli.config import ConfigCommand
from slapos.grid.svcbackend import launchSupervisord
from slapos.util import string_to_boolean
import supervisor.supervisorctl
......
......@@ -46,7 +46,6 @@ import subprocess
import sys
import threading
import time
import traceback
import zipfile
import lxml.etree
......@@ -1210,7 +1209,6 @@ class FormatConfig(object):
attr = getattr(self, option)
if isinstance(attr, str):
if attr.lower() == 'true':
root_needed = True
setattr(self, option, True)
elif attr.lower() == 'false':
setattr(self, option, False)
......
......@@ -468,7 +468,7 @@ class Partition(object):
self.logger.warning("Falling back to default buildout %r" %
buildout_binary)
else:
if len(bootstrap_candidate_list) != 1:
if len(bootstrap_candidate_list) > 1:
raise ValueError('More than one bootstrap candidate found.')
# Reads uid/gid of path, launches buildout with thoses privileges
bootstrap_file = os.path.abspath(os.path.join(bootstrap_candidate_dir,
......@@ -529,7 +529,7 @@ class Partition(object):
if os.path.exists(self.service_path):
if os.path.isdir(self.service_path):
service_list = os.listdir(self.service_path)
if len(runner_list) == 0 and len(service_list) == 0:
if not runner_list and not service_list:
self.logger.warning('No runners nor services found for partition %r' %
self.partition_id)
if os.path.exists(self.supervisord_partition_configuration_path):
......
......@@ -329,15 +329,17 @@ class Slapgrid(object):
self.buildout = buildout
self.promise_timeout = promise_timeout
self.develop = develop
if software_release_filter_list is not None:
self.software_release_filter_list = []
if software_release_filter_list:
self.software_release_filter_list = \
software_release_filter_list.split(",")
else:
self.software_release_filter_list = []
self.computer_partition_filter_list = []
if computer_partition_filter_list is not None:
if computer_partition_filter_list:
self.computer_partition_filter_list = \
computer_partition_filter_list.split(",")
self.maximum_periodicity = maximum_periodicity
def getWatchdogLine(self):
......@@ -559,7 +561,7 @@ class Slapgrid(object):
# Check if we defined explicit list of partitions to process.
# If so, if current partition not in this list, skip.
if len(self.computer_partition_filter_list) > 0 and \
if self.computer_partition_filter_list and \
(computer_partition_id not in self.computer_partition_filter_list):
return
......@@ -877,7 +879,7 @@ class Slapgrid(object):
self.logger.error(UnicodeError)
raise UnicodeError("Failed to read %s: %s" % (computer_partition_usage.usage, exc))
except (etree.XMLSyntaxError, etree.DocumentInvalid) as exc:
self.logger.info("Failed to parse %s." % (computer_partition_usage.usage))
self.logger.info("Failed to parse %s." % computer_partition_usage.usage)
self.logger.error(exc)
raise _formatXMLError(exc)
except Exception as exc:
......@@ -985,7 +987,7 @@ class Slapgrid(object):
clean_run = False
failed_script_list.append("Script %r failed." % script)
self.logger.warning('Failed to run %r' % invocation_list)
if len(failed_script_list):
if failed_script_list:
computer_partition.error('\n'.join(failed_script_list), logger=self.logger)
# Whatever happens, don't stop processing other instances
except Exception:
......
......@@ -51,13 +51,6 @@ urllib3_logger = logging.getLogger('requests.packages.urllib3')
urllib3_logger.setLevel(logging.WARNING)
# XXX fallback_logger to be deprecated together with the old CLI entry points.
fallback_logger = logging.getLogger(__name__)
fallback_handler = logging.StreamHandler()
fallback_logger.setLevel(logging.INFO)
fallback_logger.addHandler(fallback_handler)
DEFAULT_SOFTWARE_TYPE = 'RootSoftwareInstance'
class SlapDocument:
......@@ -133,7 +126,7 @@ class SoftwareRelease(SlapDocument):
else:
return self._software_release
def error(self, error_log, logger=None):
def error(self, error_log, logger):
try:
# Does not follow interface
self._connection_helper.POST('softwareReleaseError', data={
......@@ -141,7 +134,7 @@ class SoftwareRelease(SlapDocument):
'computer_id': self.getComputerId(),
'error_log': error_log})
except Exception:
(logger or fallback_logger).exception('')
logger.exception('')
def available(self):
self._connection_helper.POST('availableSoftwareRelease', data={
......@@ -439,14 +432,14 @@ class ComputerPartition(SlapRequester):
'computer_partition_id': self.getId(),
})
def error(self, error_log, logger=None):
def error(self, error_log, logger):
try:
self._connection_helper.POST('softwareInstanceError', data={
'computer_id': self._computer_id,
'computer_partition_id': self.getId(),
'error_log': error_log})
except Exception:
(logger or fallback_logger).exception('')
logger.exception('')
def bang(self, message):
self._connection_helper.POST('softwareInstanceBang', data={
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!