Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ def _load_jmx(self, ssl, host, port, jmx_metric):
response.close()
except:
logger.debug(
"[Alert][{0}] Unable to close JMX URL connection to {1}".format(
self.get_name(), url
)
f"[Alert][{self.get_name()}] Unable to close JMX URL connection to {url}"
)

json_is_valid = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def _collect(self):

if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"[Alert][{0}] Checking recovery operations for {1}".format(
self.get_name(), component
)
f"[Alert][{self.get_name()}] Checking recovery operations for {component}"
)

recovery_action_info = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,12 @@ def _load_source(self):

if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"[Alert][{0}] Executing script check {1}".format(
self.get_name(), self.path_to_script
)
f"[Alert][{self.get_name()}] Executing script check {self.path_to_script}"
)

if not self.path_to_script.endswith(".py"):
logger.error(
"[Alert][{0}] Unable to execute script {1}".format(
self.get_name(), self.path_to_script
)
f"[Alert][{self.get_name()}] Unable to execute script {self.path_to_script}"
)

return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_callable_name(func):
return func.__class__.__name__

raise TypeError(
"Unable to determine a name for %s -- " "maybe it is not a callable?" % repr(func)
f"Unable to determine a name for {repr(func)} -- maybe it is not a callable?"
)


Expand Down
4 changes: 2 additions & 2 deletions ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def test_do_erase_packages(self, get_os_type_method, run_os_command_method):
self.assertTrue(get_os_type_method.called)
self.assertTrue(run_os_command_method.called)
run_os_command_method.assert_called_with(
"yum erase -y {0}".format(" ".join(["abcd", "wxyz"]))
f"yum erase -y {' '.join(['abcd', 'wxyz'])}"
)
self.assertEqual(0, retval)

Expand All @@ -492,7 +492,7 @@ def test_do_erase_packages(self, get_os_type_method, run_os_command_method):
self.assertTrue(get_os_type_method.called)
self.assertTrue(run_os_command_method.called)
run_os_command_method.assert_called_with(
"zypper -n -q remove {0}".format(" ".join(["abcd", "wxyz"]))
f"zypper -n -q remove {' '.join(['abcd', 'wxyz'])}"
)
self.assertEqual(0, retval)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ def test_attr_to_bitmask(self):
self.assertEqual(
expected,
bitmask,
'Test set "{0}" failed, expected: {1} but got {2}'.format(
test_pattern, expected, bitmask
),
f'Test set "{test_pattern}" failed, expected: {expected} but got {bitmask}',
)
6 changes: 3 additions & 3 deletions ambari-common/src/main/python/ambari_commons/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def __init__(self, code, reason):
self.reason = reason

def __str__(self):
return repr("Fatal exception: %s, exit code %s" % (self.reason, self.code))
return repr(f"Fatal exception: {self.reason}, exit code {self.code}")


class NonFatalException(Exception):
def __init__(self, reason):
self.reason = reason

def __str__(self):
return repr("NonFatal exception: %s" % self.reason)
return repr(f"NonFatal exception: {self.reason}")


class TimeoutError(Exception):
def __str__(self):
return repr("Timeout error: %s" % self.message)
return repr(f"Timeout error: {self.message}")
18 changes: 5 additions & 13 deletions ambari-common/src/main/python/ambari_commons/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ def get_firewall_name(self):
return self.FIREWALL_SERVICE_NAME

def get_command(self):
return "%s %s %s" % (
self.SERVICE_CMD,
self.FIREWALL_SERVICE_NAME,
self.SERVICE_SUBCMD,
)
return f"{self.SERVICE_CMD} {self.FIREWALL_SERVICE_NAME} {self.SERVICE_SUBCMD}"

def check_result(self):
result = False
Expand Down Expand Up @@ -117,7 +113,7 @@ def __init__(self):
self.FIREWALL_SERVICE_NAME = "ufw"

def get_command(self):
return "%s %s" % (self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)
return f"{self.FIREWALL_SERVICE_NAME} {self.SERVICE_SUBCMD}"

def check_result(self):
# On ubuntu, the status command returns 0 whether running or not
Expand All @@ -138,11 +134,7 @@ def __init__(self):
# firewalld added to support default firewall (started from RHEL7/CentOS7)
# script default iptables checked as user can use iptables as known from previous RHEL releases.
def get_command(self):
return "%(servcmd)s is-active %(fwl1)s %(fwl2)s" % {
"servcmd": self.SERVICE_CMD,
"fwl1": "iptables",
"fwl2": "firewalld",
}
return f"{self.SERVICE_CMD} is-active iptables firewalld"

def check_result(self):
if self.stdoutdata is None:
Expand All @@ -159,7 +151,7 @@ def __init__(self):
super(Fedora18FirewallChecks, self).__init__()

def get_command(self):
return "systemctl is-active %s" % (self.FIREWALL_SERVICE_NAME)
return f"systemctl is-active {self.FIREWALL_SERVICE_NAME}"

def check_result(self):
result = False
Expand All @@ -175,7 +167,7 @@ def __init__(self):
self.FIREWALL_SERVICE_NAME = "rcSuSEfirewall2"

def get_command(self):
return "%s %s" % (self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)
return f"{self.FIREWALL_SERVICE_NAME} {self.SERVICE_SUBCMD}"

def check_result(self):
result = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_ambari_version_agent():
ambari_version = f.read().strip()
except Exception as e:
Logger.info("Unable to determine ambari version from the agent version file.")
Logger.debug("Exception: %s" % str(e))
Logger.debug(f"Exception: {str(e)}")
pass
pass
return ambari_version
8 changes: 4 additions & 4 deletions ambari-common/src/main/python/ambari_commons/inet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def download_file_anyway(link, destination, chunk_size=16 * 1024, progress_func=
if not os.path.exists(destination):
print(f"Trying to download {link} to {destination} with [curl] command.")
# print_info_msg(f"Trying to download {link} to {destination} with [curl] command.")
curl_command = "curl --fail -k -o %s %s" % (destination, link)
curl_command = f"curl --fail -k -o {destination} {link}"
retcode, out, err = os_run_os_command(curl_command)
if retcode != 0:
print_error_msg(
Expand All @@ -99,7 +99,7 @@ def download_file_anyway(link, destination, chunk_size=16 * 1024, progress_func=

if not os.path.exists(destination):
print_error_msg(f"Unable to download file {link}!")
print("ERROR: unable to donwload file %s!" % (link))
print(f"ERROR: unable to donwload file {link}!")


def download_progress(file_name, downloaded_size, blockSize, totalSize):
Expand Down Expand Up @@ -181,7 +181,7 @@ def force_download_file(link, destination, chunk_size=16 * 1024, progress_func=N
if partial_size > chunk_size:
# Re-download the last chunk, to minimize the possibilities of file corruption
resume_pos = partial_size - chunk_size
request.add_header("Range", "bytes=%s-" % resume_pos)
request.add_header("Range", f"bytes={resume_pos}-")
else:
# Make sure the full dir structure is in place, otherwise file open will fail
if not os.path.exists(dest_path):
Expand All @@ -190,7 +190,7 @@ def force_download_file(link, destination, chunk_size=16 * 1024, progress_func=N
response = urllib.request.urlopen(request)
(file_size, seek_pos) = find_range_components(response.info())

print_info_msg("Downloading to: %s Bytes: %s" % (destination, file_size))
print_info_msg(f"Downloading to: {destination} Bytes: {file_size}")

if partial_size < file_size:
if seek_pos == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def from_kerberos_record(item, hostname):
)

def __str__(self):
return "Keytab: %s Principal: %s" % (self.keytab_file_path, self.principal)
return f"Keytab: {self.keytab_file_path} Principal: {self.principal}"

@classmethod
def from_kerberos_records(self, kerberos_record, hostname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ def set_port(host, port):
host_and_port = split_host_and_port(host)

if (host_and_port is not None) and ("host" in host_and_port):
return "%s:%s" % (host_and_port["host"], port)
return f"{host_and_port['host']}:{port}"
else:
return host
4 changes: 2 additions & 2 deletions ambari-common/src/main/python/ambari_commons/os_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def initialize_data(cls):
json_data[JSON_OS_ALIASES] if JSON_OS_ALIASES in json_data else {}
)
except:
raise Exception("Couldn't load '%s' file" % OSFAMILY_JSON_RESOURCE)
raise Exception(f"Couldn't load '{OSFAMILY_JSON_RESOURCE}' file")

def __init__(cls, name, bases, dct):
cls.initialize_data()
Expand All @@ -177,7 +177,7 @@ def __getattr__(cls, name):
return name[3:]
if "_family" in name and name[:-7] in cls.FAMILY_COLLECTION:
return name[:-7]
raise Exception("Unknown class property '%s'" % name)
raise Exception(f"Unknown class property '{name}'")


class OSConst(metaclass=OS_CONST_TYPE):
Expand Down
6 changes: 3 additions & 3 deletions ambari-common/src/main/python/ambari_commons/os_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def os_set_file_permissions(file, mod, recursive, user):


def os_set_open_files_limit(maxOpenFiles):
command = "%s %s" % (ULIMIT_CMD, str(maxOpenFiles))
command = f"{ULIMIT_CMD} {str(maxOpenFiles)}"
os_run_os_command(command)


Expand All @@ -96,11 +96,11 @@ def os_getpass(prompt):
def os_is_service_exist(serviceName):
if os.path.exists("/run/systemd/system/"):
return (
os.popen('systemctl list-units --full -all | grep "%s.service"' % serviceName)
os.popen(f'systemctl list-units --full -all | grep "{serviceName}.service"')
.read()
.strip()
!= ""
)

status = os.system("service %s status >/dev/null 2>&1" % serviceName)
status = os.system(f"service {serviceName} status >/dev/null 2>&1")
return status != 256
2 changes: 1 addition & 1 deletion ambari-common/src/main/python/ambari_commons/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def set_file_permissions(file, mod, user, recursive):
if os.path.exists(file):
os_set_file_permissions(file, mod, recursive, user)
else:
print_info_msg("File %s does not exist" % file)
print_info_msg(f"File {file} does not exist")


def run_os_command(cmd, env=None, cwd=None):
Expand Down
2 changes: 1 addition & 1 deletion ambari-common/src/main/python/ambari_commons/os_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def Start(serviceName, waitSecs=30):
)
except win32service.error as exc:
if exc.winerror != 1056:
msg = "Error starting service: %s" % exc.strerror
msg = f"Error starting service: {exc.strerror}"
err = exc.winerror
return err, msg

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ def __init__(self, function, element, params, queue):

def return_name(self):
## NOTE: self.name is an attribute of multiprocessing.Process
return "Process running function '%s' for element '%s'" % (
self.function,
self.element,
)
return f"Process running function '{self.function}' for element '{self.element}'"

def run(self):
try:
Expand All @@ -65,7 +62,7 @@ def run(self):


def execute_in_parallel(function, array, params, wait_for_all=False):
logger.info("Started running %s for %s" % (function, array))
logger.info(f"Started running {function} for {array}")
processs = []
q = Queue()
counter = len(array)
Expand All @@ -86,7 +83,7 @@ def execute_in_parallel(function, array, params, wait_for_all=False):
for process in processs:
process.terminate()

logger.info("Finished running %s for %s" % (function, array))
logger.info(f"Finished running {function} for {array}")

return results

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def install_package(self, name, context):
cmd = cmd + [enable_repo_option]
cmd = cmd + [name]
cmdString = " ".join(cmd)
Logger.info("Installing package %s ('%s')" % (name, cmdString))
Logger.info(f"Installing package {name} ('{cmdString}')")
runner = shellRunner()
res = runner.run(cmd)
if res["exitCode"] != 0:
Expand All @@ -79,7 +79,7 @@ def install_package(self, name, context):
+ res["output"]
)
else:
Logger.info("Skipping installation of existing package %s" % (name))
Logger.info(f"Skipping installation of existing package {name}")

def upgrade_package(self, name, context):
"""
Expand All @@ -94,7 +94,7 @@ def upgrade_package(self, name, context):
cmd = cmd + [enable_repo_option]
cmd = cmd + [name]
cmdString = " ".join(cmd)
Logger.info("Upgrading package %s ('%s')" % (name, cmdString))
Logger.info(f"Upgrading package {name} ('{cmdString}')")
runner = shellRunner()
res = runner.run(cmd)
if res["exitCode"] != 0:
Expand All @@ -117,7 +117,7 @@ def remove_package(self, name, context, ignore_dependencies=False):
if self._check_existence(name, context):
cmd = REMOVE_CMD[context.log_output] + [name]
cmdString = " ".join(cmd)
Logger.info("Removing package %s ('%s')" % (name, " ".join(cmd)))
Logger.info(f"Removing package {name} ('{' '.join(cmd)}')")
runner = shellRunner()
res = runner.run(cmd)
if res["exitCode"] != 0:
Expand All @@ -129,7 +129,7 @@ def remove_package(self, name, context, ignore_dependencies=False):
+ res["output"]
)
else:
Logger.info("Skipping removal of non-existing package %s" % (name))
Logger.info(f"Skipping removal of non-existing package {name}")

def _check_existence(self, name, context):
cmd = CHECK_CMD[context.log_output] + [name]
Expand Down
4 changes: 2 additions & 2 deletions ambari-common/src/main/python/ambari_commons/str_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cbool(obj):
return True
if obj in ("false", "no", "off", "n", "f", "0"):
return False
raise ValueError('Unable to interpret value "%s" as boolean' % obj)
raise ValueError(f'Unable to interpret value "{obj}" as boolean')
return bool(obj)


Expand All @@ -59,7 +59,7 @@ def cint(obj):
try:
return int(obj)
except ValueError:
raise ValueError('Unable to interpret value "%s" as integer' % obj)
raise ValueError(f'Unable to interpret value "{obj}" as integer')
elif obj is None:
return obj

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __mod__(self, arg):
return self.__class__(str.__mod__(self, arg))

def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, str.__repr__(self))
return f"{self.__class__.__name__}({str.__repr__(self)})"

def join(self, seq):
return self.__class__(str.join(self, list(map(escape, seq))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ def allexcept(*args):
if cat == "Cs":
# Jython can't handle isolated surrogates
f.write(
"""\
try:
Cs = eval(r"%r")
f"""try:
Cs = eval(r"{val!r}")
except UnicodeDecodeError:
Cs = '' # Jython can't handle isolated surrogates\n\n"""
% val
Cs = '' # Jython can't handle isolated surrogates

"""
)
else:
f.write("%s = %r\n\n" % (cat, val))
f.write("cats = %r\n\n" % sorted(categories.keys()))
f.write(f"{cat} = {val!r}\n\n")
f.write(f"cats = {sorted(categories.keys())!r}\n\n")

f.write(footer)
f.close()
Loading