Example #1
0
    def setUpClass(cls):

        fsutil.makedirs(cls.testArc)

        # mount testArc to limit it's size
        cmd = "mount -t tmpfs -o size={size}M tmpfs '{_dir}'".format(
                _dir=cls.testArc, size=cls.testArcSize)
        proc.command(cmd, shell=True)
    def _archive(self, src_path):

        arc_dir = self.make_arc_dir()
        arc_fn = self.make_arc_fn(src_path)
        arc_path = os.path.join(arc_dir, arc_fn)

        cmd = "gzip -c '{src}' >> '{dst}'".format(src=src_path, dst=arc_path)
        rc, out, err = proc.command(cmd, shell=True)

        if rc is 0:
            logger.info("archive ok: {src_path} {arc_path}".format(
                src_path=src_path, arc_path=arc_path))
        else:
            logger.warn("archive failure: {src_path} {arc_path} {out} {err}".format(
                src_path=src_path, arc_path=arc_path, out=out, err=err))
Example #3
0
    def send(self, data):

        data = self.construct(data)

        self.save_to_file(data)

        returncode, out, err = proc.command(self.sender,
                                            '-c', self.agent_configfile,
                                            '-i', self.data_file)
        logger.info(out)

        if returncode == 0:

            return 0  # data sent

        else:

            logger.error("while send data to remote zabbix: " + repr(err))
            return -1  # data sent error
Example #4
0
    def test_page_no_pager(self):

        returncode, out, err = proc.command(
            'python2',
            'page_it.py',
            # pager, control_char, max_lines
            ' '.join(['python2', 'raw_pager.py', '>']),
            '0',
            '2',
            '1',
            '2',
            cwd=this_base,
        )

        dd('returncode:', returncode)
        dd('out:', out)
        dd('err:', err)

        self.assertEqual(0, returncode)
        self.assertEqual('1\n2\n', out)
Example #5
0
def start_mysql_server():

    # create docker image by run mysqlutil/test/dep/build_img.sh before test
    if not docker_does_container_exist(mysql_test_name):

        dd('create container: ' + mysql_test_name)
        dcli = _docker_cli()
        dcli.create_container(
            name=mysql_test_name,
            environment={
                'MYSQL_ROOT_PASSWORD': mysql_test_password,
            },
            image=mysql_test_tag,
        )
        time.sleep(2)

    dd('start mysql: ' + mysql_test_name)
    dcli = _docker_cli()
    dcli.start(container=mysql_test_name)

    dd('get mysql ip inside container')
    rc, out, err = proc.command(
        'docker',
        'run',
        '-i',
        '--link',
        mysql_test_name + ':mysql',
        '--rm',
        mysql_test_tag,
        'sh',
        '-c',
        'exec echo "$MYSQL_PORT_3306_TCP_ADDR"',
    )

    ip = out.strip()
    dd('ip: ' + repr(ip))

    return ip
Example #6
0
def subproc(script):
    return proc.command('sh', close_fds=True, stdin=script)
Example #7
0
from pykit import proc


returncode, out, err = proc.command('ls', '-al', cwd='/home/cheng')

'''
for i in out.split("\n"):
    print i
    print
print returncode
print err
'''

returncode, out, err = proc.shell_script('ls -al', cwd='/home/cheng')
'''
print out
'''

proc.start_process('csv_to_json.py', '/home/cheng/test_json/', 'p'='a')
Example #8
0
    def tearDownClass(cls):

        cmd = "umount '{_dir}'".format(_dir=cls.testArc)
        proc.command(cmd, shell=True)

        fsutil.remove(cls.testArc)
def subproc(script):
    return proc.command('sh', close_fds=True,
                        stdin=script)