# -*- coding: utf-8 -*- from six import print_ #from nose.tools import ok_ import os import pexpect #import sys import utils # TODO: mock_ssh.py --prompt enabled, so we can test -s -l options. TOMAHAWK_PATH = os.path.join(utils.get_bin_dir(__file__), 'tomahawk') TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) def test_06_prompt_sudo_password(): command = "%s -D --hosts=localhost --prompt-login-password --ssh-user=tomahawk_test uptime" % ( TOMAHAWK_PATH) child = pexpect.spawn(command, timeout=5) i = child.expect([pexpect.EOF, pexpect.TIMEOUT, 'Enter a password.+']) if i == 0: # EOF print_('EOF') print_(child.before) elif i == 1: # timeout print_('TIMEOUT') #ok_(False, 'Failure: ') assert True elif i == 2: child.sendline("tomahawk_test") child.expect(pexpect.EOF) #ok_(True, "execute (prompt password)") assert True
from nose.tools import assert_equal, assert_true import os import tempfile from subprocess import call, PIPE import utils TOMAHAWK_RSYNC_PATH = os.path.join(utils.get_bin_dir(__file__), 'tomahawk-rsync') TMP_DIR = os.path.join(utils.get_home_dir(__file__), 'tmp') if not os.path.exists(TMP_DIR): os.mkdir(TMP_DIR) env = os.environ del env['TOMAHAWK_ENV'] def test_01_basic(): hello_file = os.path.join(TMP_DIR, 'hello') hello_file_copied = os.path.join(TMP_DIR, 'hello.copied') if os.path.exists(hello_file_copied): os.remove(hello_file_copied) handle = open(hello_file, 'w') handle.write('hello world') handle.close() status = call( [ TOMAHAWK_RSYNC_PATH, '--hosts=localhost', hello_file, hello_file_copied ], stdout = PIPE, stderr = PIPE ) assert_equal(status, 0, 'rsync (basic)') assert_true(os.path.exists(hello_file_copied), 'rsync (basic)') def test_02_rsync_options():
# -*- coding: utf-8 -*- from six import print_ #from nose.tools import ok_ import os import pexpect #import sys import utils # TODO: mock_ssh.py --prompt enabled, so we can test -s -l options. TOMAHAWK_PATH = os.path.join(utils.get_bin_dir(__file__), 'tomahawk') TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) def test_06_prompt_sudo_password(): command = "%s -D --hosts=localhost --prompt-login-password --ssh-user=tomahawk_test uptime" % (TOMAHAWK_PATH) child = pexpect.spawn( command, timeout = 5 ) i = child.expect([ pexpect.EOF, pexpect.TIMEOUT, 'Enter a password.+' ]) if i == 0: # EOF print_('EOF') print_(child.before) elif i == 1: # timeout print_('TIMEOUT') #ok_(False, 'Failure: ') assert True elif i == 2: child.sendline("tomahawk_test") child.expect(pexpect.EOF) #ok_(True, "execute (prompt password)")
#from nose.tools import assert_equal, assert_true import os from subprocess import call, PIPE import utils TOMAHAWK_RSYNC_PATH = os.path.join(utils.get_bin_dir(__file__), 'tomahawk-rsync') TMP_DIR = os.path.join(utils.get_home_dir(__file__), 'tmp') if not os.path.exists(TMP_DIR): os.mkdir(TMP_DIR) env = os.environ if env.get('TOMAHAWK_ENV') != None: del env['TOMAHAWK_ENV'] hello_file = os.path.join(TMP_DIR, 'hello') hello_file_copied = os.path.join(TMP_DIR, 'hello.copied') if os.path.exists(hello_file_copied): os.remove(hello_file_copied) handle = open(hello_file, 'w') handle.write('hello world') handle.close() def test_03_mirror_mode_pull(): for f in ('localhost__hello', '127.0.0.1__hello'): path = os.path.join(TMP_DIR, f) if os.path.exists(path): os.remove(path) status = call([