aboutsummaryrefslogtreecommitdiffstats
path: root/tests/driver_test.py
blob: 5ea5dac4ba88ed1e38d4cb2557aee92d35110272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
import mock
from func.driver import Driver


class TestClass:
    @pytest.mark.parametrize("test_input, expected", [
        (['fuel',
          '/home',
          "iperf",
          [('host', ['10.20.0.13', '10.20.0.15'])],
          "iperf_bm.yaml",
          [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)],
          [("10.20.0.13", [None]), ("10.20.0.15", [None])],
          {'http_proxy': 'http://10.20.0.1:8118',
           'https_proxy': 'http://10.20.0.1:8118',
           'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'}],
         [{'Dest_dir': 'results',
           'ip1': '',
           'ip2': '',
           'installer': 'fuel',
           'workingdir': '/home',
           'fname': 'iperf_bm.yaml',
           'username': 'root',
           'http_proxy': 'http://10.20.0.1:8118',
           'https_proxy': 'http://10.20.0.1:8118',
           'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*',
           'duration': 20,
           'protocol': 'tcp',
           'bandwidthGbps': 0,
           "role": "host"}]),
        (['joid',
          '/home',
          "iperf",
          [('1-server', ['10.20.0.13']), ('2-host', ['10.20.0.15'])],
          "iperf_vm.yaml",
          [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)],
          [("10.20.0.13", [None]), ("10.20.0.15", [None])],
          {}],
         [{'Dest_dir': 'results',
           'ip1': '10.20.0.13',
           'ip2': '',
           'installer': 'joid',
           'privateip1': 'NONE',
           'workingdir': '/home',
           'fname': 'iperf_vm.yaml',
           'username': 'ubuntu',
           'duration': 20,
           'protocol': 'tcp',
           'bandwidthGbps': 0,
           "role": "1-server"},
          {'Dest_dir': 'results',
           'ip1': '10.20.0.13',
           'ip2': '',
           'installer': 'joid',
           'privateip1': 'NONE',
           'workingdir': '/home',
           'fname': 'iperf_vm.yaml',
           'username': 'ubuntu',
           'duration': 20,
           'protocol': 'tcp',
           'bandwidthGbps': 0,
           "role": "2-host"}])
    ])
    @mock.patch('func.driver.AnsibleApi.execute_playbook')
    @mock.patch('func.driver.AnsibleApi.get_detail_playbook_stats')
    def test_driver_success(self, mock_stats, mock_ansible, test_input, expected):
        mock_ansible.return_value = True
        mock_stats.return_value = [(u'10.20.6.14', {'unreachable': 0,
                                                    'skipped': 13,
                                                    'ok': 27,
                                                    'changed': 26,
                                                    'failures': 0}),
                                   ('localhost', {'unreachable': 0,
                                                  'skipped': 0,
                                                  'ok': 6,
                                                  'changed': 6,
                                                  'failures': 0}),
                                   (u'10.20.6.13', {'unreachable': 0,
                                                    'skipped': 13,
                                                    'ok': 27,
                                                    'changed': 26,
                                                    'failures': 0})]
        dri = Driver()
        result = dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3],
                                 test_input[4], test_input[5], test_input[6], test_input[7])
        call_list = mock_ansible.call_args_list
        for call in call_list:
            call_args, call_kwargs = call
            real_call = call_args[3]
            assert real_call == expected[call_list.index(call)]
        assert result['result'] == 0