aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/utils/args_handler_test.py
blob: b67fd9935e63a0334535ebc5403cf0453f6ea787 (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
##############################################################################
# Copyright (c) 2016 ZTE Corp and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import pytest
import mock
import qtip.utils.args_handler


class TestClass:
    @pytest.mark.parametrize("test_input, expected", [
        (['fuel', '/home', 'benchmarks/test_plan/default/network/iperf_bm.yaml'],
         ['fuel', '/home', "iperf",
          [('1-server', ['10.20.0.23']), ('2-host', ['10.20.0.24'])],
          "iperf_bm.yaml",
          [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 10)],
          [("10.20.0.24", [None]), ("10.20.0.23", [None])], {}])
    ])
    @mock.patch('qtip.utils.args_handler.Env_setup.call_ping_test')
    @mock.patch('qtip.utils.args_handler.Env_setup.call_ssh_test')
    @mock.patch('qtip.utils.args_handler.Env_setup.update_ansible')
    @mock.patch('qtip.utils.args_handler.SpawnVM')
    @mock.patch('qtip.utils.args_handler.Driver.drive_bench')
    def test_prepare_and_run_benchmark_successful(self, mock_driver, mock_sqawn_vm, mock_env_setup_ping,
                                                  mock_env_setup_ssh, mock_update_ansible, test_input, expected):
        mock_ips = mock.Mock(return_value=["10.20.0.23", "10.20.0.24"])
        qtip.utils.args_handler.Env_setup.fetch_compute_ips = mock_ips
        qtip.utils.args_handler.prepare_and_run_benchmark(test_input[0], test_input[1], test_input[2])
        call = mock_driver.call_args
        call_args, call_kwargs = call
        assert sorted(map(sorted, call_args)) == sorted(map(sorted, expected))
= HyperMock() aggregates = AggMock() class TestClass: @pytest.mark.skip(reason="(yujunz) to be fixed") @pytest.mark.parametrize("test_input, expected", [ (['compute1', 'compute2'], ['create:compute1:compute1', 'add_host:compute1:10.20.0.4', 'create:compute2:compute2', 'add_host:compute2:10.20.0.5']), (['compute1'], ['create:compute1:compute1', 'add_host:compute1:10.20.0.4']), ]) @mock.patch('qtip.utils.create_zones.client', autospec=True) @mock.patch('qtip.utils.create_zones.v2', autospec=True) @mock.patch('qtip.utils.create_zones.session') def test_create_zones_success(self, mock_keystone_session, mock_keystone_v2, mock_nova_client, test_input, expected, capfd): nova_obj = NovaMock() mock_nova_client.Client.return_value = nova_obj() k = mock.patch.dict(os.environ, {'OS_AUTH_URL': 'http://172.10.0.5:5000', 'OS_USERNAME': 'admin', 'OS_PASSWORD': 'admin', 'OS_TENANT_NAME': 'admin'}) k.start() azone = AvailabilityZone() azone.create_aggs(test_input) k.stop() resout, reserr = capfd.readouterr() for x in expected: assert x in resout @pytest.mark.parametrize("test_input, expected", [ ([get_agg_mock('10.20.0.4'), get_agg_mock('10.20.0.5')], ['get_details:10.20.0.4', 'delete:10.20.0.4', 'get_details:10.20.0.5', 'delete:10.20.0.5']), ([], []), ]) @mock.patch('qtip.utils.create_zones.client', autospec=True) @mock.patch('qtip.utils.create_zones.v2', autospec=True) @mock.patch('qtip.utils.create_zones.session') def test_clean_all_aggregates(self, mock_keystone_session, mock_keystone_v2, mock_nova_client, test_input, expected, capfd): global return_list return_list = test_input nova_obj = NovaMock() mock_nova_client.Client.return_value = nova_obj() k = mock.patch.dict(os.environ, {'OS_AUTH_URL': 'http://172.10.0.5:5000', 'OS_USERNAME': 'admin', 'OS_PASSWORD': 'admin', 'OS_TENANT_NAME': 'admin'}) k.start() azone = AvailabilityZone() azone.clean_all_aggregates() k.stop() resout, reserr = capfd.readouterr() for x in expected: assert x in resout