From: zhang ab Date: Tue, 27 Mar 2018 02:29:53 +0000 (+0000) Subject: Merge changes from topics 'add_config', 'fix_doc' X-Git-Tag: v1.1.2~26 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=d18b99f970b837e9708f2b9118a382fb3b9e78d3;hp=382204d0cc69fcd33f734ff3e172dcb5d5515b6b;p=multicloud%2Fframework.git Merge changes from topics 'add_config', 'fix_doc' * changes: Add port of api server as configuration Hack the python path --- diff --git a/.gitignore b/.gitignore index 9787425..a5beebe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .project .classpath +.vscode .settings/ .checkstyle target/ diff --git a/docs/MultCloud-Test-CSIT.rst b/docs/MultCloud-Test-CSIT.rst new file mode 100644 index 0000000..63fd87f --- /dev/null +++ b/docs/MultCloud-Test-CSIT.rst @@ -0,0 +1,18 @@ +Clone integration repo + + git clone http://gerrit.onap.org/r/integration + +Setup more contains if needed + +The file 'setup.sh' under 'test/csit/plans/multicloud/functionality1' will setup multicloud containers for CSIT test. +Add more tests + +The file 'testplan.txt' under 'test/csit/plans/multicloud/functionality1/' specific the robot tests to be run. + +The content of 'testplan.txt' will looks like following: + + # Test suites are relative paths under [integration.git]/test/csit/tests/. + # Place the suites in run order. + multicloud/provision/sanity_test_multivim.robot + +When adding tests to file 'multicloud/provision/sanity_test_multivim.robot' , a 'verify-csit' job will be trigger for related patch, and related change will be tested. diff --git a/multivimbroker/multivimbroker/pub/config/config.py b/multivimbroker/multivimbroker/pub/config/config.py index 727b0cc..e0385e2 100644 --- a/multivimbroker/multivimbroker/pub/config/config.py +++ b/multivimbroker/multivimbroker/pub/config/config.py @@ -13,7 +13,7 @@ import os # [MSB] -MSB_SERVICE_IP = '127.0.0.1' +MSB_SERVICE_IP = 'msb.onap.org' MSB_SERVICE_PORT = '10080' diff --git a/multivimbroker/multivimbroker/tests/test_fileutil.py b/multivimbroker/multivimbroker/tests/test_fileutil.py new file mode 100644 index 0000000..9840bde --- /dev/null +++ b/multivimbroker/multivimbroker/tests/test_fileutil.py @@ -0,0 +1,79 @@ +# Copyright (c) 2017-2018 VMware, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +import mock +import os +import unittest + +from multivimbroker.pub.utils import fileutil + + +class TestFileutil(unittest.TestCase): + + @mock.patch.object(os.path, "exists") + @mock.patch("os.makedirs") + def test_make_dirs_path_exists(self, mock_mkdir, mock_exists): + new_path = "/tmp/test" + mock_exists.return_value = True + fileutil.make_dirs(new_path) + mock_mkdir.assert_not_called() + + @mock.patch.object(os.path, "exists") + @mock.patch("os.makedirs") + def test_make_dirs_path_not_exists(self, mock_mkdir, mock_exists): + new_path = "/tmp/test" + mock_exists.return_value = False + fileutil.make_dirs(new_path) + mock_mkdir.assert_called_once_with(new_path, 0777) + + @mock.patch.object(os.path, "exists") + @mock.patch("shutil.rmtree") + def test_delete_dirs_success(self, mock_rmtree, mock_exists): + mock_exists.return_value = True + new_path = "/tmp/tests" + fileutil.delete_dirs(new_path) + mock_rmtree.assert_called_once_with(new_path) + + @mock.patch.object(os.path, "exists") + @mock.patch("shutil.rmtree") + def test_delete_dirs_failed(self, mock_rmtree, mock_exists): + mock_exists.return_value = True + mock_rmtree.side_effect = [Exception("Fake exception")] + new_path = "/tmp/tests" + fileutil.delete_dirs(new_path) + mock_rmtree.assert_called_once_with(new_path) + + @mock.patch.object(fileutil, "make_dirs") + @mock.patch("urllib2.urlopen") + def test_download_file_from_http_success(self, mock_urlopen, mock_mkdir): + url = "http://www.example.org/test.dat" + local_dir = "/tmp/" + file_name = "test.dat" + mock_req = mock.Mock() + mock_req.read.return_value = "hello world" + mock_urlopen.return_value = mock_req + m = mock.mock_open() + expect_ret = (True, "/tmp/test.dat") + with mock.patch('{}.open'.format(__name__), m, create=True): + ret = fileutil.download_file_from_http(url, local_dir, file_name) + self.assertEqual(expect_ret, ret) + + @mock.patch.object(fileutil, "make_dirs") + @mock.patch("urllib2.urlopen") + def test_download_file_from_http_fail(self, mock_urlopen, mock_mkdir): + url = "http://www.example.org/test.dat" + local_dir = "/tmp/" + file_name = "test.dat" + mock_req = mock.Mock() + mock_req.read.return_value = "hello world" + mock_urlopen.side_effect = [Exception("fake exception")] + expect_ret = (False, "/tmp/test.dat") + ret = fileutil.download_file_from_http(url, local_dir, file_name) + self.assertEqual(expect_ret, ret) diff --git a/multivimbroker/multivimbroker/tests/test_restcall.py b/multivimbroker/multivimbroker/tests/test_restcall.py index 235d58a..ea70dff 100644 --- a/multivimbroker/multivimbroker/tests/test_restcall.py +++ b/multivimbroker/multivimbroker/tests/test_restcall.py @@ -18,8 +18,8 @@ class TestRestCall(unittest.TestCase): def test_combine_url(self): url = ["http://a.com/test/", "http://a.com/test/", - "http://a.com/test"] - res = ["/resource", "resource", "/resource"] + "http://a.com/test", "http://a.com/test"] + res = ["/resource", "resource", "/resource", "resource"] expected = "http://a.com/test/resource" for i in range(len(url)): self.assertEqual(expected, restcall.combine_url(url[i], res[i])) @@ -49,7 +49,19 @@ class TestRestCall(unittest.TestCase): content = "no content" headers = None restcall.req_by_msb(res, method, content=content, headers=headers) - expect_url = "http://127.0.0.1:10080/" + expect_url = "http://msb.onap.org:10080/" mock_call.assert_called_once_with( expect_url, "", "", restcall.rest_no_auth, res, method, content, headers) + + @mock.patch("httplib2.Http.request") + def test_call_req_success(self, mock_req): + mock_resp = { + "status": "200" + } + resp_content = "hello" + mock_req.return_value = mock_resp, resp_content + expect_ret = [0, resp_content, "200", mock_resp] + ret = restcall.call_req("http://onap.org/", "user", "pass", + restcall.rest_no_auth, "vim", "GET") + self.assertEqual(expect_ret, ret)