| |
@@ -1,7 +1,10 @@
|
| |
import logging
|
| |
from collections import namedtuple
|
| |
import subprocess
|
| |
- import os
|
| |
+ import os, platform
|
| |
+
|
| |
+ import re
|
| |
+ import urllib
|
| |
|
| |
from libtaskotron import check
|
| |
from libtaskotron.ext.fedora import rpm_utils
|
| |
@@ -44,33 +47,24 @@
|
| |
def create_results_file():
|
| |
pass
|
| |
|
| |
- def run_standard_interface_test(koji_build, rpms, workdir='.', artifactsdir='artifacts'):
|
| |
- outcome = 'PASSED'
|
| |
-
|
| |
- name = rpm_utils.rpmformat(koji_build, 'n')
|
| |
-
|
| |
- # set envirnment vars
|
| |
+ def __set_env_vars(name, workdir='.', artifactsdir='artifacts'):
|
| |
environment = {}
|
| |
+
|
| |
inventory_filename = os.path.join(workdir, name, 'inventory')
|
| |
if os.path.exists(inventory_filename):
|
| |
environment['ANSIBLE_INVENTORY'] = inventory_filename
|
| |
else:
|
| |
environment['ANSIBLE_INVENTORY'] = '/usr/share/ansible/inventory'
|
| |
|
| |
- environment['TEST_SUBJECTS'] = ' '.join(rpms['downloaded_rpms'])
|
| |
environment['TEST_ARTIFACTS'] = artifactsdir
|
| |
|
| |
environment['HOME'] = os.environ.get('HOME', '/')
|
| |
environment['PATH'] = os.environ.get('PATH', '') + ':/usr/bin:/usr/local/bin'
|
| |
|
| |
- # create the command
|
| |
- testdir = os.path.join(workdir, name)
|
| |
- command = ['ansible-playbook', '-e', 'artifacts='+artifactsdir, '--tags', 'classic', 'tests.yml']
|
| |
+ return environment
|
| |
|
| |
- log.debug("sending environment: {}".format(environment))
|
| |
-
|
| |
-
|
| |
- # execute the tests
|
| |
+ def __execute_test(command, testdir, environment):
|
| |
+ outcome = 'PASSED'
|
| |
log.info('Running command: {} in {}'.format(' '.join(command), testdir))
|
| |
try:
|
| |
output, _ = os_utils.popen_rt(' '.join(command), shell=True, cwd=testdir, env=environment)
|
| |
@@ -88,8 +82,79 @@
|
| |
|
| |
# create results file
|
| |
|
| |
- result = Result(outcome=outcome, output=output, errors=errors, warnings=warnings)
|
| |
+ return Result(outcome=outcome, output=output, errors=errors, warnings=warnings)
|
| |
+
|
| |
+ def install_rpms_docker_playbook(rpms, artifactsdir='artifacts'):
|
| |
+ output_yml = """
|
| |
+ - hosts: localhost
|
| |
+ tags:
|
| |
+ - container
|
| |
+ tasks:
|
| |
+ """
|
| |
+ install_template = """
|
| |
+ - copy:
|
| |
+ src: RPM_PATH
|
| |
+ dest: /root/RPM_NAME
|
| |
+ - name: install RPM_NAME
|
| |
+ package: name=/root/RPM_NAME state=present
|
| |
+ """
|
| |
+ path_replace = re.compile("RPM_PATH", re.MULTILINE)
|
| |
+ name_replace = re.compile("RPM_NAME", re.MULTILINE)
|
| |
+ for path in rpms['downloaded_rpms']:
|
| |
+ tmp_template = install_template
|
| |
+ rpm_name = os.path.basename(path)
|
| |
+ tmp_template = path_replace.sub(path, tmp_template)
|
| |
+ tmp_template = name_replace.sub(rpm_name, tmp_template)
|
| |
+ output_yml += tmp_template
|
| |
+
|
| |
+ inst_yml_file = os.path.join(artifactsdir, "install_rpms.yml")
|
| |
+ y_file = open(inst_yml_file, "w")
|
| |
+ y_file.write(output_yml)
|
| |
+ y_file.close()
|
| |
+
|
| |
+ return inst_yml_file
|
| |
+
|
| |
+
|
| |
+ def run_docker_interface_test(koji_build, rpms, compose=None, workdir='.', \
|
| |
+ artifactsdir='artifacts', docker_image="docker.io/library/fedora:rawhide"):
|
| |
+
|
| |
+ name = rpm_utils.rpmformat(koji_build, 'n')
|
| |
+ environment = __set_env_vars(name, workdir, artifactsdir)
|
| |
+ testdir = os.path.join(workdir, name)
|
| |
+ yaml_rpm_install = install_rpms_docker_playbook(rpms, workdir)
|
| |
+ command = ['ansible-playbook', '-e', 'artifacts='+artifactsdir, '-e', \
|
| |
+ 'subjects=docker:'+docker_image, '--tags', 'container', yaml_rpm_install, 'tests.yml']
|
| |
+
|
| |
+ log.debug("sending environment: {}".format(environment))
|
| |
+
|
| |
+ result = __execute_test(command, testdir, environment)
|
| |
+ # compute overall results
|
| |
+ detail = check.CheckDetail(koji_build, check.ReportType.KOJI_BUILD, result.outcome)
|
| |
+ detail.update_outcome(result.outcome)
|
| |
+ detail.note = 'dist-git tests for {} finished with result {}'.format(name, detail.outcome)
|
| |
+
|
| |
+ # print some summary to console
|
| |
+ summary = 'dist-git tests %s for %s (%s)' % (detail.outcome, koji_build, detail.note)
|
| |
+ log.info(summary)
|
| |
+
|
| |
+ output = check.export_YAML(detail)
|
| |
+ return output
|
| |
+
|
| |
+ def run_standard_interface_test(koji_build, rpms, workdir='.', artifactsdir='artifacts'):
|
| |
+ name = rpm_utils.rpmformat(koji_build, 'n')
|
| |
+
|
| |
+ # set envirnment vars
|
| |
+ environment = __set_env_vars(name, workdir, artifactsdir)
|
| |
+
|
| |
+ environment['TEST_SUBJECTS'] = ' '.join(rpms['downloaded_rpms'])
|
| |
+
|
| |
+ # create the command
|
| |
+ testdir = os.path.join(workdir, name)
|
| |
+ command = ['ansible-playbook', '-e', 'artifacts='+artifactsdir, '--tags', 'classic', 'tests.yml']
|
| |
+
|
| |
+ log.debug("sending environment: {}".format(environment))
|
| |
|
| |
+ result = __execute_test(command, testdir, environment)
|
| |
# compute overall results
|
| |
detail = check.CheckDetail(koji_build, check.ReportType.KOJI_BUILD, result.outcome)
|
| |
detail.update_outcome(result.outcome)
|
| |
I'm not as familiar with how the standard interface tests are supposed to work with containers - why do the rpms under test need to be installed prior to running the test? As this is run after the non-container tests, how can a stable environment be guaranteed if the packages do need to be installed prior to running the container tests?