Add reporting of [CVP Sanity] results
- add a new method get_artifact() to JenkinsClient
- add a CLI tool get_jenkins_job_artifact.py , example usage:
export ENV_NAME=cookied-cicd-queens-dvr-sl
. tcp_tests/utils/env_salt
. tcp_tests/utils/env_jenkins_cicd
tcp_tests/utils/get_jenkins_job_artifact.py \
--job-name cvp-sanity \
--build-number lastBuild \
--artifact-path validation_artifacts/cvp-sanity_report.xml \
--destination-name ./cvp-sanity_report.xml
- add the XML report downloader to the test "test_run_cvp_func_sanity"
- add new report type "CVP Sanity" to the testrail reporter
swarm-testrail-report.groovy
Closes-Bug: #PROD-25356
Change-Id: Ic34d76c62c7f70ada5b941e3ffc5b22e1be769d0
diff --git a/tcp_tests/utils/get_jenkins_job_artifact.py b/tcp_tests/utils/get_jenkins_job_artifact.py
new file mode 100755
index 0000000..9e2295c
--- /dev/null
+++ b/tcp_tests/utils/get_jenkins_job_artifact.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# Copyright 2019 Mirantis, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import argparse
+import os
+import sys
+
+sys.path.append(os.getcwd())
+try:
+ from tcp_tests.managers.jenkins.client import JenkinsClient
+except ImportError:
+ print("ImportError: Run the application from the tcp-qa directory or "
+ "set the PYTHONPATH environment variable to directory which contains"
+ " ./tcp_tests")
+ sys.exit(1)
+
+
+def load_params():
+ """
+ Parse CLI arguments and environment variables
+
+ Returns: ArgumentParser instance
+ """
+ env_host = os.environ.get('JENKINS_URL', None)
+ env_username = os.environ.get('JENKINS_USER', None)
+ env_password = os.environ.get('JENKINS_PASS', None)
+ env_job_name = os.environ.get('JOB_NAME', None)
+ env_build_number = os.environ.get('BUILD_NUMBER', 'lastBuild')
+
+ parser = argparse.ArgumentParser(description=(
+ 'Host, username and password may be specified either by the command '
+ 'line arguments or using environment variables: JENKINS_URL, '
+ 'JENKINS_USER, JENKINS_PASS. \nCommand line arguments have the highest'
+ ' priority, after that the environment variables are used as defaults.'
+ ))
+ parser.add_argument('--host',
+ metavar='JENKINS_URL',
+ help='Jenkins Host',
+ default=env_host)
+ parser.add_argument('--username',
+ metavar='JENKINS_USER',
+ help='Jenkins Username',
+ default=env_username)
+ parser.add_argument('--password',
+ metavar='JENKINS_PASS',
+ help='Jenkins Password or API token',
+ default=env_password)
+ parser.add_argument('--job-name',
+ metavar='JOB_NAME',
+ help='Jenkins job name',
+ default=env_job_name)
+ parser.add_argument('--build-number',
+ metavar='BUILD_NUMBER',
+ help='Jenkins job build number',
+ default=env_build_number)
+ parser.add_argument('--artifact-path',
+ help='Relative path of the artifact in Jenkins',
+ default=None,
+ type=str)
+ parser.add_argument('--destination-name',
+ help='Local filename for the saving artifact',
+ default=None,
+ type=str)
+ return parser
+
+
+def download_artifact(host, username, password,
+ job_name, build_number,
+ artifact_path, destination_name):
+
+ jenkins = JenkinsClient(
+ host=host,
+ username=username,
+ password=password)
+
+ content = jenkins.get_artifact(job_name, build_number,
+ artifact_path, destination_name)
+
+ with open(destination_name, 'wb') as f:
+ f.write(content)
+
+
+def main(args=None):
+ parser = load_params()
+ opts = parser.parse_args()
+
+ if (opts.host is None or opts.job_name is None
+ or opts.artifact_path is None or opts.destination_name is None):
+ print("JENKINS_URL, job_name and destination_name are required!")
+ parser.print_help()
+ return 10
+ else:
+ download_artifact(
+ opts.host,
+ opts.username,
+ opts.password,
+ opts.job_name,
+ opts.build_number,
+ opts.artifact_path,
+ opts.destination_name)
+
+
+if __name__ == "__main__":
+ sys.exit(main())