Skip to content

Commit 1bea7d5

Browse files
Merge pull request #5293 from kasturinarra/auto_case_83241
USHIFT-5723: Add test for GDP device allocation
2 parents 94ca82d + 88b6228 commit 1bea7d5

File tree

2 files changed

+110
-5
lines changed

2 files changed

+110
-5
lines changed

test/suites/optional/generic-device-plugin.robot

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Test Tags generic-device-plugin
1414

1515

1616
*** Variables ***
17-
${NAMESPACE} ${EMPTY}
17+
${NAMESPACE} ${EMPTY}
18+
${DEVICE_COUNT} 5
1819

1920

2021
*** Test Cases ***
@@ -36,6 +37,18 @@ Verify that mountPath correctly renames the device within the container
3637

3738
[Teardown] GDP Test Teardown
3839

40+
Verify ttyUSB glob pattern device discovery and allocation
41+
[Documentation] Tests GDP with glob pattern to discover multiple ttyUSB devices and verify device allocation across multiple pods
42+
[Tags] glob-pattern
43+
[Setup] TtyUSB Glob Test Setup
44+
45+
# Create and verify pods with device allocation
46+
Create Pod And Verify Allocation serial-test-pod 2 2
47+
Create Pod And Verify Allocation serial-test-pod1 1 3
48+
Create Pod And Verify Allocation serial-test-pod2 2 5
49+
50+
[Teardown] TtyUSB Glob Test Teardown
51+
3952

4053
*** Keywords ***
4154
GDP Test Setup
@@ -119,20 +132,21 @@ Create Test Job With Modified Script
119132

120133
Wait Until Device Is Allocatable
121134
[Documentation] Waits until device device.microshift.io/fakeserial is allocatable
135+
[Arguments] ${expected_count}=1
122136
${node}= Run With Kubeconfig oc get node -o=name
123137
${node_name}= Remove String ${node} node/
124138
Wait Until Keyword Succeeds 60s 5s
125-
... Device Should Be Allocatable ${node_name}
139+
... Device Should Be Allocatable ${node_name} ${expected_count}
126140

127141
Device Should Be Allocatable
128142
[Documentation] Checks if device device.microshift.io/fakeserial is allocatable
129-
[Arguments] ${node_name}
143+
[Arguments] ${node_name} ${expected_count}=1
130144
${device_amount}= Oc Get JsonPath
131145
... node
132146
... ${EMPTY}
133147
... ${node_name}
134148
... .status.allocatable.device\\.microshift\\.io/fakeserial
135-
Should Be Equal As Integers ${device_amount} 1
149+
Should Be Equal As Integers ${device_amount} ${expected_count}
136150

137151
Wait For Job Completion And Check Logs
138152
[Documentation] Waits for Job completion and checks Pod logs looking for 'Test successful' message
@@ -146,12 +160,69 @@ Wait For Job Completion And Check Logs
146160
${logs}= Oc Logs ${pod} ${NAMESPACE}
147161
Should Contain ${logs} Test successful
148162

163+
Create TtyUSB Devices
164+
[Documentation] Creates dummy ttyUSB devices
165+
FOR ${i} IN RANGE ${DEVICE_COUNT}
166+
Command Execution sudo mknod --mode=666 /dev/ttyUSB${i} c 166 ${i}
167+
END
168+
169+
Remove Dummy TtyUSB Devices
170+
[Documentation] Removes dummy ttyUSB devices
171+
FOR ${i} IN RANGE ${DEVICE_COUNT}
172+
Command Execution sudo rm -f /dev/ttyUSB${i}
173+
END
174+
175+
TtyUSB Glob Test Setup
176+
[Documentation] Setup for ttyUSB glob pattern test - creates devices, configures GDP, waits for allocation
177+
Create TtyUSB Devices
178+
Drop In MicroShift Config ${GDP_CONFIG_SERIAL_GLOB} 10-gdp
179+
Restart MicroShift
180+
Wait Until Device Is Allocatable ${DEVICE_COUNT}
181+
182+
TtyUSB Glob Test Teardown
183+
[Documentation] Cleanup for ttyUSB glob pattern test
184+
Oc Delete pod --all -n ${NAMESPACE}
185+
Remove Dummy TtyUSB Devices
186+
Disable GDP
187+
188+
Verify Node Device Allocation
189+
[Documentation] Verifies device allocation on the node matches expected total
190+
[Arguments] ${expected_total_allocated}
191+
${node}= Run With Kubeconfig oc get node -o=name
192+
${node_name}= Remove String ${node} node/
193+
${describe_output}= Run With Kubeconfig oc describe node ${node_name}
194+
${allocated_line}= Get Lines Containing String ${describe_output} device.microshift.io/fakeserial
195+
${allocated_count}= Get Regexp Matches
196+
... ${allocated_line}
197+
... device\\.microshift\\.io/fakeserial\\s+(\\d+)
198+
... 1
199+
VAR ${allocated_count}= ${allocated_count[0]}
200+
Should Be Equal As Integers ${allocated_count} ${expected_total_allocated}
201+
202+
Create Pod And Verify Allocation
203+
[Documentation] Creates a pod using dynamic spec generation and verifies device allocation
204+
[Arguments] ${pod_name} ${requested_devices} ${expected_total_allocated}
205+
206+
# Generate pod spec dynamically
207+
${pod_spec}= Get Ttyusb Pod Definition ${pod_name} ${requested_devices}
208+
209+
# Create and wait for pod
210+
${path}= Create Random Temp File ${pod_spec}
211+
Oc Create -f ${path} -n ${NAMESPACE}
212+
Oc Wait -n ${NAMESPACE} pod/${pod_name} --for=condition=Ready --timeout=120s
213+
214+
# Verify correct number of devices allocated to pod
215+
${devices_in_pod}= Oc Exec ${pod_name} ls /dev/ | grep ttyUSB | wc -l ${NAMESPACE}
216+
Should Be Equal As Integers ${devices_in_pod} ${requested_devices}
217+
218+
# Verify node shows correct allocation
219+
Verify Node Device Allocation ${expected_total_allocated}
220+
149221
Teardown Suite With GDP Cleanup
150222
[Documentation] Suite teardown that cleans up GDP configuration and restarts MicroShift
151223
# Clean up any remaining GDP configuration
152224
Remove Drop In MicroShift Config 10-gdp
153225
# Restart MicroShift to clean state for next suite
154226
Restart MicroShift
155227
Restart Greenboot And Wait For Success
156-
# Call original suite teardown
157228
Teardown Suite With Namespace

test/suites/optional/strings.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
mountPath: /dev/myrenamedserial
2020
'''
2121

22+
GDP_CONFIG_SERIAL_GLOB = '''
23+
genericDevicePlugin:
24+
status: Enabled
25+
devices:
26+
- name: fakeserial
27+
groups:
28+
- paths:
29+
- path: /dev/ttyUSB*
30+
'''
31+
2232
CONFIGMAP_PREAMBLE = '''
2333
apiVersion: v1
2434
kind: ConfigMap
@@ -36,6 +46,30 @@
3646
'''
3747

3848

49+
def get_ttyusb_pod_definition(name: str, num_devices: int):
50+
return f"""
51+
apiVersion: v1
52+
kind: Pod
53+
metadata:
54+
name: {name}
55+
spec:
56+
containers:
57+
- name: serialdevice-app-container
58+
image: registry.access.redhat.com/ubi9/ubi:9.6
59+
command: ["sleep", "infinity"]
60+
resources:
61+
limits:
62+
device.microshift.io/fakeserial: "{num_devices}"
63+
securityContext:
64+
allowPrivilegeEscalation: false
65+
capabilities:
66+
drop: ["ALL"]
67+
runAsNonRoot: true
68+
seccompProfile:
69+
type: "RuntimeDefault"
70+
"""
71+
72+
3973
def append_to_preamble(content: str) -> str:
4074
# Add 4 spaces before each line
4175
content = " " + content.replace("\n", "\n ")

0 commit comments

Comments
 (0)