pystorcli.cmdRunner
CMDRunner
1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2022, Rafael Leira & Naudit HPCN S.L. <rafael.leira@naudit.es> 4# See LICENSE for details. 5 6'''CMDRunner 7''' 8 9import os 10import shutil 11import subprocess 12from . import exc 13 14 15class CMDRunner(): 16 """This is a simple wrapper for subprocess.Popen()/subprocess.run(). The main idea is to inherit this class and create easy mockable tests. 17 """ 18 19 def run(self, args, **kwargs) -> subprocess.CompletedProcess: 20 """Runs a command and returns the output. 21 """ 22 return subprocess.run(args, **kwargs) 23 24 def binaryCheck(self, binary): 25 """Verify and return full binary path 26 """ 27 _bin = shutil.which(binary) 28 if not _bin: 29 raise exc.StorCliError( 30 "Cannot find storcli binary '%s' in path: %s" % (binary, os.environ['PATH'])) 31 return _bin
class
CMDRunner:
16class CMDRunner(): 17 """This is a simple wrapper for subprocess.Popen()/subprocess.run(). The main idea is to inherit this class and create easy mockable tests. 18 """ 19 20 def run(self, args, **kwargs) -> subprocess.CompletedProcess: 21 """Runs a command and returns the output. 22 """ 23 return subprocess.run(args, **kwargs) 24 25 def binaryCheck(self, binary): 26 """Verify and return full binary path 27 """ 28 _bin = shutil.which(binary) 29 if not _bin: 30 raise exc.StorCliError( 31 "Cannot find storcli binary '%s' in path: %s" % (binary, os.environ['PATH'])) 32 return _bin
This is a simple wrapper for subprocess.Popen()/subprocess.run(). The main idea is to inherit this class and create easy mockable tests.
def
run(self, args, **kwargs) -> subprocess.CompletedProcess:
20 def run(self, args, **kwargs) -> subprocess.CompletedProcess: 21 """Runs a command and returns the output. 22 """ 23 return subprocess.run(args, **kwargs)
Runs a command and returns the output.
def
binaryCheck(self, binary)
25 def binaryCheck(self, binary): 26 """Verify and return full binary path 27 """ 28 _bin = shutil.which(binary) 29 if not _bin: 30 raise exc.StorCliError( 31 "Cannot find storcli binary '%s' in path: %s" % (binary, os.environ['PATH'])) 32 return _bin
Verify and return full binary path