diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/driver_test.py | 29 | ||||
-rw-r--r-- | tests/fetchimg_test.py | 34 | ||||
-rw-r--r-- | tests/qtip_server_test.py | 21 | ||||
-rw-r--r-- | tests/spawn_vm_test.py | 13 |
4 files changed, 43 insertions, 54 deletions
diff --git a/tests/driver_test.py b/tests/driver_test.py index 9162ca16..bc705dad 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -35,13 +35,13 @@ class TestClass: [('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])], + [('1-server', '10.10.17.4'), ('2-host', '10.10.17.5')], {}], [{'Dest_dir': 'results', 'ip1': '10.20.0.13', 'ip2': '', 'installer': 'joid', - 'privateip1': 'NONE', + 'privateip1': '10.10.17.4', 'workingdir': '/home', 'fname': 'iperf_vm.yaml', 'username': 'ubuntu', @@ -53,7 +53,7 @@ class TestClass: 'ip1': '10.20.0.13', 'ip2': '', 'installer': 'joid', - 'privateip1': 'NONE', + 'privateip1': '10.10.17.4', 'workingdir': '/home', 'fname': 'iperf_vm.yaml', 'username': 'ubuntu', @@ -63,13 +63,30 @@ class TestClass: "role": "2-host"}]) ]) @mock.patch('func.driver.AnsibleApi.execute_playbook') - def test_driver_success(self, mock_ansible, test_input, expected): + @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() - 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]) + 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 diff --git a/tests/fetchimg_test.py b/tests/fetchimg_test.py deleted file mode 100644 index 5d482567..00000000 --- a/tests/fetchimg_test.py +++ /dev/null @@ -1,34 +0,0 @@ -import mock -from func.fetchimg import FetchImg - - -class TestClass: - @mock.patch('func.fetchimg.os') - @mock.patch('func.fetchimg.os.path') - def test_fetch_img_success(self, mock_path, mock_os): - mock_os.system.return_value = True - mock_path.isfile.return_value = True - img = FetchImg() - img.download() - - @mock.patch('func.fetchimg.time') - @mock.patch('func.fetchimg.os.system') - @mock.patch('func.fetchimg.os.path') - def test_fetch_img_fail(self, mock_path, mock_system, mock_time): - img = FetchImg() - mock_system.return_value = True - mock_path.isfile.side_effect = [False, False, True] - img.download() - assert mock_time.sleep.call_count == 2 - - @mock.patch('func.fetchimg.time') - @mock.patch('func.fetchimg.os.system') - @mock.patch('func.fetchimg.os.path') - def test_fetch_temp_success(self, mock_path, mock_system, mock_time): - img = FetchImg() - mock_system.return_value = True - mock_path.isfile.side_effect = [True] - img.download() - filepath = './Temp_Img/QTIP_CentOS.qcow2' - imgstorepath = "/home/opnfv/imgstore/QTIP_CentOS.qcow2" - mock_system.assert_called_with("ln -s %s %s" % (imgstorepath, filepath)) diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py index 3f70a1f6..511d209a 100644 --- a/tests/qtip_server_test.py +++ b/tests/qtip_server_test.py @@ -41,7 +41,7 @@ class TestClass: {'state': 'finished', 'benchmark': 'ramspeed_bm.yaml'}, {'state': 'finished', 'benchmark': 'dpi_bm.yaml'}, {'state': 'finished', 'benchmark': 'ssl_bm.yaml'}], - 'result': []}), + 'result': 0}), ({'installer_type': 'fuel', 'installer_ip': '10.20.0.2', 'pod_name': 'zte-pod1', @@ -61,10 +61,27 @@ class TestClass: {u'state': u'finished', u'benchmark': u'ramspeed_vm.yaml'}, {u'state': u'finished', u'benchmark': u'dpi_vm.yaml'}, {u'state': u'finished', u'benchmark': u'ssl_vm.yaml'}], - 'result': []}) + 'result': 0}) ]) @mock.patch('restful_server.qtip_server.args_handler.prepare_and_run_benchmark') def test_post_get_delete_job_successful(self, mock_args_handler, app_client, body, expected): + mock_args_handler.return_value = {'result': 0, + 'detail': {'host': [(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})]}} + reply = app_client.post("/api/v1.0/jobs", data=body) print(reply.data) id = json.loads(reply.data)['job_id'] diff --git a/tests/spawn_vm_test.py b/tests/spawn_vm_test.py index eb843ad9..b22745d7 100644 --- a/tests/spawn_vm_test.py +++ b/tests/spawn_vm_test.py @@ -10,15 +10,6 @@ class KeystoneMock(MagicMock): v2_0 = Mock() -class ImageMock(MagicMock): - name = 'QTIP_CentOS' - - -class ImagesMock(MagicMock): - def list(self): - return [ImageMock()] - - class StackMock(MagicMock): status = 'COMPLETE' outputs = [{'output_key': 'availability_instance_1', @@ -55,13 +46,11 @@ class TestClass: @mock.patch('func.spawn_vm.FetchImg') @mock.patch('func.spawn_vm.create_zones') @mock.patch('func.spawn_vm.client', autospec=True) - @mock.patch('func.spawn_vm.glanceclient', autospec=True) @mock.patch('func.spawn_vm.keystoneclient.v2_0', autospec=True) @mock.patch('func.spawn_vm.heatclient.client', autospec=True) - def test_create_zones_success(self, mock_heat, mock_keystone, mock_glance, + def test_create_zones_success(self, mock_heat, mock_keystone, mock_nova_client, mock_zone, mock_fetch, mock_setup, test_input, expected): - mock_glance.Client.return_value = Mock(images=ImagesMock()) mock_nova_client.Client.return_value = Mock() mock_heat.Client.return_value = Mock(stacks=HeatMock()) k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel'}) |