|
1 | 1 | #!/usr/bin/env python
|
2 |
| -""" |
| 2 | +r""" |
3 | 3 | Test Procedure Specification (TPS) Report Manifest Shim
|
4 | 4 | =======================================================
|
5 | 5 |
|
|
36 | 36 | requests, and execute the next phase using capabilities implemented within this
|
37 | 37 | file.
|
38 | 38 |
|
| 39 | +Download the shim |
| 40 | +
|
| 41 | +.. code-block:: console |
| 42 | + :test: |
| 43 | + :replace: import os; cmds[0] = ["cp", os.path.join(ctx["root"], "dffml", "util", "testing", "manifest", "shim.py"), "shim.py"] |
| 44 | +
|
| 45 | + $ curl -sfLO https://github.com/intel/dffml/raw/manifest/dffml/util/testing/manifest/shim.py |
| 46 | +
|
| 47 | +Create the following file. |
| 48 | +
|
| 49 | +**manifest-sample.yaml** |
| 50 | +
|
| 51 | +.. code-block:: yaml |
| 52 | + :test: |
| 53 | + :filepath: manifest-sample.yaml |
| 54 | +
|
| 55 | + $document_format: tps.manifest |
| 56 | + $document_version: 0.0.1 |
| 57 | + testplan: |
| 58 | + - git: |
| 59 | + repo: https://example.com/my-repo.git |
| 60 | + branch: main |
| 61 | + file: my_test.py |
| 62 | + - git: |
| 63 | + repo: https://example.com/their-repo.git |
| 64 | + branch: main |
| 65 | + file: beef.py |
| 66 | + - git: |
| 67 | + repo: https://example.com/their-repo.git |
| 68 | + branch: main |
| 69 | + file: other.py |
| 70 | + - git: |
| 71 | + repo: https://example.com/my-repo.git |
| 72 | + branch: main |
| 73 | + file: face.py |
| 74 | +
|
| 75 | +A script to list the git repos given manifests |
| 76 | +
|
| 77 | +**ls-manifest-testplan-git-repo.sh** |
| 78 | +
|
| 79 | +.. code-block:: bash |
| 80 | + :test: |
| 81 | + :filepath: ls-manifest-testplan-git-repo.sh |
| 82 | +
|
| 83 | + #!/usr/bin/env sh |
| 84 | + set -euo pipefail |
| 85 | +
|
| 86 | + # Python to use |
| 87 | + PYTHON=${PYTHON:-"python3"} |
| 88 | + # Absolute path to the directory this file is in |
| 89 | + SELF_DIR="$(realpath $(dirname $0))" |
| 90 | + # Path to manifest shim |
| 91 | + SHIM="${PYTHON} ${SELF_DIR}/shim.py" |
| 92 | +
|
| 93 | + export TPS_MANIFEST_PARSER_NAME_ENV_STYLE="env-style" |
| 94 | + export TPS_MANIFEST_PARSER_FORMAT_ENV_STYLE="tps.manifest" |
| 95 | + export TPS_MANIFEST_PARSER_VERSION_ENV_STYLE="0.0.1" |
| 96 | + export TPS_MANIFEST_PARSER_SERIALIZE_ENV_STYLE="env" |
| 97 | + export TPS_MANIFEST_PARSER_ACTION_ENV_STYLE="stdout" |
| 98 | +
|
| 99 | + while test $# -gt 0 |
| 100 | + do |
| 101 | + $SHIM --insecure --input-target "${1}" \ |
| 102 | + --parser env-style | grep '_GIT_REPO=' | sed -e 's/.*_GIT_REPO=//g' |
| 103 | + shift |
| 104 | + done |
| 105 | +
|
| 106 | +.. code-block:: console |
| 107 | + :test: |
| 108 | +
|
| 109 | + $ bash ls-manifest-testplan-git-repo.sh ./manifest-sample.yaml |
| 110 | + https://example.com/my-repo.git |
| 111 | + https://example.com/their-repo.git |
| 112 | + https://example.com/their-repo.git |
| 113 | + https://example.com/my-repo.git |
| 114 | +
|
| 115 | +A script to list the test property of the given git repo for the given manifests |
| 116 | +
|
| 117 | +**ls-manifest-testplan-git-test.sh** |
| 118 | +
|
| 119 | +.. code-block:: bash |
| 120 | + :test: |
| 121 | + :filepath: ls-manifest-testplan-git-test.sh |
| 122 | +
|
| 123 | + #!/usr/bin/env sh |
| 124 | + set -euo pipefail |
| 125 | +
|
| 126 | + GIT_REPO="${1}" |
| 127 | + shift |
| 128 | +
|
| 129 | + # Python to use |
| 130 | + PYTHON=${PYTHON:-"python3"} |
| 131 | + # Absolute path to the directory this file is in |
| 132 | + SELF_DIR="$(realpath $(dirname $0))" |
| 133 | + # Path to manifest shim |
| 134 | + SHIM="${PYTHON} ${SELF_DIR}/shim.py" |
| 135 | +
|
| 136 | + # This script uses the shim layer to call the appropriate parser for the |
| 137 | + # manifest version. Currently there is only one version of the format. If we |
| 138 | + # move the to the next version we might want to parse it differently. |
| 139 | + export TPS_MANIFEST_PARSER_NAME_ENV_STYLE="env-style" |
| 140 | + export TPS_MANIFEST_PARSER_FORMAT_ENV_STYLE="tps.manifest" |
| 141 | + export TPS_MANIFEST_PARSER_VERSION_ENV_STYLE="0.0.1" |
| 142 | + export TPS_MANIFEST_PARSER_SERIALIZE_ENV_STYLE="env" |
| 143 | + export TPS_MANIFEST_PARSER_ACTION_ENV_STYLE="stdout" |
| 144 | +
|
| 145 | + while test $# -gt 0 |
| 146 | + do |
| 147 | + # Parse the manifest from YAML into essentially a bash environment |
| 148 | + # KEY=value. It will now be in the following form: |
| 149 | + # |
| 150 | + # $DOCUMENT_FORMAT=tps.manifest |
| 151 | + # $DOCUMENT_VERSION=0.0.1 |
| 152 | + # TESTPLAN_0_GIT_REPO=https://example.com/my-repo.git |
| 153 | + # TESTPLAN_0_GIT_BRANCH=main |
| 154 | + # TESTPLAN_0_GIT_FILE=my_test.py |
| 155 | + # TESTPLAN_1_GIT_REPO=https://example.com/their-repo.git |
| 156 | + # TESTPLAN_1_GIT_BRANCH=main |
| 157 | + # TESTPLAN_1_GIT_FILE=beef.py |
| 158 | + # TESTPLAN_2_GIT_REPO=https://example.com/their-repo.git |
| 159 | + # TESTPLAN_2_GIT_BRANCH=main |
| 160 | + # TESTPLAN_2_GIT_FILE=other.py |
| 161 | + # TESTPLAN_3_GIT_REPO=https://example.com/my-repo.git |
| 162 | + # TESTPLAN_3_GIT_BRANCH=main |
| 163 | + # TESTPLAN_3_GIT_FILE=face.py |
| 164 | + # |
| 165 | + manifest=$($SHIM --insecure --input-target "${1}" --parser env-style) |
| 166 | + shift |
| 167 | + # Find any GIT_REPO lines which match the repo we're looking for. |
| 168 | + # Cut off the _GIT_REPO and after part, we need to know the prefix since |
| 169 | + # we need to know the GIT_FILE that is referenced by the same prefix. |
| 170 | + testplan_indexes=$(grep "_GIT_REPO=$GIT_REPO" <<<"${manifest}" \ |
| 171 | + | sed -e 's/_GIT_REPO.*//g') |
| 172 | + # If it doesn't then check the next index |
| 173 | + if [ "x${testplan_indexes}" == "x" ]; then |
| 174 | + continue |
| 175 | + fi |
| 176 | + # Check each index we found. Look for the file associated with the index |
| 177 | + for testplan_index in ${testplan_indexes[@]}; do |
| 178 | + testcase=$(grep "${testplan_index}_GIT_FILE=" <<<"${manifest}" \ |
| 179 | + | sed -e 's/.*_GIT_FILE=//g') |
| 180 | + echo "$GIT_REPO/$testcase" |
| 181 | + done |
| 182 | + done |
| 183 | +
|
| 184 | +.. code-block:: console |
| 185 | + :test: |
| 186 | +
|
| 187 | + $ bash ls-manifest-testplan-git-test.sh https://example.com/my-repo.git ./manifest-sample.yaml |
| 188 | + https://example.com/my-repo.git/my_test.py |
| 189 | + https://example.com/my-repo.git/face.py |
| 190 | +
|
39 | 191 | Contributing
|
40 | 192 | ------------
|
41 | 193 |
|
|
93 | 245 |
|
94 | 246 | ``$schema: "https://example.com/eff.my.document.format.0.0.0.schema.json"``
|
95 | 247 |
|
| 248 | +Testing |
| 249 | +``````` |
| 250 | +
|
| 251 | +DFFML's ``tests/test_docstrings.py`` currently handles testing of the shim. |
| 252 | +
|
| 253 | +.. code-block:: console |
| 254 | +
|
| 255 | + $ python -u -m unittest discover -v -k manifest |
| 256 | +
|
96 | 257 | TODO
|
97 | 258 | ----
|
98 | 259 |
|
| 260 | +- Review hash calls and update allowlist in ``test_hash_usages()`` |
| 261 | +
|
99 | 262 | - Verification of the manifest. Idea: Developer generates manifest.
|
100 | 263 | Signs manifest with public asymmetric key. Prepends base64 encoded
|
101 | 264 | signature as a valid key, ``$signature``. This means you have to
|
|
138 | 301 | import subprocess
|
139 | 302 | import dataclasses
|
140 | 303 | import importlib.util
|
141 |
| -from typing import Dict, List, Callable, Any, Union, Optional |
| 304 | +from typing import Any, Callable, Dict, List, Optional |
142 | 305 |
|
143 | 306 |
|
144 | 307 | def popen_write_to_stdin(
|
|
0 commit comments