---
# System prepended metadata

title: Untitled

---

## Use tmt to create polarion tests, run tests, export test results to polarion

Next steps:
- Investigate running kola tests through tmt either locally inside a container or run via container (coreos-assembler)
- Create the plans/tests pointing to the kola test
- Import tests into Polarion from tmt
- Report results from tmt to Polarion

Useful links:
- https://tmt.readthedocs.io/en/latest/examples.html
- https://tmt.readthedocs.io/en/latest/spec/plans.html#spec-plans-provision

First:
get rpm-ostree new version from brew
upgrade rpm-ostree on the latest rhcos image
run regression tests
write jenkins job to run tests

Todo:
- Get rpm-ostree new version URL
- Make tmt to download latest rhcos image?
- Define/write regression test
- Write jenkins job to run tests


Second:
- Put results to polarion
- Add tmt test cases to cosa(from Colin)?




## Use tmt to run tests with rhcos

Refer link: 
- https://docs.google.com/document/d/1dKprS3bh49mzs6hD9HoXdAaG1gfqAYqDp0LjwQgWEGY/edit#
- https://gitlab.cee.redhat.com/atomic-qe/container-tools-tests/-/tree/main/

Project link
- https://github.com/teemtee/tmt

Fixed Issues
1) Enable root login and disable default core for rhcos
    - https://github.com/teemtee/tmt/pull/1917 merged

### Create a test plan
```
$ tmt init --template mini
Tree '/home/fedora/mini' initialized.
Applying template 'mini'.
Directory '/home/fedora/mini/plans' created.
Plan '/home/fedora/mini/plans/example.fmf' created.
```

#### give an overview of plans
tmt plans

#### list available plans
tmt plans ls

#### show plan details
tmt plans show

### create plans/basic
Download qcow2 image to local: rhcos-412.86.202303011010-0-qemu.x86_64.qcow2
```
$ mv plans/example.fmf plans/basic.fmf
$ cat plans/basic.fmf 

summary: Basic tests
discover:
    how: fmf
    test: /tests/smoke
prepare:
    how: shell
    script: rpm-ostree status
provision:
    how: virtual
    image: /home/fedora/data/rhcos-412.86.202303132350-0-qemu.x86_64.qcow2
    memory: 2048
    disk: 16
execute:
    how: tmt


$ cat plans/update.fmf

summary: Run tests with upgrade version
discover:
    how: fmf
    test: /tests/smoke
prepare:
  - name: update rpm-ostree
    how: shell
    script: |
        rpm-ostree override replace http://download.eng.bos.redhat.com/brewroot/vol/rhel-8/packages/rpm-ostree/2022.10.115.g15eba7b1/2.el8_8/x86_64/rpm-ostree-2022.10.115.g15eba7b1-2.el8_8.x86_64.rpm http://download.eng.bos.redhat.com/brewroot/vol/rhel-8/packages/rpm-ostree/2022.10.115.g15eba7b1/2.el8_8/x86_64/rpm-ostree-libs-2022.10.115.g15eba7b1-2.el8_8.x86_64.rpm
        rpm-ostree ex apply-live --allow-replacement
        rpm -q rpm-ostree
provision:
    how: virtual
    image: /home/fedora/data/rhcos-412.86.202303132350-0-qemu.x86_64.qcow2
    memory: 2048
    disk: 16
execute:
    how: tmt
```

### Create tests
```
$ tmt test create tests/smoke -t shell
$ cat tests/smoke/test.sh
#!/bin/sh -eux

rpm-ostree status
```

#### give an overview
tmt tests
#### list available tests
tmt tests ls
#### show test details
tmt tests show

### Run tests
$ tmt run plan --name basic -dddvvv
$ tmt run plan --name update -dddvvv
$ tmt run -a -dddvvv

### Show last result
$ tmt run -l report -vvv

---

## tmt Polarion integration
Refer to https://docs.engineering.redhat.com/pages/viewpage.action?spaceKey=Automotive&title=tmt+Polarion+integration

1. Create .pylero file in your home folder
```
[webservice]
url=https://polarion.engineering.redhat.com/polarion
svn_repo=https://polarion.engineering.redhat.com/repo
user=kerberos_login
token=your_awesome_token
default_project=RHELEDGE
```

2. New test cases and export to polarion

```$ tmt tests export --how polarion --project-id RHELEDGE --create .```

3. Export existed case to polarion

```$ tmt tests export --how polarion --project-id RHELEDGE .```

4. Run tests and upload results to polarion

```
$ cat Dockerfile
FROM quay.io/coreos-assembler/coreos-assembler:latest
USER root
RUN dnf install -y tmt-all && \
    dnf install -y python3-pylero && \
    dnf clean all

COPY .pylero /root/.pylero
WORKDIR /srv/
ENTRYPOINT ["/usr/bin/dumb-init", "/usr/bin/tmt"]


$ podman build -t tmt-cosa .
$ podman run --rm -ti --security-opt label=disable --privileged\
              -v ${PWD}:/srv/ --tmpfs /tmp -v /var/tmp:/var/tmp --name test \
              --entrypoint /bin/sh localhost/tmt-cosa:latest
# fix certificate verify failed issue
curl https://password.corp.redhat.com/RH-IT-Root-CA.crt -o /etc/pki/ca-trust/source/anchors/Red_Hat_IT_Root_CA.crt
curl https://password.corp.redhat.com/pki-ca-chain.crt -o /etc/pki/ca-trust/source/anchors/PKI_CA_Chain.crt
ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/tls/certs/ca-bundle.crt
update-ca-trust
sh-5.2# tmt run -vvvddd
...
    report
    workdir: /var/tmp/tmt/run-005/plans/kola-basic/report
        how: polarion
        order: 50
    Read file '/var/tmp/tmt/run-005/plans/kola-basic/execute/data/tests/kola/basic/output.txt'.
        Response code is 401 with text: <!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1></body></html>
        summary: 1 test passed
    status: done
```