本文整理汇总了Python中src.stonix_resources.CommandHelper.CommandHelper.getOutputString方法的典型用法代码示例。如果您正苦于以下问题:Python CommandHelper.getOutputString方法的具体用法?Python CommandHelper.getOutputString怎么用?Python CommandHelper.getOutputString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.stonix_resources.CommandHelper.CommandHelper
的用法示例。
在下文中一共展示了CommandHelper.getOutputString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zzzTestRuleNoCoreDumps
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutputString [as 别名]
class zzzTestRuleNoCoreDumps(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = NoCoreDumps(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.logger = self.logdispatch
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.checkUndo = True
self.ch = CommandHelper(self.logger)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
"""
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Ekkehard J. Koch
"""
success = True
if self.environ.getosfamily() == "linux":
if not self.setLinuxConditions():
success = False
elif self.environ.getostype() == "mac":
if not self.setMacConditions():
success = False
return success
def setMacConditions(self):
success = True
self.ch.executeCommand("/usr/bin/launchctl limit core")
retcode = self.ch.getReturnCode()
if retcode != 0:
self.detailedresults += "\nFailed to run launchctl command to get current value of core dumps configuration"
errmsg = self.ch.getErrorString()
self.logger.log(LogPriority.DEBUG, errmsg)
else:
output = self.ch.getOutputString()
if output:
if not re.search("1", output):
self.ch.executeCommand("/usr/bin/launchctl limit core 1 1")
def setLinuxConditions(self):
success = True
path1 = "/etc/security/limits.conf"
if os.path.exists(path1):
lookfor1 = "(^\*)\s+hard\s+core\s+0?"
contents = readFile(path1, self.logger)
if contents:
tempstring = ""
for line in contents:
if not re.search(lookfor1, line.strip()):
tempstring += line
if not writeFile(path1, tempstring, self.logger):
debug = "unable to write incorrect contents to " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
if checkPerms(path1, [0, 0, 0o644], self.logger):
if not setPerms(path1, [0, 0, 0o777], self.logger):
debug = "Unable to set incorrect permissions on " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
debug = "successfully set incorrect permissions on " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
self.ch.executeCommand("/sbin/sysctl fs.suid_dumpable")
retcode = self.ch.getReturnCode()
if retcode != 0:
self.detailedresults += "Failed to get value of core dumps configuration with sysctl command\n"
errmsg = self.ch.getErrorString()
self.logger.log(LogPriority.DEBUG, errmsg)
success = False
else:
output = self.ch.getOutputString()
if output.strip() != "fs.suid_dumpable = 1":
if not self.ch.executeCommand("/sbin/sysctl -w fs.suid_dumpable=1"):
debug = "Unable to set incorrect value for fs.suid_dumpable"
self.logger.log(LogPriority.DEBUG, debug)
success = False
elif not self.ch.executeCommand("/sbin/sysctl -p"):
debug = "Unable to set incorrect value for fs.suid_dumpable"
self.logger.log(LogPriority.DEBUG, debug)
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
"""
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
#.........这里部分代码省略.........
示例2: zzzTestRuleDisableOpenSafeSafari
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutputString [as 别名]
class zzzTestRuleDisableOpenSafeSafari(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableOpenSafeSafari(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.dc = "/usr/bin/defaults"
self.path = "com.apple.Safari"
self.key = "AutoOpenSafeDownloads"
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
This makes sure the intial report fails by executing the following
commands:
defaults write com.apple.Safari AutoOpenSafeDownloads -bool yes
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: dwalker
'''
success = False
cmd = [self.dc, "write", self.path, self.key, "-bool", "yes"]
self.logdispatch.log(LogPriority.DEBUG, str(cmd))
if self.ch.executeCommand(cmd):
success = self.checkReportForRule(False, True)
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
To see what happended run these commands:
defaults read com.apple.Safari AutoOpenSafeDownloads
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
cmd = [self.dc, "read", self.path, self.key]
self.logdispatch.log(LogPriority.DEBUG, str(cmd))
if self.ch.executeCommand(cmd):
output = self.ch.getOutputString()
return success
def checkFixForRule(self, pRuleSuccess):
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = self.checkReportForRule(True, pRuleSuccess)
return success
def checkUndoForRule(self, pRuleSuccess):
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = self.checkReportForRule(False, pRuleSuccess)
return success
示例3: zzzTestRuleConfigureLinuxFirewall
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutputString [as 别名]
class zzzTestRuleConfigureLinuxFirewall(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = ConfigureLinuxFirewall(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.logger = self.logdispatch
self.ch = CommandHelper(self.logger)
self.servicehelper = ServiceHelper(self.environ, self.logger)
self.checkUndo = True
self.isfirewalld = False
self.isufw = False
if os.path.exists('/bin/firewall-cmd'):
self.isfirewalld = True
if os.path.exists('/usr/sbin/ufw'):
self.isufw = True
# mostly pertains to RHEL6, Centos6
self.iptables = "/usr/sbin/iptables"
if not os.path.exists(self.iptables):
self.iptables = '/sbin/iptables'
self.ip6tables = "/usr/sbin/ip6tables"
if not os.path.exists(self.ip6tables):
self.ip6tables = '/sbin/ip6tables'
if os.path.exists("/usr/sbin/iptables-restore"):
self.iprestore = "/usr/sbin/iptables-restore"
elif os.path.exists("/sbin/iptables-restore"):
self.iprestore = "/sbin/iptables-restore"
if os.path.exists("/usr/sbin/ip6tables-restore"):
self.ip6restore = "/usr/sbin/ip6tables-restore"
elif os.path.exists("/sbin/ip6tables-restore"):
self.ip6restore = "/sbin/ip6tables-restore"
self.scriptType = ""
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
self.detailedresults = ""
self.iptScriptPath = ""
scriptExists = ""
debug = ""
if self.isfirewalld:
if self.servicehelper.auditService('firewalld.service'):
if not self.servicehelper.disableService('firewalld.service'):
success = False
if self.isufw:
cmdufw = '/usr/sbin/ufw status'
if not self.ch.executeCommand(cmdufw):
debug = "Unable to run ufw status command in unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
outputufw = self.ch.getOutputString()
if re.search('Status: active', outputufw):
ufwcmd = '/usr/sbin/ufw --force disable'
if not self.ch.executeCommand(ufwcmd):
debug = "Unable to disable firewall for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
cmdufw = "/usr/sbin/ufw status verbose"
if not self.ch.executeCommand(cmdufw):
debug = "Unable to get verbose status for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
outputfw = self.cmdhelper.getOutputString()
if re.search("Default\:\ deny\ \(incoming\)", outputfw):
ufwcmd = "/usr/sbin/ufw default allow incoming"
if not self.ch.executeCommand(ufwcmd):
debug = "Unable to set allow status for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
elif os.path.exists('/usr/bin/system-config-firewall') or \
os.path.exists('/usr/bin/system-config-firewall-tui'):
print "system-config-firewall commands exist\n"
fwpath = '/etc/sysconfig/system-config-firewall'
iptpath = '/etc/sysconfig/iptables'
ip6tpath = '/etc/sysconfig/ip6tables'
if os.path.exists(fwpath):
os.remove(fwpath)
if os.path.exists(iptpath):
os.remove(iptpath)
if os.path.exists(ip6tpath):
#.........这里部分代码省略.........