|
""" |
|
Test script to verify directory permissions and file creation capabilities. |
|
This script should be run inside the container to verify the fixes. |
|
""" |
|
import os |
|
import tempfile |
|
import sys |
|
from pathlib import Path |
|
|
|
def test_directory_permissions(): |
|
"""Test if we can create directories and files in the expected locations.""" |
|
|
|
print("=== Directory Permission Test ===") |
|
|
|
|
|
test_dirs = [ |
|
"/data/advisorai-data/test", |
|
"/data/merged/test", |
|
"/data/alpaca/test", |
|
"/data/crypto-bubbles/test", |
|
"/data/finnhub/test", |
|
"/data/finviz/test", |
|
"/data/marketaux/test" |
|
] |
|
|
|
success_count = 0 |
|
for test_dir in test_dirs: |
|
try: |
|
|
|
os.makedirs(test_dir, mode=0o755, exist_ok=True) |
|
|
|
|
|
test_file = os.path.join(test_dir, "test_write.txt") |
|
with open(test_file, 'w') as f: |
|
f.write(f"Test write successful at {test_dir}") |
|
|
|
|
|
with open(test_file, 'r') as f: |
|
content = f.read() |
|
|
|
|
|
os.remove(test_file) |
|
os.rmdir(test_dir) |
|
|
|
print(f"β
SUCCESS: {test_dir}") |
|
success_count += 1 |
|
|
|
except Exception as e: |
|
print(f"β FAILED: {test_dir} - {e}") |
|
|
|
print(f"\nπ Results: {success_count}/{len(test_dirs)} directories passed the test") |
|
|
|
if success_count == len(test_dirs): |
|
print("π All directory permission tests PASSED!") |
|
return True |
|
else: |
|
print("β οΈ Some directory permission tests FAILED!") |
|
return False |
|
|
|
def test_user_info(): |
|
"""Display current user and process information.""" |
|
print("\n=== User & Process Information ===") |
|
|
|
|
|
if hasattr(os, 'getuid'): |
|
|
|
print(f"Current UID: {os.getuid()}") |
|
print(f"Current GID: {os.getgid()}") |
|
print(f"Effective UID: {os.geteuid()}") |
|
print(f"Effective GID: {os.getegid()}") |
|
|
|
|
|
if os.getuid() == 0: |
|
print("β
Running as root user") |
|
else: |
|
print("βΉοΈ Running as non-root user") |
|
else: |
|
|
|
print("βΉοΈ Running on Windows system") |
|
print(f"Current user: {os.getenv('USERNAME', 'Unknown')}") |
|
|
|
print(f"Process ID: {os.getpid()}") |
|
print(f"Parent Process ID: {os.getppid()}") |
|
|
|
def test_filebase_connectivity(): |
|
"""Test if we can load environment variables needed for Filebase.""" |
|
print("\n=== Environment Variables Test ===") |
|
|
|
required_vars = [ |
|
'FILEBASE_ENDPOINT', |
|
'FILEBASE_ACCESS_KEY', |
|
'FILEBASE_SECRET_KEY', |
|
'FILEBASE_BUCKET' |
|
] |
|
|
|
missing_vars = [] |
|
for var in required_vars: |
|
value = os.getenv(var) |
|
if value: |
|
|
|
if 'KEY' in var: |
|
print(f"β
{var}: ***redacted*** (length: {len(value)})") |
|
else: |
|
print(f"β
{var}: {value}") |
|
else: |
|
print(f"β {var}: NOT SET") |
|
missing_vars.append(var) |
|
|
|
if missing_vars: |
|
print(f"β οΈ Missing environment variables: {missing_vars}") |
|
return False |
|
else: |
|
print("π All required environment variables are set!") |
|
return True |
|
|
|
if __name__ == "__main__": |
|
print("Starting permission and environment tests...\n") |
|
|
|
test_user_info() |
|
perm_test = test_directory_permissions() |
|
env_test = test_filebase_connectivity() |
|
|
|
print(f"\n=== Final Results ===") |
|
if perm_test and env_test: |
|
print("π ALL TESTS PASSED! The container should work correctly.") |
|
sys.exit(0) |
|
else: |
|
print("β SOME TESTS FAILED! Check the output above for details.") |
|
sys.exit(1) |
|
|