diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/args_handler_test.py | 2 | ||||
-rw-r--r-- | tests/cli_test.py | 6 | ||||
-rw-r--r-- | tests/create_zones_test.py | 58 | ||||
-rw-r--r-- | tests/qtip_server_test.py | 8 | ||||
-rw-r--r-- | tests/spawn_vm_test.py | 2 |
5 files changed, 51 insertions, 25 deletions
diff --git a/tests/args_handler_test.py b/tests/args_handler_test.py index ebf500f3..e6500862 100644 --- a/tests/args_handler_test.py +++ b/tests/args_handler_test.py @@ -13,7 +13,7 @@ import func.args_handler class TestClass: @pytest.mark.parametrize("test_input, expected", [ - (['fuel', '/home', './test_cases/zte-pod1/network/iperf_bm.yaml'], + (['fuel', '/home', './test_cases/default/network/iperf_bm.yaml'], ['fuel', '/home', "iperf", [('1-server', ['10.20.0.23']), ('2-host', ['10.20.0.24'])], "iperf_bm.yaml", diff --git a/tests/cli_test.py b/tests/cli_test.py index fe05327d..12d0abb0 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -1,7 +1,7 @@ import pytest import mock import os -from func.cli import cli +from func.cli import Cli class TestClass: @@ -19,7 +19,7 @@ class TestClass: k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel', 'PWD': '/home'}) with pytest.raises(SystemExit): k.start() - cli(test_input) + Cli(test_input) k.stop() resout, reserr = capfd.readouterr() assert expected in resout @@ -35,7 +35,7 @@ class TestClass: def test_cli_successful(self, mock_args_handler, test_input, expected): k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel', 'PWD': '/home'}) k.start() - cli(test_input) + Cli(test_input) k.stop() call_list = map(lambda x: mock_args_handler.call_args_list[x][0], range(len(expected))) assert sorted(call_list) == sorted(expected) diff --git a/tests/create_zones_test.py b/tests/create_zones_test.py index e431a907..39e71c17 100644 --- a/tests/create_zones_test.py +++ b/tests/create_zones_test.py @@ -2,7 +2,7 @@ import pytest import mock from mock import Mock, MagicMock import os -from func.create_zones import create_zones +from func.create_zones import AvailabilityZone return_list = [] @@ -22,7 +22,7 @@ class HyperMock(MagicMock): class AggMock(MagicMock): def get_details(self, agg_id): - print "get_detail:{0}".format(agg_id) + print "get_details:{0}".format(agg_id) return Mock(hosts=[]) def create(self, host, agg): @@ -41,6 +41,7 @@ class AggMock(MagicMock): pass def remove_host(self, agg_id, host): + print "remove_host:{0}:{1}".format(agg_id, host) pass @@ -51,29 +52,48 @@ class NovaMock(MagicMock): class TestClass: @pytest.mark.parametrize("test_input, expected", [ - ([[], ['compute1', 'compute2']], - ['create:10.20.0.4:compute1', + (['compute1', 'compute2'], + ['create:compute1:compute1', 'add_host:compute1:10.20.0.4', - 'create:10.20.0.5:compute2', + 'create:compute2:compute2', 'add_host:compute2:10.20.0.5']), - ([[get_agg_mock('10.20.0.4'), get_agg_mock('10.20.0.5')], ['compute1', 'compute2']], - ['delete:10.20.0.4', - 'create:10.20.0.4:compute1', - 'get_detail:10.20.0.4', - 'add_host:10.20.0.4:10.20.0.4', - 'delete:10.20.0.5', - 'create:10.20.0.5:compute2', - 'get_detail:10.20.0.5', - 'add_host:10.20.0.5:10.20.0.5']), - ([[], ['compute1', 'compute5']], - ['The specified compute node doesnt exist. using compute 1']) + (['compute1', 'compute1'], + ['create:compute1:compute1', + 'add_host:compute1:10.20.0.4']), ]) @mock.patch('func.create_zones.client', autospec=True) @mock.patch('func.create_zones.v2', autospec=True) @mock.patch('func.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_agg(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('func.create_zones.client', autospec=True) + @mock.patch('func.create_zones.v2', autospec=True) + @mock.patch('func.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[0] + 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', @@ -81,8 +101,8 @@ class TestClass: 'OS_PASSWORD': 'admin', 'OS_TENANT_NAME': 'admin'}) k.start() - create = create_zones() - create.create_agg(test_input[1]) + azone = AvailabilityZone() + azone.clean_all_aggregates() k.stop() resout, reserr = capfd.readouterr() for x in expected: diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py index 2f9eebf1..9def21f8 100644 --- a/tests/qtip_server_test.py +++ b/tests/qtip_server_test.py @@ -35,6 +35,8 @@ class TestClass: 'suite_name': 'compute', 'max_minutes': 60, 'type': 'BM', + 'testdb_url': None, + 'node_name': None, 'state': 'finished', 'state_detail': [{'state': 'finished', 'benchmark': 'dhrystone_bm.yaml'}, {'state': 'finished', 'benchmark': 'whetstone_bm.yaml'}, @@ -48,7 +50,9 @@ class TestClass: 'max_minutes': 20, 'suite_name': 'compute', 'type': 'VM', - 'benchmark_name': 'dhrystone_vm.yaml'}, + 'benchmark_name': 'dhrystone_vm.yaml', + 'testdb_url': 'http://testresults.opnfv.org/test/api/v1', + 'node_name': 'zte-pod2'}, {'job_id': '', 'installer_type': 'fuel', 'installer_ip': '10.20.0.2', @@ -56,6 +60,8 @@ class TestClass: 'suite_name': 'compute', 'max_minutes': 20, 'type': 'VM', + 'testdb_url': 'http://testresults.opnfv.org/test/api/v1', + 'node_name': 'zte-pod2', 'state': 'finished', 'state_detail': [{u'state': u'finished', u'benchmark': u'dhrystone_vm.yaml'}], 'result': 0}) diff --git a/tests/spawn_vm_test.py b/tests/spawn_vm_test.py index 0ec5c902..7890abd1 100644 --- a/tests/spawn_vm_test.py +++ b/tests/spawn_vm_test.py @@ -43,7 +43,7 @@ class TestClass: [('172.10.0.154', '')]), ]) @mock.patch('func.spawn_vm.Env_setup') - @mock.patch('func.spawn_vm.create_zones') + @mock.patch('func.spawn_vm.AvailabilityZone') @mock.patch('func.spawn_vm.client', autospec=True) @mock.patch('func.spawn_vm.keystoneclient.v2_0', autospec=True) @mock.patch('func.spawn_vm.heatclient.client', autospec=True) |