Beispiel #1
0
class TestController(object):
    def __init__(self, test_file, max_iterations=None, max_retries=None):
        self.test_file = test_file
        if max_iterations:
            self.max_iterations = max_iterations
        else:
            self.max_iterations = settings.get_variable('NUTS_WAIT_ITERATIONS',
                                                        default=25)
        if max_iterations:
            self.retries = max_retries
        else:
            self.retries = settings.get_variable('NUTS_MAX_RETRIES', default=0)

        self.test_suite = TestSuite('SuiteName')
        self.file_handler = FileHandler(self.test_suite, self.test_file)
        self.runner = Runner(self.test_suite,
                             SaltApi(),
                             max_iterations=self.max_iterations)
        self.evaluator = Evaluator(self.test_suite)

    def logic(self):
        self.file_handler.read_file(self.test_file)
        self.run_tests()

    def run_tests(self):
        self.test_suite.print_all_test_cases()
        self.runner.run_all()
        self.evaluator.validate_all_results()
        while self.test_suite.has_failed_tests() and self.retries > 0:
            self.re_run_failed_tests()

    def re_run_failed_tests(self):
        self.test_suite.prepare_re_run()
        self.run_tests()
Beispiel #2
0
def test_start_task(example_testsuite, api_mock):
    runner = Runner(example_testsuite, api_mock)
    test_case = example_testsuite.get_test_by_name('testPingFromAToB')
    runner._start_test_async(test_case)
    api_mock.start_task_async.assert_called_with(
        runner.create_test_task(test_case.devices, test_case.command,
                                test_case.parameter))
    assert test_case.job_id == u'20170302070941729675'
Beispiel #3
0
def test_create_task(example_testsuite, api_mock):
    runner = Runner(example_testsuite, api_mock)
    test_case = example_testsuite.get_test_by_name('testPingFromAToB')
    task = runner.create_test_task(test_case.devices, test_case.command,
                                   test_case.parameter)
    assert 'targets' in task
    assert 'function' in task
    assert 'arguments' in task
    assert task['targets'] == 'Server01'
    assert task['function'] == 'nuts.connectivity'
    assert task['arguments'] == ['8.8.8.8']
Beispiel #4
0
def test_collect_result(example_testsuite, api_mock):
    runner = Runner(example_testsuite, api_mock)
    test_case = example_testsuite.get_test_by_name('testPingFromAToB')
    test_case.job_id = u'20170302070941729675'
    runner._collect_result(test_case)
    api_mock.get_task_result.assert_called_with(taskid=u'20170302070941729675')
    assert test_case.get_actual_result() == {
        u'cisco.csr.1000v': {
            'resulttype': 'single',
            'result': '00:0C:29:EA:D1:68'
        }
    }
Beispiel #5
0
def test_run(example_testsuite, api_mock):
    runner = Runner(example_testsuite, api_mock)
    test_case = example_testsuite.get_test_by_name('testPingFromAToB')
    runner._start_test_sync(test_case)
    api_mock.start_task.assert_called_with(
        runner.create_test_task(test_case.devices, test_case.command,
                                test_case.parameter))
    assert test_case.get_actual_result() == {
        u'cisco.csr.1000v': {
            'resulttype': 'single',
            'result': '00:0C:29:EA:D1:68'
        }
    }
Beispiel #6
0
def test_extract_return_empty():
    return_dict = {u'return': [{u'cisco.csr.1000v': None}]}
    assert Runner._extract_return(return_dict) == {
        u'cisco.csr.1000v': {
            'resulttype': 'single',
            'result': None
        }
    }
Beispiel #7
0
    def __init__(self, test_file, max_iterations=None, max_retries=None):
        self.test_file = test_file
        if max_iterations:
            self.max_iterations = max_iterations
        else:
            self.max_iterations = settings.get_variable('NUTS_WAIT_ITERATIONS',
                                                        default=25)
        if max_iterations:
            self.retries = max_retries
        else:
            self.retries = settings.get_variable('NUTS_MAX_RETRIES', default=0)

        self.test_suite = TestSuite('SuiteName')
        self.file_handler = FileHandler(self.test_suite, self.test_file)
        self.runner = Runner(self.test_suite,
                             SaltApi(),
                             max_iterations=self.max_iterations)
        self.evaluator = Evaluator(self.test_suite)
Beispiel #8
0
def test_run_all_sync(example_testsuite, api_mock):
    example_testsuite.test_cases_sync += example_testsuite.test_cases_async
    example_testsuite.test_cases_async = []
    with patch.object(Runner, '_start_test_sync') as run_method_mocked:
        Runner(example_testsuite, api_mock).run_all()
        api_mock.connect.assert_called()
        run_method_mocked.assert_any_call(
            example_testsuite.get_test_by_name('testPingFromAToB'))
        run_method_mocked.assert_any_call(
            example_testsuite.get_test_by_name('checkuser'))
        run_method_mocked.assert_any_call(
            example_testsuite.get_test_by_name('Count ospf neighbors'))
        run_method_mocked.assert_any_call(
            example_testsuite.get_test_by_name('bandwidth test'))
Beispiel #9
0
def test_extract_return():
    return_dict = {
        'return': [{
            'cisco.csr.1000v': {
                'resulttype': 'single',
                'result': '00:0C:29:EA:D1:68'
            }
        }]
    }
    assert Runner._extract_return(return_dict) == {
        u'cisco.csr.1000v': {
            'resulttype': 'single',
            'result': '00:0C:29:EA:D1:68'
        }
    }
Beispiel #10
0
def test_create_task_render():
    task = Runner.create_test_task(devices='sw01{{ id }}',
                                   command='test.{{cmd}}',
                                   parameter=['{{ par }}', 'test2 {{ par2 }}'],
                                   render_data={
                                       'id': 123,
                                       'cmd': 'command',
                                       'par': 'parameter',
                                       'par2': 2
                                   })
    assert 'targets' in task
    assert 'function' in task
    assert 'arguments' in task
    assert task['targets'] == 'sw01123'
    assert task['function'] == 'test.command'
    assert task['arguments'] == ['parameter', 'test2 2']
Beispiel #11
0
def test_run_setup_teardown_sync(api_mock):
    test_suite = TSuite('TestTestSuite')
    test_suite.create_test(name='test',
                           command='testcmd',
                           devices='sw01',
                           parameter='',
                           operator='=',
                           expected=True,
                           setup=[{
                               'command': 'test setup cmd'
                           }],
                           teardown=[{
                               'command': 'test setup cmd'
                           }])
    with patch.object(Runner, '_start_tasks') as start_task_method_mocked:
        Runner(test_suite, api_mock).run_all()
        start_task_method_mocked.assert_any_call(
            test_suite.test_cases_sync[0].setup_tasks)
        start_task_method_mocked.assert_any_call(
            test_suite.test_cases_sync[0].teardown_tasks)
Beispiel #12
0
def test_return_setup(api_mock):
    test_suite = TSuite('TestTestSuite')
    test_suite.create_test(name='test',
                           command='testcmd',
                           devices='sw01',
                           parameter='',
                           operator='=',
                           expected=True,
                           setup=[{
                               'command': 'test setup cmd',
                               'devices': 'sw99',
                               'save': 'ip'
                           }])
    with patch.object(Runner, '_get_task_result') as create_task_method_mocked:
        Runner(test_suite, api_mock).run_all()
        test_case = test_suite.test_cases_sync[0]
        saved_data = {
            'ip': {
                'resulttype': 'single',
                'result': '00:0C:29:EA:D1:68'
            }
        }
        create_task_method_mocked.assert_any_call(test_case, saved_data)
Beispiel #13
0
def test_create_task_add_nuts():
    task = Runner.create_test_task(devices='sw01', command='test')

    assert 'function' in task
    assert task['function'] == 'nuts.test'