diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-02-28 19:03:10 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-02-28 19:03:10 +0000 |
| commit | 5311f86822fab4bddd11018399b23dfd4119daf4 (patch) | |
| tree | c88489c73d5fb6d54dd9f6a2bc6c25a314bf869c | |
| parent | 0c7cf6fdc4c0bdc6de50de2a48579f4a62aaf132 (diff) | |
| parent | 320c1f92724d6c7bce45398dd783c4334969d23d (diff) | |
| download | kolla-5311f86822fab4bddd11018399b23dfd4119daf4.tar.gz kolla-5311f86822fab4bddd11018399b23dfd4119daf4.zip | |
Merge "Add timeout to requests.get() in kolla/cmd/build.py"
| -rwxr-xr-x | kolla/cmd/build.py | 9 | ||||
| -rw-r--r-- | kolla/common/config.py | 2 | ||||
| -rw-r--r-- | kolla/tests/test_build.py | 22 |
3 files changed, 32 insertions, 1 deletions
diff --git a/kolla/cmd/build.py b/kolla/cmd/build.py index dcbef7718..42eaa3011 100755 --- a/kolla/cmd/build.py +++ b/kolla/cmd/build.py @@ -164,7 +164,14 @@ class WorkerThread(threading.Thread): if source.get('type') == 'url': LOG.debug("%s:Getting archive from %s", image['name'], source['source']) - r = requests.get(source['source']) + try: + r = requests.get(source['source'], timeout=self.conf.timeout) + except requests_exc.Timeout: + LOG.exception('Request timed out while getting archive' + ' from %s', source['source']) + image['status'] = "error" + image['logs'] = str() + return if r.status_code == 200: with open(dest_archive, 'wb') as f: diff --git a/kolla/common/config.py b/kolla/common/config.py index f8629e438..2eeb8c9ca 100644 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -131,6 +131,8 @@ _CLI_OPTS = [ cfg.BoolOpt('template-only', default=False, deprecated_group='kolla-build', help=("Don't build images. Generate Dockerfile only")), + cfg.IntOpt('timeout', default=120, + help='Time in seconds after which any operation times out'), ] _BASE_OPTS = [ diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index 76020ef2a..b6eeffa7d 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -14,6 +14,7 @@ import fixtures import itertools import mock import os +import requests from kolla.cmd import build from kolla.tests import base @@ -106,6 +107,27 @@ class WorkerThreadTest(base.TestCase): nocache=False, rm=True, pull=True, forcerm=True, buildargs=build_args) + @mock.patch('docker.Client') + @mock.patch('requests.get') + def test_requests_get_timeout(self, mock_get, mock_client): + worker = build.WorkerThread(mock.Mock(), + mock.Mock(), + self.conf) + self.image['source'] = { + 'source': 'http://fake/source', + 'type': 'url', + 'name': 'fake-image-base' + } + mock_get.side_effect = requests.exceptions.Timeout + get_result = worker.process_source(self.image, + self.image['source']) + + self.assertIsNone(get_result) + self.assertEqual(self.image['status'], 'error') + self.assertEqual(self.image['logs'], str()) + mock_get.assert_called_once_with(self.image['source']['source'], + timeout=120) + class KollaWorkerTest(base.TestCase): |
