Skip to content

Commit

Permalink
Merge pull request #41 from reactiveops/sudermanjr/fix-40
Browse files Browse the repository at this point in the history
Fixes #40.  Handle the minimum error exception
  • Loading branch information
Andrew Suderman authored Jan 16, 2019
2 parents d6108e9 + 911b93b commit a274c36
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.11.1]

### Fixed
- output when minimum versions are not met is no longer a stacktrace
- Fixes #40

## [0.11.0]

### Added
Expand Down
8 changes: 6 additions & 2 deletions reckoner/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
import semver
import traceback
import reckoner
import sys

import oyaml as yaml

Expand Down Expand Up @@ -74,7 +74,11 @@ def __init__(self, file):
self.helm.repo_update()

if not self.config.local_development:
self._compare_required_versions()
try:
self._compare_required_versions()
except MinimumVersionException as e:
logging.error(e)
sys.exit(1)

def __str__(self):
return str(self._dict)
Expand Down
2 changes: 1 addition & 1 deletion reckoner/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.11.0'
__version__ = '0.11.1'
__author__ = 'ReactiveOps, Inc.'
61 changes: 61 additions & 0 deletions reckoner/tests/test_course.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import mock
import unittest
from reckoner.exception import MinimumVersionException
from reckoner.course import Course


@mock.patch('reckoner.repository.Repository', autospec=True)
@mock.patch('reckoner.course.sys')
@mock.patch('reckoner.course.yaml', autospec=True)
@mock.patch('reckoner.course.HelmClient', autospec=True)
@mock.patch('reckoner.course.Config', autospec=True)
class TestMinVersion(unittest.TestCase):
def test_init_error_fails_min_version_reckoner(self, configMock, helmClientMock, yamlLoadMock, sysMock, repoMock):
"""Tests that minimum version will throw an exit."""
c = configMock()
c.helm_args = ['provided args']
c.local_development = False

yamlLoadMock.load.return_value = {
'repositories': {
'name': {},
},
'helm_args': None,
'minimum_versions': {
'reckoner': '1000.1000.1000', # minimum version needed
# find the version of reckoner at meta.py __version__
}
}

sysMock.exit.return_value = None

course = Course(None)

sysMock.exit.assert_called_once
return True

def test_init_error_fails_min_version_helm(self, configMock, helmClientMock, yamlLoadMock, sysMock, repoMock):
"""Tests that minimum version will throw an exit."""
c = configMock()
c.helm_args = ['provided args']
c.local_development = False

h = helmClientMock()
h.client_version = '0.0.1'

yamlLoadMock.load.return_value = {
'repositories': {
'name': {},
},
'helm_args': None,
'minimum_versions': {
'helm': '1000.1000.1000', # minimum version needed
}
}

sysMock.exit.return_value = None

course = Course(None)

sysMock.exit.assert_called_once
return True
2 changes: 1 addition & 1 deletion tests/test_course.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories:
url: https://kubernetes-charts-incubator.storage.googleapis.com
minimum_versions: #set minimum version requirements here
helm: 2.8.2
reckoner: 0.5.0
reckoner: 0.0.0
helm_args:
- --recreate-pods
charts:
Expand Down
5 changes: 0 additions & 5 deletions tests/test_reckoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,6 @@ def test_course_values(self):
self.assertEqual(self.c.minimum_versions.keys(), test_minimum_versions)
self.assertIsInstance(self.c.repositories, list)

def test_minimum_version(self):
self.configure_subprocess_mock(test_helm_version_return_string, '', 0)
self.c.minimum_versions['reckoner'] = test_reckoner_version
self.assertRaises(MinimumVersionException, self.c._compare_required_versions)

def test_plot_course(self):
self.configure_subprocess_mock('', '', 0) # TODO: Lots of work do do here on installation of the list of charts
self.c.plot(list(self.c._dict['charts']))
Expand Down

0 comments on commit a274c36

Please sign in to comment.