Repository: eclipse-bluechi/bluechi (language: python)

Issue:
Use generated hirte rpms inside e2e wokflow
## Hirte e2e images should use rpmbuild workflow outputs

Based on the following discussion
https://github.com/containers/hirte/pull/152#pullrequestreview-1305672866

##  rpm-artifacts of the workflow should be copied into the hirte-image

Remove this part: https://github.com/containers/hirte/blob/main/.github/workflows/e2e.yaml#L26-L32
And copy the generated rpms into container and dnf local install




Discussion / hints:
I think we can use the [upload/download artifact feature](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts) of github. We already upload the RPM artifact from the build (see [here](https://github.com/containers/hirte/blob/main/.github/workflows/build.yml#L100-L104)). This can be downloaded and installed in the hirte test container. For an example, see the [download artifact github action](https://github.com/actions/download-artifact#download-a-single-artifact).

Thanks,
But if this is done as port of the CI, we have to make sure that the E2E test is executed after the artifacts for the PR and built and that the test uses the correct version (the same one of the PR)
> But if this is done as port of the CI, we have to make sure that the E2E test is executed after the artifacts for the PR and built and that the test uses the correct version (the same one of the PR)

Correct
Need to find the best way out of the follwoing to consume the rpms 
1) Call https://github.com/containers/hirte/blob/main/.github/workflows/build.yml#L57
2) move rpmbuild job into e2e workflow


Not sure if there are any pitfalls, but maybe the [trigger workflow_run](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run) can set that dependency. For example, in our case on the `Build` it would look like this:
```yaml
// e2e.yaml
name: E2E
on:
  workflow_run:
    workflows: ["Build"]
    branches: [main]
    types: 
      - completed
```

Fix patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9d87a0e0fb..9cd2c1cf37 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -109,3 +109,8 @@ jobs:
         with:
           name: rpm-artifacts
           path: ${{ env.ARTIFACTS_DIR}}
+
+  e2e:
+    needs: rpmbuild
+    uses: ./.github/workflows/e2e.yml
+


Test patch:
diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml
deleted file mode 100644
index 4ac553bcd6..0000000000
--- a/.github/workflows/e2e.yaml
+++ /dev/null
@@ -1,79 +0,0 @@
-name: Integration Testing
-
-on:
-  push:
-    branches: [main]
-  pull_request:
-    branches: [main]
-  workflow_dispatch:
-
-jobs:
-  test:
-    name: cs9 x86_64 e2e
-    runs-on: ubuntu-latest
-    steps:
-      - name: Install dependencies
-        run: |
-          sudo apt-get -y install podman
-
-      - name: Checkout sources
-        uses: actions/checkout@v3
-        with:
-          fetch-depth: 0
-          # Use githash of a tested commit instead of merge commit
-          ref: ${{ github.event.pull_request.head.sha }}
-
-      - name: build hirte tests containers
-        run: |
-          podman run --rm --name hirte-builder \
-          -v  ${PWD}:/hirte:Z -it \
-          registry.gitlab.com/centos/automotive/sample-images/hirte/hirte-builder:1.0.0 \
-          /bin/bash -c "rm -rf builddir; meson setup builddir -Dapi_bus=user; \
-          meson install -C builddir --destdir bin"
-          podman build -f tests/Containerfile -t hirte-image .
-
-      - name: run hirte containers
-        run: |
-          podman run -d --net podman --rm -p 2020:2020 --name hirte-mgr \
-          $(podman images *hirte-image --format {{.ID}})
-          podman run -d --net podman --rm --name hirte-agent-foo \
-          $(podman images *hirte-image --format {{.ID}})
-          podman run -d --net podman --rm --name hirte-agent-bar \
-          $(podman images *hirte-image --format {{.ID}})
-          PODMAN_NET=$(hostname -I | awk '{print $1}')
-          echo "PODMAN_NET=$PODMAN_NET" >> $GITHUB_ENV
-
-      - name: run hirte orchestrator
-        run: |
-          podman exec -t  hirte-mgr \
-          su - test-user -c  "(/usr/local/bin/hirte -c /hirte/example-hirte.ini > mgr.log 2>&1 &)"
-
-      - name: run hirte agent-bar
-        run: |
-          # Change node name in config file
-          podman exec -it hirte-agent-bar \
-          sed -i "s/\(NodeName=\)\(.*\)/\1bar/" /hirte/example-hirte-agent.ini
-          # Change manager address in config file
-          podman exec -it hirte-agent-bar \
-          sed -i "s/\(ManagerHost=\)\(.*\)/\1${{ env.PODMAN_NET }}/" /hirte/example-hirte-agent.ini
-          podman exec -t hirte-agent-bar \
-          su - test-user -c "(/usr/local/bin/hirte-agent -c \
-          /hirte/example-hirte-agent.ini > bar.log 2>&1 &)"
-          podman exec -it hirte-agent-bar /usr/bin/pkill --signal TERM hirte-agent
-          podman exec -w /home/test-user -u test-user -it hirte-agent-bar \
-          grep "Agent 'bar' connection attempt 0: success" bar.log
-
-      - name: run hirte agent-foo
-        run: |
-          # Change node name in config file
-          podman exec -it hirte-agent-foo \
-          sed -i "s/\(NodeName=\)\(.*\)/\1foo/" /hirte/example-hirte-agent.ini
-          # Change manager address in config file
-          podman exec -it hirte-agent-foo \
-          sed -i "s/\(ManagerHost=\)\(.*\)/\1${{ env.PODMAN_NET }}/" /hirte/example-hirte-agent.ini
-          podman exec -t hirte-agent-foo \
-          su - test-user -c  "(/usr/local/bin/hirte-agent -c \
-          /hirte/example-hirte-agent.ini > foo.log 2>&1 &)"
-          podman exec -it hirte-agent-foo /usr/bin/pkill --signal TERM hirte-agent
-          podman exec -w /home/test-user -u test-user -it hirte-agent-foo \
-          grep "Agent 'foo' connection attempt 0: success" foo.log
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
new file mode 100644
index 0000000000..c57c6a5b72
--- /dev/null
+++ b/.github/workflows/e2e.yml
@@ -0,0 +1,89 @@
+name: Integration Testing
+
+on:
+  workflow_call:
+  workflow_dispatch:
+
+jobs:
+  test:
+    name: cs9 x86_64 e2e
+    runs-on: ubuntu-latest
+    env:
+      ARTIFACTS_DIR: exported-artifacts
+    steps:
+      - name: Install dependencies
+        run: |
+          sudo apt-get -y install podman
+
+      - name: Checkout sources
+        uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+          # Use githash of a tested commit instead of merge commit
+          ref: ${{ github.event.pull_request.head.sha }}
+
+      - name: Download artifact
+        uses: actions/download-artifact@v3
+        with:
+          name: rpm-artifacts
+          path: ${{ env.ARTIFACTS_DIR}}
+
+      - name: build hirte tests containers
+        run: |
+          podman build -f tests/Containerfile -t hirte-image .
+
+      - name: run hirte containers
+        run: |
+          podman run -d --net podman --rm -p 2020:2020 --name hirte-mgr \
+          $(podman images *hirte-image --format {{.ID}})
+          podman run -d --net podman --rm --name hirte-node-bar \
+          $(podman images *hirte-image --format {{.ID}})
+          podman run -d --net podman --rm --name hirte-node-foo \
+          $(podman images *hirte-image --format {{.ID}})
+          PODMAN_NET=$(hostname -I | awk '{print $1}')
+          echo "PODMAN_NET=$PODMAN_NET" >> $GITHUB_ENV
+
+      - name: run hirte manager 
+        run: |
+          podman exec -it hirte-mgr \
+               bash -c   "sed -i \"s/\(AllowedNodeNames=\)\(.*\)/\1foo,bar/\" /etc/hirte/hirte.conf"
+          podman exec -it hirte-mgr \
+               bash -c "cat >> /etc/hirte/hirte.conf << _EOF
+          ManagerPort=2020
+          LogLevel=DEBUG
+          _EOF"
+          podman exec -it hirte-mgr \
+               bash -c "systemctl start hirte.service"
+
+      - name: run hirte agent-bar
+        run: |
+          podman exec -it hirte-node-bar bash -c \
+               "sed -i \"s/\(ManagerHost=\)\(.*\)/\1${{ env.PODMAN_NET }}/\" /etc/hirte/agent.conf"
+          podman exec -it hirte-node-bar \
+               bash -c "sed -i \"s/\(NodeName=\)\(.*\)/\1bar/\" /etc/hirte/agent.conf"
+          podman exec -it hirte-node-bar \
+               bash -c "cat >> /etc/hirte/agent.conf << _EOF
+          ManagerPort=2020
+          LogLevel=DEBUG
+          _EOF"
+          podman exec -d hirte-node-bar \
+               bash -c "systemctl start hirte-agent.service"
+          podman exec -it hirte-node-bar \
+               bash -c "journalctl -b | grep \"Agent 'bar' connection attempt 0: success\""
+
+      - name: run hirte agent-foo
+        run: |
+          podman exec -it hirte-node-foo bash -c \
+               "sed -i \"s/\(ManagerHost=\)\(.*\)/\1${{ env.PODMAN_NET }}/\" /etc/hirte/agent.conf"
+          podman exec -it hirte-node-foo \
+               bash -c "sed -i \"s/\(NodeName=\)\(.*\)/\1foo/\" /etc/hirte/agent.conf"
+          podman exec -it hirte-node-foo \
+               bash -c "cat >> /etc/hirte/agent.conf << _EOF
+          ManagerPort=2020
+          LogLevel=DEBUG
+          _EOF"
+          podman exec -d hirte-node-foo \
+               bash -c "systemctl start hirte-agent.service"
+          podman exec -it hirte-node-foo \
+               bash -c "journalctl -b | grep \"Agent 'foo' connection attempt 0: success\""
+
diff --git a/tests/Containerfile b/tests/Containerfile
index 08c4881b7b..f8b934c749 100644
--- a/tests/Containerfile
+++ b/tests/Containerfile
@@ -1,11 +1,9 @@
 FROM registry.gitlab.com/centos/automotive/sample-images/hirte/hirte-builder:1.0.0
-COPY ./builddir/bin/usr/local/bin/* /usr/local/bin
-
-CMD mkdir -p /usr/local/share/dbus-1/interfaces/
-COPY ./builddir/bin/usr/local/share/dbus-1/interfaces/* \
-     /usr/local/share/dbus-1/interfaces/
-COPY ./doc/example-hirte*.ini /hirte/
-
+RUN mkdir -p /tmp/rpms
+COPY ./exported-artifacts/ /tmp/rpms/
+RUN dnf install -y --repo local-hirte-snapshot \
+    --repofrompath local-hirte-snapshot,file:///tmp/rpms \
+    --nogpgcheck hirte hirte-agent
 CMD [ "/sbin/init" ]
 
 WORKDIR /hirte