-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_etcd_client_logging.py
More file actions
65 lines (49 loc) · 1.85 KB
/
fix_etcd_client_logging.py
File metadata and controls
65 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Script to replace clientv3.New() calls with the new NewEtcdClient() helper function
that suppresses lease keep-alive warnings.
"""
import re
import glob
import os
def process_file(filepath):
"""Process a single test file to replace clientv3.New() calls."""
with open(filepath, 'r') as f:
content = f.read()
original_content = content
# Pattern 1: Simple clientv3.New with Config on same line
# Example: clientv3.New(clientv3.Config{
# Endpoints: []string{addr},
# DialTimeout: 5 * time.Second,
# })
# Find all occurrences
pattern = r'clientv3\.New\(clientv3\.Config\{([^}]+)\}\)'
def replace_match(match):
config_content = match.group(1)
# Extract endpoints and dial timeout
endpoints_match = re.search(r'Endpoints:\s*(\[[^\]]+\])', config_content)
timeout_match = re.search(r'DialTimeout:\s*([^,\n]+)', config_content)
if not endpoints_match or not timeout_match:
# If we can't parse it, leave it as is
return match.group(0)
endpoints = endpoints_match.group(1).strip()
timeout = timeout_match.group(1).strip().rstrip(',')
return f'NewEtcdClient({endpoints}, {timeout})'
content = re.sub(pattern, replace_match, content, flags=re.DOTALL)
# Only write if changed
if content != original_content:
with open(filepath, 'w') as f:
f.write(content)
return True
return False
def main():
"""Process all test files in the test directory."""
test_files = glob.glob('test/*_test.go')
modified_count = 0
for filepath in test_files:
if process_file(filepath):
print(f'Modified: {filepath}')
modified_count += 1
print(f'\nTotal files modified: {modified_count}')
if __name__ == '__main__':
main()