summaryrefslogtreecommitdiffstats
path: root/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py')
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py56
1 files changed, 0 insertions, 56 deletions
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py
deleted file mode 100644
index 29dd2c02..00000000
--- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py
+++ /dev/null
@@ -1,56 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import subprocess
-import threading
-import logging
-from vstf.common import constants
-
-LOG = logging.getLogger(__name__)
-
-
-class CommandLine(object):
-
- def __init__(self):
- super(CommandLine, self).__init__()
- self.proc = None
- self.is_timeout = False
-
- def __kill_proc(self):
- self.is_timeout = True
- self.proc.kill()
-
- def execute(self, cmd, timeout=constants.TIMEOUT, shell=False):
- """this func call subprocess.Popen(),
- here setup a timer to deal with timeout.
- :param cmd: cmd list like ['ls', 'home']
- :param timeout: for timer count for timeout
- :return: (ret, output) the output (stdout+'\n'+stderr)
- """
- # reset the timeout flag
- self.is_timeout = False
- self.proc = subprocess.Popen(cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- shell=shell)
-
- timer = threading.Timer(timeout, self.__kill_proc, [])
- timer.start()
- stdout, stderr = self.proc.communicate()
- timer.cancel()
-
- if self.proc.returncode or self.is_timeout:
- if self.is_timeout:
- LOG.error("run cmd<%(cmd)s> timeout", {"cmd": cmd})
- ret = False
- output = "".join([stderr, stdout])
- else:
- ret = True
- output = stdout
- return ret, output