Commit Graph

61 Commits

Author SHA1 Message Date
Jeremy Stanley 9ae9f7936e Pin python requests when installing docker-compose
New urllib3 and python requests break python docker-compose. Pin
requests back which should use an older urllib3. Hopefully this
fixes docker-compose.

Note this should probably only be used as a temporary workaround. A
more permanent fix should change the way we install docker-compose.

Also stop relying on six since it's no longer available and we
dropped Python 2.7 support quite some time back anyway.

Clean up some things in tox.ini which regressed in Tox v4.

Co-Authored-By: Clark Boylan <cboylan@sapwetik.org>
Change-Id: I69a7ba09f737130a403f0657708877ce986f751c
2023-05-19 13:42:55 +00:00
Zuul cf83939469 Merge "Update documentation" 2021-05-07 01:40:09 +00:00
Tristan Cacqueray d30b133a89 Add ignore events filter
This change enables GerritWatcher user to ignore noisy events
such as replicated-ref event.

Change-Id: If95d560a3dbb20e530e9ea1e94c1250aa083c9ea
2021-04-07 19:57:19 +00:00
Brian Rosmaita f34c110fd9 Update documentation
Update various URLs in the docs, add .eggs to .gitignore, and correct
a pep8 problem in gerrit.py

Change-Id: Ie86ff3a7cb6e9c742eac0eab243cc374ead42fb6
2021-01-04 22:19:38 -05:00
Clark Boylan a7f00a4d9b Handle newer Gerrit ls-groups command syntax
In Gerrit 2.14 the -q flag to ls-groups was deprecated in favor of -g.
At some point between 2.14 and 3.2 the -q support was removed entirely.
This change checks the gerrit version then uses the appropriate flag for
querying a group based on that.

We also add more robust testing to check creation of groups with spaces
in their names. We also check that if an acl is updated without group
changes that we don't try to recreate the group and get the group uuid
successfully.

Change-Id: I58c0aa2b496bcd792c8f4bc7db89b08cefa3af3d
2020-12-02 14:36:20 -08:00
Zuul 05d2786986 Merge "Avoid crash due to POLLIN event check" 2020-12-02 14:29:33 +00:00
Ian Wienand 194ddff30a Handle empty reads as closed connections
When the new Opendev 3.2 Gerrit closes the SSH connection, gerritlib
goes into a hard loop.  Either this has never really worked, or our
new version of gerrit closes the SSH connection differently and
triggers this.

Currently the _read() function in this code interprets a 0 read as
data and continues the event loop.  This means the _listen() function
never exits.  The poll() keeps returning that there is a POLLIN event
and the _read() function keeps reading the empty FD.

Modify this to set the state to DISCONNECTED for a blank read.
Additionally improve the error message if we see invalid data (which
shouldn't happen).  Insert a short-circuit in the listen to check if
the state has switched to DISCONNECTED and exit the loop in that case.

Change-Id: I46849bcbfc3a0d409baa654867018994ce717481
2020-11-24 11:58:48 +11:00
Sorin Sbarnea 12e395e8ea Avoid crash due to POLLIN event check
Fixed bug which prevented use on newer version of python as we
incorrectly checked event value against the bitmask.

Also improves exception by included value of the event in it.

Change-Id: I49f41d2555f53f2377c32c7626e1350c4f42b8de
2020-11-03 09:27:08 +00:00
Sorin Sbarnea ac82273984 Allow custom retries on gerrit connection
Previous code was not allowing use of Gerrit without hardcoded infinite
retries inside Gerrit constructor, meaning that wrong credentials
would create an endless loop which gerritlib consumer could not
prevent.

This allows client to specify number of attempts and delay before
a failure is returned.

Change-Id: I5bd14a14539a2705babb9f9922c800383031c6ac
2020-09-28 16:50:00 +01:00
Arun S A G 40858f3678 Add support for TCP keep alive in gerritlib
Clients using gerritlib behind NAT/firewall
can be stuck when the NAT/firewall discard
packets belong to the TCP connection after extended
silent periods thinking the connection is dead.

This change allows clients using gerritlib to set
keep alive interval to a non zero value. This will
enable TCP keep alive packets to be sent in
configured intervals keeping the TCP connections alive.

Change-Id: I588706bb51ce41810cd2243f4969763d193d1d55
2020-09-09 17:45:39 -07:00
Clark Boylan 6058d994b8 Add branches arg to createProject
This new functiona argument will allow callers to set the default
project branch on repo creation. It takes a list, all branches will be
created with the first being repo HEAD.

Change-Id: Iae5a71662740678e663bcd73d6ac660559db5d9a
2020-07-15 11:11:44 -07:00
Sorin Sbarnea 95e17ddf05 Fixed linting issues
Newer versions of flake8 identify these valid violations.
N802 added as skip because the entire library uses camelcase.

Change-Id: Ia687b05bb8d0590eb30a970a710a2639548dbc60
2020-05-21 17:12:40 +01:00
Sorin Sbarnea a0a5f260ea Enable py36-py38 testing
- updates tox.ini, also fixing a typo
- enables new jobs, which would at least test ability to install
  package under these versions.
- updates Trove metadata
- replace fake sole-survivor unittest with a bit more practical one

Change-Id: Iae224a19850489ba3563ad5a40d358002dacdb97
2020-05-20 19:38:05 +01:00
Sorin Sbarnea c49a8e0e5f Added missing retry_delay instance variable
Found exception at line 179, where self.retry_delay was references
without being assigned.

Change-Id: I6d00fe9478ed3467120e0441bed3c32f68e20bca
2020-05-20 18:13:21 +01:00
Clark Boylan 17380a3e71 Return lists from listing functions
We use filter to filter out entries when listing items like groups. This
returns a list in python2 but an iterable in python3. Return a
consistent list via forced coersion.

Change-Id: Iad84f6f383fb85363f3ef51c4bd1da05b8069e43
2020-03-27 14:18:05 -07:00
Clark Boylan fa0a23a751 Pass Gerrit not GerritConnection to GerritWatcher
We want to call addEvent on the 'gerrit' arg passed to GerritWatcher.
For that to work it needs to be of type Gerrit not GerritConnection.

Update the location of username, port, etc data to the connection
details in the gerrit object.

Change-Id: Ic739ddc970f6761f5587ab8fcba3e619a98a4379
2020-01-28 14:14:20 -08:00
Zuul d244a41362 Merge "Convert gerrit output to utf8 unicode" 2020-01-28 02:28:47 +00:00
Clark Boylan 945d2088a7 Convert gerrit output to utf8 unicode
We get back bytestrings from paramiko when it talks to gerrit. Make this
a bit more user friendly for python3 and decode these bytestrings into
utf8 unicode.

Change-Id: I1866de53d0978f805faef0933ef37e68454ff5f3
2020-01-27 16:13:13 -08:00
Darragh Bailey a731676fd1 Support querying for single group info
Allow querying to check if a single group entry exists, which when
combined with 'verbose=True' will return the UUID for a single group.

Change-Id: I851ab29999c0d059c9cb71bd38a821c035ae98f7
2020-01-23 12:11:34 +00:00
Darragh Bailey 500c8d2cc9 Reuse same paramiko connection recreating on errors
Move connection related code to a common object to allow reuse of the
connection setup code. This helps avoiding unnecessary recreation of
the connection where it is being used multiple times within the same
process for multiple calls.

Change-Id: Idf318ce5c36100e550182e773ce55da69fe35063
2020-01-23 12:01:52 +00:00
Clark Boylan 2de58d560f Close ssh connections when done with them
Newer paramiko leaks connections if they are not explicitly closed. Add
a finally handler to always close the ssh connections when we are done
with it to avoid leaking these connections.

Change-Id: Ia2e53998d362683a42bda074d82e3a3a75f380b4
2018-05-03 13:39:57 -07:00
Clark Boylan 01a634014e Add group membership management functions
Add functions to list group members and add and remove users from
groups.

Change-Id: Id5d8915f2c0bf6f6057b414785b8ec1b18e810f2
2017-09-22 10:24:53 -07:00
Clark Boylan eb6588734c Handle different gerrit versions with create-project
Gerrit < 2.12 used a --name argument on create-project. Newer Gerrit
simply takes the project name as an arg. Check the Gerrit version before
constructing the create-project command.

Change-Id: I59ca051627d54a11ef6524cce9b5a4414fd2193d
2017-09-19 16:25:39 -07:00
Khai Do 4527edd4ad Remove deprecated create-project '--name' option
The create-project '--name' option was removed[1] in Gerrit 2.12.
Update gerritlib to match the command for Gerrit-2.12+. This is also
compatible with Gerrit 2.11

[1] https://gerrit-review.googlesource.com/#/c/69738/

Change-Id: Ie70d938501cbf88dbbb0e9ab22abcc921f89ccdc
2016-12-01 15:05:50 -08:00
Khai Do 33feeb837b Allow creating projects with spaces
Gerrit supports creating projects that contain spaces in it.
Quote the project name otherwise the command will fail when user
attempts to create a project with spaces in it.

Change-Id: Ie1db92812355b4d8f7603c3b4b8d20434ca54bb3
2016-12-01 15:04:50 -08:00
Jeremy Stanley fba7102ae4 Specify testenv command for tox>=2.5
As of the tox 2.5.0 release, failure to specify a default commands
key in the fallback testenv section of tox.ini instantly fails with
"ERROR: Commands not specified. Please update relevant section of
.../tox.ini".

Copy the testenv.commands entry from the openstack/cookiecutter
repo's template. While at it, copy the boilerplate placeholder test
from the cookiecutter templates so that jobs don't freak out when
they discover (and then run) no tests.

Change-Id: Ifb8fcfbb6d76edd8c7dcf814a705ee7eff3a9819
2016-12-01 20:20:59 +00:00
Khai Do 58ca447785 Update project docs
This change does the following:
  Update docs with more info
  Add an example usage of this library
  Add pbr versioning to docs
  Updates the requirements
  Rarrange the docs to look better on pypi

Lots of the elements to do above were borrowed from
python-jenkins and jenkins-job-builder projects.

Change-Id: Idc7dfc88cc26e1147b027fd55d41229c4bf3910f
2015-04-20 13:10:34 -07:00
Jenkins 8366b574ed Merge "Add functionality to Gerritlib to set project descriptions" 2014-10-12 17:13:21 +00:00
Andrey Nikitin 7125e80a08 Update listGroups function in gerrit.py
Added ability to view extended information about the groups to obtain information about the uuid.
Function listGroups will be used in jeepyb (in file manage-project.py) for checking
and creating groups in gerrit database if groups does not exist.

Change-Id: Id11e358141d3802026bc7e531146e2d84546463d
2014-09-11 16:51:59 +04:00
Chmouel Boudjnah bedb0439f9 Python3 support
Change-Id: Icf60ab88682aeda1fee73b35cfe9d3ca3f2ca2be
2014-08-11 09:23:40 +02:00
Yolanda Robla 0425620240 Add functionality to Gerritlib to set project descriptions
Enabled functionality into gerritlib for setting descriptions
when creating a project, or have the ability to update
existing projects to update their descriptions.

This will allow jeepyb to create projects into Gerrit
having proper descriptions.

Change-Id: Id7fdef1599e8632edbdd8af5255207c18c9da7e0
Closes-Bug: #1349372
2014-07-28 16:26:07 +02:00
Jenkins 9809fbe25f Merge "add getVersion and listPlugin commands and update replicate command" 2014-04-03 00:13:29 +00:00
Anita Kuno ed6a6c2b67 Add empty-commit flag when creating a project with no commits
When creating a new project, if you pass the --empty-commit
flag, a sha is created for the master branch allowing for
cloning and other subsequent actions on the repo. If the project
has no commits and is created without the --empty-commit flag,
the repo is created with no sha for the master branch creating
problems with any subsequent actions on the repo.

Change-Id: Ic233057c2503b7fd9fc234d97d71431520ea70b8
2014-03-27 20:57:20 -04:00
Jenkins 5c85312837 Merge "Expose the gerrit watcher as a thread with defined transitions" 2014-03-17 16:29:54 +00:00
Khai Do d0bca22df9 add getVersion and listPlugin commands and update replicate command
The replication command string changed after replication became a plugin in gerrit.
This patch adds a getVersion[1] and a listPlugins[2] command to gerritlib.  The listPlugin
command is used to determine the correct replication string to execute in the replication
command.

[1] Only available on gerrit version >= 2.6
[2] Only available on gerrit version >= 2.5
Closes-Bug: #1273891
Partial-Bug: #1082781

Change-Id: I966037851b3f27536f415230edd1ae4e710321fb
2014-02-25 21:30:56 -05:00
Jenkins 996a04dbf6 Merge "remove extra item from listGroups and listProjects methods" 2014-02-21 01:28:32 +00:00
Khai Do 8f24b9651c remove extra item from listGroups and listProjects methods
On gerrit 2.4.x and gerrit 2.8 the list returned by the listGroups and listProjects
methods always contains one extra item at the end of the list for example listGroups
returns something like.. ['Administrators', 'Anonymous Users', 'Non-Interactive Users',
'Project Owners','Registered Users', '']

This change removes the last item from the returned list.

Change-Id: I2af52a35ef5bc7fd300b12911fce18faab474222
2014-02-14 15:12:23 -08:00
Jeremy Stanley 82df224c39 Quote group names in case of spaces
* gerritlib/gerrit.py(Gerrit.createGroup): Quote the group name in
the API call so that Gerrit won't get confused by spaces.

Change-Id: Iad7110bedc2b5b4090313fd70679f0552292a807
2014-02-09 23:43:07 +00:00
Joshua Harlow a68b5972f5 Expose the gerrit watcher as a thread with defined transitions
Instead of just maintaining a simple boolean that denotes
whether the thread is connected or not, expose a more rich
set of state transitions that can be used by external users
to know exactly the state the thread is currently in.

This new list is:

* IDLE (not initialized/started running)
* DISCONNECTED (not connected to gerrit)
* CONNECTING (attempting to connect)
* CONNECTED (connected to gerrit)
* CONSUMING (consuming events from gerrit)
* DEAD (thread has exited its run method)

The state transitions are the following:

IDLE -> DISCONNECTED
DISCONNECTED -> CONNECTING
CONNECTING -> CONNECTED
CONNECTED -> CONSUMING
CONSUMING -> DISCONNECTED (on consuming failure)
CONNECTING -> DEAD (if no more retries)

Change-Id: Ib4ecef4f093b6d6925bc4b553020e15111248617
2014-02-01 22:10:26 -08:00
Jenkins 996343b115 Merge "Allow startWatching to take in watcher connection limits" 2014-01-31 18:10:36 +00:00
Jenkins f1544a182c Merge "Add connection attempt limit" 2014-01-31 18:07:56 +00:00
Joshua Harlow de4cbc8141 Allow startWatching to take in watcher connection limits
In order to allow the GerritWatcher new features for connection
limits and retry limits to be used we need to have a way to
pass those parameters to the watcher when it is constructed.

Change-Id: I199e515e7105b267acbff55a74e03cb117752bab
2013-12-28 20:22:58 -08:00
Joshua Harlow c1ea16e0b3 Add connection attempt limit
Add a connect() function that connects
to the ssh server, if this fails it
does a retry algorithm until that fails
and then the thread dies.

If that works, consume from the given client
and if that fails, allow for retrying using
a new client (after a given consume_retry_delay
delay).

To maintain previous behavior the default of
attempting to connect forever is provided when the
number of connection_attempts is <= 0.

Change-Id: I1a2cb764c7cef04b8137a7e4b05d9a4cc45498b0
2013-12-28 20:21:23 -08:00
Monty Taylor ac865aa175 Add replicate command
In order to trigger a replication in jeepyb, we need a replicate command
in gerritlib.

Change-Id: Icaea639f9f7a17b1697b573788665bff638ac695
2013-12-02 12:56:12 -05:00
Robert Collins edb43f70f4 Allow ctrl-Cing gerritlib programs.
If the GerritWatcher thread is not set as daemon, the program won't
exit when the main thread exits. This is usually undesirable.

As part of making the thread be a daemon, I've moved the ownership of
threading logic to the gerrit startWatching method, decoupling
GerritWatcher's logic from the implementation detail of being a thread
(vs a co-process etc).

Change-Id: Ib28d5bfec47d2c4c88b99e07dec50ee4dd0104bf
2013-10-08 09:13:10 +13:00
Robert Collins 6f44bad47d Simplify GerritWatcher creation.
We have all the parameters as public attributes, and never want them
to be different so splitting them out is undesirable.

Change-Id: Ie2826af31100fbc287813e2968a126ff2af50f1f
2013-10-03 10:45:09 +13:00
Clark Boylan 6d58714528 Add method to list Gerrit Groups.
* gerritlib/gerrit.py: Add listGroups() method that will run `gerrit
ls-groups` and return the result as a python list.

Change-Id: I2cb6b7b6a23f3efdb81f90b492c07075c4606c38
2013-09-25 11:04:28 -07:00
Sean Dague d16c93bece fix param ordering to fix review function
the change id needs to come before the args, otherwise it can't
parse the change id.

Change-Id: I2d83fa3000cd4739f0d8ec5524aa3ca2391506de
2013-09-23 07:58:31 -04:00
Matthew Treinish 139c168bb3 Add comments option to query
This commit adds a new option to the query function for returning
comments for the commit.

Change-Id: I67d52f64a92cedc8ca449f0e54c2d1da2766c0a2
2013-09-19 11:03:22 -04:00
Yegor Minin e652bf2a60 Add option to query commit messages
Change-Id: If232c326525f516931b885c55f549049ad470b8d
2013-08-14 18:49:16 +03:00