cloudstack/test/integration/smoke/test_human_readable_logs.py
Spaceman1984 b586eb22f1
Human readable sizes in logs (#4207)
This PR adds outputting human readable byte sizes in the management server logs, agent logs, and usage records. A non-dynamic global variable is added (display.human.readable.sizes) to control switching this feature on and off. This setting is sent to the agent on connection and is only read from the database when the management server is started up. The setting is kept in memory by the use of a static field on the NumbersUtil class and is available throughout the codebase.

Instead of seeing things like:
2020-07-23 15:31:58,593 DEBUG [c.c.a.t.Request] (AgentManager-Handler-12:null) (logid:) Seq 8-1863645820801253428: Processing: { Ans: , MgmtId: 52238089807, via: 8, Ver: v1, Flags: 10, [{"com.cloud.agent.api.NetworkUsageAnswer":{"routerName":"r-224-VM","bytesSent":"106496","bytesReceived":"0","result":"true","details":"","wait":"0",}}] }

The KB MB and GB values will be printed out:

2020-07-23 15:31:58,593 DEBUG [c.c.a.t.Request] (AgentManager-Handler-12:null) (logid:) Seq 8-1863645820801253428: Processing: { Ans: , MgmtId: 52238089807, via: 8, Ver: v1, Flags: 10, [{"com.cloud.agent.api.NetworkUsageAnswer":{"routerName":"r-224-VM","bytesSent":"(104.00 KB) 106496","bytesReceived":"(0 bytes) 0","result":"true","details":"","wait":"0",}}] }

FS: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Human+Readable+Byte+sizes
2020-08-13 15:55:16 +05:30

95 lines
3.6 KiB
Python

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import time
from marvin.cloudstackAPI import updateConfiguration
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.sshClient import SshClient
from nose.plugins.attrib import attr
class TestHumanReadableLogs(cloudstackTestCase):
"""
Test correct output when logging byte size values.
"""
def setUp(self):
self.apiClient = self.testClient.getApiClient()
self.mgtSvrDetails = self.config.__dict__["mgtSvr"][0].__dict__
@attr(tags=["devcloud", "basic", "advanced"], required_hardware="false")
def test_01_disableHumanReadableLogs(self):
"""
Test log file output after disabling human readable sizes feature
"""
#create ssh client
sshClient = getSSHClient(self)
# Disable feature
updateConfig(self, "false")
# Restart service
command = "systemctl restart cloudstack-management"
sshClient.execute(command)
# CapacityChecker runs as soon as management server is up
# Check if "usedMem: (" is printed out within 60 seconds while server is starting
command = "timeout 60 tail -f /var/log/cloudstack/management/management-server.log | grep 'usedMem: ('";
sshClient.timeout = 60
result = sshClient.runCommand(command)
self.assertTrue(result['status'] == "FAILED")
@attr(tags=["devcloud", "basic", "advanced"], required_hardware="false")
def test_02_enableHumanReadableLogs(self):
"""
Test log file output after enabling human readable sizes feature
"""
# create ssh client
sshClient = getSSHClient(self)
# Enable feature
updateConfig(self, "true")
# Restart service
command = "systemctl restart cloudstack-management"
sshClient.execute(command)
# CapacityChecker runs as soon as management server is up
# Check if "usedMem: (" is printed out within 60 seconds while server is restarting
command = "timeout 60 tail -f /var/log/cloudstack/management/management-server.log | grep 'usedMem: ('";
sshClient.timeout = 60
result = sshClient.runCommand(command)
self.assertTrue(result['status'] == "SUCCESS")
def updateConfig(self, enableFeature):
updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
updateConfigurationCmd.name = "display.human.readable.sizes"
updateConfigurationCmd.value = enableFeature
updateConfigurationResponse = self.apiClient.updateConfiguration(updateConfigurationCmd)
self.debug("updated the parameter %s with value %s" % (
updateConfigurationResponse.name, updateConfigurationResponse.value))
def getSSHClient(self):
sshClient = SshClient(
self.mgtSvrDetails["mgtSvrIp"],
22,
self.mgtSvrDetails["user"],
self.mgtSvrDetails["passwd"]
)
return sshClient