summaryrefslogtreecommitdiffstats
path: root/libs/utils/serverutils.py
blob: 068dd1733e6c2ca9f860dc02bc76b996520a1585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""serverutils module
"""
import re
import hostutils
from atfglobals import GlobalObj

def execute_on_brick(brickkey, command, commandInput=None):
    """
    """
    output = {}
    output["exitstatus"] = None
    output["stdoutdata"] = None
    output["stderrdata"] = None
    
    logger = GlobalObj.getLoggerObj()
    env = GlobalObj.getTestenvObj()

    raw_brick_obj = env.getRawBrick(brickkey)
    if not raw_brick_obj:
        logger.error("InValid Brick. %s not defined in TestEnvironment"
                     % brickkey)
        return output
    serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
    
    brick_obj = env.getBrick(brickkey)
    if not brick_obj:
        logger.error("InValid Brick. %s not defined in TestEnvironment"
                     % brickkey)
        return output
    exportdirpath = brick_obj.path

    command = "cd " + exportdirpath + ";" + command
    output = hostutils.execute_command(serverkey, command, commandInput)
    return output

__all__ = ['execute_on_brick']