Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMBARI-26134]Resolve Test case failures in Ambari Metrics host Monitoring #133

Merged
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
6 changes: 4 additions & 2 deletions .github/workflows/ambari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
java-version: 8
distribution: temurin
cache: maven
- name: Set up Python 2
run: sudo apt-get update && sudo apt-get install -y python2-dev python-is-python2
- name: Install Kerberos development libraries
run: sudo apt-get install -y libkrb5-dev
- name: Install Kerberos
run: pip3 install kerberos
- name: Build with Maven
run: mvn -B clean package
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 @@ -26,7 +26,7 @@
try:
import kerberos
except ImportError:
from resource_monitoring.core import krberr as kerberos
from krberr import krberr as kerberos
logger.warn('import kerberos exception: %s' % str(ImportError))
pass

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
Loading