diff --git a/.gitignore b/.gitignore index ff3d4d717..55f16a11a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .*.swp *.egg +*.eggs *.egg-info *.pyc .test diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 62aad784a..1c60d25ae 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -109,7 +109,8 @@ class JenkinsManager(object): Jenkins instance. """ try: - plugins_list = self.jenkins.get_plugins_info() + plugins_list = self.jenkins.get_plugins().values() + except jenkins.JenkinsException as e: if re.search("Connection refused", str(e)): logger.warning( diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py index 1d14cf506..d714b29a1 100644 --- a/jenkins_jobs/cli/entry.py +++ b/jenkins_jobs/cli/entry.py @@ -106,8 +106,8 @@ class JenkinsJobs(object): key = 'CTRL+Z' else: key = 'CTRL+D' - logger.warn("Reading configuration from STDIN. " - "Press %s to end input.", key) + logger.warning("Reading configuration from STDIN. " + "Press %s to end input.", key) else: # take list of paths self.options.path = self.options.path.split(os.pathsep) diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py index 19d13b82d..cf172815f 100644 --- a/jenkins_jobs/config.py +++ b/jenkins_jobs/config.py @@ -113,8 +113,8 @@ class JJBConfig(object): if config_file_required: raise JJBConfigException(CONFIG_REQUIRED_MESSAGE) else: - logger.warn("Config file, {0}, not found. Using default " - "config values.".format(conf)) + logger.warning("Config file, {0}, not found. Using " + "default config values.".format(conf)) if config_fp is not None: if PY2: @@ -172,10 +172,10 @@ class JJBConfig(object): # check the ignore_cache setting if config.has_option('jenkins', 'ignore_cache'): - logging.warn("ignore_cache option should be moved to the " - "[job_builder] section in the config file, the " - "one specified in the [jenkins] section will be " - "ignored in the future") + logging.warning("ignore_cache option should be moved to the " + "[job_builder] section in the config file, the " + "one specified in the [jenkins] section will be " + "ignored in the future") self.ignore_cache = config.getboolean('jenkins', 'ignore_cache') elif config.has_option('job_builder', 'ignore_cache'): self.ignore_cache = config.getboolean('job_builder', diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py index fc8e66b21..473b592de 100644 --- a/jenkins_jobs/local_yaml.py +++ b/jenkins_jobs/local_yaml.py @@ -365,10 +365,10 @@ class YamlIncludeRawEscape(YamlIncludeRaw): def from_yaml(cls, loader, node): data = YamlIncludeRaw.from_yaml(loader, node) if isinstance(data, LazyLoader): - logger.warn("Replacing %s tag with %s since lazy loading means " - "file contents will not be deep formatted for " - "variable substitution.", cls.yaml_tag, - YamlIncludeRaw.yaml_tag) + logger.warning("Replacing %s tag with %s since lazy loading means " + "file contents will not be deep formatted for " + "variable substitution.", cls.yaml_tag, + YamlIncludeRaw.yaml_tag) return data else: return loader.escape_callback(data) diff --git a/jenkins_jobs/modules/notifications.py b/jenkins_jobs/modules/notifications.py index ddb1139d3..d9b4c56c4 100644 --- a/jenkins_jobs/modules/notifications.py +++ b/jenkins_jobs/modules/notifications.py @@ -56,13 +56,13 @@ def http_endpoint(registry, xml_parent, data): 'com.tikal.hudson.plugins.notification.' 'Endpoint') supported_formats = ['JSON', 'XML'] - format = data.get('format', 'JSON').upper() - if format not in supported_formats: + fmt = data.get('format', 'JSON').upper() + if fmt not in supported_formats: raise JenkinsJobsException( "format must be one of %s" % ", ".join(supported_formats)) else: - XML.SubElement(endpoint_element, 'format').text = format + XML.SubElement(endpoint_element, 'format').text = fmt XML.SubElement(endpoint_element, 'protocol').text = 'HTTP' diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 737758a5b..356572d9f 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -747,7 +747,7 @@ def slack(registry, xml_parent, data): plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0")) if plugin_ver >= pkg_resources.parse_version("2.0"): - logger.warn( + logger.warning( "properties section is not used with plugin version >= 2.0", ) diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py index 904345c2c..fdd93af9c 100644 --- a/jenkins_jobs/parser.py +++ b/jenkins_jobs/parser.py @@ -154,12 +154,12 @@ class YamlParser(object): "named '{0}'. Missing indent?" .format(n)) # allow any entry to specify an id that can also be used - id = dfn.get('id', dfn['name']) - if id in group: + _id = dfn.get('id', dfn['name']) + if _id in group: self._handle_dups( "Duplicate entry found in '{0}: '{1}' already " - "defined".format(fp.name, id)) - group[id] = dfn + "defined".format(fp.name, _id)) + group[_id] = dfn self.data[cls] = group def parse(self, fn): diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index 27c2839c9..57ce3e148 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -203,9 +203,9 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): jenkins_jobs.builder.JenkinsManager.get_plugins_info """ - @mock.patch('jenkins.Jenkins.get_plugins_info') + @mock.patch('jenkins.Jenkins.get_plugins') def test_console_output_jenkins_connection_failure_warning( - self, get_plugins_info_mock): + self, get_plugins_mock): """ Run test mode and verify that failed Jenkins connection attempt exception does not bubble out of cmd.main. Ideally, we would also test @@ -214,7 +214,7 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): suite. """ - get_plugins_info_mock.side_effect = \ + get_plugins_mock.side_effect = \ jenkins.JenkinsException("Connection refused") with mock.patch('sys.stdout'): try: @@ -226,9 +226,9 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): except: pass # only care about jenkins.JenkinsException for now - @mock.patch('jenkins.Jenkins.get_plugins_info') + @mock.patch('jenkins.Jenkins.get_plugins') def test_skip_plugin_retrieval_if_no_config_provided( - self, get_plugins_info_mock): + self, get_plugins_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if no config file provided. @@ -237,10 +237,10 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): args = ['--conf', self.default_config_file, 'test', os.path.join(self.fixtures_path, 'cmd-001.yaml')] entry.JenkinsJobs(args) - self.assertFalse(get_plugins_info_mock.called) + self.assertFalse(get_plugins_mock.called) @mock.patch('jenkins.Jenkins.get_plugins_info') - def test_skip_plugin_retrieval_if_disabled(self, get_plugins_info_mock): + def test_skip_plugin_retrieval_if_disabled(self, get_plugins_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if a config file provided and disables @@ -253,7 +253,7 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): 'test', os.path.join(self.fixtures_path, 'cmd-001.yaml')] entry.JenkinsJobs(args) - self.assertFalse(get_plugins_info_mock.called) + self.assertFalse(get_plugins_mock.called) class MatchesDirMissingFilesMismatch(object): diff --git a/tests/jenkins_manager/test_manager.py b/tests/jenkins_manager/test_manager.py index 91b5796b6..f3b32e7ca 100644 --- a/tests/jenkins_manager/test_manager.py +++ b/tests/jenkins_manager/test_manager.py @@ -20,28 +20,42 @@ from tests import base from tests.base import mock +_plugins_info = {} +_plugins_info['plugin1'] = {'longName': '', + 'shortName': '', + 'version': ''} + + @mock.patch('jenkins_jobs.builder.JobCache', mock.MagicMock) class TestCaseTestJenkinsManager(base.BaseTestCase): + def setUp(self): super(TestCaseTestJenkinsManager, self).setUp() self.jjb_config = JJBConfig() self.jjb_config.validate() def test_plugins_list(self): - self.jjb_config.builder['plugins_info'] = ['plugin1', 'plugin2'] + self.jjb_config.builder['plugins_info'] = _plugins_info + self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config) - self.assertEqual(self.builder.plugins_list, ['plugin1', 'plugin2']) + self.assertEqual(self.builder.plugins_list, _plugins_info) @mock.patch.object(jenkins_jobs.builder.jenkins.Jenkins, - 'get_plugins_info', return_value=['p1', 'p2']) + 'get_plugins', + return_value=_plugins_info) def test_plugins_list_from_jenkins(self, jenkins_mock): # Trigger fetching the plugins from jenkins when accessing the property - self.jjb_config.builder['plugins_info'] = None + self.jjb_config.builder['plugins_info'] = {} self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config) - self.assertEqual(self.builder.plugins_list, ['p1', 'p2']) + # See https://github.com/formiaczek/multi_key_dict/issues/17 + # self.assertEqual(self.builder.plugins_list, k) + for key_tuple in self.builder.plugins_list.keys(): + for key in key_tuple: + self.assertEqual(self.builder.plugins_list[key], + _plugins_info[key]) def test_delete_managed(self): - self.jjb_config.builder['plugins_info'] = [] + self.jjb_config.builder['plugins_info'] = {} self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config) with mock.patch.multiple('jenkins_jobs.builder.JenkinsManager', diff --git a/tox.ini b/tox.ini index f29c9950f..8432eb53a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] minversion = 1.6 -envlist = pep8, py34, py27 +envlist = pep8, py34, py35, py27 +skip_missing_interpreters = true [testenv] # Note(Vek): JJB is not compatible with a non-zero PYTHONHASHSEED