11#!/usr/bin/env python3
22
3- # Copyright 2025 "Google LLC"
3+ # Copyright 2026 "Google LLC"
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ def setUp(self):
3030 # Reset the REPAIR_FILE path for each test
3131 repair .REPAIR_FILE = Path ("/slurm/repair_operations.json" )
3232
33- @patch ('repair.get_operations ' )
33+ @patch ('repair._get_operations ' )
3434 def test_is_node_being_repaired (self , mock_get_operations ):
3535 mock_get_operations .return_value = {
3636 "node-1" : {"status" : "REPAIR_IN_PROGRESS" },
@@ -43,26 +43,26 @@ def test_is_node_being_repaired(self, mock_get_operations):
4343 @patch ('builtins.open' , new_callable = mock_open , read_data = '{"node-1": {"status": "REPAIR_IN_PROGRESS"}}' )
4444 @patch ('pathlib.Path.exists' , return_value = True )
4545 def test_get_operations_success (self , mock_exists , mock_open_file ):
46- ops = repair .get_operations ()
46+ ops = repair ._get_operations ()
4747 self .assertEqual (ops , {"node-1" : {"status" : "REPAIR_IN_PROGRESS" }})
4848 mock_open_file .assert_called_with (repair .REPAIR_FILE , 'r' , encoding = 'utf-8' )
4949
5050 @patch ('builtins.open' , new_callable = mock_open , read_data = 'invalid json' )
5151 @patch ('pathlib.Path.exists' , return_value = True )
5252 def test_get_operations_json_decode_error (self , mock_exists , mock_open_file ):
53- ops = repair .get_operations ()
53+ ops = repair ._get_operations ()
5454 self .assertEqual (ops , {})
5555
5656 @patch ('pathlib.Path.exists' , return_value = False )
5757 def test_get_operations_file_not_found (self , mock_exists ):
58- ops = repair .get_operations ()
58+ ops = repair ._get_operations ()
5959 self .assertEqual (ops , {})
6060
6161 @patch ('builtins.open' , new_callable = mock_open )
6262 @patch ('fcntl.lockf' )
63- def test_store_operations (self , mock_lockf , mock_open_file ):
63+ def test_write_all_operations (self , mock_lockf , mock_open_file ):
6464 operations = {"node-1" : {"status" : "SUCCESS" }}
65- repair .store_operations (operations )
65+ repair ._write_all_operations (operations )
6666 mock_open_file .assert_called_with (repair .REPAIR_FILE , 'w' , encoding = 'utf-8' )
6767 handle = mock_open_file ()
6868 expected_json_string = json .dumps (operations , indent = 4 )
@@ -72,10 +72,10 @@ def test_store_operations(self, mock_lockf, mock_open_file):
7272 mock_lockf .assert_any_call (handle , fcntl .LOCK_EX )
7373 mock_lockf .assert_any_call (handle , fcntl .LOCK_UN )
7474
75- @patch ('repair.get_operations ' , return_value = {})
76- @patch ('repair.store_operations ' )
75+ @patch ('repair._get_operations ' , return_value = {})
76+ @patch ('repair._write_all_operations ' )
7777 @patch ('repair.datetime' )
78- def test_store_operation (self , mock_datetime , mock_store_operations , mock_get_operations ):
78+ def test_store_operation (self , mock_datetime , mock_write_all_operations , mock_get_operations ):
7979 mock_now = datetime (2025 , 1 , 1 , tzinfo = timezone .utc )
8080 mock_datetime .now .return_value = mock_now
8181
@@ -89,7 +89,7 @@ def test_store_operation(self, mock_datetime, mock_store_operations, mock_get_op
8989 "timestamp" : mock_now .isoformat (),
9090 }
9191 }
92- mock_store_operations .assert_called_with (expected_operations )
92+ mock_write_all_operations .assert_called_with (expected_operations )
9393
9494 @patch ('repair.lookup' )
9595 @patch ('repair.run' )
@@ -104,14 +104,14 @@ def test_call_rr_api_success(self, mock_run, mock_lookup):
104104 returncode = 0
105105 )
106106
107- op_id = repair .call_rr_api ("node-1" , "XID" )
107+ op_id = repair ._call_rr_api ("node-1" , "XID" )
108108 self .assertEqual (op_id , "op-123" )
109109 mock_run .assert_called_once ()
110110
111111 @patch ('repair.lookup' )
112112 def test_call_rr_api_instance_not_found (self , mock_lookup ):
113113 mock_lookup .return_value .instance .return_value = None
114- op_id = repair .call_rr_api ("node-1" , "XID" )
114+ op_id = repair ._call_rr_api ("node-1" , "XID" )
115115 self .assertIsNone (op_id )
116116
117117 @patch ('repair.lookup' )
@@ -120,24 +120,24 @@ def test_call_rr_api_run_error(self, mock_run, mock_lookup):
120120 mock_instance = MagicMock ()
121121 mock_instance .zone = "us-central1-a"
122122 mock_lookup .return_value .instance .return_value = mock_instance
123- op_id = repair .call_rr_api ("node-1" , "XID" )
123+ op_id = repair ._call_rr_api ("node-1" , "XID" )
124124 self .assertIsNone (op_id )
125125
126126 @patch ('repair.run' )
127127 def test_get_operation_status_success (self , mock_run ):
128128 mock_run .return_value .stdout = '[{"status": "DONE"}]'
129- status = repair .get_operation_status ("op-123" )
129+ status = repair ._get_operation_status ("op-123" )
130130 self .assertEqual (status , {"status" : "DONE" })
131131
132132 @patch ('repair.run' )
133133 def test_get_operation_status_empty_list (self , mock_run ):
134134 mock_run .return_value .stdout = '[]'
135- status = repair .get_operation_status ("op-123" )
135+ status = repair ._get_operation_status ("op-123" )
136136 self .assertIsNone (status )
137137
138- @patch ('repair.get_operations ' )
139- @patch ('repair.store_operations ' )
140- @patch ('repair.get_operation_status ' )
138+ @patch ('repair._get_operations ' )
139+ @patch ('repair._write_all_operations ' )
140+ @patch ('repair._get_operation_status ' )
141141 @patch ('repair.lookup' )
142142 @patch ('repair.run' )
143143 def test_poll_operations (self , mock_run , mock_lookup , mock_get_op_status , mock_store_ops , mock_get_ops ):
0 commit comments