From cd0242780e52ed0a9c9a060d921ec4a745f8b866 Mon Sep 17 00:00:00 2001 From: Marshall Margenau Date: Thu, 12 Jul 2018 13:57:22 -0500 Subject: [PATCH] Run helm tests by default - Armada will now run helm tests by default, and the charts must disable tests if they choose. A helm test that does not exist is still a happy-path resolution. - Documentation and schema updates to signify new deault behavior. - Preparing to deprecate `test_charts` in ChartGroup processing. Change-Id: I8e51e33a5d9559b11c2b75e122ecfc97af084ca4 --- armada/handlers/armada.py | 37 ++++++++++++------- armada/schemas/armada-chart-schema.yaml | 4 +- armada/schemas/armada-chartgroup-schema.yaml | 1 + armada/tests/unit/handlers/test_armada.py | 2 +- .../unit/resources/keystone-manifest.yaml | 1 - .../unit/resources/valid_armada_document.yaml | 1 - .../operations/guide-build-armada-yaml.rst | 31 +++++++++++----- examples/keystone-manifest.yaml | 1 - 8 files changed, 47 insertions(+), 31 deletions(-) diff --git a/armada/handlers/armada.py b/armada/handlers/armada.py index bdc0b009..b0e1ce02 100644 --- a/armada/handlers/armada.py +++ b/armada/handlers/armada.py @@ -254,11 +254,19 @@ class Armada(object): cg_name = chartgroup.get('name', '') cg_desc = chartgroup.get('description', '') cg_sequenced = chartgroup.get('sequenced', False) - cg_test_all_charts = chartgroup.get('test_charts', False) - LOG.info( - 'Processing ChartGroup: %s (%s), sequenced=%s, ' - 'test_charts=%s', cg_name, cg_desc, cg_sequenced, - cg_test_all_charts) + LOG.info('Processing ChartGroup: %s (%s), sequenced=%s', cg_name, + cg_desc, cg_sequenced) + + # TODO(MarshM): Deprecate the `test_charts` key + cg_test_all_charts = chartgroup.get('test_charts') + if isinstance(cg_test_all_charts, bool): + LOG.warn('The ChartGroup `test_charts` key is deprecated, ' + 'and support for this will be removed. See the ' + 'Chart `test` key for more information.') + else: + # This key defaults to True. Individual charts must + # explicitly disable helm tests if they choose + cg_test_all_charts = True ns_label_set = set() tests_to_run = [] @@ -363,7 +371,8 @@ class Armada(object): 'instead.') test_this_chart = test_chart_override else: - test_this_chart = test_chart_override['enabled'] + # NOTE: helm tests are enabled by default + test_this_chart = test_chart_override.get('enabled', True) test_cleanup = test_chart_override.get('options', {}).get( 'cleanup', False) @@ -474,25 +483,19 @@ class Armada(object): tiller_result.__dict__) msg['install'].append(release_name) - # Sequenced ChartGroup should run tests after each Chart + # Keeping track of time remaining timer = int(round(deadline - time.time())) test_chart_args = (release_name, timer, test_cleanup) if test_this_chart: + # Sequenced ChartGroup should run tests after each Chart if cg_sequenced: LOG.info( 'Running sequenced test, timeout remaining: ' '%ss.', timer) - if timer <= 0: - reason = ('Timeout expired before testing ' - 'sequenced release %s' % release_name) - LOG.error(reason) - raise armada_exceptions.ArmadaTimeoutException( - reason) self._test_chart(*test_chart_args) # Un-sequenced ChartGroup should run tests at the end else: - # Keeping track of time remaining tests_to_run.append( functools.partial(self._test_chart, *test_chart_args)) @@ -574,6 +577,12 @@ class Armada(object): 'release=%s with timeout %ss.', release_name, timeout) return True + if timeout <= 0: + reason = ('Timeout expired before testing ' + 'release %s' % release_name) + LOG.error(reason) + raise armada_exceptions.ArmadaTimeoutException(reason) + success = test_release_for_success( self.tiller, release_name, timeout=timeout, cleanup=cleanup) if success: diff --git a/armada/schemas/armada-chart-schema.yaml b/armada/schemas/armada-chart-schema.yaml index 6a710563..954f2032 100644 --- a/armada/schemas/armada-chart-schema.yaml +++ b/armada/schemas/armada-chart-schema.yaml @@ -73,9 +73,7 @@ data: type: boolean additionalProperties: false additionalProperties: false - required: - - enabled - + # TODO(MarshM): Deprecate this `timeout` in favor of `wait.timeout` timeout: type: integer wait: diff --git a/armada/schemas/armada-chartgroup-schema.yaml b/armada/schemas/armada-chartgroup-schema.yaml index 36b3ac46..a7e66ddd 100644 --- a/armada/schemas/armada-chartgroup-schema.yaml +++ b/armada/schemas/armada-chartgroup-schema.yaml @@ -27,6 +27,7 @@ data: type: string sequenced: type: boolean + # TODO(MarshM): Deprecate `test_charts`, it is no longer useful test_charts: type: boolean chart_group: diff --git a/armada/tests/unit/handlers/test_armada.py b/armada/tests/unit/handlers/test_armada.py index 66984c37..c9f6b359 100644 --- a/armada/tests/unit/handlers/test_armada.py +++ b/armada/tests/unit/handlers/test_armada.py @@ -334,7 +334,7 @@ class ArmadaHandlerTestCase(base.ArmadaTestCase): chart_group = armada_obj.manifest['armada']['chart_groups'][0] charts = chart_group['chart_group'] - cg_test_all_charts = chart_group.get('test_charts', False) + cg_test_all_charts = chart_group.get('test_charts', True) m_tiller = mock_tiller.return_value m_tiller.list_charts.return_value = known_releases diff --git a/armada/tests/unit/resources/keystone-manifest.yaml b/armada/tests/unit/resources/keystone-manifest.yaml index 83d84fb4..5d6b5f72 100644 --- a/armada/tests/unit/resources/keystone-manifest.yaml +++ b/armada/tests/unit/resources/keystone-manifest.yaml @@ -120,7 +120,6 @@ metadata: data: description: "Deploying OpenStack Keystone" sequenced: True - test_charts: False chart_group: - keystone --- diff --git a/armada/tests/unit/resources/valid_armada_document.yaml b/armada/tests/unit/resources/valid_armada_document.yaml index 63d30b84..00a388e1 100644 --- a/armada/tests/unit/resources/valid_armada_document.yaml +++ b/armada/tests/unit/resources/valid_armada_document.yaml @@ -124,7 +124,6 @@ metadata: data: description: "Deploying OpenStack Keystone" sequenced: True - test_charts: False chart_group: - keystone --- diff --git a/doc/source/operations/guide-build-armada-yaml.rst b/doc/source/operations/guide-build-armada-yaml.rst index 2346a1c0..5120c0b8 100644 --- a/doc/source/operations/guide-build-armada-yaml.rst +++ b/doc/source/operations/guide-build-armada-yaml.rst @@ -52,9 +52,15 @@ armada/ChartGroup/v1 +-----------------+----------+------------------------------------------------------------------------+ | sequenced | bool | enables sequenced chart deployment in a group | +-----------------+----------+------------------------------------------------------------------------+ -| test_charts | bool | run pre-defined helm tests helm in a ChartGroup | +| test_charts | bool | run pre-defined helm tests in a ChartGroup (DEPRECATED) | +-----------------+----------+------------------------------------------------------------------------+ +.. DANGER:: + + DEPRECATION: The ``test_charts`` key will be removed, as Armada will run + helm tests for all charts by default. + + Chart Group Example ^^^^^^^^^^^^^^^^^^^ @@ -98,7 +104,7 @@ Chart | protected | object | do not delete FAILED releases when encountered from previous run (provide the | | | | 'continue_processing' bool to continue or halt execution (default: halt)) | +-----------------+----------+---------------------------------------------------------------------------------------+ -| test | object | Run helm tests on the chart after install/upgrade | +| test | object | Run helm tests on the chart after install/upgrade (default enabled) | +-----------------+----------+---------------------------------------------------------------------------------------+ | install | object | install the chart into your Kubernetes cluster | +-----------------+----------+---------------------------------------------------------------------------------------+ @@ -116,20 +122,25 @@ Chart Test ^^^^ -+-------------+----------+---------------------------------------------------------------+ -| keyword | type | action | -+=============+==========+===============================================================+ -| enabled | bool | whether to enable helm tests for this chart | -+-------------+----------+---------------------------------------------------------------+ -| options | object | options to pass through to helm | -+-------------+----------+---------------------------------------------------------------+ ++-------------+----------+--------------------------------------------------------------------+ +| keyword | type | action | ++=============+==========+====================================================================+ +| enabled | bool | whether to enable/disable helm tests for this chart (default True) | ++-------------+----------+--------------------------------------------------------------------+ +| options | object | options to pass through to helm | ++-------------+----------+--------------------------------------------------------------------+ + +.. note:: + + Armada will attempt to run helm tests by default. They may be disabled by + setting the ``enabled`` key to ``False``. .. DANGER:: DEPRECATION: In addition to an object with the above fields, the ``test`` key currently also supports ``bool``, which maps to ``enabled``, but this is deprecated and will be removed. The ``cleanup`` option below is set to true - in this case for backward compatability. + in this case for backward compatibility. Test - Options ^^^^^^^^^^^^^^ diff --git a/examples/keystone-manifest.yaml b/examples/keystone-manifest.yaml index a89b379f..c4147cd0 100644 --- a/examples/keystone-manifest.yaml +++ b/examples/keystone-manifest.yaml @@ -125,7 +125,6 @@ metadata: data: description: "Deploying OpenStack Keystone" sequenced: True - test_charts: False chart_group: - keystone ---