Skip to content

Commit 3b56e6d

Browse files
committed
cleanup
1 parent 275ed64 commit 3b56e6d

File tree

10 files changed

+283
-257
lines changed

10 files changed

+283
-257
lines changed

images/tests/run-tests.sh

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ cleanup_on_exit() {
5555
echo "WARNING: TEST_USER_USERNAME not found, cannot cleanup RBAC"
5656
fi
5757

58-
# Set Kueue Component to Removed State
59-
echo "Setting Kueue component to Removed state..."
60-
DSC_NAME=$(get_dsc_name 2>/dev/null || echo "")
61-
62-
if [ -n "$DSC_NAME" ] && [[ ! "$DSC_NAME" =~ ^ERROR ]]; then
63-
set_kueue_management_state "Removed" "$DSC_NAME" 2>/dev/null || {
64-
echo "WARNING: Failed to set Kueue to Removed state"
65-
}
66-
wait_for_dsc_ready 600 2>/dev/null || {
67-
echo "WARNING: DataScienceCluster did not reach Ready state after setting Kueue to Removed"
68-
}
58+
# Set Kueue Component to Removed State (only if we changed it)
59+
if [ "${INITIAL_KUEUE_STATE:-}" = "Unmanaged" ]; then
60+
echo "Kueue was already Unmanaged at start, skipping state change in cleanup"
6961
else
70-
echo "WARNING: Failed to get DataScienceCluster name, skipping Kueue cleanup"
62+
echo "Setting Kueue component to Removed state..."
63+
DSC_NAME=$(get_dsc_name 2>/dev/null || echo "")
64+
65+
if [ -n "$DSC_NAME" ] && [[ ! "$DSC_NAME" =~ ^ERROR ]]; then
66+
set_kueue_management_state "Removed" "$DSC_NAME" 2>/dev/null || {
67+
echo "WARNING: Failed to set Kueue to Removed state"
68+
}
69+
wait_for_dsc_ready 600 2>/dev/null || {
70+
echo "WARNING: DataScienceCluster did not reach Ready state after setting Kueue to Removed"
71+
}
72+
else
73+
echo "WARNING: Failed to get DataScienceCluster name, skipping Kueue cleanup"
74+
fi
7175
fi
7276
else
7377
echo "WARNING: Failed to login with OCP_ADMIN_USER for cleanup"
@@ -186,6 +190,28 @@ wait_for_dsc_ready() {
186190
return 1
187191
}
188192

193+
# Get Kueue component management state
194+
# Arguments: cluster_name
195+
get_kueue_management_state() {
196+
local cluster_name=$1
197+
198+
if [ -z "$cluster_name" ]; then
199+
echo "ERROR: Invalid arguments for get_kueue_management_state"
200+
return 1
201+
fi
202+
203+
local state
204+
state=$(oc get DataScienceCluster "$cluster_name" -o jsonpath='{.spec.components.kueue.managementState}' 2>/dev/null)
205+
206+
if [ -z "$state" ]; then
207+
echo "ERROR: Failed to get Kueue management state"
208+
return 1
209+
fi
210+
211+
echo "$state"
212+
return 0
213+
}
214+
189215
# Set Kueue component management state
190216
# Arguments: state (Unmanaged or Removed), cluster_name
191217
set_kueue_management_state() {
@@ -296,22 +322,38 @@ echo "Successfully logged in with OCP_ADMIN_USER (verified: $CURRENT_USER)"
296322
# ============================================================================
297323
# Set Kueue Component to Unmanaged State
298324
# ============================================================================
299-
echo "Setting Kueue component to Unmanaged state..."
325+
echo "Checking current Kueue component state..."
300326
DSC_NAME=$(get_dsc_name) || {
301327
echo "ERROR: Failed to get DataScienceCluster name"
302328
exit 1
303329
}
304330

305-
set_kueue_management_state "Unmanaged" "$DSC_NAME" || {
306-
echo "ERROR: Failed to set Kueue to Unmanaged state"
331+
# Get and store the initial Kueue management state
332+
INITIAL_KUEUE_STATE=$(get_kueue_management_state "$DSC_NAME") || {
333+
echo "ERROR: Failed to get initial Kueue management state"
307334
exit 1
308335
}
336+
echo "Initial Kueue management state: $INITIAL_KUEUE_STATE"
309337

310-
# Wait for DataScienceCluster to be Ready after setting Kueue to Unmanaged
311-
wait_for_dsc_ready 600 || {
312-
echo "ERROR: DataScienceCluster did not reach Ready state after setting Kueue to Unmanaged"
313-
exit 1
314-
}
338+
# Export it so cleanup function can access it
339+
export INITIAL_KUEUE_STATE
340+
341+
# Only set to Unmanaged if it's not already Unmanaged
342+
if [ "$INITIAL_KUEUE_STATE" = "Unmanaged" ]; then
343+
echo "Kueue is already in Unmanaged state, skipping state change"
344+
else
345+
echo "Setting Kueue component to Unmanaged state..."
346+
set_kueue_management_state "Unmanaged" "$DSC_NAME" || {
347+
echo "ERROR: Failed to set Kueue to Unmanaged state"
348+
exit 1
349+
}
350+
351+
# Wait for DataScienceCluster to be Ready after setting Kueue to Unmanaged
352+
wait_for_dsc_ready 600 || {
353+
echo "ERROR: DataScienceCluster did not reach Ready state after setting Kueue to Unmanaged"
354+
exit 1
355+
}
356+
fi
315357

316358
# ============================================================================
317359
# Apply RBAC Policies

results/results.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="codeflare-sdk" errors="0" failures="0" skipped="0" tests="2" time="201.043" timestamp="2025-11-27T10:03:00.294945" hostname="73450509f8a1"><testcase classname="tests.upgrade.01_raycluster_sdk_upgrade_test.TestMnistJobSubmit" name="test_mnist_job_submission" time="27.377" /><testcase classname="tests.upgrade.02_dashboard_ui_upgrade_test.TestDistributedWorkloadsUIPostUpgrade" name="test_verify_cluster_persists_after_upgrade" time="169.695" /></testsuite></testsuites>

tests/ui/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,3 @@ The UI tests are designed to run in the same container as the other tests. The `
223223
- Add cross-browser testing (Firefox, Edge)
224224
- Expand coverage to other RHOAI Dashboard pages
225225
- Add performance metrics collection
226-

tests/ui/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-

tests/ui/conftest.py

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
114114

115115
# Give page time to load
116116
import time
117+
117118
time.sleep(3)
118119

119120
try:
120121
print(f"Current URL after navigation: {driver.current_url}")
121122
print(f"Page title: {driver.title}")
122-
123+
123124
# First, check if we're already on the dashboard (no login required)
124125
try:
125126
# Try multiple possible dashboard indicators
@@ -135,12 +136,14 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
135136
(By.CSS_SELECTOR, "[class*='odh-dashboard']"),
136137
(By.CSS_SELECTOR, "[class*='app-launcher']"),
137138
]
138-
139+
139140
for locator in dashboard_indicators:
140141
try:
141142
element = driver.find_element(*locator)
142143
if element.is_displayed():
143-
print(f"Already on dashboard, no login required (found: {locator})")
144+
print(
145+
f"Already on dashboard, no login required (found: {locator})"
146+
)
144147
return driver
145148
except:
146149
continue
@@ -149,19 +152,19 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
149152

150153
# Not on dashboard, try to login
151154
print("Dashboard not found, attempting login...")
152-
155+
153156
# First, check if we need to select an identity provider (OpenShift OAuth page)
154157
# This page typically shows buttons like "htpasswd", "ldap", etc.
155158
try:
156159
print("Checking for identity provider selection page...")
157-
160+
158161
# Try to find all available IDPs
159162
idp_selectors = [
160163
(By.XPATH, "//a[contains(@href, 'oauth/authorize')]"),
161164
(By.XPATH, "//div[@data-test-id='login']//a"),
162165
(By.XPATH, "//div[contains(@class, 'login')]//a"),
163166
]
164-
167+
165168
all_idp_buttons = []
166169
for by, value in idp_selectors:
167170
try:
@@ -170,33 +173,49 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
170173
elem_text = elem.text.lower() if elem.text else ""
171174
elem_href = elem.get_attribute("href") or ""
172175
# Check if it's an IDP link
173-
if "authorize" in elem_href or any(keyword in elem_text for keyword in ["htpasswd", "ldap", "login", "log in", "sign in", "kube"]):
176+
if "authorize" in elem_href or any(
177+
keyword in elem_text
178+
for keyword in [
179+
"htpasswd",
180+
"ldap",
181+
"login",
182+
"log in",
183+
"sign in",
184+
"kube",
185+
]
186+
):
174187
all_idp_buttons.append((elem, elem.text, elem_href))
175-
print(f"Found IDP option: text='{elem.text}', href='{elem_href[:100]}'")
188+
print(
189+
f"Found IDP option: text='{elem.text}', href='{elem_href[:100]}'"
190+
)
176191
except Exception as e:
177192
continue
178-
193+
179194
if all_idp_buttons:
180195
# Try to intelligently select the right IDP based on username
181196
username = test_credentials["username"].lower()
182197
selected_idp = None
183-
198+
184199
# Strategy 1: Match username pattern to IDP name
185200
if "ldap" in username:
186201
# Look for ldap IDP
187202
for elem, text, href in all_idp_buttons:
188203
if "ldap" in text.lower() or "ldap" in href.lower():
189204
selected_idp = (elem, text)
190-
print(f"Selected LDAP IDP based on username pattern: {text}")
205+
print(
206+
f"Selected LDAP IDP based on username pattern: {text}"
207+
)
191208
break
192209
elif "htpasswd" in username or "admin" in username:
193210
# Look for htpasswd IDP
194211
for elem, text, href in all_idp_buttons:
195212
if "htpasswd" in text.lower() or "htpasswd" in href.lower():
196213
selected_idp = (elem, text)
197-
print(f"Selected htpasswd IDP based on username pattern: {text}")
214+
print(
215+
f"Selected htpasswd IDP based on username pattern: {text}"
216+
)
198217
break
199-
218+
200219
# Strategy 2: If no match, use environment variable if set
201220
if not selected_idp:
202221
idp_name = os.getenv("OPENSHIFT_IDP_NAME", "").lower()
@@ -206,16 +225,18 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
206225
selected_idp = (elem, text)
207226
print(f"Selected IDP from environment variable: {text}")
208227
break
209-
228+
210229
# Strategy 3: If still no match and only one IDP, use it
211230
if not selected_idp and len(all_idp_buttons) == 1:
212231
selected_idp = (all_idp_buttons[0][0], all_idp_buttons[0][1])
213232
print(f"Only one IDP available, using: {selected_idp[1]}")
214-
233+
215234
# Strategy 4: If multiple IDPs and no match, skip IDP selection
216235
# (some clusters may not require IDP selection if there's a default)
217236
if not selected_idp:
218-
print(f"Multiple IDPs found but couldn't determine which to use. Available: {[text for _, text, _ in all_idp_buttons]}")
237+
print(
238+
f"Multiple IDPs found but couldn't determine which to use. Available: {[text for _, text, _ in all_idp_buttons]}"
239+
)
219240
print("Skipping IDP selection, will try direct login form")
220241
else:
221242
print(f"Clicking identity provider button: {selected_idp[1]}")
@@ -224,7 +245,7 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
224245
print(f"After IDP click - URL: {driver.current_url}")
225246
except Exception as e:
226247
print(f"No identity provider selection needed or failed to handle: {e}")
227-
248+
228249
# Handle OpenShift OAuth login flow
229250
# Wait for username field (various possible IDs depending on OAuth provider)
230251
username_field = None
@@ -292,18 +313,18 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
292313
# Try multiple possible indicators that we're on the dashboard
293314
print("Waiting for dashboard to load...")
294315
dashboard_loaded = False
295-
316+
296317
for i in range(6): # Try for up to 30 seconds (6 * 5 seconds)
297318
time.sleep(5)
298319
print(f"Attempt {i+1}/6 - Current URL: {driver.current_url}")
299320
print(f"Attempt {i+1}/6 - Page title: {driver.title}")
300-
321+
301322
# Check if page title indicates we're on the dashboard
302323
if "Red Hat OpenShift AI" in driver.title or "OpenShift" in driver.title:
303324
print(f"Dashboard loaded successfully (title: {driver.title})")
304325
dashboard_loaded = True
305326
break
306-
327+
307328
# Try finding dashboard elements
308329
for locator in dashboard_indicators:
309330
try:
@@ -314,7 +335,7 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
314335
break
315336
except:
316337
continue
317-
338+
318339
if dashboard_loaded:
319340
break
320341

@@ -336,14 +357,13 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
336357
print(f"Screenshot saved to: {screenshot_path}")
337358
except:
338359
pass
339-
360+
340361
# Print page source for debugging (first 1000 chars)
341362
try:
342363
print(f"\nPage source preview:\n{driver.page_source[:1000]}")
343364
except:
344365
pass
345-
366+
346367
raise
347368

348369
return driver
349-

tests/ui/pages/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-

0 commit comments

Comments
 (0)