Skip to content

Commit

Permalink
[AMBARI-26134]Resolve Test case failures in Ambari Metrics host Monit…
Browse files Browse the repository at this point in the history
…oring
  • Loading branch information
sandeep318kumar committed Sep 20, 2024
1 parent 395d653 commit de9ea71
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import logging
import threading

from resource_monitoring.core.security import CachedHTTPSConnection, CachedHTTPConnection
from resource_monitoring.core.blacklisted_set import BlacklistedSet
from resource_monitoring.core.config_reader import ROUND_ROBIN_FAILOVER_STRATEGY
from resource_monitoring.core.spnego_kerberos_auth import SPNEGOKerberosAuth
from security import CachedHTTPSConnection, CachedHTTPConnection
from blacklisted_set import BlacklistedSet
from config_reader import ROUND_ROBIN_FAILOVER_STRATEGY
from spnego_kerberos_auth import SPNEGOKerberosAuth

logger = logging.getLogger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def get_mem_info(self):
swap_total = self.__host_static_info.get('swap_total')

bytes2kilobytes = lambda x: x / 1024
mem_total = psutil.virtual_memory().total

return {
'mem_total': bytes2kilobytes(mem_total) if mem_total else 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import logging
import time
import json
from resource_monitoring.core.instance_type_provider import HostInstanceTypeProvider
from instance_type_provider import HostInstanceTypeProvider

logger = logging.getLogger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import logging
from time import time
from resource_monitoring.core.event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
from resource_monitoring.core.metering import MeteringMetricHandler
from event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
from metering import MeteringMetricHandler

logger = logging.getLogger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import json
import logging
import time
import distro

from unittest import TestCase
from mock.mock import patch, MagicMock
Expand All @@ -30,7 +31,7 @@

os_distro_value = ('Suse','11','Final')

with patch("platform.linux_distribution", return_value = os_distro_value):
with patch("distro.linux_distribution", return_value=os_distro_value):
from application_metric_map import ApplicationMetricMap
from config_reader import Configuration
from emitter import Emitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,33 @@ def testMemInfo(self, vm_mock, sw_mock):
vm.free = 2312043
vm.shared = 1243
vm.buffers = 23435
vm.cached = 23545
vm.available = 2312043
vm.total = 8192 * 1024
vm.used = 4096 * 1024
vm.cached = 1024 * 1024

sw = sw_mock.return_value
sw.free = 2341234
sw.used = 1024 * 1024
sw.total = 2048 * 1024
sw.sin = 512 * 1024
sw.sout = 256 * 1024

hostinfo = HostInfo(MagicMock())

mem = hostinfo.get_mem_info()

self.assertAlmostEqual(mem['mem_free'], 2257)
self.assertAlmostEqual(mem['mem_shared'], 1)
self.assertAlmostEqual(mem['mem_buffered'], 22)
self.assertAlmostEqual(mem['mem_cached'], 22)
self.assertAlmostEqual(mem['swap_free'], 2286)
self.assertAlmostEqual(mem['mem_free'], 2257, delta = 1)
self.assertAlmostEqual(mem['mem_shared'], 1, delta=0.5)
self.assertAlmostEqual(mem['mem_buffered'], 22, delta = 1)
self.assertAlmostEqual(mem['mem_cached'], 1024, delta = 1)
self.assertAlmostEqual(mem['swap_free'], 2286, delta = 1)
self.assertAlmostEqual(mem['mem_total'], 8192, delta = 1)
self.assertAlmostEqual(mem['mem_used'], 3072, delta = 1)
self.assertAlmostEqual(mem['swap_used'], 1024, delta = 1)
self.assertAlmostEqual(mem['swap_total'], 2048, delta = 1)
self.assertAlmostEqual(mem['swap_in'], 512, delta = 1)
self.assertAlmostEqual(mem['swap_out'], 256, delta = 1)


@patch("psutil.process_iter")
Expand Down
2 changes: 2 additions & 0 deletions ambari-metrics-host-monitoring/src/test/python/mock/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import pprint
import sys
import distro
os_distro_value = distro.linux_distribution(full_distribution_name=False)

try:
import inspect
Expand Down

0 comments on commit de9ea71

Please sign in to comment.