Review LOG levels

Adjust LOG levels throughout the code.

Story: 2005051
Task: 48516

Change-Id: Ie54a0d6a50c373ebc8b1d272aa5b574d5821b399
Signed-off-by: Daniel Caires <daniel.caires@encora.com>
This commit is contained in:
Daniel Caires 2023-09-04 13:57:58 -03:00 committed by Daniel Marques Caires
parent a41fffdefc
commit b5768ae359
8 changed files with 51 additions and 43 deletions

View File

@ -32,7 +32,7 @@ def unlock_host(stream, hostname):
try:
serial.expect_bytes(stream, "locked")
except streamexpect.ExpectTimeout:
LOG.info("Host %s not locked", hostname)
LOG.error("Host %s not locked", hostname)
return 1
LOG.info("#### Unlock %s", hostname)
@ -58,7 +58,7 @@ def lock_host(stream, hostname):
try:
serial.expect_bytes(stream, "unlocked")
except streamexpect.ExpectTimeout:
LOG.info("Host %s not unlocked", hostname)
LOG.error("Host %s not unlocked", hostname)
return 1
LOG.info("Lock %s", hostname)

View File

@ -53,7 +53,7 @@ def config_controller(stream, password):
serial.send_bytes(stream, cmd, expect_prompt=False, log=False)
ret = serial.expect_bytes(stream, "[0]", timeout=HostTimeout.NORMAL_OP, log=False)
if ret != 0:
LOG.info("Configuration failed. Exiting installer.")
LOG.error("Configuration failed. Exiting installer.")
raise SystemExit("Configcontroller failed")
LOG.info("Successful bootstrap ansible playbook execution")

View File

@ -45,7 +45,8 @@ class CreateportforwardTestCase(unittest.TestCase):
@patch("helper.vboxmanage.vboxmanage_addportforward")
@patch("helper.vboxmanage.vboxmanage_deleteportforward", return_value=None)
@patch('utils.install_log.LOG.info')
def test_rewrite_rule_yes_to_all(self, mock_log, mock_deleteport, mock_addport, mock_getrule, mock_v_box_options):
@patch('utils.install_log.LOG.warning')
def test_rewrite_rule_yes_to_all(self, mock_warning, mock_info, mock_deleteport, mock_addport, mock_getrule, mock_v_box_options):
"""
Test create_port_forward method that fails to create rule and the installer was called with --y (yes to all) as an argument
"""
@ -59,9 +60,9 @@ class CreateportforwardTestCase(unittest.TestCase):
result = create_port_forward(self.hostname, self.network, self.local_port, self.guest_port, self.guest_ip)
# Assert
mock_log.assert_any_call(
mock_warning.assert_any_call(
"Trying to create a port-forwarding rule with port: %s, but it is already in use with rule name: %s", "8080", "Rule1")
mock_log.assert_any_call("Rewriting portforwarding rule...")
mock_info.assert_any_call("Rewriting portforwarding rule...")
mock_getrule.assert_called_once_with('NatNetwork', '8080')
mock_deleteport.assert_called_once_with('Rule1', 'NatNetwork')
mock_addport.assert_called_with('TestVM', '8080', '10.10.10.1', '80', 'NatNetwork')
@ -72,7 +73,7 @@ class CreateportforwardTestCase(unittest.TestCase):
@patch("helper.vboxmanage.vboxmanage_getrulename")
@patch("helper.vboxmanage.vboxmanage_addportforward")
@patch("helper.vboxmanage.vboxmanage_deleteportforward", return_value=None)
@patch('utils.install_log.LOG.info')
@patch('utils.install_log.LOG.warning')
def test_rewrite_rule(self, mock_log, mock_deleteport, mock_addport, mock_getrule, mock_y_n_prompt):
"""
Test create_port_forward method that fails to create rule and the user input 'y' to rewrite the existing rule
@ -99,7 +100,8 @@ class CreateportforwardTestCase(unittest.TestCase):
@patch("helper.vboxmanage.vboxmanage_getrulename")
@patch("helper.vboxmanage.vboxmanage_addportforward")
@patch('utils.install_log.LOG.info')
def test_dont_rewrite_rule(self, mock_log, mock_addport, mock_getrule,mock_y_n_prompt):
@patch('utils.install_log.LOG.warning')
def test_dont_rewrite_rule(self, mock_warning, mock_info, mock_addport, mock_getrule,mock_y_n_prompt):
"""
Test create_port_forward method that fails to create rule and the user input 'n' to rewrite the existing rule
"""
@ -113,9 +115,9 @@ class CreateportforwardTestCase(unittest.TestCase):
result = create_port_forward(self.hostname, self.network, self.local_port, self.guest_port, self.guest_ip)
# Assert
mock_log.assert_any_call(
mock_warning.assert_any_call(
"Trying to create a port-forwarding rule with port: %s, but it is already in use with rule name: %s", "8080", "Rule1")
mock_log.assert_any_call("Ignoring the creation of the port-forward rule and continuing installation!")
mock_info.assert_any_call("Ignoring the creation of the port-forward rule and continuing installation!")
mock_getrule.assert_called_once_with('NatNetwork', '8080')
mock_addport.assert_called_once_with('TestVM', '8080', '10.10.10.1', '80', 'NatNetwork')
@ -124,9 +126,10 @@ class CreateportforwardTestCase(unittest.TestCase):
@patch("helper.vboxmanage.vboxmanage_getrulename")
@patch("helper.vboxmanage.vboxmanage_addportforward")
@patch('utils.install_log.LOG.info')
@patch('utils.install_log.LOG.error')
@patch('utils.install_log.LOG.critical')
@patch("sys.exit")
def test_norule(self, mock_exit, mock_log, mock_addport, mock_getrule):
def test_norule(self, mock_exit, mock_critical, mock_error, mock_addport, mock_getrule):
"""
Test create_port_forward method that fails to create rule and no existing rule is found
"""
@ -144,9 +147,9 @@ class CreateportforwardTestCase(unittest.TestCase):
# Assert
self.assertEqual(cm.exception.code, 1)
mock_log.assert_any_call(
mock_critical.assert_any_call(
"Could not add a port-forwarding rule using port %s, and could not find any rule already using it. Check the Nat Network and/or local port.", "8080")
mock_log.assert_any_call("Aborting!")
mock_error.assert_any_call("Aborting!")
if __name__ == '__main__':

View File

@ -1352,7 +1352,8 @@ class VboxmanageAddportforwardTestCase(unittest.TestCase):
@patch('subprocess.check_output')
@patch('utils.install_log.LOG.info')
def test_vboxmanage_addportforward_error(self, mock_log, mock_check_output):
@patch('utils.install_log.LOG.error')
def test_vboxmanage_addportforward_error(self, mock_error, mock_info, mock_check_output):
"""
Test vboxmanage_addportforward method with error
"""
@ -1365,9 +1366,9 @@ class VboxmanageAddportforwardTestCase(unittest.TestCase):
self.network)
# Assert
mock_log.assert_any_call(
mock_info.assert_any_call(
"Creating port-forwarding rule to: %s", "rule1:tcp:[]:8080:[10.10.10.1]:80")
mock_log.assert_any_call(
mock_error.assert_any_call(
"Error while trying to create port-forwarding rule. Continuing installation!")
mock_check_output.assert_called_once_with([
@ -1429,7 +1430,8 @@ class VboxmanageDeleteportforwardTestCase(unittest.TestCase):
@patch('subprocess.check_output')
@patch('utils.install_log.LOG.info')
def test_vboxmanage_deleteportforward_error(self, mock_log, mock_check_output):
@patch('utils.install_log.LOG.error')
def test_vboxmanage_deleteportforward_error(self, mock_error, mock_info, mock_check_output):
"""
Test vboxmanage_deleteportforward method with error
"""
@ -1441,9 +1443,9 @@ class VboxmanageDeleteportforwardTestCase(unittest.TestCase):
result = vboxmanage.vboxmanage_deleteportforward(self.rule_name, self.network)
# Assert
mock_log.assert_any_call(
mock_info.assert_any_call(
"Removing previous forwarding rule '%s' from NAT network '%s'", "rule1", "NatNetwork")
mock_log.assert_any_call(
mock_error.assert_any_call(
"Error while trying to delete port-forwarding rule. Continuing installation!")
mock_check_output.assert_called_once_with([

View File

@ -865,7 +865,7 @@ def vboxmanage_addportforward(rule_name, local_port, guest_ip, guest_port, netwo
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
LOG.info("Error while trying to create port-forwarding rule. Continuing installation!")
LOG.error("Error while trying to create port-forwarding rule. Continuing installation!")
return False
return True
@ -900,4 +900,4 @@ def vboxmanage_deleteportforward(rule_name, network):
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
LOG.info("Error while trying to delete port-forwarding rule. Continuing installation!")
LOG.error("Error while trying to delete port-forwarding rule. Continuing installation!")

View File

@ -208,7 +208,7 @@ def install_controller_0(cont0_stream, menu_select_dict, network_dict):
"login:",
timeout=HostTimeout.INSTALL)
except Exception as exception: # pylint: disable=E0012, W0703
LOG.info("Connection failed for controller-0 with %s", exception)
LOG.exception("Connection failed for controller-0 with %s", exception)
# Sometimes we get UnicodeDecodeError exception due to the output
# of installation. So try one more time maybe
LOG.info("So ignore the exception and wait for controller-0 to be installed again.")
@ -246,7 +246,7 @@ def delete_lab(labname):
node_list = vboxmanage.get_all_vms(labname, option="vms")
if len(node_list) != 0:
LOG.info("This will delete lab %s with vms: %s", labname, node_list)
LOG.warning("This will delete lab %s with vms: %s", labname, node_list)
#LOG.info("Continue? (y/N)")
if yes_no_prompt("Delete lab?"):
LOG.info("#### Deleting lab %s.", labname)
@ -268,7 +268,7 @@ def get_disk_sizes(comma_list):
for size in sizes:
val = int(size)
if val < 0:
LOG.info("Disk sizes must be a comma separated list of positive integers.")
LOG.error("Disk sizes must be a comma separated list of positive integers.")
raise ValueError("Disk sizes must be a comma separated list of positive integers.")
return sizes
@ -313,13 +313,13 @@ def create_port_forward(hostname, network, local_port, guest_port, guest_ip):
):
rule_name = vboxmanage.vboxmanage_getrulename(network, local_port)
if not rule_name:
LOG.info(
LOG.critical(
"Could not add a port-forwarding rule using port %s, "
"and could not find any rule already using it. "
"Check the Nat Network and/or local port.", local_port)
LOG.info("Aborting!")
LOG.error("Aborting!")
sys.exit(1)
LOG.info(
LOG.warning(
"Trying to create a port-forwarding rule with port: %s, "
"but it is already in use with rule name: %s",
local_port,
@ -706,7 +706,7 @@ def wait_for_hosts(
start_time = time.time()
while hostnames:
if (time.time() - start_time) > HostTimeout.HOST_INSTALL:
LOG.info("VMs not booted in %s, aborting: %s", timeout, hostnames)
LOG.error("VMs not booted in %s, aborting: %s", timeout, hostnames)
raise TimeoutError(f"VMs failed to go {status}!")
# Get host list
host_statuses, _, _ = run_ssh_cmd(
@ -719,7 +719,7 @@ def wait_for_hosts(
if host in host_status and status in host_status:
hostnames.remove(host)
if hostnames:
LOG.info("Hosts not %s: %s", status, hostnames)
LOG.warning("Hosts not %s: %s", status, hostnames)
LOG.info("Waiting %s sec before re-checking host status.", interval)
time.sleep(interval)
@ -815,7 +815,7 @@ def set_serial_prompt_mode(stream, mode):
if serial.expect_bytes(stream, "ogin:", fail_ok=True, timeout=4):
serial.send_bytes(stream, "exit\n", expect_prompt=False)
if serial.expect_bytes(stream, "ogin:", fail_ok=True, timeout=4):
LOG.info("Expected login prompt, connect to console" \
LOG.error("Expected login prompt, connect to console" \
"stop any running processes and log out.")
raise RuntimeError("Failure getting login prompt on serial console!")
serial.send_bytes(
@ -863,7 +863,7 @@ def serial_prompt_mode(mode):
try:
set_serial_prompt_mode(kwargs['stream'], mode)
except: # pylint: disable=bare-except
LOG.info("Serial console login as '%s' failed. Retrying once.", mode)
LOG.warning("Serial console login as '%s' failed. Retrying once.", mode)
set_serial_prompt_mode(kwargs['stream'], mode)
return func(*args, **kwargs)
@ -1199,7 +1199,7 @@ def stage_rsync_config():
"""
if not V_BOX_OPTIONS.config_files_dir and not V_BOX_OPTIONS.config_files_dir_dont_follow_links:
LOG.info("No rsync done! Please set config-files-dir "
LOG.warning("No rsync done! Please set config-files-dir "
"and/or config-files-dir-dont-follow-links")
return
@ -1268,7 +1268,7 @@ def _run_lab_setup(ssh_client):
if exitcode != 0:
msg = f"Lab setup failed, expecting exit code of 0 but got {exitcode}."
LOG.info(msg)
LOG.error(msg)
raise RuntimeError(msg)
@ -1866,7 +1866,7 @@ def get_custom_script_options(options_list):
not_allowed = ['\n', ' ', '*']
for char in not_allowed:
if char in options_list:
LOG.info("Char '%s' not allowed in options list: %s.", char, options_list)
LOG.error("Char '%s' not allowed in options list: %s.", char, options_list)
raise TypeError("Char not allowed in options_list")
# get options
@ -2579,8 +2579,8 @@ if __name__ == "__main__":
if stage not in AVAILABLE_STAGES:
invalid_stages.append(stage)
if invalid_stages:
LOG.info("Following custom stages are not supported: %s.\n\
Choose from: %s", invalid_stages, AVAILABLE_STAGES)
LOG.warning("Following custom stages are not supported: %s.\n" \
"Choose from: %s", invalid_stages, AVAILABLE_STAGES)
sys.exit(1)
else:
# List all stages between 'from-stage' to 'to-stage'
@ -2629,7 +2629,7 @@ if __name__ == "__main__":
except Exception as stg_exc:
stg_duration = time.time() - stg_start_time
kpi.set_kpi_metric(stage, stg_duration)
LOG.info("INSTALL FAILED, ABORTING!")
LOG.error("INSTALL FAILED, ABORTING!")
kpi.print_kpi_metrics()
LOG.info("Exception details: %s", repr(stg_exc))
raise

View File

@ -282,13 +282,14 @@ class InstallController0TestCase(unittest.TestCase):
)
@patch("serial.LOG.info")
@patch("serial.LOG.exception")
@patch("install_vbox.serial")
@patch("install_vbox.host_helper")
@patch("install_vbox.time")
@patch("install_vbox.menu_selector")
@patch("install_vbox.setup_networking")
def test_install_controller_0_exception(
self, mock_setup_networking, mock_menu_selector, mock_time, mock_host_helper, mock_serial, mock_log_info
self, mock_setup_networking, mock_menu_selector, mock_time, mock_host_helper, mock_serial, mock_log_exception, mock_log_info
):
"""
Test install_controller_0 when an exception occurs during login
@ -308,7 +309,8 @@ class InstallController0TestCase(unittest.TestCase):
mock_setup_networking.assert_called_once()
mock_host_helper.change_password.assert_called_once()
mock_host_helper.disable_logout.assert_called_once()
self.assertEqual(mock_log_info.call_count, 4)
self.assertEqual(mock_log_info.call_count, 3)
self.assertEqual(mock_log_exception.call_count, 1)
class DeleteLabTestCase(unittest.TestCase):
@ -339,11 +341,12 @@ class DeleteLabTestCase(unittest.TestCase):
# Assert
mock_vboxmanage.get_all_vms.assert_called_once_with(self.mock_labname, option="vms")
mock_log.info.assert_has_calls([
call("This will delete lab %s with vms: %s", self.mock_labname, self.mock_node_list),
#call("Continue? (y/N)"),
call("#### Deleting lab %s.", self.mock_labname),
call("VMs in lab: %s.", self.mock_node_list),
])
mock_log.warning.assert_called_once_with(
"This will delete lab %s with vms: %s", self.mock_labname, self.mock_node_list)
mock_vboxmanage.vboxmanage_controlvms.assert_called_once_with(self.mock_node_list, "poweroff")
mock_time.sleep.assert_called_once_with(2)
mock_vboxmanage.vboxmanage_deletevms.assert_called_once_with(self.mock_node_list)
@ -430,7 +433,7 @@ class GetDiskSizesTestCase(unittest.TestCase):
install_vbox.get_disk_sizes(invalid_input)
self.assertTrue("Disk sizes must be a comma separated list of positive integers." in str(context.exception))
mock_log.info.assert_called_once_with("Disk sizes must be a comma separated list of positive integers.")
mock_log.error.assert_called_once_with("Disk sizes must be a comma separated list of positive integers.")
class TestCreateLab(unittest.TestCase):

View File

@ -45,7 +45,7 @@ def sftp_send(source, destination, client_dict):
sftp_client = ssh_client.open_sftp()
retry = 8
except Exception: # pylint: disable=W0703
LOG.info("******* try again")
LOG.warning("******* try again")
retry += 1
LOG.info("Waiting 10s")
time.sleep(10)