You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ha...@apache.org on 2017/11/22 13:56:26 UTC
[2/2] ambari git commit: AMBARI-22497 Disk usage is not updated
(dgrinenko)
AMBARI-22497 Disk usage is not updated (dgrinenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9572882f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9572882f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9572882f
Branch: refs/heads/trunk
Commit: 9572882fdd345ac35a2b509d7e616579734d4fde
Parents: b902c13
Author: Dmytro Grinenko <ha...@apache.org>
Authored: Wed Nov 22 15:55:56 2017 +0200
Committer: Dmytro Grinenko <ha...@apache.org>
Committed: Wed Nov 22 15:55:56 2017 +0200
----------------------------------------------------------------------
.../src/main/python/ambari_agent/Hardware.py | 130 +++++++++++--------
.../src/main/python/ambari_agent/Heartbeat.py | 8 +-
.../src/main/python/ambari_agent/HostInfo.py | 83 ++++++------
.../test/python/ambari_agent/TestHardware.py | 56 ++++++--
.../python/ambari_agent/TestRegistration.py | 5 +-
5 files changed, 165 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9572882f/ambari-agent/src/main/python/ambari_agent/Hardware.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Hardware.py b/ambari-agent/src/main/python/ambari_agent/Hardware.py
index 696438e..56ce872 100644
--- a/ambari-agent/src/main/python/ambari_agent/Hardware.py
+++ b/ambari-agent/src/main/python/ambari_agent/Hardware.py
@@ -44,55 +44,72 @@ class Hardware:
IGNORE_DEVICES = ["proc", "tmpfs", "cgroup", "mqueue", "shm"]
LINUX_PATH_SEP = "/"
- def __init__(self, config):
+ def __init__(self, config=None, cache_info=True):
+ """
+ Initialize hardware object with available metrics. Metrics cache could be
+ disabled by setting cache_info to False
+
+ :param config Ambari Agent Configuration
+ :param cache_info initialize hardware dictionary with available metrics
+
+ :type config AmbariConfig
+ :type cache_info bool
+ """
+ self.config = config
+ self._hardware = None
+
+ if cache_info:
+ self._cache_hardware_info()
+
+ def _cache_hardware_info(self):
+ """
+ Creating cache with hardware information
+ """
logger.info("Initializing host system information.")
- self.hardware = {
- 'mounts': Hardware.osdisks()
+ self._hardware = {
+ 'mounts': self.osdisks()
}
- self.config = config
- self.hardware.update(Facter(self.config).facterInfo())
- logger.info("Host system information: %s", self.hardware)
+ self._hardware.update(Facter(self.config).facterInfo())
+ logger.info("Host system information: %s", self._hardware)
- @classmethod
- def _parse_df_line(cls, line):
+ def _parse_df(self, lines):
"""
- Initialize data-structure from string in specific 'df' command output format
+ Generator, which parses df command output and yields parsed entities
Expected string format:
device fs_type disk_size used_size available_size capacity_used_percents mount_point
- :type line str
+ :type lines list[str]
+ :rtype collections.Iterable
"""
+ titles = ["device", "type", "size", "used", "available", "percent", "mountpoint"]
- line_split = line.split()
- if len(line_split) != 7:
- return None
+ for line in lines:
+ line_split = line.split()
+ if len(line_split) != 7:
+ continue
- titles = ["device", "type", "size", "used", "available", "percent", "mountpoint"]
- return dict(zip(titles, line_split))
+ yield dict(zip(titles, line_split))
- @classmethod
- def _get_mount_check_timeout(cls, config=None):
+ def _get_mount_check_timeout(self):
"""Return timeout for df call command"""
- if config and config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY) \
- and config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY) != "0":
+ if self.config and self.config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY) \
+ and self.config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY) != "0":
- return config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY)
+ return self.config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY)
return Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_DEFAULT
- @classmethod
- def _check_remote_mounts(cls, config=None):
+ def _check_remote_mounts(self):
"""Verify if remote mount allowed to be processed or not"""
- if config and config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY) and \
- config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY).lower() == "false":
+ if self.config and self.config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY) and \
+ self.config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY).lower() == "false":
return False
return True
- @classmethod
- def _is_mount_blacklisted(cls, blacklist, mount_point):
+ def _is_mount_blacklisted(self, blacklist, mount_point):
"""
Verify if particular mount point is in the black list.
@@ -111,49 +128,44 @@ class Hardware:
if not blacklist or not mount_point:
return False
- mount_point_elements = mount_point.split(cls.LINUX_PATH_SEP)
+ # in this way we excluding possibility
+ mount_point_elements = mount_point.split(self.LINUX_PATH_SEP)
for el in blacklist:
- el_list = el.split(cls.LINUX_PATH_SEP)
+ el_list = el.split(self.LINUX_PATH_SEP)
# making patch elements comparision
if el_list == mount_point_elements[:len(el_list)]:
return True
return False
-
- @classmethod
@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
- def osdisks(cls, config=None):
+ def osdisks(self):
""" Run df to find out the disks on the host. Only works on linux
platforms. Note that this parser ignores any filesystems with spaces
and any mounts with spaces. """
- timeout = cls._get_mount_check_timeout(config)
+ timeout = self._get_mount_check_timeout()
command = ["timeout", timeout, "df", "-kPT"]
blacklisted_mount_points = []
- if config:
- ignore_mount_value = config.get("agent", "ignore_mount_points", default="")
- blacklisted_mount_points = [item.strip() for item in ignore_mount_value.split(",")]
+ if self.config:
+ ignore_mount_value = self.config.get("agent", "ignore_mount_points", default="")
+ blacklisted_mount_points = [item.strip() for item in ignore_mount_value.split(",") if len(item.strip()) != 0]
- if not cls._check_remote_mounts(config):
+ if not self._check_remote_mounts():
command.append("-l")
try:
- code, out, err = shell.call(command, stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = int(timeout), quiet = True)
+ code, out, err = shell.call(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=int(timeout), quiet=True)
dfdata = out
except Exception as ex:
logger.warn("Checking disk usage failed: " + str(ex))
dfdata = ''
- mounts = [cls._parse_df_line(line) for line in dfdata.splitlines() if line]
result_mounts = []
ignored_mounts = []
- for mount in mounts:
- if not mount:
- continue
-
+ for mount in self._parse_df(dfdata.splitlines()):
"""
We need to filter mounts by several parameters:
- mounted device is not in the ignored list
@@ -161,11 +173,11 @@ class Hardware:
- it is not file-mount (docker environment)
- mount path or a part of mount path is not in the blacklist
"""
- if mount["device"] not in cls.IGNORE_DEVICES and\
- mount["mountpoint"].split("/")[0] not in cls.IGNORE_ROOT_MOUNTS and\
- cls._chk_writable_mount(mount['mountpoint']) and\
+ if mount["device"] not in self.IGNORE_DEVICES and\
+ mount["mountpoint"].split("/")[0] not in self.IGNORE_ROOT_MOUNTS and\
+ self._chk_writable_mount(mount['mountpoint']) and\
not path_isfile(mount["mountpoint"]) and\
- not cls._is_mount_blacklisted(blacklisted_mount_points, mount["mountpoint"]):
+ not self._is_mount_blacklisted(blacklisted_mount_points, mount["mountpoint"]):
result_mounts.append(mount)
else:
@@ -177,8 +189,7 @@ class Hardware:
return result_mounts
- @classmethod
- def _chk_writable_mount(cls, mount_point):
+ def _chk_writable_mount(self, mount_point):
if os.geteuid() == 0:
return os.access(mount_point, os.W_OK)
else:
@@ -196,9 +207,8 @@ class Hardware:
logger.exception("Exception happened while checking mount {0}".format(mount_point))
return False
- @classmethod
@OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
- def osdisks(cls, config=None):
+ def osdisks(self):
mounts = []
runner = shellRunner()
command_result = runner.runPowershell(script_block=Hardware.WINDOWS_GET_DRIVES_CMD)
@@ -216,16 +226,28 @@ class Hardware:
return mounts
- def get(self):
- return self.hardware
+ def get(self, invalidate_cache=False):
+ """
+ Getting cached hardware information
+
+ :param invalidate_cache resets hardware metrics cache
+ :type invalidate_cache bool
+ """
+ if invalidate_cache:
+ self._hardware = None
+
+ if not self._hardware:
+ self._cache_hardware_info()
+
+ return self._hardware
def main():
from resource_management.core.logger import Logger
Logger.initialize_logger()
- config = None
- print Hardware(config).get()
+ print Hardware().get()
+
if __name__ == '__main__':
main()
http://git-wip-us.apache.org/repos/asf/ambari/blob/9572882f/ambari-agent/src/main/python/ambari_agent/Heartbeat.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Heartbeat.py b/ambari-agent/src/main/python/ambari_agent/Heartbeat.py
index 1e05aae..d7c0325 100644
--- a/ambari-agent/src/main/python/ambari_agent/Heartbeat.py
+++ b/ambari-agent/src/main/python/ambari_agent/Heartbeat.py
@@ -75,14 +75,11 @@ class Heartbeat:
if int(id) == 0:
componentsMapped = False
-
-
logger.debug("Building Heartbeat: {responseId = %s, timestamp = %s, "
"commandsInProgress = %s, componentsMapped = %s,"
"recoveryTimestamp = %s}",
str(id), str(timestamp), repr(commandsInProgress), repr(componentsMapped), str(recovery_timestamp))
-
logger.debug("Heartbeat: %s", pformat(heartbeat))
hostInfo = HostInfo(self.config)
@@ -93,10 +90,9 @@ class Heartbeat:
# this must be the last step before returning heartbeat
hostInfo.register(nodeInfo, componentsMapped, commandsInProgress)
heartbeat['agentEnv'] = nodeInfo
- mounts = Hardware.osdisks(self.config)
+ mounts = Hardware(config=self.config, cache_info=False).osdisks()
heartbeat['mounts'] = mounts
-
logger.debug("agentEnv: %s", str(nodeInfo))
logger.debug("mounts: %s", str(mounts))
@@ -105,6 +101,7 @@ class Heartbeat:
return heartbeat
+
def main(argv=None):
from ambari_agent.ActionQueue import ActionQueue
from ambari_agent.AmbariConfig import AmbariConfig
@@ -122,5 +119,6 @@ def main(argv=None):
heartbeat = Heartbeat(actionQueue)
print json.dumps(heartbeat.build('3',3))
+
if __name__ == '__main__':
main()
http://git-wip-us.apache.org/repos/asf/ambari/blob/9572882f/ambari-agent/src/main/python/ambari_agent/HostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostInfo.py b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
index b8545cc..4a752fc 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -57,6 +57,9 @@ class HostInfo(object):
self.config = config
self.reportFileHandler = HostCheckReportFileHandler(config)
+ def register(self, dict_obj, componentsMapped=True, commandsInProgress=True):
+ raise NotImplementedError()
+
def dirType(self, path):
if not os.path.exists(path):
return 'not_exist'
@@ -245,21 +248,20 @@ class HostInfoLinux(HostInfo):
cmd = cmd.replace('\0', ' ')
if not 'AmbariServer' in cmd:
if 'java' in cmd:
- dict = {}
- dict['pid'] = int(pid)
- dict['hadoop'] = False
+ metrics = {}
+ metrics['pid'] = int(pid)
+ metrics['hadoop'] = False
for filter in self.PROC_FILTER:
if filter in cmd:
- dict['hadoop'] = True
- dict['command'] = unicode(cmd.strip(), errors='ignore')
+ metrics['hadoop'] = True
+ metrics['command'] = unicode(cmd.strip(), errors='ignore')
for line in open(os.path.join('/proc', pid, 'status')):
if line.startswith('Uid:'):
uid = int(line.split()[1])
- dict['user'] = pwd.getpwuid(uid).pw_name
- list.append(dict)
+ metrics['user'] = pwd.getpwuid(uid).pw_name
+ list.append(metrics)
except:
logger.exception("Checking java processes failed")
- pass
def getTransparentHugePage(self):
thp_regex = "\[(.+)\]"
@@ -312,54 +314,54 @@ class HostInfoLinux(HostInfo):
logger.exception('Unable to get information about JCE')
return None
- def register(self, dict, componentsMapped=True, commandsInProgress=True):
+ def register(self, metrics, componentsMapped=True, commandsInProgress=True):
""" Return various details about the host
componentsMapped: indicates if any components are mapped to this host
commandsInProgress: indicates if any commands are in progress
"""
- dict['hostHealth'] = {}
+ metrics['hostHealth'] = {}
java = []
self.javaProcs(java)
- dict['hostHealth']['activeJavaProcs'] = java
+ metrics['hostHealth']['activeJavaProcs'] = java
liveSvcs = []
self.checkLiveServices(self.DEFAULT_LIVE_SERVICES, liveSvcs)
- dict['hostHealth']['liveServices'] = liveSvcs
+ metrics['hostHealth']['liveServices'] = liveSvcs
- dict['umask'] = str(self.getUMask())
+ metrics['umask'] = str(self.getUMask())
- dict['transparentHugePage'] = self.getTransparentHugePage()
- dict['firewallRunning'] = self.checkFirewall()
- dict['firewallName'] = self.getFirewallName()
- dict['reverseLookup'] = self.checkReverseLookup()
- dict['hasUnlimitedJcePolicy'] = self.checkUnlimitedJce()
+ metrics['transparentHugePage'] = self.getTransparentHugePage()
+ metrics['firewallRunning'] = self.checkFirewall()
+ metrics['firewallName'] = self.getFirewallName()
+ metrics['reverseLookup'] = self.checkReverseLookup()
+ metrics['hasUnlimitedJcePolicy'] = self.checkUnlimitedJce()
# If commands are in progress or components are already mapped to this host
# Then do not perform certain expensive host checks
if componentsMapped or commandsInProgress:
- dict['alternatives'] = []
- dict['stackFoldersAndFiles'] = []
- dict['existingUsers'] = []
+ metrics['alternatives'] = []
+ metrics['stackFoldersAndFiles'] = []
+ metrics['existingUsers'] = []
else:
etcs = []
self.etcAlternativesConf(self.DEFAULT_PROJECT_NAMES, etcs)
- dict['alternatives'] = etcs
+ metrics['alternatives'] = etcs
existingUsers = []
self.checkUsers(self.DEFAULT_USERS, existingUsers)
- dict['existingUsers'] = existingUsers
+ metrics['existingUsers'] = existingUsers
dirs = []
self.checkFolders(self.DEFAULT_BASEDIRS, self.DEFAULT_PROJECT_NAMES, self.EXACT_DIRECTORIES, existingUsers, dirs)
- dict['stackFoldersAndFiles'] = dirs
+ metrics['stackFoldersAndFiles'] = dirs
- self.reportFileHandler.writeHostCheckFile(dict)
+ self.reportFileHandler.writeHostCheckFile(metrics)
pass
# The time stamp must be recorded at the end
- dict['hostHealth']['agentTimeStampAtReporting'] = int(time.time() * 1000)
+ metrics['hostHealth']['agentTimeStampAtReporting'] = int(time.time() * 1000)
pass
@@ -434,43 +436,42 @@ class HostInfoWindows(HostInfo):
code, out, err = run_powershell_script(self.SERVICE_STATUS_CMD.format(serivce_name))
return out, err, code
- def register(self, dict, componentsMapped=True, commandsInProgress=True):
+ def register(self, metrics, componentsMapped=True, commandsInProgress=True):
""" Return various details about the host
componentsMapped: indicates if any components are mapped to this host
commandsInProgress: indicates if any commands are in progress
"""
- dict['hostHealth'] = {}
+ metrics['hostHealth'] = {}
java = []
self.javaProcs(java)
- dict['hostHealth']['activeJavaProcs'] = java
+ metrics['hostHealth']['activeJavaProcs'] = java
liveSvcs = []
self.checkLiveServices(self.DEFAULT_LIVE_SERVICES, liveSvcs)
- dict['hostHealth']['liveServices'] = liveSvcs
+ metrics['hostHealth']['liveServices'] = liveSvcs
- dict['umask'] = str(self.getUMask())
+ metrics['umask'] = str(self.getUMask())
- dict['firewallRunning'] = self.checkFirewall()
- dict['firewallName'] = self.getFirewallName()
- dict['reverseLookup'] = self.checkReverseLookup()
+ metrics['firewallRunning'] = self.checkFirewall()
+ metrics['firewallName'] = self.getFirewallName()
+ metrics['reverseLookup'] = self.checkReverseLookup()
# If commands are in progress or components are already mapped to this host
# Then do not perform certain expensive host checks
if componentsMapped or commandsInProgress:
- dict['alternatives'] = []
- dict['stackFoldersAndFiles'] = []
- dict['existingUsers'] = []
+ metrics['alternatives'] = []
+ metrics['stackFoldersAndFiles'] = []
+ metrics['existingUsers'] = []
else:
existingUsers = []
self.checkUsers(self.DEFAULT_USERS, existingUsers)
- dict['existingUsers'] = existingUsers
+ metrics['existingUsers'] = existingUsers
# TODO check HDP stack and folders here
- self.reportFileHandler.writeHostCheckFile(dict)
+ self.reportFileHandler.writeHostCheckFile(metrics)
pass
# The time stamp must be recorded at the end
- dict['hostHealth']['agentTimeStampAtReporting'] = int(time.time() * 1000)
-
+ metrics['hostHealth']['agentTimeStampAtReporting'] = int(time.time() * 1000)
def main(argv=None):
http://git-wip-us.apache.org/repos/asf/ambari/blob/9572882f/ambari-agent/src/test/python/ambari_agent/TestHardware.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHardware.py b/ambari-agent/src/test/python/ambari_agent/TestHardware.py
index 5400e26..e78f8f2 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHardware.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHardware.py
@@ -26,14 +26,12 @@ import unittest
import platform
import socket
import subprocess
-import os
from only_for_platform import not_for_platform, PLATFORM_WINDOWS
from ambari_agent import hostname
from ambari_agent.Hardware import Hardware
from ambari_agent.AmbariConfig import AmbariConfig
from ambari_agent.Facter import Facter, FacterLinux
from ambari_commons import OSCheck
-from resource_management.core import shell
@not_for_platform(PLATFORM_WINDOWS)
@@ -61,10 +59,10 @@ class TestHardware(TestCase):
def test_build(self, get_os_version_mock, get_os_type_mock):
get_os_type_mock.return_value = "suse"
get_os_version_mock.return_value = "11"
- config = None
- hardware = Hardware(config)
+ hardware = Hardware()
result = hardware.get()
osdisks = hardware.osdisks()
+
for dev_item in result['mounts']:
self.assertTrue(dev_item['available'] >= 0)
self.assertTrue(dev_item['used'] >= 0)
@@ -113,7 +111,33 @@ class TestHardware(TestCase):
chk_writable_mount_mock.side_effect = chk_writable_mount_side_effect
shell_call_mock.return_value = (0, df_output, '')
- result = Hardware.osdisks()
+ result = Hardware(cache_info=False).osdisks()
+
+ self.assertEquals(1, len(result))
+
+ expected_mounts_left = ["/"]
+ mounts_left = [item["mountpoint"] for item in result]
+
+ self.assertEquals(expected_mounts_left, mounts_left)
+
+ @patch.object(Hardware, "_chk_writable_mount")
+ @patch("ambari_agent.Hardware.path_isfile")
+ @patch("resource_management.core.shell.call")
+ def test_osdisks_no_ignore_property(self, shell_call_mock, isfile_mock, chk_writable_mount_mock):
+ df_output = \
+ """Filesystem Type 1024-blocks Used Available Capacity Mounted on
+ /dev/mapper/docker-253:0-4980899-d45c264d37ab18c8ed14f890f4d59ac2b81e1c52919eb36a79419787209515f3 xfs 31447040 1282384 30164656 5% /
+ """
+
+ isfile_mock.return_value = False
+ chk_writable_mount_mock.return_value = True
+ shell_call_mock.return_value = (0, df_output, '')
+ config = AmbariConfig()
+
+ # check, that config do not define ignore_mount_points property
+ self.assertEquals("test", config.get('agent', 'ignore_mount_points', default="test"))
+
+ result = Hardware(config=config, cache_info=False).osdisks()
self.assertEquals(1, len(result))
@@ -128,35 +152,35 @@ class TestHardware(TestCase):
def test_osdisks_remote(self, shell_call_mock, get_os_version_mock, get_os_type_mock):
get_os_type_mock.return_value = "suse"
get_os_version_mock.return_value = "11"
- Hardware.osdisks()
+ Hardware(cache_info=False).osdisks()
timeout = 10
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
config = AmbariConfig()
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
config.add_section(AmbariConfig.AMBARI_PROPERTIES_CATEGORY)
config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY, "true")
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_KEY, "false")
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT", "-l"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY, "0")
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT", "-l"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
timeout = 1
config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY, str(timeout))
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT", "-l"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
timeout = 2
config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_KEY, str(timeout))
- Hardware.osdisks(config)
+ Hardware(config=config, cache_info=False).osdisks()
shell_call_mock.assert_called_with(['timeout', str(timeout), "df", "-kPT", "-l"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = timeout, quiet = True)
def test_parse_df_line(self):
@@ -182,7 +206,11 @@ class TestHardware(TestCase):
]
for sample in samples:
- result = Hardware._parse_df_line(sample["sample"])
+ try:
+ result = Hardware(cache_info=False)._parse_df([sample["sample"]]).next()
+ except StopIteration:
+ result = None
+
self.assertEquals(result, sample["expected"], "Failed with sample: '{0}', expected: {1}, got: {2}".format(
sample["sample"],
sample["expected"],
@@ -430,7 +458,7 @@ SwapFree: 1598676 kB
}
conf.configure_mock(**attr)
- result = Hardware.osdisks(conf)
+ result = Hardware(config=conf, cache_info=False).osdisks()
self.assertEquals(1, len(result))
http://git-wip-us.apache.org/repos/asf/ambari/blob/9572882f/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
index a5c23fa..fada29c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
@@ -19,7 +19,6 @@ limitations under the License.
'''
from unittest import TestCase
-import os
import tempfile
from mock.mock import patch
from mock.mock import MagicMock
@@ -35,13 +34,14 @@ class TestRegistration(TestCase):
@patch("subprocess.Popen")
@patch.object(Hardware, "_chk_writable_mount", new = MagicMock(return_value=True))
+ @patch("__builtin__.open", new=MagicMock())
@patch.object(FacterLinux, "facterInfo", new = MagicMock(return_value={}))
@patch.object(FacterLinux, "__init__", new = MagicMock(return_value = None))
@patch("resource_management.core.shell.call")
@patch.object(OSCheck, "get_os_type")
@patch.object(OSCheck, "get_os_version")
def test_registration_build(self, get_os_version_mock, get_os_type_mock, run_os_cmd_mock, Popen_mock):
- config = AmbariConfig().getConfig()
+ config = AmbariConfig()
tmpdir = tempfile.gettempdir()
config.set('agent', 'prefix', tmpdir)
config.set('agent', 'current_ping_port', '33777')
@@ -58,7 +58,6 @@ class TestRegistration(TestCase):
self.assertEquals(data['timestamp'] > 1353678475465L, True, "timestamp should not be empty")
self.assertEquals(len(data['agentEnv']) > 0, True, "agentEnv should not be empty")
self.assertEquals(data['agentVersion'], reference_version, "agentVersion should not be empty")
- print data['agentEnv']['umask']
self.assertEquals(not data['agentEnv']['umask']== "", True, "agents umask should not be empty")
self.assertEquals(data['currentPingPort'] == 33777, True, "current ping port should be 33777")
self.assertEquals(data['prefix'], config.get('agent', 'prefix'), 'The prefix path does not match')