Skip to content

Commit 47dcd3f

Browse files
committed
ci: Run the OpenStack Assistant e2e test from lightspeed-tests
Assisted-By: OpenCode:GLM-5.3
1 parent 523af6b commit 47dcd3f

3 files changed

Lines changed: 136 additions & 9 deletions

File tree

‎ci/playbooks/inject-ssh-key.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
# Add lpiwowar's public SSH keys (fetched from GitHub) to every node of the
18+
# job so that a Zuul autohold request can keep a failed node alive and it can
19+
# be debugged over SSH, as demonstrated in [1].
20+
#
21+
# NOTE: this playbook must remain LAST in the job's pre-run list.
22+
# create_lightspeed_secret.yml replaces authorized_keys with the job's
23+
# automation keys only and would drop any key added before it.
24+
#
25+
# [1] https://github.com/openstack-k8s-operators/lightspeed-operator/pull/69
26+
- name: Inject lpiwowar public SSH keys for autohold debugging
27+
hosts: all
28+
gather_facts: false
29+
tasks:
30+
- name: Fetch lpiwowar public SSH keys from GitHub
31+
ansible.builtin.uri:
32+
url: https://github.com/lpiwowar.keys
33+
return_content: true
34+
register: lpiwowar_pubkeys
35+
36+
- name: Add lpiwowar public SSH keys to authorized_keys
37+
ansible.posix.authorized_key:
38+
user: "{{ ansible_user }}"
39+
key: "{{ lpiwowar_pubkeys.content }}"
40+
state: present

‎ci/playbooks/install-openstack-lightspeed.yml‎

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727

2828
# Kubeconfig path - use user-provided or default to CRC location
2929
kubeconfig_path: "{{ cifmw_openshift_kubeconfig | default(ansible_env.HOME ~ '/.crc/machines/crc/kubeconfig') }}"
30+
31+
# test-operator assigns every test pod a dedicated ServiceAccount named
32+
# "<CRD name>-<CR instance name>" (e.g., the "ansibletest-ansibletest-lightspeed"
33+
# SA for an AnsibleTest CR named "ansibletest-lightspeed"). The ci-framework
34+
# test_operator role names the AnsibleTest CR as follows:
35+
#
36+
# "<cifmw_test_operator_ansibletest_name>-<cifmw_test_operator_stages[*].name>".
37+
#
38+
# The current default value of openstack_lightspeed_ansibletest_service_account ensures
39+
# that we mount the necessary lightspeed permissions (get /ls-access) to the correct SA used
40+
# by test-operator. Note that this works only when there is a single ansibletest step in
41+
# cifmw_test_operator_stages. If more steps are introduced, this needs to be updated
42+
# appropriately.
43+
openstack_lightspeed_ansibletest_stage: >-
44+
{{
45+
cifmw_test_operator_stages | default([])
46+
| selectattr('type', 'equalto', 'ansibletest')
47+
| map(attribute='name') | first | default('lightspeed')
48+
}}
49+
openstack_lightspeed_ansibletest_service_account: >-
50+
ansibletest-{{ cifmw_test_operator_ansibletest_name | default('ansibletest') }}-{{ openstack_lightspeed_ansibletest_stage }}
3051
environment:
3152
KUBECONFIG: "{{ kubeconfig_path }}"
3253

@@ -468,9 +489,58 @@
468489
kind: ClusterRole
469490
name: lightspeed-access
470491
subjects:
471-
# The current test-operator uses the namespace's default account.
492+
# The dedicated ServiceAccount that test-operator runs the
493+
# test Pod under (see openstack_lightspeed_ansibletest_service_account).
494+
- kind: ServiceAccount
495+
name: "{{ openstack_lightspeed_ansibletest_service_account }}"
496+
namespace: "{{ cifmw_test_operator_namespace | default('openstack') }}"
497+
498+
# The OpenStack Assistant e2e test from lightspeed-tests execs into
499+
# the openstack-assistant Pod (goose acp) over pods/exec. The request
500+
# is authorized as the test Pod's ServiceAccount, which needs both:
501+
#
502+
# 1. create/get on the pods/exec subresource (plus get/list on pods)
503+
# in the namespace where the assistant Pod runs;
504+
# 2. "use" of the SCC that admitted the assistant Pod (nonroot-v2).
505+
#
506+
# (2) is already granted to the ServiceAccount by test-operator itself,
507+
# so only (1) needs to be bound here. Note that during exec OpenShift
508+
# revalidates the target Pod's security context against the SCCs
509+
# available to the caller, which is why (2) matters at all.
510+
- name: Authorize the test Pod to exec into the OpenStack Assistant
511+
when: openstack_assistant_enabled | default(false) | bool
512+
kubernetes.core.k8s:
513+
state: present
514+
definition:
515+
apiVersion: rbac.authorization.k8s.io/v1
516+
kind: ClusterRole
517+
metadata:
518+
name: lightspeed-tests-assistant-exec
519+
rules:
520+
- apiGroups: [""]
521+
resources: ["pods"]
522+
verbs: ["get", "list"]
523+
- apiGroups: [""]
524+
resources: ["pods/exec"]
525+
verbs: ["create", "get"]
526+
527+
- name: Bind the exec permissions to the test-operator ServiceAccount
528+
when: openstack_assistant_enabled | default(false) | bool
529+
kubernetes.core.k8s:
530+
state: present
531+
definition:
532+
apiVersion: rbac.authorization.k8s.io/v1
533+
kind: RoleBinding
534+
metadata:
535+
name: lightspeed-tests-assistant-exec
536+
namespace: "{{ cifmw_test_operator_namespace | default('openstack') }}"
537+
roleRef:
538+
apiGroup: rbac.authorization.k8s.io
539+
kind: ClusterRole
540+
name: lightspeed-tests-assistant-exec
541+
subjects:
472542
- kind: ServiceAccount
473-
name: default
543+
name: "{{ openstack_lightspeed_ansibletest_service_account }}"
474544
namespace: "{{ cifmw_test_operator_namespace | default('openstack') }}"
475545

476546
- name: Create test-operator dummy config ConfigMap

‎zuul.d/jobs.yaml‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
- name: openai_credentials
1515
secret: lightspeed-openai-token
1616
# Creates the token Secret in-cluster before the run (see playbook header).
17-
pre-run: ci/playbooks/create_lightspeed_secret.yml
17+
# The SSH key injection must stay last: create_lightspeed_secret.yml
18+
# replaces authorized_keys with the automation keys only and would drop
19+
# any key added before it.
20+
pre-run:
21+
- ci/playbooks/create_lightspeed_secret.yml
22+
- ci/playbooks/inject-ssh-key.yml
1823
# cleanup: true so Zuul still attempts the delete when the job is canceled.
1924
post-run:
2025
- name: ci/playbooks/cleanup_lightspeed_secret.yml
@@ -34,12 +39,13 @@
3439

3540
cifmw_test_operator_namespace: openstack
3641
cifmw_test_operator_privileged: false
37-
cifmw_test_operator_selinux_level: s0:c478,c978
3842
cifmw_test_operator_ansibletest_name: ansibletest
3943
cifmw_test_operator_ansibletest_image: quay.io/podified-antelope-centos9/openstack-ansible-tests
4044
cifmw_test_operator_ansibletest_image_tag: current-podified
41-
cifmw_test_operator_ansibletest_ansible_git_repo: https://github.com/openstack-k8s-operators/lightspeed-tests
42-
cifmw_test_operator_ansibletest_ansible_git_branch: ""
45+
# TODO(lpiwowar): switch back to openstack-k8s-operators/lightspeed-tests
46+
# (default branch) once feature/openstack-assistant-test merges upstream.
47+
cifmw_test_operator_ansibletest_ansible_git_repo: https://github.com/lpiwowar/lightspeed-tests
48+
cifmw_test_operator_ansibletest_ansible_git_branch: feature/openstack-assistant-test
4349
cifmw_test_operator_ansibletest_ansible_playbook_path: playbooks/run_lightspeed_tests.yaml
4450
cifmw_test_operator_ansibletest_ansible_inventory: |
4551
localhost ansible_connection=local ansible_python_interpreter=python3
@@ -63,13 +69,13 @@
6369
test-operator-logs-pod-{{ run_test_fw | default('ansibletest') }}-{{
6470
test_operator_instance_name | default('ansibletest-lightspeed') }}
6571
namespace: "{{ cifmw_test_operator_namespace }}"
72+
annotations:
73+
openshift.io/required-scc: nonroot-v2
6674
spec:
6775
securityContext:
6876
runAsUser: 227
6977
runAsGroup: 227
7078
fsGroup: 227
71-
seLinuxOptions:
72-
level: "{{ cifmw_test_operator_selinux_level }}"
7379
containers:
7480
- name: test-operator-logs-container
7581
image: "{{ cifmw_test_operator_logs_image | default('quay.io/quay/busybox') }}"
@@ -89,7 +95,9 @@
8995
lightspeed_url: "https://lightspeed-app-server.{{ cifmw_openstack_lightspeed_namespace | default('openstack-lightspeed') }}.svc.cluster.local:8443"
9096
lightspeed_timeout: 120
9197
lightspeed_model: "provider-default-model/default-model"
92-
pytest_args: "-v --tb=short --color=no -m 'not llm_dependent' tests/integration"
98+
# The test suite lives in the installed rhos_lightspeed_tests package;
99+
# the entry point resolves this dotted path with pytest --pyargs.
100+
pytest_args: "-v --tb=short --color=no -m 'not llm_dependent' rhos_lightspeed_tests.tests"
93101
junit_xml_path: /var/lib/AnsibleTests/external_files/baseline.xml
94102
cifmw_test_operator_ansibletest_extra_mounts:
95103
- name: lightspeed
@@ -103,6 +111,15 @@
103111
- serviceAccountToken:
104112
path: token
105113
expirationSeconds: 3600
114+
# The OpenStack Assistant e2e test builds a Kubernetes
115+
# client from the in-cluster credentials and reads the
116+
# CA from the standard path. The test pod disables SA
117+
# token automounting, so the CA must be projected too.
118+
- configMap:
119+
name: kube-root-ca.crt
120+
items:
121+
- key: ca.crt
122+
path: ca.crt
106123
mounts:
107124
- name: lightspeed-client-token
108125
mountPath: /var/run/secrets/kubernetes.io/serviceaccount

0 commit comments

Comments
 (0)