pdmv-http-client 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. pdmv_http_client-2.1.0/.gitignore +171 -0
  2. pdmv_http_client-2.1.0/.gitlab-ci.yml +172 -0
  3. pdmv_http_client-2.1.0/LICENSE +21 -0
  4. pdmv_http_client-2.1.0/PKG-INFO +68 -0
  5. pdmv_http_client-2.1.0/README.md +51 -0
  6. pdmv_http_client-2.1.0/examples/README.md +3 -0
  7. pdmv_http_client-2.1.0/examples/chain_req_forcedone.py +16 -0
  8. pdmv_http_client-2.1.0/examples/chain_request_resubmission.py +59 -0
  9. pdmv_http_client-2.1.0/examples/change_priority2.py +28 -0
  10. pdmv_http_client-2.1.0/examples/clone_example.py +26 -0
  11. pdmv_http_client-2.1.0/examples/get_requests.py +37 -0
  12. pdmv_http_client-2.1.0/examples/modify_request.py +35 -0
  13. pdmv_http_client-2.1.0/pyproject.toml +63 -0
  14. pdmv_http_client-2.1.0/setup.cfg +4 -0
  15. pdmv_http_client-2.1.0/src/pdmv_http_client.egg-info/PKG-INFO +68 -0
  16. pdmv_http_client-2.1.0/src/pdmv_http_client.egg-info/SOURCES.txt +53 -0
  17. pdmv_http_client-2.1.0/src/pdmv_http_client.egg-info/dependency_links.txt +1 -0
  18. pdmv_http_client-2.1.0/src/pdmv_http_client.egg-info/requires.txt +1 -0
  19. pdmv_http_client-2.1.0/src/pdmv_http_client.egg-info/top_level.txt +1 -0
  20. pdmv_http_client-2.1.0/src/rest/__init__.py +10 -0
  21. pdmv_http_client-2.1.0/src/rest/_version.py +34 -0
  22. pdmv_http_client-2.1.0/src/rest/applications/__init__.py +0 -0
  23. pdmv_http_client-2.1.0/src/rest/applications/base.py +238 -0
  24. pdmv_http_client-2.1.0/src/rest/applications/mcm/__init__.py +0 -0
  25. pdmv_http_client-2.1.0/src/rest/applications/mcm/core.py +277 -0
  26. pdmv_http_client-2.1.0/src/rest/applications/mcm/invalidate_request.py +399 -0
  27. pdmv_http_client-2.1.0/src/rest/applications/mcm/resubmission.py +431 -0
  28. pdmv_http_client-2.1.0/src/rest/applications/rereco/core.py +78 -0
  29. pdmv_http_client-2.1.0/src/rest/applications/stats/core.py +95 -0
  30. pdmv_http_client-2.1.0/src/rest/client/__init__.py +0 -0
  31. pdmv_http_client-2.1.0/src/rest/client/auth/__init__.py +0 -0
  32. pdmv_http_client-2.1.0/src/rest/client/auth/auth_interface.py +102 -0
  33. pdmv_http_client-2.1.0/src/rest/client/auth/handlers/__init__.py +0 -0
  34. pdmv_http_client-2.1.0/src/rest/client/auth/handlers/oauth2_tokens.py +307 -0
  35. pdmv_http_client-2.1.0/src/rest/client/auth/handlers/session_cookies.py +110 -0
  36. pdmv_http_client-2.1.0/src/rest/client/session.py +99 -0
  37. pdmv_http_client-2.1.0/src/rest/utils/__init__.py +0 -0
  38. pdmv_http_client-2.1.0/src/rest/utils/logger.py +36 -0
  39. pdmv_http_client-2.1.0/src/rest/utils/miscellaneous.py +47 -0
  40. pdmv_http_client-2.1.0/src/rest/utils/shell.py +57 -0
  41. pdmv_http_client-2.1.0/tests/__init__.py +0 -0
  42. pdmv_http_client-2.1.0/tests/applications/mcm/test_invalidate_request.py +191 -0
  43. pdmv_http_client-2.1.0/tests/applications/mcm/test_rest.py +80 -0
  44. pdmv_http_client-2.1.0/tests/applications/mcm/test_resubmission.py +211 -0
  45. pdmv_http_client-2.1.0/tests/applications/stats/test_stats.py +85 -0
  46. pdmv_http_client-2.1.0/tests/client/README.md +1 -0
  47. pdmv_http_client-2.1.0/tests/client/auth/handlers/test_oauth2_tokens_handlers.py +134 -0
  48. pdmv_http_client-2.1.0/tests/client/auth/handlers/test_session_cookie_handler.py +45 -0
  49. pdmv_http_client-2.1.0/tests/client/test_session.py +148 -0
  50. pdmv_http_client-2.1.0/tests/fixtures/__init__.py +0 -0
  51. pdmv_http_client-2.1.0/tests/fixtures/files.py +48 -0
  52. pdmv_http_client-2.1.0/tests/fixtures/mcm.py +81 -0
  53. pdmv_http_client-2.1.0/tests/fixtures/oauth.py +76 -0
  54. pdmv_http_client-2.1.0/tests/utils/test_shell.py +24 -0
  55. pdmv_http_client-2.1.0/uv.lock +652 -0
@@ -0,0 +1,171 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ # IDE configuration
165
+ .vscode
166
+
167
+ # Also ignore this working folder
168
+ draft
169
+
170
+ # Do not track the _version file for setuptools-scm
171
+ _version.py
@@ -0,0 +1,172 @@
1
+ stages:
2
+ - quality
3
+ - test
4
+ - build
5
+ - publish
6
+ - create_release
7
+
8
+ lint:
9
+ stage: quality
10
+ image: registry.cern.ch/docker.io/library/python:3.9
11
+ before_script:
12
+ - python -m pip install --upgrade pip
13
+ - pip install uv
14
+ - uv sync
15
+ script:
16
+ - uv run black --check .
17
+ - uv run isort --check .
18
+
19
+ .test-setup:
20
+ stage: test
21
+ parallel:
22
+ matrix:
23
+ # Before including more Python versions to the matrix, confirm they are available for the
24
+ # AlmaLinux 9 image via RPM.
25
+ - PYTHON_VERSION: ["3.9", "3.11", "3.12"]
26
+ image: gitlab-registry.cern.ch/linuxsupport/rpmci/builder-al9:latest
27
+ variables:
28
+ AUTH_GET_SSO_COOKIE_URL: http://linuxsoft.cern.ch/internal/repos/authz9-stable/x86_64/os/Packages/auth-get-sso-cookie-2.3.0-1.el9.noarch.rpm
29
+ before_script:
30
+ - if [ -z "${KRB_USERNAME}" ]; then echo "KRB_USERNAME is not set. Provide a username"; exit 1; fi;
31
+ - if [ -z "${KRB_PASSWORD}" ]; then echo "KRB_PASSWORD is not set. Provide a password"; exit 1; fi;
32
+ - echo "${KRB_PASSWORD}" | kinit "${KRB_USERNAME}@CERN.CH"
33
+ - klist
34
+ - curl -s -o package.rpm ${AUTH_GET_SSO_COOKIE_URL}
35
+ - dnf install -y ./package.rpm
36
+ - export PYTHON_INTERPRETER="python${PYTHON_VERSION}"
37
+ - echo "Running test for ${PYTHON_INTERPRETER}"
38
+ - dnf install -y "${PYTHON_INTERPRETER}"
39
+ - $PYTHON_INTERPRETER -m venv venv && source ./venv/bin/activate
40
+ - pip install uv && export UV_PROJECT_ENVIRONMENT="${VIRTUAL_ENV}"
41
+ - uv sync
42
+
43
+ smoke-test:
44
+ extends: .test-setup
45
+ script:
46
+ - uv run pytest -k 'TestSessionFactory or test_rest' -vv
47
+ needs:
48
+ - lint
49
+
50
+ integration-test:
51
+ extends: .test-setup
52
+ script:
53
+ - uv run pytest -vv
54
+ needs:
55
+ - smoke-test
56
+ rules:
57
+ - if: '$CI_COMMIT_TAG'
58
+ when: always
59
+ - when: never
60
+
61
+ build:
62
+ stage: build
63
+ image: registry.cern.ch/docker.io/library/python:3.12
64
+ before_script:
65
+ - python -m pip install --upgrade pip
66
+ - pip install uv
67
+ - uv sync
68
+ script:
69
+ - rm -rf dist/
70
+ - uv build
71
+ artifacts:
72
+ paths:
73
+ - dist/
74
+ expire_in: 1 hour
75
+ needs:
76
+ - job: smoke-test
77
+ - job: integration-test
78
+ optional: true
79
+
80
+ publish:
81
+ stage: publish
82
+ image: registry.cern.ch/docker.io/library/python:3.12
83
+ rules:
84
+ - if: '$CI_COMMIT_TAG'
85
+ when: always
86
+ - when: never
87
+ before_script:
88
+ - python -m pip install --upgrade pip
89
+ - pip install uv
90
+ needs:
91
+ - build
92
+ script:
93
+ - |
94
+ # UV_PUBLISH_TOKEN has to be set in CI/CD variables
95
+ if [ -z "${PYPI_PRODUCTION}" ]; then
96
+ uv publish --index testpypi
97
+ else
98
+ export UV_PUBLISH_TOKEN="${CMS_PPD_PYPI_TOKEN}"
99
+ uv publish
100
+ fi
101
+
102
+ create_release:
103
+ stage: create_release
104
+ image: registry.cern.ch/registry.gitlab.com/gitlab-org/cli:latest
105
+ rules:
106
+ - if: $CI_COMMIT_TAG
107
+ variables:
108
+ GITLAB_HOST: $CI_SERVER_FQDN
109
+ GITLAB_TOKEN: $GITLAB_API_ACCESS_TOKEN
110
+ before_script:
111
+ - apk add jq --no-cache
112
+ script:
113
+ - |
114
+ set -x
115
+
116
+ # Fetch all tags
117
+ git fetch --tags
118
+
119
+ # Try to get the previous tag
120
+ PREV_TAG=$(git describe --tags --abbrev=0 "${CI_COMMIT_TAG}^" 2>/dev/null || true)
121
+
122
+ if [ -z "$PREV_TAG" ]; then
123
+ echo "Generating release for ${CI_COMMIT_TAG} - No previous tag found, assuming this is the first release."
124
+ COMMIT_RANGE_LINEAR_COMP=""
125
+ COMMIT_RANGE_SYMMETRIC_DIFF=""
126
+ else
127
+ echo "Generating release for ${CI_COMMIT_TAG} (MRs since ${PREV_TAG})"
128
+ COMMIT_RANGE_LINEAR_COMP="${PREV_TAG}..${CI_COMMIT_TAG}"
129
+ COMMIT_RANGE_SYMMETRIC_DIFF="${PREV_TAG}...${CI_COMMIT_TAG}"
130
+ fi
131
+
132
+ # Setup auth
133
+ glab auth login --token "$GITLAB_TOKEN"
134
+
135
+ # Generate release notes
136
+ if [ -z "$COMMIT_RANGE_LINEAR_COMP" ]; then
137
+ echo "### First release: ${CI_COMMIT_TAG}:" > release_notes.md
138
+ echo "" >> release_notes.md
139
+ else
140
+ echo "### Changes since ${PREV_TAG}:" > release_notes.md
141
+ echo "" >> release_notes.md
142
+ echo "[${COMMIT_RANGE_SYMMETRIC_DIFF}]($CI_PROJECT_URL/-/compare/${COMMIT_RANGE_SYMMETRIC_DIFF})" >> release_notes.md
143
+ echo "" >> release_notes.md
144
+ fi
145
+
146
+ # Get MR numbers between the two tags by parsing commit messages
147
+ MR_NUMBERS=$(git log ${COMMIT_RANGE_LINEAR_COMP} --merges --pretty=format:"%b" | grep -oE '!([0-9]+)' || :)
148
+ MR_NUMBERS=$(echo "$MR_NUMBERS" | tr -d '!' | sort -u)
149
+
150
+ # Update release notes, fallback to commit list if merge request list is empty
151
+ if [ -z "$MR_NUMBERS" ]; then
152
+ COMMIT_LIST=$(git log --pretty=format:"- #%h from %an <%ae>: %s" ${COMMIT_RANGE_LINEAR_COMP})
153
+ echo "${COMMIT_LIST}" >> release_notes.md
154
+ else
155
+ for mr in $MR_NUMBERS; do
156
+ echo "Fetching MR $mr metadata"
157
+ mr_metadata=$(glab mr view "$mr" -R "$CI_PROJECT_PATH" -F json || echo 'Unable to find the MR at origin!')
158
+ if [ -n "$mr_metadata" ] && [ "$mr_metadata" != "{}" ]; then
159
+ mr_web_url=$(echo "$mr_metadata" | jq -r '.web_url')
160
+ title=$(echo "$mr_metadata" | jq -r '.title')
161
+ author_username=$(echo "$mr_metadata" | jq -r '.author.username')
162
+ author_username_web_url=$(echo "$mr_metadata" | jq -r '.author.web_url')
163
+ echo "- [!${mr}](${mr_web_url}) from [@${author_username}](${author_username_web_url}): ${title}" >> release_notes.md
164
+ fi
165
+ done
166
+ fi
167
+
168
+ # Create the release
169
+ echo "Creating release for tag $CI_COMMIT_TAG"
170
+ glab release create "${CI_COMMIT_TAG}" -R "$CI_PROJECT_PATH" -F release_notes.md
171
+ needs:
172
+ - publish
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 The CMS PPD Technical Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: pdmv-http-client
3
+ Version: 2.1.0
4
+ Summary: A HTTP client wrapper to handle authenticated requests to CERN internal applications
5
+ Maintainer-email: PdmV Service <pdmv.service@cern.ch>, PPD Technical Support <cms-PPD-technical-support@cern.ch>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://gitlab.cern.ch/cms-ppd/technical-support/libraries/pdmv-http-client
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests>=2.32.5
16
+ Dynamic: license-file
17
+
18
+ # PdmV HTTP Client
19
+
20
+ This project provides an HTTP client based on [requests](https://github.com/psf/requests) to handle authenticated requests to CERN
21
+ internal applications. Furthermore, it includes some clients to ease the interaction with the APIs of
22
+ PdmV applications. This version is a refactor of the old [McM Scripts](https://github.com/cms-PdmV/mcm_scripts) project, and it is published at
23
+ PyPI to be public available.
24
+
25
+ ### How to use this package
26
+
27
+ #### Prerequisite
28
+
29
+ Create an isolated virtual environment using a Python version >= 3.9 like, for instance:
30
+
31
+ `python3.9 -m venv venv && source ./venv/bin/activate`
32
+
33
+ #### Development version
34
+
35
+ If you want to set up a development environment to contribute to this project:
36
+
37
+ Install `uv` and the required dependencies.
38
+
39
+ `pip install uv`
40
+
41
+ Set the current `venv` to use with `uv`:
42
+
43
+ `export UV_PROJECT_ENVIRONMENT="${VIRTUAL_ENV}"`
44
+
45
+ Install the packages via: `uv sync`
46
+
47
+ Run the test suite via:
48
+ `uv run pytest -s -vv`
49
+
50
+ > [!IMPORTANT]
51
+ > Make sure your execution environment has a valid Kerberos ticket to consume CERN services!
52
+
53
+ #### Build package
54
+
55
+ If you just want to use this package in your own project, install it via:
56
+
57
+ `pip install pdmv-http-client`
58
+
59
+ Make sure to remove the `sys.path.append(...)` statement, if you have them in your script, to avoid overloading old versions from CERN AFS.
60
+
61
+ ### Examples
62
+
63
+ At the `examples/` folder, you will find some scripts explaining how to use the clients and the HTTP client.
64
+
65
+ ### Priority change
66
+ * If you want to use priority-changing scripts or do anything else related to cmsweb, you'll have to use voms-proxy:
67
+ * `voms-proxy-init -voms cms`
68
+ * `export X509_USER_PROXY=$(voms-proxy-info --path)`
@@ -0,0 +1,51 @@
1
+ # PdmV HTTP Client
2
+
3
+ This project provides an HTTP client based on [requests](https://github.com/psf/requests) to handle authenticated requests to CERN
4
+ internal applications. Furthermore, it includes some clients to ease the interaction with the APIs of
5
+ PdmV applications. This version is a refactor of the old [McM Scripts](https://github.com/cms-PdmV/mcm_scripts) project, and it is published at
6
+ PyPI to be public available.
7
+
8
+ ### How to use this package
9
+
10
+ #### Prerequisite
11
+
12
+ Create an isolated virtual environment using a Python version >= 3.9 like, for instance:
13
+
14
+ `python3.9 -m venv venv && source ./venv/bin/activate`
15
+
16
+ #### Development version
17
+
18
+ If you want to set up a development environment to contribute to this project:
19
+
20
+ Install `uv` and the required dependencies.
21
+
22
+ `pip install uv`
23
+
24
+ Set the current `venv` to use with `uv`:
25
+
26
+ `export UV_PROJECT_ENVIRONMENT="${VIRTUAL_ENV}"`
27
+
28
+ Install the packages via: `uv sync`
29
+
30
+ Run the test suite via:
31
+ `uv run pytest -s -vv`
32
+
33
+ > [!IMPORTANT]
34
+ > Make sure your execution environment has a valid Kerberos ticket to consume CERN services!
35
+
36
+ #### Build package
37
+
38
+ If you just want to use this package in your own project, install it via:
39
+
40
+ `pip install pdmv-http-client`
41
+
42
+ Make sure to remove the `sys.path.append(...)` statement, if you have them in your script, to avoid overloading old versions from CERN AFS.
43
+
44
+ ### Examples
45
+
46
+ At the `examples/` folder, you will find some scripts explaining how to use the clients and the HTTP client.
47
+
48
+ ### Priority change
49
+ * If you want to use priority-changing scripts or do anything else related to cmsweb, you'll have to use voms-proxy:
50
+ * `voms-proxy-init -voms cms`
51
+ * `export X509_USER_PROXY=$(voms-proxy-info --path)`
@@ -0,0 +1,3 @@
1
+ # Examples
2
+
3
+ This folder has some examples of how to query requests in McM (using the client included in this folder) and how to modify its attributes. You can use them as a guideline to develop your scripts.
@@ -0,0 +1,16 @@
1
+ from rest import McM
2
+
3
+ mcm = McM(id=McM.OIDC, dev=True)
4
+
5
+ # Example how to move a chained_request to force_done status
6
+ # Needs production_manager or higher role
7
+ chained_request = mcm.get(
8
+ "chained_requests",
9
+ "B2G-chain_RunIISummer15wmLHEGS_flowRunIISpring16DR80PU2016withHLT_flowRunIISpring16MiniAODv2withHLT-00002",
10
+ )
11
+
12
+ assert isinstance(chained_request, dict)
13
+ chained_request["status"] = "force_done"
14
+
15
+ update_answer = mcm.update("chained_requests", chained_request)
16
+ print(update_answer)
@@ -0,0 +1,59 @@
1
+ """
2
+ This example shows some alternatives to patch several chained
3
+ requests when it is required to apply changes on its
4
+ the chained campaign.
5
+ """
6
+
7
+ import random
8
+ from datetime import datetime
9
+
10
+ from rest import McM
11
+ from rest.applications.mcm.resubmission import (
12
+ ChainRequestResubmitter,
13
+ InvalidateDeleteRequests,
14
+ )
15
+
16
+ # Instances for the client.
17
+ mcm = McM(id=McM.OIDC, dev=True)
18
+ chain_resubmitter = ChainRequestResubmitter(mcm=mcm)
19
+ invalidator = InvalidateDeleteRequests(mcm=mcm)
20
+
21
+ # For this example, let's modify the block number for a chained campaign
22
+ # and resubmit all the chained request linked to it by using the related
23
+ # root request.
24
+ chained_campaign_prepid = "chain_Run3Summer22EEFSGenPremix_flowRun3Summer22EEFSMiniAODv4_flowRun3Summer22EEFSNanoAODv12"
25
+ chained_campaign = mcm.get(
26
+ object_type="chained_campaigns", object_id=chained_campaign_prepid
27
+ )
28
+ assert isinstance(chained_campaign, dict), "Chained campaign not found"
29
+
30
+ block_number = 6
31
+ print("Setting block number to: ", block_number)
32
+ chained_campaign["action_parameters"]["block_number"] = block_number
33
+ chained_campaign[
34
+ "notes"
35
+ ] += f"Updated via McM scripts for example 'chain_request_resubmission.py': {datetime.now().isoformat()}\n"
36
+ result = mcm.update(object_type="chained_campaigns", object_data=chained_campaign)
37
+ assert result and result.get("results"), "Issue updating chained campaign"
38
+
39
+ # Pick the chained request linked to this chained campaign
40
+ chained_requests = mcm.get(
41
+ object_type="chained_requests",
42
+ query=f"member_of_campaign={chained_campaign_prepid}",
43
+ )
44
+ assert isinstance(chained_requests, list), "Chained requests not found"
45
+ only_chain_prepids: list[str] = [
46
+ ch["prepid"] for ch in chained_requests if ch.get("prepid")
47
+ ]
48
+
49
+ # Only retrieve the root request included in these chained requests.
50
+ only_root_request: list[str] = list(
51
+ set([ch["chain"][0] for ch in chained_requests if ch.get("chain")])
52
+ )
53
+ assert only_root_request, "Root request's list is empty"
54
+
55
+ chain_resubmitter.resubmit_chain_request(
56
+ root_request_prepid=only_root_request[0],
57
+ tracking_tag="McM_Scripts_Example_Resubmission",
58
+ )
59
+ print("Chained requests resubmitted: ", only_chain_prepids)
@@ -0,0 +1,28 @@
1
+ # NEEDS wmcontrol path to be added. run this before the script
2
+ # export PATH=/afs/cern.ch/cms/PPD/PdmV/tools/wmcontrol:${PATH}
3
+ # voms-proxy-init also has to be set
4
+
5
+ import subprocess
6
+
7
+ from rest import McM
8
+
9
+ mcm = McM(id=McM.OIDC, dev=True)
10
+
11
+
12
+ def run_wmpriority(workflow, priority):
13
+ print("Changing priority of %s to %s" % (workflow, priority))
14
+ p = subprocess.Popen(["wmpriority.py", workflow, priority], stdout=subprocess.PIPE)
15
+ output = p.communicate()[0]
16
+ print(output)
17
+
18
+
19
+ if __name__ == "__main__":
20
+ list_of_requests = ["B2G-PhaseIISpr18AODMiniAOD-00054"]
21
+ for prepid in list_of_requests:
22
+ # Get request we want to change:
23
+ request = mcm.get("requests", prepid, method="get")
24
+ assert isinstance(request, dict)
25
+ workflow: str = request["reqmgr_name"][-1]["name"]
26
+
27
+ # Run actual priority change
28
+ run_wmpriority(workflow, "85001")
@@ -0,0 +1,26 @@
1
+ from json import dumps
2
+
3
+ from rest import McM
4
+
5
+ mcm = McM(id=McM.OIDC, dev=True)
6
+
7
+ # Script clones a request to another campaign.
8
+ # Define a list of modifications
9
+ # If member_of_campaign is different, it will clone to another campaign
10
+ modifications = {"extension": 1, "total_events": 101, "member_of_campaign": "Summer12"}
11
+
12
+ request_prepid_to_clone = "SUS-RunIIWinter15wmLHE-00040"
13
+
14
+ # Get a request object that we want to clone
15
+ request = mcm.get("requests", request_prepid_to_clone)
16
+ assert isinstance(request, dict)
17
+
18
+ # Make predefined modifications
19
+ for key in modifications:
20
+ request[key] = modifications[key]
21
+
22
+ clone_answer = mcm.clone_request(request)
23
+ if clone_answer.get("results"):
24
+ print("Clone PrepID: %s" % (clone_answer["prepid"]))
25
+ else:
26
+ print("Something went wrong while cloning a request. %s" % (dumps(clone_answer)))
@@ -0,0 +1,37 @@
1
+ from json import dumps
2
+
3
+ from rest import McM
4
+
5
+ mcm = McM(id=McM.OIDC, dev=True, debug=True)
6
+
7
+ # Example to get ALL requests which are members of a given campaign and are submitted
8
+ # It uses a generic search for specified columns: query='status=submitted'
9
+ # Queries can be combined: query='status=submitted&member_of_campaign=Summer12'
10
+ campaign_requests = mcm.get(
11
+ "requests", query="member_of_campaign=Summer12&status=submitted"
12
+ )
13
+ assert isinstance(campaign_requests, list)
14
+ assert all([isinstance(el, dict)] for el in campaign_requests)
15
+
16
+ for request in campaign_requests:
17
+ print(request["prepid"])
18
+
19
+ # Example to retrieve single request dictionary
20
+ # More methods are here:
21
+ # https://cms-pdmv-dev.web.cern.ch/mcm/restapi/requests/
22
+ single_request_prepid = "TOP-Summer12-00368"
23
+ single_request = mcm.get("requests", single_request_prepid, method="get")
24
+ print(
25
+ 'Single request "%s":\n%s'
26
+ % (single_request_prepid, dumps(single_request, indent=4))
27
+ )
28
+
29
+ # Example of how to get multiple requests using a range
30
+ requests_query = """
31
+ B2G-Fall13-00001
32
+ B2G-Fall13-00005 -> B2G-Fall13-00015
33
+ """
34
+ range_of_requests = mcm.get_range_of_requests(requests_query)
35
+ print("Found %s requests" % (len(range_of_requests)))
36
+ for request in range_of_requests:
37
+ print(request["prepid"])
@@ -0,0 +1,35 @@
1
+ from datetime import datetime
2
+
3
+ from rest import McM
4
+
5
+ mcm = McM(id=McM.OIDC, dev=True)
6
+
7
+ # Example to edit a request parameter(-s) and save it back in McM
8
+ request_prepid_to_update = "B2G-Fall13-00001"
9
+ field_to_update = "notes"
10
+
11
+ # get a the dictionnary of a request
12
+ request = mcm.get("requests", request_prepid_to_update)
13
+ assert isinstance(
14
+ request, dict
15
+ ), f"Request {request_prepid_to_update} does not exist..."
16
+
17
+ print(
18
+ 'Request\'s "%s" field "%s" BEFORE update: %s'
19
+ % (request_prepid_to_update, field_to_update, request[field_to_update])
20
+ )
21
+
22
+ # Modify what we want
23
+ request[field_to_update] = f"Hace a nice day! {datetime.now().isoformat()}"
24
+
25
+ # Push it back to McM
26
+ update_response = mcm.update("requests", request)
27
+ print("Update response: %s" % (update_response))
28
+
29
+ # Fetch the request again, after the update, to check whether the value changed
30
+ request2 = mcm.get("requests", request_prepid_to_update)
31
+ assert isinstance(request2, dict)
32
+ print(
33
+ 'Request\'s "%s" field "%s" AFTER update: %s'
34
+ % (request_prepid_to_update, field_to_update, request2[field_to_update])
35
+ )