From f4303037ccb3c3e4e85d909db846743a5e9fb7eb Mon Sep 17 00:00:00 2001 From: drewwalters96 Date: Wed, 28 Jun 2017 18:35:27 +0000 Subject: [PATCH] [Bug] Adds required Oslo configuration to API and unit tests - Register Oslo logging configurations in server.py, test_armada.py, test_chartbuilder.py, and test_tiller.py - Add mock to test-requirements.txt - Update .travis.yml - Add mock case for tiller IP --- .travis.yml | 2 +- armada/tests/unit/handlers/test_armada.py | 11 ++++++++--- armada/tests/unit/handlers/test_chartbuilder.py | 7 ++++--- armada/tests/unit/handlers/test_tiller.py | 14 +++++++++++--- server.py | 5 ++++- test-requirements.txt | 1 + tox.ini | 4 ++-- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0ddfee2..b6496b5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ install: script: - flake8 - armada -h - - nosetests -w ./armada --with-coverage --cover-package=armada --cover-tests + - nosetests -w armada/tests/unit --cover-package=armada --with-coverage --cover-tests # after_success: # - codecov diff --git a/armada/tests/unit/handlers/test_armada.py b/armada/tests/unit/handlers/test_armada.py index d1f7082e..e3593757 100644 --- a/armada/tests/unit/handlers/test_armada.py +++ b/armada/tests/unit/handlers/test_armada.py @@ -1,9 +1,13 @@ -from armada.handlers.armada import Armada - import mock import unittest import yaml +# Required Oslo configuration setup +from armada.conf import default +default.register_opts() + +from armada.handlers.armada import Armada + class ArmadaTestCase(unittest.TestCase): test_yaml = """ endpoints: &endpoints @@ -41,7 +45,7 @@ class ArmadaTestCase(unittest.TestCase): """ @mock.patch('armada.handlers.armada.ChartBuilder') - @mock.patch('armada.handlers.tiller.Tiller') + @mock.patch('armada.handlers.armada.Tiller') def test_install(self, mock_tiller, mock_chartbuilder): '''Test install functionality from the sync() method''' @@ -81,6 +85,7 @@ class ArmadaTestCase(unittest.TestCase): timeout=chart_2['timeout'])] mock_tiller.install_release.assert_has_calls(method_calls) + @unittest.skip('skipping update') def test_upgrade(self): '''Test upgrade functionality from the sync() method''' # TODO diff --git a/armada/tests/unit/handlers/test_chartbuilder.py b/armada/tests/unit/handlers/test_chartbuilder.py index fdd6eae3..964ab5b6 100644 --- a/armada/tests/unit/handlers/test_chartbuilder.py +++ b/armada/tests/unit/handlers/test_chartbuilder.py @@ -11,15 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - - import unittest import mock from supermutes.dot import dotify -from armada.handlers.chartbuilder import ChartBuilder +# Required Oslo configuration setup +from armada.conf import default +default.register_opts() +from armada.handlers.chartbuilder import ChartBuilder class ChartBuilderTestCase(unittest.TestCase): chart_stream = """ diff --git a/armada/tests/unit/handlers/test_tiller.py b/armada/tests/unit/handlers/test_tiller.py index 9230e949..786d2cde 100644 --- a/armada/tests/unit/handlers/test_tiller.py +++ b/armada/tests/unit/handlers/test_tiller.py @@ -1,19 +1,27 @@ -from armada.handlers.tiller import Tiller - import mock import unittest +# Required Oslo configuration setup +from armada.conf import default +default.register_opts() + +from armada.handlers.tiller import Tiller + class TillerTestCase(unittest.TestCase): + @mock.patch.object(Tiller, '_get_tiller_ip') + @mock.patch('armada.handlers.tiller.K8s') @mock.patch('armada.handlers.tiller.grpc') @mock.patch('armada.handlers.tiller.Config') @mock.patch('armada.handlers.tiller.InstallReleaseRequest') @mock.patch('armada.handlers.tiller.ReleaseServiceStub') def test_install_release(self, mock_stub, mock_install_request, - mock_config, mock_grpc): + mock_config, mock_grpc, mock_k8s, mock_ip): # instantiate Tiller object mock_grpc.insecure_channel.return_value = None + mock_ip.return_value = '0.0.0.0' tiller = Tiller() + assert tiller._get_tiller_ip() == '0.0.0.0' # set params chart = mock.Mock() diff --git a/server.py b/server.py index 6060b5e4..ace2fd97 100644 --- a/server.py +++ b/server.py @@ -13,6 +13,7 @@ # limitations under the License. # +from armada.conf import default import falcon import json @@ -21,6 +22,9 @@ from falcon import HTTP_200 from oslo_config import cfg from oslo_log import log as logging +# Required Oslo configuration setup +default.register_opts() + from armada.handlers.tiller import Tiller as tillerHandler from armada.handlers.armada import Armada as armadaHandler @@ -28,7 +32,6 @@ LOG = logging.getLogger(__name__) CONF = cfg.CONF DOMAIN = "armada" -logging.register_options(CONF) logging.setup(CONF, DOMAIN) class Tiller(object): diff --git a/test-requirements.txt b/test-requirements.txt index ef2749bf..5066d592 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,3 +9,4 @@ flake8==3.3.0 nose==1.3.7 testtools==2.3.0 codecov +mock diff --git a/tox.ini b/tox.ini index f21fe111..6259d9f9 100644 --- a/tox.ini +++ b/tox.ini @@ -24,7 +24,7 @@ commands = flake8 . [testenv:testing] commands = nosetest -w armada -[flake8] -ignore=E302,H306 +[flake8] #TODO: Remove E402 +ignore=E302,H306,E402 exclude= libgit2-0.25.0, .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi