Lazy load plugin list
This will allow us to wait for jenkins to come up properly before getting this list. Otherwise we'd have to duplicate the error handling logic. Change-Id: I663bf32e53e917284d93422526078b4dcf76e9c1
This commit is contained in:
parent
b43eb4ee35
commit
de2b287d6d
@ -730,11 +730,13 @@ class Builder(object):
|
||||
self.cache = CacheStorage(jenkins_url, flush=flush_cache)
|
||||
self.global_config = config
|
||||
self.ignore_cache = ignore_cache
|
||||
self._plugins_list = plugins_list
|
||||
|
||||
if plugins_list is None:
|
||||
self.plugins_list = self.jenkins.get_plugins_info()
|
||||
else:
|
||||
self.plugins_list = plugins_list
|
||||
@property
|
||||
def plugins_list(self):
|
||||
if self._plugins_list is None:
|
||||
self._plugins_list = self.jenkins.get_plugins_info()
|
||||
return self._plugins_list
|
||||
|
||||
def load_files(self, fn):
|
||||
self.parser = YamlParser(self.global_config, self.plugins_list)
|
||||
|
41
tests/builder/test_builder.py
Normal file
41
tests/builder/test_builder.py
Normal file
@ -0,0 +1,41 @@
|
||||
# vim: set fileencoding=utf-8 :
|
||||
#
|
||||
# - Copyright 2014 Guido Günther <agx@sigxcpu.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, 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 mock
|
||||
|
||||
import jenkins_jobs.builder
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
|
||||
class TestCaseTestBuilder(TestCase):
|
||||
def setUp(self):
|
||||
self.builder = jenkins_jobs.builder.Builder(
|
||||
'http://jenkins.example.com',
|
||||
'doesnot', 'matter',
|
||||
plugins_list=['plugin1', 'plugin2'],
|
||||
)
|
||||
TestCase.setUp(self)
|
||||
|
||||
def test_plugins_list(self):
|
||||
self.assertEqual(self.builder.plugins_list, ['plugin1', 'plugin2'])
|
||||
|
||||
@mock.patch.object(jenkins_jobs.builder.jenkins.Jenkins,
|
||||
'get_plugins_info', return_value=['p1', 'p2'])
|
||||
def test_plugins_list_from_jenkins(self, jenkins_mock):
|
||||
# Trigger fetching the plugins from jenkins when accessing the property
|
||||
self.builder._plugins_list = None
|
||||
self.assertEqual(self.builder.plugins_list, ['p1', 'p2'])
|
Loading…
Reference in New Issue
Block a user