Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / common / cmds.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import commands
11 import logging
12
13 LOG = logging.getLogger(__name__)
14
15
16 def execute(cmd=None, care_result=True):
17     if not cmd:
18         LOG.error('The cmd is None')
19         return None
20     try:
21         (status, ret) = commands.getstatusoutput(cmd)
22         if care_result and 0 != status:
23             LOG.error(
24                 'CMD<%(cmd)s> \nSTDOUT:\n%(ret)s.', {
25                     'cmd': cmd, 'ret': ret})
26             return None
27         else:
28             return ret
29     except Exception as e:
30         raise e