Browse Source

test: Add test-specific timeout option

Currently, tests executed during chart deployment use the wait timeout
value, `wait.timeout`. This value can be too large of a timeout value
for Helm tests. This change introduces a timeout for tests,
`test.timeout` that is only used as a timeout for running Helm tests for
a release.

Story: 2003899

Depends-On: https://review.openstack.org/618355
Change-Id: Iee746444d5aede0b84b1805eb19f59f0f03c8f9e
changes/85/618585/7
Drew Walters 6 months ago
parent
commit
9a7c1f4006

+ 1
- 0
armada/const.py View File

@@ -24,6 +24,7 @@ KEYWORD_RELEASE = 'release'
24 24
 
25 25
 # Armada
26 26
 DEFAULT_CHART_TIMEOUT = 900
27
+DEFAULT_TEST_TIMEOUT = 300
27 28
 
28 29
 # Tiller
29 30
 DEFAULT_TILLER_TIMEOUT = 300

+ 4
- 11
armada/handlers/chart_deploy.py View File

@@ -244,25 +244,18 @@ class ChartDeploy(object):
244 244
         run_test = test_handler.test_enabled and (just_deployed or
245 245
                                                   not last_test_passed)
246 246
         if run_test:
247
-            timer = int(round(deadline - time.time()))
248
-            self._test_chart(release_name, timer, test_handler)
247
+            self._test_chart(release_name, test_handler)
249 248
 
250 249
         return result
251 250
 
252
-    def _test_chart(self, release_name, timeout, test_handler):
251
+    def _test_chart(self, release_name, test_handler):
253 252
         if self.dry_run:
254 253
             LOG.info(
255 254
                 'Skipping test during `dry-run`, would have tested '
256
-                'release=%s with timeout %ss.', release_name, timeout)
255
+                'release=%s', release_name)
257 256
             return True
258 257
 
259
-        if timeout <= 0:
260
-            reason = ('Timeout expired before testing '
261
-                      'release %s' % release_name)
262
-            LOG.error(reason)
263
-            raise armada_exceptions.ArmadaTimeoutException(reason)
264
-
265
-        success = test_handler.test_release_for_success(timeout=timeout)
258
+        success = test_handler.test_release_for_success()
266 259
         if not success:
267 260
             raise tiller_exceptions.TestFailedException(release_name)
268 261
 

+ 10
- 7
armada/handlers/test.py View File

@@ -58,6 +58,8 @@ class Test(object):
58 58
 
59 59
         test_values = self.chart.get('test', None)
60 60
 
61
+        self.timeout = const.DEFAULT_TEST_TIMEOUT
62
+
61 63
         # NOTE(drewwalters96): Support the chart_group `test_charts` key until
62 64
         # its deprecation period ends. The `test.enabled`, `enable_all` flag,
63 65
         # and deprecated, boolean `test` key override this value if provided.
@@ -79,6 +81,7 @@ class Test(object):
79 81
             # provided.
80 82
             if self.cleanup is None:
81 83
                 self.cleanup = True
84
+
82 85
         elif test_values:
83 86
             test_enabled_opt = test_values.get('enabled')
84 87
             if test_enabled_opt is not None:
@@ -90,6 +93,8 @@ class Test(object):
90 93
             if self.cleanup is None:
91 94
                 test_options = test_values.get('options', {})
92 95
                 self.cleanup = test_options.get('cleanup', False)
96
+
97
+            self.timeout = test_values.get('timeout', self.timeout)
93 98
         else:
94 99
             # Default cleanup value
95 100
             if self.cleanup is None:
@@ -98,16 +103,14 @@ class Test(object):
98 103
         if enable_all:
99 104
             self.test_enabled = True
100 105
 
101
-    def test_release_for_success(self, timeout=const.DEFAULT_TILLER_TIMEOUT):
106
+    def test_release_for_success(self):
102 107
         """Run the Helm tests corresponding to a release for success (i.e. exit
103 108
         code 0).
104 109
 
105
-        :param timeout: Timeout value for a release's tests completion
106
-        :type timeout: int
107
-
108
-        :rtype: Helm test suite run result
110
+        :return: Helm test suite run result
109 111
         """
110
-        LOG.info('RUNNING: %s tests', self.release_name)
112
+        LOG.info('RUNNING: %s tests with timeout=%ds', self.release_name,
113
+                 self.timeout)
111 114
 
112 115
         try:
113 116
             self.delete_test_pods()
@@ -116,7 +119,7 @@ class Test(object):
116 119
                           self.release_name)
117 120
 
118 121
         test_suite_run = self.tiller.test_release(
119
-            self.release_name, timeout=timeout, cleanup=self.cleanup)
122
+            self.release_name, timeout=self.timeout, cleanup=self.cleanup)
120 123
 
121 124
         success = get_test_suite_run_success(test_suite_run)
122 125
         if success:

+ 2
- 0
armada/schemas/armada-chart-schema.yaml View File

@@ -66,6 +66,8 @@ data:
66 66
           properties:
67 67
             enabled:
68 68
               type: boolean
69
+            timeout:
70
+              type: integer
69 71
             options:
70 72
               type: object
71 73
               properties:

+ 40
- 0
armada/tests/unit/handlers/test_test.py View File

@@ -14,6 +14,8 @@
14 14
 
15 15
 import mock
16 16
 
17
+from armada import const
18
+
17 19
 from armada.handlers import test
18 20
 from armada.handlers import tiller
19 21
 from armada.tests.unit import base
@@ -188,6 +190,16 @@ class TestHandlerTestCase(base.ArmadaTestCase):
188 190
         assert test_handler.test_enabled is True
189 191
         assert test_handler.cleanup is True
190 192
 
193
+    def test_deprecated_test_key_timeout(self):
194
+        """Test that the default Tiller timeout is used when tests are enabled
195
+        using the deprecated, boolean value for a chart's `test` key.
196
+        """
197
+        mock_tiller = mock.Mock()
198
+        test_handler = test.Test(
199
+            chart={'test': True}, release_name='release', tiller=mock_tiller)
200
+
201
+        assert test_handler.timeout == const.DEFAULT_TEST_TIMEOUT
202
+
191 203
     def test_tests_disabled(self):
192 204
         """Test that tests are disabled by a chart's values using the
193 205
         `test.enabled` path.
@@ -276,3 +288,31 @@ class TestHandlerTestCase(base.ArmadaTestCase):
276 288
 
277 289
         assert test_handler.test_enabled is True
278 290
         assert test_handler.cleanup is True
291
+
292
+    def test_default_timeout_value(self):
293
+        """Test that the default timeout value is used if a test timeout value,
294
+        `test.timeout` is not provided.
295
+        """
296
+        test_handler = test.Test(
297
+            chart={'test': {
298
+                'enabled': True
299
+            }},
300
+            release_name='release',
301
+            tiller=mock.Mock(),
302
+            cleanup=True)
303
+
304
+        assert test_handler.timeout == const.DEFAULT_TILLER_TIMEOUT
305
+
306
+    def test_timeout_value(self):
307
+        """Test that a chart's test timeout value, `test.timeout` overrides the
308
+        default test timeout.
309
+        """
310
+        chart = {'test': {'enabled': True, 'timeout': 800}}
311
+
312
+        test_handler = test.Test(
313
+            chart=chart,
314
+            release_name='release',
315
+            tiller=mock.Mock(),
316
+            cleanup=True)
317
+
318
+        assert test_handler.timeout is chart['test']['timeout']

+ 2
- 0
doc/source/operations/guide-build-armada-yaml.rst View File

@@ -174,6 +174,8 @@ Run helm tests on the chart after install/upgrade.
174 174
 +=============+==========+====================================================================+
175 175
 | enabled     | bool     | whether to enable/disable helm tests for this chart (default True) |
176 176
 +-------------+----------+--------------------------------------------------------------------+
177
+| timeout     | int      | time (in sec) to wait for completion of Helm tests                 |
178
++-------------+----------+--------------------------------------------------------------------+
177 179
 | options     | object   | See `Test Options`_.                                               |
178 180
 +-------------+----------+--------------------------------------------------------------------+
179 181
 

Loading…
Cancel
Save