本文整理汇总了Python中ambari_agent.HostInfo.HostInfo类的典型用法代码示例。如果您正苦于以下问题:Python HostInfo类的具体用法?Python HostInfo怎么用?Python HostInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hostinfo_register_suse
def test_hostinfo_register_suse(self, hvlc_mock, hvrc_mock, eac_mock, cf_mock, jp_mock,
cls_mock, cu_mock, gir_mock, gipbr_mock, gipbn_mock,
gpd_mock, aip_mock, aap_mock, whcf_mock, odas_mock,
os_umask_mock, get_os_type_mock):
hvlc_mock.return_value = 1
hvrc_mock.return_value = 1
gipbr_mock.return_value = ["pkg1"]
gipbn_mock.return_value = ["pkg2"]
gpd_mock.return_value = ["pkg1", "pkg2"]
odas_mock.return_value = [{'name':'name1'}]
get_os_type_mock.return_value = "suse"
hostInfo = HostInfo()
dict = {}
hostInfo.register(dict, False, False)
self.assertFalse(gir_mock.called)
self.assertFalse(gpd_mock.called)
self.assertFalse(aip_mock.called)
self.assertFalse(aap_mock.called)
self.assertTrue(odas_mock.called)
self.assertTrue(os_umask_mock.called)
self.assertFalse(whcf_mock.called)
self.assertTrue(0 == len(dict['installedPackages']))
self.assertTrue('agentTimeStampAtReporting' in dict['hostHealth'])
示例2: execute_last_agent_env_check
def execute_last_agent_env_check(self):
print "Last Agent Env check started."
hostInfo = HostInfo()
last_agent_env_check_structured_output = { }
hostInfo.register(last_agent_env_check_structured_output)
print "Last Agent Env check completed successfully."
return last_agent_env_check_structured_output
示例3: build
def build(self, id='-1', state_interval=-1, componentsMapped=False):
global clusterId, clusterDefinitionRevision, firstContact
timestamp = int(time.time()*1000)
queueResult = self.actionQueue.result()
nodeStatus = { "status" : "HEALTHY",
"cause" : "NONE" }
heartbeat = { 'responseId' : int(id),
'timestamp' : timestamp,
'hostname' : hostname(self.config),
'nodeStatus' : nodeStatus
}
rec_status = self.actionQueue.controller.recovery_manager.get_recovery_status()
heartbeat['recoveryReport'] = rec_status
commandsInProgress = False
if not self.actionQueue.commandQueue.empty():
commandsInProgress = True
if len(queueResult) != 0:
heartbeat['reports'] = queueResult['reports']
heartbeat['componentStatus'] = queueResult['componentStatus']
if len(heartbeat['reports']) > 0:
# There may be IN_PROGRESS tasks
commandsInProgress = True
pass
# For first request/heartbeat assume no components are mapped
if int(id) == 0:
componentsMapped = False
logger.info("Building Heartbeat: {responseId = %s, timestamp = %s, commandsInProgress = %s, componentsMapped = %s}",
str(id), str(timestamp), repr(commandsInProgress), repr(componentsMapped))
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Heartbeat: %s", pformat(heartbeat))
hostInfo = HostInfo(self.config)
if (int(id) >= 0) and state_interval > 0 and (int(id) % state_interval) == 0:
nodeInfo = { }
# for now, just do the same work as registration
# this must be the last step before returning heartbeat
hostInfo.register(nodeInfo, componentsMapped, commandsInProgress)
heartbeat['agentEnv'] = nodeInfo
mounts = Hardware.osdisks(self.config)
heartbeat['mounts'] = mounts
if logger.isEnabledFor(logging.DEBUG):
logger.debug("agentEnv: %s", str(nodeInfo))
logger.debug("mounts: %s", str(mounts))
if self.collector is not None:
heartbeat['alerts'] = self.collector.alerts()
return heartbeat
示例4: test_hostinfo_register
def test_hostinfo_register(
self,
get_transparentHuge_page_mock,
cit_mock,
hvlc_mock,
hvrc_mock,
eac_mock,
cf_mock,
jp_mock,
cls_mock,
cu_mock,
gir_mock,
gipbr_mock,
gipbn_mock,
gpd_mock,
aip_mock,
aap_mock,
whcf_mock,
os_umask_mock,
get_os_type_mock,
):
cit_mock.return_value = True
hvlc_mock.return_value = 1
hvrc_mock.return_value = 1
gipbr_mock.return_value = ["pkg1"]
gipbn_mock.return_value = ["pkg2"]
gpd_mock.return_value = ["pkg1", "pkg2"]
get_os_type_mock.return_value = "redhat"
hostInfo = HostInfo()
dict = {}
hostInfo.register(dict, True, True)
self.verifyReturnedValues(dict)
hostInfo.register(dict, True, False)
self.verifyReturnedValues(dict)
hostInfo.register(dict, False, True)
self.verifyReturnedValues(dict)
self.assertTrue(os_umask_mock.call_count == 2)
cit_mock.reset_mock()
hostInfo = HostInfo()
dict = {}
hostInfo.register(dict, False, False)
self.assertTrue(gir_mock.called)
self.assertTrue(gpd_mock.called)
self.assertTrue(aip_mock.called)
self.assertTrue(cit_mock.called)
self.assertEqual(1, cit_mock.call_count)
for existingPkg in ["pkg1", "pkg2"]:
self.assertTrue(existingPkg in dict["installedPackages"])
args, kwargs = gpd_mock.call_args_list[0]
for existingPkg in ["pkg1", "pkg2"]:
self.assertTrue(existingPkg in args[1])
示例5: test_checkFolders
def test_checkFolders(self, path_mock):
path_mock.return_value = True
hostInfo = HostInfo()
results = []
existingUsers = [{"name": "a1", "homeDir": "/home/a1"}, {"name": "b1", "homeDir": "/home/b1"}]
hostInfo.checkFolders(["/etc/conf", "/var/lib", "/home/"], ["a1", "b1"], existingUsers, results)
self.assertEqual(4, len(results))
names = [i["name"] for i in results]
for item in ["/etc/conf/a1", "/var/lib/a1", "/etc/conf/b1", "/var/lib/b1"]:
self.assertTrue(item in names)
示例6: test_checkFolders
def test_checkFolders(self, path_mock):
path_mock.return_value = True
hostInfo = HostInfo()
results = []
existingUsers = [{'name':'a1', 'homeDir':'/home/a1'}, {'name':'b1', 'homeDir':'/home/b1'}]
hostInfo.checkFolders(["/etc/conf", "/var/lib", "/home/"], ["a1", "b1"], existingUsers, results)
self.assertEqual(4, len(results))
names = [i['name'] for i in results]
for item in ['/etc/conf/a1', '/var/lib/a1', '/etc/conf/b1', '/var/lib/b1']:
self.assertTrue(item in names)
示例7: test_hadoopVarRunCount
def test_hadoopVarRunCount(self, glob_glob_mock, os_path_exists_mock):
hostInfo = HostInfo()
os_path_exists_mock.return_value = True
glob_glob_mock.return_value = ['pid1','pid2','pid3']
result = hostInfo.hadoopVarRunCount()
self.assertEquals(result, 3)
os_path_exists_mock.return_value = False
result = hostInfo.hadoopVarRunCount()
self.assertEquals(result, 0)
示例8: test_hadoopVarLogCount
def test_hadoopVarLogCount(self, glob_glob_mock, os_path_exists_mock):
hostInfo = HostInfo()
os_path_exists_mock.return_value = True
glob_glob_mock.return_value = ['log1','log2']
result = hostInfo.hadoopVarLogCount()
self.assertEquals(result, 2)
os_path_exists_mock.return_value = False
result = hostInfo.hadoopVarLogCount()
self.assertEquals(result, 0)
示例9: test_getReposToRemove
def test_getReposToRemove(self):
l1 = ["Hortonworks Data Platform Utils Version - HDP-UTILS-1.1.0.15", "Ambari 1.x", "HDP"]
l2 = ["Ambari", "HDP-UTIL"]
hostInfo = HostInfo()
l3 = hostInfo.getReposToRemove(l1, l2)
self.assertTrue(1, len(l3))
self.assertEqual(l3[0], "HDP")
l1 = ["AMBARI.dev-1.x", "HDP-1.3.0"]
l3 = hostInfo.getReposToRemove(l1, l2)
self.assertTrue(1, len(l3))
self.assertEqual(l3[0], "HDP-1.3.0")
示例10: test_checkFolders
def test_checkFolders(self, path_mock):
path_mock.return_value = True
hostInfo = HostInfo()
results = []
existingUsers = [{'name':'a1', 'homeDir':os.path.join('home', 'a1')}, {'name':'b1', 'homeDir':os.path.join('home', 'b1')}]
hostInfo.checkFolders([os.path.join("etc", "conf"), os.path.join("var", "lib"), "home"], ["a1", "b1"], ["c","d"], existingUsers, results)
print results
self.assertEqual(6, len(results))
names = [i['name'] for i in results]
for item in [os.path.join('etc','conf','a1'), os.path.join('var','lib','a1'), os.path.join('etc','conf','b1'), os.path.join('var','lib','b1')]:
self.assertTrue(item in names)
示例11: test_createAlerts
def test_createAlerts(self, osdiskAvailableSpace_mock):
hostInfo = HostInfo()
osdiskAvailableSpace_mock.return_value = {
"size": "100",
"used": "50",
"available": "50",
"percent": "50%",
"mountpoint": "/testmount",
"type": "ext4",
"device": "device",
}
result = hostInfo.createAlerts([])
self.assertEquals(1, len(result))
示例12: test_osdiskAvailableSpace
def test_osdiskAvailableSpace(self, extract_mount_info_mock, subproc_popen_mock):
hostInfo = HostInfo()
p = MagicMock()
p.communicate.return_value = ['some']
subproc_popen_mock.return_value = p
extract_mount_info_mock.return_value = {'info' : 'info'}
result = hostInfo.osdiskAvailableSpace('')
self.assertTrue(result['info'], 'info')
p.communicate.return_value = ''
result = hostInfo.osdiskAvailableSpace('')
self.assertEquals(result, {})
示例13: test_osdiskAvailableSpace
def test_osdiskAvailableSpace(self, extract_mount_info_mock, subproc_popen_mock):
hostInfo = HostInfo()
p = MagicMock()
p.communicate.return_value = ["some"]
subproc_popen_mock.return_value = p
extract_mount_info_mock.return_value = {"info": "info"}
result = hostInfo.osdiskAvailableSpace("")
self.assertTrue(result["info"], "info")
p.communicate.return_value = ""
result = hostInfo.osdiskAvailableSpace("")
self.assertEquals(result, {})
示例14: test_javaProcs
def test_javaProcs(self, pwd_getpwuid_mock, buitin_open_mock, os_listdir_mock):
hostInfo = HostInfo()
openRead = MagicMock()
openRead.read.return_value = "/java/;/hadoop/"
buitin_open_mock.side_effect = [openRead, ["Uid: 22"]]
pwuid = MagicMock()
pwd_getpwuid_mock.return_value = pwuid
pwuid.pw_name = "user"
os_listdir_mock.return_value = ["1"]
list = []
hostInfo.javaProcs(list)
self.assertEquals(list[0]["command"], "/java/;/hadoop/")
self.assertEquals(list[0]["pid"], 1)
self.assertTrue(list[0]["hadoop"])
self.assertEquals(list[0]["user"], "user")
示例15: test_etcAlternativesConf
def test_etcAlternativesConf(self, os_path_realpath_mock, os_path_islink_mock, os_listdir_mock, os_path_exists_mock):
hostInfo = HostInfo()
os_path_exists_mock.return_value = False
result = hostInfo.etcAlternativesConf('',[])
self.assertEquals(result, [])
os_path_exists_mock.return_value = True
os_listdir_mock.return_value = ['config1']
os_path_islink_mock.return_value = True
os_path_realpath_mock.return_value = 'real_path_to_conf'
result = []
hostInfo.etcAlternativesConf('project',result)
self.assertEquals(result[0]['name'], 'config1')
self.assertEquals(result[0]['target'], 'real_path_to_conf')