<commit_before>#!/usr/bin/env python

import argparse
from fabric import api
import os

TEMPEST_FILE_XML = 'tempest_results.xml'
TEMPEST_FILE_SUBUNIT = 'tempest_results.subunit'
TEMPEST_RUN_CMD = 'testr run --subunit {0} | subunit-2to1 | tools/colorizer.py'
TEMPEST_SUBUNIT_CMD = 'testr last --subunit > ' + TEMPEST_FILE_SUBUNIT
TEMPEST_XML_CMD = 'testr last --subunit | subunit-1to2 | subunit2junitxml --output-to=' + TEMPEST_FILE_XML


def main(host, user, password, tempest_filter, tempest_dir, tempest_list_file):
    settings = {'host_string': host,
                'user': user,
                'password': password,
                'warn_only': True}
    with api.settings(**settings):
        with api.cd(tempest_dir):
            if tempest_list_file:
                api.put(local_path=tempest_list_file, remote_path='list.txt')
                cmd = TEMPEST_RUN_CMD.format('--load-list=list.txt')
            else:
                cmd = TEMPEST_RUN_CMD.format(tempest_filter)
            api.run(command=cmd)
            api.run(command=TEMPEST_SUBUNIT_CMD)
            api.run(command=TEMPEST_XML_CMD)
            api.get(remote_path=TEMPEST_FILE_XML, local_path=TEMPEST_FILE_XML)
            api.get(remote_path=TEMPEST_FILE_SUBUNIT, local_path=TEMPEST_FILE_SUBUNIT)


if __name__ == '__main__':
    p = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.add_argument('-r', '--remote', required=True,
                   help='ip address of host where tempest is deployed')
    p.add_argument('-u', '--user', default='localadmin')
    p.add_argument('-p', '--password', default='<PASSWORD>')
    p.add_argument('-d', '--dir', default='/opt/stack/tempest')
    p.add_argument('-f', '--filter', default='',
                   help='filter to choose a set of tests to be run')
    p.add_argument('-l', '--list', default=None, type=file,
                   help='file with list of tests, overrides --filter')
    args = p.parse_args()
    main(host=args.remote, user=args.user, password=args.password,
         tempest_filter=args.filter, tempest_list_file=args.list,
         tempest_dir=args.dir)<commit_msg>script to run tempest remotely:  fix bug: junitxml may be not installed  fix bug: testr repo may not be activated enhancement: change err printing in case xml and subunit reports not found enhancement: use run_tempest.sh with possibility to run versus venv<commit_after>#!/usr/bin/env python

from __future__ import print_function
import argparse
from fabric import api
from fabric.contrib import files
import sys

TEMPEST_FILE_XML = 'tempest_results.xml'
TEMPEST_FILE_SUBUNIT = 'tempest_results.subunit'
TEMPEST_SUBUNIT_CMD = 'testr last --subunit > ' + TEMPEST_FILE_SUBUNIT
TEMPEST_XML_CMD = 'testr last --subunit | subunit-1to2 | subunit2junitxml --output-to=' + TEMPEST_FILE_XML


def main(host, user, password, tempest_filter, tempest_dir, tempest_list_file, is_venv):
    cmd = './run_tempest.sh {venv} -- {filter_or_list}'.format(
        venv='-V' if is_venv else '-N',
        filter_or_list='--load-list=list.txt' if tempest_list_file else tempest_filter)
    settings = {'host_string': host,
                'user': user,
                'password': password,
                'warn_only': True}
    with api.settings(**settings):
        with api.cd(tempest_dir):
            if tempest_list_file:
                api.put(local_path=tempest_list_file, remote_path='list.txt')
            api.sudo(command='pip install junitxml')
            api.run(command='testr init')
            api.run(command=cmd)
            api.run(command=TEMPEST_SUBUNIT_CMD)
            api.run(command=TEMPEST_XML_CMD)
            if files.exists(path=TEMPEST_FILE_XML):
                api.get(remote_path=TEMPEST_FILE_XML, local_path=TEMPEST_FILE_XML)
                api.run('rm ' + TEMPEST_FILE_XML)
            else:
                print(TEMPEST_FILE_XML + ' is not created on remote', file=sys.stderr)
            if files.exists(path=TEMPEST_FILE_SUBUNIT):
                api.get(remote_path=TEMPEST_FILE_SUBUNIT, local_path=TEMPEST_FILE_SUBUNIT)
                api.run('rm ' + TEMPEST_FILE_SUBUNIT)
            else:
                print(TEMPEST_FILE_SUBUNIT + ' is not created on remote', file=sys.stderr)


if __name__ == '__main__':
    p = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.add_argument('-r', '--remote', required=True,
                   help='ip address of host where tempest is deployed')
    p.add_argument('-u', '--user', default='localadmin')
    p.add_argument('-p', '--password', default='<PASSWORD>')
    p.add_argument('-d', '--dir', default='/opt/stack/tempest')
    p.add_argument('-v', '--venv', default=False, type=bool, help='use venv?')
    p.add_argument('-f', '--filter', default='',
                   help='filter to choose a set of tests to be run')
    p.add_argument('-l', '--list', default=None, type=file,
                   help='file with list of tests, overrides --filter')
    args = p.parse_args()
    main(host=args.remote, user=args.user, password=args.password,
         tempest_filter=args.filter, tempest_list_file=args.list,
         tempest_dir=args.dir, is_venv=args.venv)
{'fraction_non_alphanumeric': 0.12219881248802911, 'fraction_numerical': 0.001723807699674392, 'mean_word_length': 3.0386697602474864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3936372', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1679, 'n_words': 340}