Commit Graph

127 Commits

Author SHA1 Message Date
Clark Boylan e6653ea2aa Raise an error if acl pushes fail
Previously it was possible for an acl push to fail then we would record
successful acl push via our project cache's sha entry for that acl file.
The reason for this is despite success or failure of the acl push we
continue on without "problems". Unfortunately this can lead to projects
failing to update without any indication this has happened.

Update jeepyb to raise an exception if there is a failure pushing. THis
should prevent the project cache file from being updated and will cause
manage-projects to try again later. The downside to this is we will
short circuit our project handling if there are many updates to perform.
THis seems preferable to silently "succeeding".

Note that we special case read only projects by detecting the error
pushing an acl to a read only project and treating this as success. This
will allow us to delete our cache file and update everythin while
passing over read only projects as is.

Change-Id: I0d1c1160f2a28fc023fd71c8010ddcf6555efa14
2023-01-24 13:41:08 -08:00
Zuul ca156fe7ef Merge "Just use flake8 instead of hacking" 2020-12-03 18:57:45 +00:00
Zuul 255a6e6f2a Merge "Make local git dir creation optional" 2020-11-17 21:15:24 +00:00
Zuul 14270d487a Merge "Update OpenDev Manual URL in new contributor intro" 2020-11-12 23:00:04 +00:00
Clark Boylan 454e31c4d7 Make local git dir creation optional
manage-projects unconditionally set up a local git dir even if the
config option was unset. We change that behavior because new gerrit url
paths make a local git dir option less straight forward. If you've set a
git dir path we'll continue to honor it, otherwise this step is skipped.

Depends-On: https://review.opendev.org/762196
Change-Id: I39ef5ba7cd8747d52487cb0252a9b12878d6247b
2020-11-10 19:02:06 +00:00
Clark Boylan 6efdfe9f87 Set repo HEAD on gerrit project creation
By default we set repo HEAD to master but add configuration that allows
us to set it to some other value for new projects. Note this shouldn't
be used until tools for other systems like Gitea are ready.

We explicitly set the default to master as we rely on Gitea and Gerrit
and Git to all be in sync with the default branch. That is the case
today but may not be going forward. Being explicit allows us to avoid
early unexpected change but would also allow us to swap before all tools
update their defaults as well.

Note that we configure our local operating copy with the default head as
well to ensure there isn't additional confusion between the local repo
used to create .gitreview files and the gerrit canonical copy.

Depends-On: https://review.opendev.org/741277
Change-Id: Ie064056ba1722b1bca309dd9f96b61aae0a2fef9
2020-07-16 17:13:56 -07:00
Jeremy Stanley bc7087425a Update OpenDev Manual URL in new contributor intro
The OpenDev Manual (formerly OpenStack Infra Manual) has moved to
opendev.org, so update the link for it in the welcome message
accordingly. Do the same for the pull request closer utility, and
also reword it for better generality (a bit of de-OpenStacking).

While we're here, update outdated URLs for other content and
services which have moved to opendev.org, refresh some configuration
examples, and correct some lingering OpenStack LLC copyrights to
OpenStack Foundation per the guidance at
https://wiki.openstack.org/wiki/LegalIssuesFAQ#Copyright_Headers
(though I did not touch scripts we no longer use, like create
cgitrepos or openstackwatch).

Change-Id: Ibb34d1ab8ab58dee653c51141a871834b93cd54b
Depends-On: https://review.opendev.org/729362
2020-05-19 19:31:03 +00:00
Zuul 4b0999f64d Merge "Inspect all configs in manage-projects" 2020-05-04 15:43:38 +00:00
Monty Taylor 77bed1ae7a Username is on the connection objet
We're manipulating a Gerrit object not a GerritConnection object.
The username property is found on the Gerrit object.

Change-Id: I9b4c4cc0dacf456c1cb71c3798141ac726b1db71
2020-03-30 08:03:44 -05:00
Jeremy Stanley ce25e06d8f Catch exceptions when checking for groups
Work around gerritlib raising a generic "Exception" exception when
listGroup() finds no group.

Change-Id: I63de5aac729b29366b37f1304369419328f4a051
2020-03-29 20:44:24 +00:00
Monty Taylor ca1945dc63 More python3 fixes
Return strings from run_command

jeepyb is written expecting strings. Decode the bytes into a
string.

Fix fsck_command for python3

We fixed run_command to return strings, but fsck_command was
looking for bytes.

Filter returns an interator not a list in python3, wrap in a
list.

Change-Id: Ibb4d540a987711bd6b4c804a3f6b7cb2ccfe1baa
2020-03-27 16:22:21 -05:00
Monty Taylor 80b1e15236 Encode the input to hashlib
Another python3-ism.

Change-Id: Ide54c16fd75b1e06b45a926b771d65575d50ca2e
2020-03-25 14:47:56 -05:00
Monty Taylor 96ca93b2e3 Just use flake8 instead of hacking
We don't use hacking in Infra. Use flake8 instead.

Change-Id: I04ac08a0c4218398b43e906a6d65f75b3ff104c3
2020-03-24 15:00:12 -05:00
Monty Taylor 20808ddc5d Update ConfigParser imports for python3
We're starting to run jeepyb under python3 in the new gerrit image.

Change-Id: Ia71cb13f3b45055bbb9a311807fa65a89c8be62a
2020-03-21 16:42:29 -05:00
Clark Boylan 369d025428 Log errors when committing and pushing acls
For some reason we don't log the git output so failures are opaque to
us. Fix that by adding additonal logging.

Change-Id: If212ae6115c8266e1352431588c04547c897e982
2020-01-28 10:46:45 -08:00
Clark Boylan cef1dde44f Don't use the db in manage-projects
Direct access to the db restricts where we can run manage-projects from
and complicates testing. Instead rely on the list-groups ssh command to
get group uuid info. Note that this should be tested using new
integration testing before we merge it.

Change-Id: I6e3f0881398da8efeab5dfef370ad8d35163a7be
2020-01-28 09:52:51 -08:00
Clark Boylan f9771e88ca Inspect all configs in manage-projects
We were skipping the setting of retired project acls in manage-projects
because we were iterating over projects that weren't retired. In
manage-projects we don't want to skip over retired projects so that we
can retire the projects properly.

Address this by adding a new registry property that returns all projects
retired or not then iterate over that in manage-projects.

Change-Id: I7aa89b53696fb0fca262fc7068e5e2ad2b7ad8fc
2019-03-18 15:03:46 -07:00
azvyagintsev dcd2739069 manage_projects: exit with error code
* Currently, manage_projects always perform
   `exit 0`, even if some errors were.
 * Patch would add `exit 1` beh., in
   case any issues were during processing.
   It would affect only exit code , and will not
   stop processing.
 * Misc: perform auto-ident

Change-Id: I50d425e5a9e02441a50f7b1d32219485f80e6632
2018-12-21 16:43:12 +02:00
Clark Boylan 87b466c0c5 Remove self from group after group creation
Newer gerrit automatically adds the user creating a group to that group.
We don't actually want this behavior as the user used to manage this is
used for nothing else. Check if the current user was added to the group
and if so remove it.

Depends-On: Id5d8915f2c0bf6f6057b414785b8ec1b18e810f2
Change-Id: Ia0ca5faaaa466ae7a930bbbfb78e2975771f3af9
2017-09-22 10:27:21 -07:00
Monty Taylor 858dc72bf7
Revert "Add description to needs_update calculations"
This reverts commit f12da78132.

Change-Id: I0bdd154deea16f345f3ba1aed15c419393bb6d93
2017-09-22 05:53:35 -05:00
Monty Taylor f12da78132
Add description to needs_update calculations
We're caching the data already. If we at this, it'll cause us to update
descriptions in github when they change.

Change-Id: I1941958cca6387bd17fd3dcfd3c519af8b355453
2017-06-29 11:23:15 -05:00
Monty Taylor 45585f0c48
Don't mark as created in github until we're done
created-in-github being True prevents the subsequent github actions
from happening. If we fail updating the github project after creation
though, with the current code we can be left with half-created projects.

Don't set it until we've actually make it through.

Change-Id: I159eda5d1a3e5a30eed5f322d1e29477a80c5bee
2017-06-29 11:23:15 -05:00
Jenkins b88dafc17d Merge "If we're going to apply acls, we need a dir" 2017-03-23 20:32:53 +00:00
Jenkins 205a1f5dcc Merge "Deduplicate some more code" 2017-03-23 18:39:20 +00:00
Monty Taylor f9131bd502
If we're going to apply acls, we need a dir
We need the git repo to exist if we need to send in acls.

Change-Id: I29b0e8dae152e41c1a9e0556a74caa5f70813706
2017-03-23 13:26:31 -05:00
Jenkins 61ee4bd673 Merge "Allow to customize values in .gitreview file" 2017-02-17 14:46:15 +00:00
Monty Taylor 38f3a87ad6
Deduplicate some more code
fsck_repo is used in both files, so move it to utils. push_to_gerrit is
only used in manage-projects and sync_upstream is only used in
track-upstream.

Change-Id: Ia81c8a54023d5f0cac6443a6e28475b0d2243aa0
2017-02-17 08:44:25 -06:00
Jenkins a9728a54e1 Merge "Move make_local_copy to utils" 2017-02-17 14:42:31 +00:00
Jenkins 9ae0c06299 Merge "Skip retry loop on first check for group" 2017-02-17 14:42:01 +00:00
Sergey Kulanov d9dc2e264a Allow to customize values in .gitreview file
There might be situation when project creation can be done from
other "endpoint" then common users have access. So we need to have
an ability to customise GERRIT_HOST and GERRIT_PORT parameters
inside .gitreview file for newly created project.

This change adds two parameters, that can be re-defined in
projects.ini file to format correct connection string to gerrit:
  * GITREVIEW_GERRIT_HOST (by default = GERRIT_HOST)
  * GITREVIEW_GERRIT_PORT (by default = GERRIT_PORT)

Change-Id: Ie3fc35c5b6714c579314faa18160594aeae79cb7
2017-02-17 16:30:20 +02:00
Monty Taylor 36f4fa47f3
Move make_local_copy to utils
This is also shared by manage-projecs and track-upstream - but there was
also a change to its logic in the former patch which would be hard to
see if we moved it and changed it in the same patch.

Change-Id: Iab287596d1e0db529e9557cc057d558d5b7ecccb
2017-02-15 07:53:23 -06:00
Monty Taylor a4b8f3668b
Correct a boolean inversion for github updating
The not is important. Also, add in some more logging for when it does
happen.

Change-Id: I3b2a8779a3d699f72682c93f418b498506b86a01
2017-02-14 12:20:12 -06:00
Monty Taylor fa743024d3
Split track-upstream from manage-projects
We spend a very large amount of time in track-upstream code now because
of all of the debian repos. That's fine - but it makes iterating on
project creation issues exceptionally difficult. Also, now that we're
caching the flag as to whether or not the project is created,
track-upstream can read it and know whether or not it's safe to run for
a given project.

Change-Id: I454b1ba400dc86abcc9b939564eb4eb7c324308c
2017-02-14 12:20:07 -06:00
Monty Taylor 6d1ba2f169
Continue to optimize manage-projects for resiliency
Saving the state for having created the project was sticking to false.
If we had the git repo locally but it wasn't in gerrit, the logic was
all message up. Checking for homepage and downloads in github kills us -
although it would be fine if we'd started from caching homepage and
description in the first place, so maybe we need a script that sets
status quo in the cache file.

Change-Id: I15802082c0bef9e9362eb9482b058f81d1e566d7
2017-02-13 17:44:20 -06:00
Monty Taylor 182fede1b4
Make a few less github API calls
We continue to hit the GH rate limit. But honestly, in most cases, we
should not need to make a bazillion GH api calls.

Change-Id: Iac709a4f7f18d6348b21520bbc7aeacfa991ec1a
2017-02-13 09:36:04 -06:00
Monty Taylor 725317ed1a
Cache acl application and skip if necessary
Turns out processing git acls is the most expensive thing we do.

Change-Id: I14a46a9af2b32c0636db457cdd59fd2a118d0f85
2017-02-09 17:42:30 -06:00
Monty Taylor 1c7264f925
Cache status of stages in manage-projects
Implement a trivial caching system that will allow us to skip even
attempting gerrit and github remote operations for projects that we've
processed successfully in previous passes. This should hopefully reduce
the amount of time we spend processing the projects.yaml file.

In the future, we could extend this to tracking more specific actions-
such as the description set in github, so that we could know whether or
not they have changed and thus need to be processed again.

In this form, acls files will always be processed.

Change-Id: I07b13c8663e6f9ee1255a4e56caf556ea49fb51b
2017-02-07 09:56:05 -06:00
Jenkins 961da2b3b4 Merge "Update projects on GitHub" 2017-02-07 15:24:03 +00:00
Olivier Lemasle 6fa2848e51
Update projects on GitHub
If project's attributes are modified, changes will now be reflected
on GitHub.

Change-Id: I6775b55811a47402d3c774611436267f9074a53a
2017-02-07 09:12:19 -06:00
Darragh Bailey 882eea76d2 Skip retry loop on first check for group
Don't retry checking the DB multiple times on first call to see if group
exists when determining whether the group needs to be created.

If the group exists, a previous iteration would already have waited for
the group to be written down from the cache. So if nothing is returned
then the group does not exist, and there is no point rechecking multiple
times to see if it will appear from the cache.

This speeds up creation of new groups by avoiding a 10 second wait
before creation due to the first call for group uuid unnecessarily
retrying multiple times.

Change-Id: I0afbc716159e8aecf1ade6442d9b02674094fa08
2017-01-04 11:47:59 +00:00
Clark Boylan 533faad18d Check git fsck output when importing projects
This is a sanity check to properly log when repos are corrupt and not
able to be imported into Gerrit. The import will fail either way but at
least with this change in place we will get more direct logging of the
reason for the import failure.

Change-Id: Ibb1839329065e5d4a9747f95ff21029148801874
2016-08-17 15:56:19 -07:00
Jenkins 3a9b21810c Merge "Use oauth token to create GitHub project if available" 2016-03-10 21:21:21 +00:00
Mathieu Gagné 0adaee5977 Don't create new groups for system ones
A Gerrit bug[1] allowed manage_projects to create a Gerrit
internal group with the same name as a system group
('Registered Users').  This happened after upgrading to
Gerrit 2.11 because there are existing projects with 'Registered
Users' in acls config files.  Even though Gerrit shouldn't allow
creation of a group with the same name as a system group,
manage_projects shouldn't even attempt to do it.

This change prevents manage_projecsts from creating
groups with the same name as Gerrit system groups.  It
will also add correct entries to group files for system groups.
Below is the group file entries that Gerrit expects for
system groups:

global:Anonymous-Users                  	Anonymous Users
global:Change-Owner                     	Change Owner
global:Project-Owners                   	Project Owners
global:Registered-Users                 	Registered Users

For backward compatibility, the existing group UUID will be returned
if one is found in the database.

[1] https://code.google.com/p/gerrit/issues/detail?id=3831

Change-Id: I17d6e1a5553f98ff910480d41a2ac7b3a2522809
2016-02-09 10:55:53 -08:00
Mathieu Gagné 6d97045c8c Use oauth token to create GitHub project if available
Make sure you have repo/public_repo and write:org scopes.

Change-Id: I773331d2b0051865d783af5024fac1490c64c782
2016-02-08 13:39:13 -05:00
Jenkins df70c55bdf Merge "Swap logging levels for command and its output" 2015-11-14 17:32:56 +00:00
Steve Kowalik 5c5a9e18bd Refactor logging arguments into a common module
The command line utilities provided only haphazardly set up logging
using command line arguments. Refactor it into a common module, and
make use of it in all scripts that use logging.

This changes expire-old-reviews.py to not hardcode the log file, but
that is fine, it has no scripts calling it.

Change-Id: Ibc85f8e3b47f9c7898ad4334511b44e91ecbd736
2015-08-27 14:07:48 +10:00
Timothy Chavez f3c58c1c43 Only add 'groups' file to the repo if it exists
The 'groups' file gets created only if there are groups mentioned in
the 'project.config' file.  A 'project.config' file is not required to
mention any groups, thus we should only attempt to add the 'groups' file
if it exists.

Change-Id: I333df5156bc27db29143ee412d86e12606faa751
2015-06-04 18:30:24 -05:00
K Jonathan Harker abc18ab908 Swap logging levels for command and its output
The command being run is more informative than it's output, so raise the
logging level of the command being run to info and lower its output to
debug.

Change-Id: Ic4f764192384e3d0911380e5daf60fcdf0d2a200
2015-05-27 11:08:27 -07:00
Jenkins e6761903d7 Merge "Log project names as the projects are processed" 2015-04-20 16:22:29 +00:00
K Jonathan Harker 9a2968e6fc Log project names as the projects are processed
Currently info-level logs only contain project names when errors
occur, and otherwise have a lot of information about branch processing
with no information about which projects the branches belong to. This
adds an info-level message with the project name so that well-behaved
runs of manage-projects have enough context to give meaningful logs.

Change-Id: Ibea0a8d8367da1b6e20d244e8117ddc241337e88
2015-03-31 10:14:04 -07:00