From 72ba8a377f3f2fec2742f13d39c813b1b07610ab Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 7 Aug 2014 10:40:16 -0600 Subject: [PATCH 1/5] Moving tty function over to cmdmod --- salt/modules/cmdmod.py | 32 ++++++++++++++++++++++++++++++++ salt/modules/test.py | 32 -------------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index 1d6a9f0547..076100f139 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -1228,6 +1228,38 @@ def exec_code(lang, code, cwd=None): return ret +def tty(device, echo=None): + ''' + Echo a string to a specific tty + + CLI Example: + + .. code-block:: bash + + salt '*' cmd.tty tty0 'This is a test' + salt '*' cmd.tty pts3 'This is a test' + ''' + if device.startswith('tty'): + teletype = '/dev/{0}'.format(device) + elif device.startswith('pts'): + teletype = '/dev/{0}'.format(device.replace('pts', 'pts/')) + else: + return {'Error': 'The specified device is not a valid TTY'} + + cmd = 'echo {0} > {1}'.format(echo, teletype) + ret = run_all(cmd) + if ret['retcode'] == 0: + return { + 'Success': 'Message was successfully echoed to {0}'.format(teletype) + } + else: + return { + 'Error': 'Echoing to {0} returned error code {1}'.format( + teletype, + ret['retcode']) + } + + def run_chroot(root, cmd): ''' .. versionadded:: 2014.7.0 diff --git a/salt/modules/test.py b/salt/modules/test.py index 0e240d7975..e73744c5ef 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -393,38 +393,6 @@ def opts_pkg(): return ret -def tty(device, echo=None): - ''' - Echo a string to a specific tty - - CLI Example: - - .. code-block:: bash - - salt '*' test.tty tty0 'This is a test' - salt '*' test.tty pts3 'This is a test' - ''' - if device.startswith('tty'): - teletype = '/dev/{0}'.format(device) - elif device.startswith('pts'): - teletype = '/dev/{0}'.format(device.replace('pts', 'pts/')) - else: - return {'Error': 'The specified device is not a valid TTY'} - - cmd = 'echo {0} > {1}'.format(echo, teletype) - ret = __salt__['cmd.run_all'](cmd) - if ret['retcode'] == 0: - return { - 'Success': 'Message was successfully echoed to {0}'.format(teletype) - } - else: - return { - 'Error': 'Echoing to {0} returned error code {1}'.format( - teletype, - ret['retcode']) - } - - def rand_str(size=9999999999): ''' Return a random string From 0d3b6b14d4939f2b58b690b943b2ee1f81b77ea5 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 7 Aug 2014 10:47:24 -0600 Subject: [PATCH 2/5] Return plain error string in old func --- salt/modules/test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/salt/modules/test.py b/salt/modules/test.py index e73744c5ef..be4583a6b5 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -433,3 +433,10 @@ def stack(): salt '*' test.stack ''' return ''.join(traceback.format_stack()) + + +def tty(*args, **kwargs): + ''' + Deprecated. Moved to cmdmod. + ''' + return 'ERROR: This function has been moved to cmd.tty' From ab37e99b9da3be8a156d3528f68f975ac5ab29fd Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 7 Aug 2014 10:57:08 -0600 Subject: [PATCH 3/5] Pylint --- salt/modules/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/test.py b/salt/modules/test.py index be4583a6b5..fca7f1d389 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -435,7 +435,7 @@ def stack(): return ''.join(traceback.format_stack()) -def tty(*args, **kwargs): +def tty(*args, **kwargs): #pylint: disable=W0613 ''' Deprecated. Moved to cmdmod. ''' From fbbfb44642762a09e8f7596fcfa3eb2422a5e2ce Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 7 Aug 2014 11:32:55 -0600 Subject: [PATCH 4/5] More lint and doc strings for test --- salt/modules/test.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/salt/modules/test.py b/salt/modules/test.py index fca7f1d389..9479540a0c 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -435,8 +435,16 @@ def stack(): return ''.join(traceback.format_stack()) -def tty(*args, **kwargs): #pylint: disable=W0613 +def tty(*args, **kwargs): # pylint: disable=W0613 + ''' + Deprecated! Moved to cmdmod. + + CLI Example: + + .. code-block:: bash + + salt '*' test.tty tty0 'This is a test' + salt '*' test.tty pts3 'This is a test' ''' - Deprecated. Moved to cmdmod. ''' return 'ERROR: This function has been moved to cmd.tty' From c3b476a6c05df102a7acacd2cfe27de71fd5a9f9 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 7 Aug 2014 11:37:06 -0600 Subject: [PATCH 5/5] Grr, typo --- salt/modules/test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/modules/test.py b/salt/modules/test.py index 9479540a0c..a643631e47 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -446,5 +446,4 @@ def tty(*args, **kwargs): # pylint: disable=W0613 salt '*' test.tty tty0 'This is a test' salt '*' test.tty pts3 'This is a test' ''' - ''' return 'ERROR: This function has been moved to cmd.tty'