forked from ramonvanalteren/jenkinsapi-old
-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements #864
Open
mghesh-yseop
wants to merge
12
commits into
pycontribs:master
Choose a base branch
from
mghesh-yseop:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c257fe2
Add the server's update center url
mghesh-yseop 02aaa76
Update type and documentation about what plugin variable can really be
mghesh-yseop ca707c9
Upload node configs with an xml content type
mghesh-yseop 281992e
Introduce url field, to save times when we already know where the plu…
mghesh-yseop 7b096ff
Enhance the string representation of a plugin by displaying the versi…
mghesh-yseop 77385ba
Add a method to check if installation is successful for all plugins
mghesh-yseop 5945739
Provide info to jenkins instead of local downloading the plugin
mghesh-yseop c115925
Cache the center dict content to save time
mghesh-yseop 3384375
Add the server specific center dict, which may differ from the cloud one
mghesh-yseop b5d0db5
Upload node configs with an xml content type
mrrsm 6a9215a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6456b91
Merge branch 'master' into master
clintonsteiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,22 @@ def check_updates_server(self) -> None: | |
|
||
@property | ||
def update_center_dict(self): | ||
update_center = "https://updates.jenkins.io/update-center.json" | ||
jsonp = requests.get(update_center).content.decode("utf-8") | ||
return json.loads(jsonp_to_json(jsonp)) | ||
if not hasattr(self, "_update_center_dict"): | ||
update_center = ( | ||
"https://updates.jenkins.io/update-center.actual.json" | ||
) | ||
jsonp = requests.get(update_center).content.decode("utf-8") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not directly use the |
||
self._update_center_dict = json.loads(jsonp) | ||
return self._update_center_dict | ||
|
||
@property | ||
def update_center_dict_server(self): | ||
if not hasattr(self, "_update_center_dict_server"): | ||
jsonp = self.jenkins_obj.requester.get_url( | ||
self.jenkins_obj.get_update_center_url(2) | ||
).content.decode("utf-8") | ||
self._update_center_dict_server = json.loads(jsonp) | ||
return self._update_center_dict_server | ||
|
||
def _poll(self, tree=None): | ||
return self.get_data(self.baseurl, tree=tree) | ||
|
@@ -145,16 +158,11 @@ def _install_specific_version(self, plugin: "Plugin") -> None: | |
download_link: str = plugin.get_download_link( | ||
update_center_dict=self.update_center_dict | ||
) | ||
downloaded_plugin: BytesIO = self._download_plugin(download_link) | ||
plugin_dependencies = self._get_plugin_dependencies(downloaded_plugin) | ||
log.debug("Installing dependencies for plugin '%s'", plugin.shortName) | ||
self.jenkins_obj.install_plugins(plugin_dependencies) | ||
url = "%s/pluginManager/uploadPlugin" % self.jenkins_obj.baseurl | ||
requester = self.jenkins_obj.requester | ||
downloaded_plugin.seek(0) | ||
requester.post_and_confirm_status( | ||
url, | ||
files={"file": ("plugin.hpi", downloaded_plugin)}, | ||
files={"filename": plugin.shortName, "pluginUrl": download_link}, | ||
data={}, | ||
params={}, | ||
) | ||
|
@@ -209,6 +217,24 @@ def _plugin_has_finished_installation(self, plugin) -> bool: | |
except JenkinsAPIException: | ||
return False # lack of update_center in Jenkins 1.X | ||
|
||
def _plugins_has_finished_installation(self) -> bool: | ||
""" | ||
Return True if installation is marked as 'Success' or | ||
'SuccessButRequiresRestart' in Jenkins' update_center, | ||
else return False. | ||
""" | ||
try: | ||
jobs = self.update_center_install_status["data"]["jobs"] | ||
for job in jobs: | ||
if job["installStatus"] not in [ | ||
"Success", | ||
"SuccessButRequiresRestart", | ||
]: | ||
return False | ||
return True | ||
except JenkinsAPIException: | ||
return False # lack of update_center in Jenkins 1.X | ||
|
||
def plugin_version_is_being_installed(self, plugin) -> bool: | ||
""" | ||
Return true if plugin is currently being installed. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer something like
self._plugin_cache
to make it clear that it is data and not a method.