mirror of
https://github.com/valitydev/yandex-tank.git
synced 2024-11-06 10:25:17 +00:00
commit
acc7d92b61
@ -84,7 +84,7 @@ http://uucode.com/blog/2015/02/20/workaround-for-ctr-mode-needs-counter-paramete
|
||||
return client
|
||||
|
||||
def execute(self, cmd):
|
||||
logger.info("Execute on %s: %s", self.host, cmd)
|
||||
logger.debug("Execute on %s: %s", self.host, cmd)
|
||||
with self.connect() as client:
|
||||
_, stdout, stderr = client.exec_command(cmd)
|
||||
output = stdout.read()
|
||||
|
1
yandextank/plugins/Platform/__init__.py
Normal file
1
yandextank/plugins/Platform/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from plugin import *
|
89
yandextank/plugins/Platform/plugin.py
Normal file
89
yandextank/plugins/Platform/plugin.py
Normal file
@ -0,0 +1,89 @@
|
||||
''' Module that collects remote system information '''
|
||||
|
||||
import logging
|
||||
import getpass
|
||||
|
||||
from ...core.interfaces import AbstractPlugin
|
||||
from ..Monitoring.collector import SecuredShell
|
||||
from ..Phantom import PhantomPlugin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Plugin(AbstractPlugin):
|
||||
'''Plugin that collects remote system information'''
|
||||
SECTION = "platform"
|
||||
|
||||
@staticmethod
|
||||
def get_key():
|
||||
return __file__
|
||||
|
||||
def __init__(self, core):
|
||||
AbstractPlugin.__init__(self, core)
|
||||
self.hosts = []
|
||||
self.port = None
|
||||
self.logfile = None
|
||||
self.default_target = None
|
||||
_echo_wrapper = lambda cmd: 'echo "====Executing: {cmd}"; {cmd}'.format(cmd=cmd)
|
||||
cmds = {
|
||||
"dpkg": "dpkg -l",
|
||||
"uname": "uname -a",
|
||||
"ulimit": "ulimit -a",
|
||||
"os_identifier": "cat /etc/issue.net",
|
||||
"uptime": "uptime",
|
||||
"cpuinfo": "cat /proc/cpuinfo",
|
||||
"meminfo": "cat /proc/meminfo",
|
||||
"free": "free -m",
|
||||
"mounts": "cat /proc/mounts",
|
||||
"df": "df -h",
|
||||
"ifconfig": "ifconfig -a",
|
||||
"sysctl": "cat /etc/sysctl.conf",
|
||||
"lsmod": "lsmod"
|
||||
}
|
||||
self.cmd = "%s" % ";\n".join([_echo_wrapper(cmd) for key, cmd in cmds.iteritems()])
|
||||
|
||||
def get_available_options(self):
|
||||
return ["hosts", "port", "username", "timeout"]
|
||||
|
||||
def configure(self):
|
||||
try:
|
||||
hosts = self.get_option("hosts", "").strip()
|
||||
if hosts:
|
||||
self.hosts = hosts.split(" ")
|
||||
self.port = int(self.get_option("port", 22))
|
||||
self.username = self.get_option("username", getpass.getuser())
|
||||
self.timeout = int(self.get_option("timeout", 3))
|
||||
except:
|
||||
logger.error('Exception trying to configure Platform plugin', exc_info=True)
|
||||
|
||||
self.logfile = self.core.mkstemp(".log", "platform_")
|
||||
self.core.add_artifact_file(self.logfile)
|
||||
|
||||
|
||||
def prepare_test(self):
|
||||
try:
|
||||
phantom = self.core.get_plugin_of_type(PhantomPlugin)
|
||||
info = phantom.get_info()
|
||||
if info:
|
||||
if info.address and info.address not in self.hosts:
|
||||
logger.debug("Adding platform check of default_target %s", info.address)
|
||||
self.hosts.append(info.address)
|
||||
except KeyError, ex:
|
||||
logger.debug("Phantom plugin not found: %s", ex)
|
||||
for host in self.hosts:
|
||||
self.ssh = SecuredShell(host, self.port, self.username, self.timeout)
|
||||
try:
|
||||
out, errors, err_code = self.ssh.execute(self.cmd)
|
||||
except Exception:
|
||||
logger.warning("Failed to check remote system information at %s:%s", host, self.port)
|
||||
logger.debug("Failed to check remote system information at %s:%s", host, self.port, exc_info=True)
|
||||
else:
|
||||
# logger.info('Remote system `%s` information: %s', host, out)
|
||||
with open(self.logfile, 'w') as f:
|
||||
f.write(out)
|
||||
if errors:
|
||||
logging.debug("[%s] error: '%s'", host, errors)
|
||||
|
||||
|
||||
def is_test_finished(self):
|
||||
return -1
|
Loading…
Reference in New Issue
Block a user