Skip to content

Commit

Permalink
Resolve quality-gate conflict between PR and master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
psafont committed Jan 31, 2024
2 parents dc2b046 + 4ea474b commit 4bd7423
Show file tree
Hide file tree
Showing 59 changed files with 1,658 additions and 513 deletions.
99 changes: 89 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,99 @@ on:
# run daily, this refreshes the cache
- cron: '13 2 * * *'

concurrency: # On new push, cancel old workflows from the same PR, branch or tag:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
python-test:
name: Python tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
docker-image: # See https://hub.docker.com/_/python/tags for images
- python:2.7.18-alpine3.11
- python:3.11.4-alpine3.18
container: ${{ matrix.docker-image }}
python-version: ['2.7', '3.11']
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # To check which files changed: origin/master..HEAD
- uses: LizardByte/setup-python-action@master
with:
python-version: ${{matrix.python-version}}

- uses: actions/cache@v3
name: Setup cache for running pre-commit fast
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install python 2 dependencies
if: ${{ startsWith(matrix.docker-image, 'python:2.7.18') }}
- run: echo "::add-matcher::.github/workflows/python-warning-matcher.json"
name: "Setup GitHub for reporting Python warnings as annotations in pull request code review"

- uses: pre-commit/[email protected]
name: Run pre-commit checks (no spaces at end of lines, etc)
if: ${{ matrix.python-version != '2.7' }}
with:
extra_args: --all-files --verbose --hook-stage commit
env:
SKIP: no-commit-to-branch

- name: Install dependencies only needed for python 2
if: ${{ matrix.python-version == '2.7' }}
run: pip install enum

- name: Install dependencies
run: pip install mock pytest
- name: Install dependencies only needed for python 3
if: ${{ matrix.python-version != '2.7' }}
run: pip install pandas pytype toml

- name: Run python tests
run: pytest scripts
- name: Install common dependencies for Python ${{matrix.python-version}}
run: pip install mock pytest-coverage pytest-mock

- name: Run Pytest tests for Python ${{matrix.python-version}}
run: >
pytest --cov scripts scripts/ -vv -rA
--junitxml=.git/pytest${{matrix.python-version}}.xml
--cov-report term-missing
--cov-report xml:.git/coverage${{matrix.python-version}}.xml
env:
PYTHONDEVMODE: yes

- name: Upload Python ${{matrix.python-version}} coverage report to Codecov
uses: codecov/codecov-action@v3
with:
directory: .git
files: coverage${{matrix.python-version}}.xml
env_vars: OS,PYTHON
fail_ci_if_error: false
flags: python${{matrix.python-version}}
name: coverage${{matrix.python-version}}
verbose: true

- uses: dciborow/[email protected]
if: ${{ matrix.python-version != '2.7' }}
with:
reporter: github-pr-review
level: warning
# To be customized to cover remaining Python scripts:
glob_pattern: "**/*.py"

- name: Run pytype checks
if: ${{ matrix.python-version != '2.7' }}
run: ./pytype_reporter.py
env:
PR_NUMBER: ${{ github.event.number }}

# Try to add pytype_report.py's summary file as a comment to the PR:
# Documentation: https://github.com/marketplace/actions/add-pr-comment
- name: Add the pytype summary as a comment to the PR (if permitted)
uses: mshick/add-pr-comment@v2
# Depends on pytype checks, which are not run for python 2.7:
if: ${{ matrix.python-version != '2.7' }}
# Fails for user workflows without permissions(fork-based pull requests):
continue-on-error: true
with:
message-path: .git/pytype-summary.md # Add the content of it as comment

ocaml-test:
name: Ocaml tests
Expand Down Expand Up @@ -115,3 +184,13 @@ jobs:

- name: quality-gate
run: make quality-gate

- uses: reviewdog/action-actionlint@v1
name: GitHub Action linter from https://github.com/reviewdog/action-actionlint

- name: pyflakes
uses: reviewdog/action-pyflakes@master
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
17 changes: 17 additions & 0 deletions .github/workflows/python-warning-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "python-warnings",
"severity": "warning",
"pattern": [
{
"regexp": "^.*/xen-api/(.+):([0-9]*):(.*):(.*)$",
"file": 1,
"line": 2,
"code": 3,
"message": 4
}
]
}
]
}
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Configuration of pre-commit, a Python framework for git hooks.
# pre-commit is run for each git push by GitHub CI. It can run
# locally as well for early feedback and automatic formatting
# like trailing whitespace removal (to be configured later):
#
## For only installing the package itself, run:
# pip3 install pre-commit
#
## For activating it as a pre-commit and pre-push hook (recommended):
# pre-commit install --hook-type pre-push --hook-type pre-commit
#
## For manually executing the pre-push hook:
# pre-commit run -av --hook-stage pre-push
#
default_stages: [commit, push]
repos:
# Recommendation for a minimal git pre-commit hook:
# https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: no-commit-to-branch
name: "The master branch should be pulled only, don't commit to it"
args: [--branch, master]
always_run: true
- id: check-merge-conflict
- id: check-yaml
- id: check-executables-have-shebangs
exclude: ocaml

# Recommendation for a minimal git pre-push hook:
# While using pre-commit yields great results, it
# is "not fast". Therefore only run it pre-push,
# (but always in GitHub CI of course):
#
# Calls ./pytype_reporter.py in a dedicated venv:
# pre-commit run -av --hook-stage push
- repo: local
hooks:
- id: pytype
name: pytype
entry: python3 pytype_reporter.py
types: [python]
stages: [push]
verbose: true
# This hook runs locally only when Python files change:
language: python
# Pytype supports running on Python 3.8 to Python3.11 currently:
# https://google.github.io/pytype/support.html
# If a dev's default python3 interpreter is outside that range, but
# developers have such version installed, it can be configured here:
# language_version: python3.11
require_serial: true
additional_dependencies: [pandas, pytype]
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ test:
trap "kill $${PSTREE_SLEEP_PID}" SIGINT SIGTERM EXIT; \
timeout --foreground $(TEST_TIMEOUT2) \
dune runtest --profile=$(PROFILE) --error-reporting=twice -j $(JOBS)
ifneq ($(PY_TEST), NO)
dune build @runtest-python --profile=$(PROFILE)
endif

stresstest:
dune build @stresstest --profile=$(PROFILE) --no-buffer -j $(JOBS)
Expand Down
4 changes: 2 additions & 2 deletions ocaml/idl/datamodel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ module PIF_metrics = struct
; field ~qualifier:DynamicRO ~ty:String "device_name"
"Report device name"
; field ~qualifier:DynamicRO ~ty:Int "speed"
"Speed of the link (if available)"
"Speed of the link in Mbit/s (if available)"
; field ~qualifier:DynamicRO ~ty:Bool "duplex"
"Full duplex capability of the link (if available)"
; field ~qualifier:DynamicRO ~ty:String "pci_bus_path"
Expand Down Expand Up @@ -2211,7 +2211,7 @@ module Tunnel = struct
param_type= tunnel_protocol
; param_name= "protocol"
; param_doc= "Protocol used for the tunnel (GRE or VxLAN)"
; param_release= next_release
; param_release= numbered_release "1.250.0"
; param_default= Some (VEnum "gre")
}
]
Expand Down
9 changes: 9 additions & 0 deletions ocaml/idl/datamodel_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ let t =
(Some (VString Constants.default_smapiv3_cluster_stack))
"Simply the string 'corosync'. No other cluster stacks are \
currently supported"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool "is_quorate"
~default_value:(Some (VBool false))
"Whether the cluster stack thinks the cluster is quorate"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int "quorum"
~default_value:(Some (VInt 0L))
"Number of live hosts in order to be quorate"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int "live_hosts"
~default_value:(Some (VInt 0L))
"Current number of live hosts, according to the cluster stack"
]
@ allowed_and_current_operations cluster_operation
@ [
Expand Down
28 changes: 22 additions & 6 deletions ocaml/idl/datamodel_cluster_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,33 @@ let t =
"Reference to the Cluster object"
; field ~qualifier:StaticRO ~lifecycle ~ty:(Ref _host) "host"
~default_value:(Some (VRef null_ref)) "Reference to the Host object"
; field ~qualifier:StaticRO ~lifecycle ~ty:Bool "enabled"
; field ~qualifier:DynamicRO ~lifecycle ~ty:Bool "enabled"
~default_value:(Some (VBool false))
"Whether the cluster host believes that clustering should be \
enabled on this host"
enabled on this host. This field can be altered by calling the \
enable/disable message on a cluster host. Only enabled members run \
the underlying cluster stack. Disabled members are still \
considered a member of the cluster (see joined), and can be \
re-enabled by the user."
; field ~qualifier:StaticRO ~lifecycle ~ty:(Ref _pif) "PIF"
~default_value:(Some (VRef null_ref)) "Reference to the PIF object"
; field ~qualifier:StaticRO ~lifecycle ~ty:Bool "joined"
; field ~qualifier:DynamicRO ~lifecycle ~ty:Bool "joined"
~default_value:(Some (VBool true))
"Whether the cluster host has joined the cluster"
(* TODO: add `live` member to represent whether corosync believes that this
cluster host actually is enabled *)
"Whether the cluster host has joined the cluster. Contrary to \
enabled, a host that is not joined is not considered a member of \
the cluster, and hence no operations (e.g. enable/disable) can be \
performed on this host. This field can be altered by calling leave \
or destroy on a cluster host. It can also be set automatically if \
cluster stack believes that this node is not part of the cluster. "
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool "live"
~default_value:(Some (VBool false))
"Whether the underlying cluster stack thinks we are live. This \
field is set automatically based on updates from the cluster stack \
and cannot be altered by the user."
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:DateTime
"last_update_live" ~default_value:(Some (VDateTime Date.epoch))
"Time when the live field was last updated based on information \
from the cluster stack"
]
@ allowed_and_current_operations cluster_host_operation
@ [
Expand Down
16 changes: 13 additions & 3 deletions ocaml/idl/datamodel_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Datamodel_roles
to leave a gap for potential hotfixes needing to increment the schema version.*)
let schema_major_vsn = 5

let schema_minor_vsn = 772
let schema_minor_vsn = 774

(* Historical schema versions just in case this is useful later *)
let rio_schema_major_vsn = 5
Expand Down Expand Up @@ -349,9 +349,19 @@ let get_product_releases in_product_since =
in
go_through_release_order release_order

let next_release =
let numbered_release version =
let ok fmt =
try Scanf.sscanf version fmt true
with Stdlib.Scanf.Scan_failure _ -> false
in
if not (ok "%_d.%_d.%_d%!" || ok "%_d.%_d.%_d-next%!") then
failwith
(Printf.sprintf
"Invalid numbered release: %s. Use the format x.y.z or x.y.z-next."
version
) ;
{
internal= get_product_releases rel_next
internal= get_product_releases version
; opensource= get_oss_releases None
; internal_deprecated_since= None
}
Expand Down
4 changes: 2 additions & 2 deletions ocaml/idl/datamodel_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ let evacuate =
param_type= Ref _network
; param_name= "network"
; param_doc= "Optional preferred network for migration"
; param_release= next_release
; param_release= numbered_release "1.297.0"
; param_default= Some (VRef null_ref)
}
; {
Expand All @@ -381,7 +381,7 @@ let evacuate =
; param_doc=
"The maximum number of VMs to be migrated per batch 0 will use the \
value `evacuation-batch-size` defined in xapi.conf"
; param_release= next_release
; param_release= numbered_release "23.27.0"
; param_default= Some (VInt 0L)
}
]
Expand Down
18 changes: 14 additions & 4 deletions ocaml/idl/datamodel_lifecycle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ let prototyped_of_field = function
Some "23.14.0"
| "Repository", "gpgkey_path" ->
Some "22.12.0"
| "Cluster_host", "last_update_live" ->
Some "24.2.1-next"
| "Cluster_host", "live" ->
Some "24.2.1-next"
| "Cluster", "live_hosts" ->
Some "24.2.1-next"
| "Cluster", "quorum" ->
Some "24.2.1-next"
| "Cluster", "is_quorate" ->
Some "24.2.1-next"
| "VTPM", "contents" ->
Some "22.26.0"
| "VTPM", "is_protected" ->
Expand All @@ -30,7 +40,7 @@ let prototyped_of_field = function
| "VTPM", "persistence_backend" ->
Some "22.26.0"
| "host", "numa_affinity_policy" ->
Some "23.32.0-next"
Some "24.0.0"
| "host", "latest_synced_updates_applied" ->
Some "23.18.0"
| "host", "recommended_guidances" ->
Expand Down Expand Up @@ -66,7 +76,7 @@ let prototyped_of_field = function
| "pool", "migration_compression" ->
Some "22.33.0"
| "pool", "custom_uefi_certificates" ->
Some "23.32.0-next"
Some "24.0.0"
| _ ->
None

Expand Down Expand Up @@ -104,7 +114,7 @@ let prototyped_of_message = function
| "host", "set_https_only" ->
Some "22.27.0"
| "host", "set_numa_affinity_policy" ->
Some "23.32.0-next"
Some "24.0.0"
| "VM", "restart_device_models" ->
Some "23.30.0"
| "pool", "set_ext_auth_max_threads" ->
Expand All @@ -122,6 +132,6 @@ let prototyped_of_message = function
| "pool", "set_https_only" ->
Some "22.27.0"
| "pool", "set_custom_uefi_certificates" ->
Some "23.32.0-next"
Some "24.0.0"
| _ ->
None
Loading

0 comments on commit 4bd7423

Please sign in to comment.