Skip to content

Commit

Permalink
Added condition.release() after killing storm-webdav
Browse files Browse the repository at this point in the history
  • Loading branch information
vrbanecd committed Jan 24, 2025
1 parent a52b95e commit 025093f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion robot/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
curl -O https://syncandshare.desy.de/index.php/s/Ncj3Lfk8iEGYGsf/download/teapot-tests.robot
curl -O https://syncandshare.desy.de/index.php/s/Zzr8qMipiL2En5D/download/variables.py
robot --outputdir robot/output/ /tmp/teapot-tests.robot
echo "Something . "
echo "Something else. "
while true; do sleep 1; done'
networks:
- test
Expand Down
30 changes: 11 additions & 19 deletions teapot.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ async def _start_webdav_instance(username, port):
# the process in it's own process group
# such that it can be managed on its own.

logger.info("trying to start process for user %s", username)
logger.debug("trying to start process for user %s", username)
loc = f"/var/lib/{APP_NAME}/user-{username}/config/application.yml"
# trunk-ignore(bandit/B108)
cmd = f"sudo --preserve-env={','.join(env_pass)} -u {username} \
Expand All @@ -403,15 +403,10 @@ async def _start_webdav_instance(username, port):
--spring.config.additional-location=optional:file:{loc} \
1>$STORM_WEBDAV_OUT 2>$STORM_WEBDAV_ERR &"

# try:
logger.info("cmd=%s", cmd)
logger.debug("cmd=%s", cmd)
p = subprocess.Popen(
cmd, shell=True, preexec_fn=os.setsid # trunk-ignore(bandit/B602)
) # GitHub Issue #30
# except subprocess.CalledProcessError as e:
# logger.error("Failed to start subprocess for user %s: %s", username,
# str(e))
# return False

# wait for it...
await anyio.sleep(1)
Expand Down Expand Up @@ -476,6 +471,7 @@ async def _stop_webdav_instance(username, state, condition):
if state[username] == "RUNNING":
state[username] = "STOPPING"
condition.notify()
logger.debug("Stopping storm-webdav server for user %s", user)
async with app.state.state_lock:
try:
session = app.state.session_state.pop(username)
Expand Down Expand Up @@ -505,6 +501,8 @@ async def _stop_webdav_instance(username, state, condition):
if state[username] == "STOPPING":
state[username] = "NOT RUNNING"
condition.notify()
condition.release()

except subprocess.CalledProcessError as e:
logger.error(
"Exception occurred while trying to kill process \
Expand Down Expand Up @@ -537,20 +535,10 @@ async def stop_expired_instances():
"""
while True:
await asyncio.sleep(CHECK_INTERVAL_SEC)
logger.debug("checking for expired instances")
async with app.state.state_lock:
logger.debug(
"stop_expired_instances: acquired 'users' lock at %s",
{datetime.datetime.now().isoformat()},
)
users = list(app.state.session_state.keys())
now = datetime.datetime.now()
for user in users:
logger.debug(
"stop_expired_instances: trying to acquire 'user_dict' \
lock at %s",
{datetime.datetime.now().isoformat()},
)
async with app.state.state_lock:
user_dict = app.state.session_state.get(user, None)
if user_dict is not None:
Expand Down Expand Up @@ -744,13 +732,17 @@ async def storm_webdav_state(state, condition, user):
state[user] = "STARTING"
condition.notify()
should_start_sw = True
logger.debug("Storm-webdav instance for user %s is starting", user)

elif state[user] == "RUNNING":
async with app.state.state_lock:
app.state.session_state[user]["last_accessed"] = str(
datetime.datetime.now()
)
should_start_sw = False
logger.debug(
"Storm webdav instance for user %s is already running", user
)

else:
await condition.wait()
Expand Down Expand Up @@ -780,14 +772,14 @@ async def storm_webdav_state(state, condition, user):
async with condition:
if state[user] == "STARTING":
state[user] = "RUNNING"
condition.notify()
async with app.state.state_lock:
app.state.session_state[user] = {
"pid": pid,
"port": port,
"created_at": datetime.datetime.now(),
"last_accessed": str(datetime.datetime.now()),
}
condition.notify()
logger.info(
"StoRM-WebDAV instance for user %s is now starting on port %d",
user,
Expand All @@ -801,7 +793,7 @@ async def storm_webdav_state(state, condition, user):
port = app.state.session_state[user].get("port", None)
logger.info(
"StoRM-WebDAV instance for %s is running on port %d", user, port
)
)
return port


Expand Down

1 comment on commit 025093f

@vrbanecd
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
32 0 0 32 100 53.439946s

Passed Tests

Name ⏱️ Duration Suite
GET USER1 9.573 s Teapot-Tests
GET USER2 9.617 s Teapot-Tests
GET NO TOKEN 0.013 s Teapot-Tests
GET INVALID TOKEN 0.040 s Teapot-Tests
PUT REQUEST INVALID TOKEN 0.010 s Teapot-Tests
PUT REQUEST NO TOKEN 0.009 s Teapot-Tests
PUT REQUEST USER1 2.196 s Teapot-Tests
PUT REQUEST USER2 2.184 s Teapot-Tests
GET FILE USER1 3.201 s Teapot-Tests
GET FILE USER2 3.196 s Teapot-Tests
GET FILE NO TOKEN 0.011 s Teapot-Tests
GET FILE INVALID TOKEN 0.009 s Teapot-Tests
DELETE REQUEST USER1 2.114 s Teapot-Tests
DELETE REQUEST USER2 2.120 s Teapot-Tests
DELETE REQUEST INVALID TOKEN 0.011 s Teapot-Tests
DELETE REQUEST NO TOKEN 0.010 s Teapot-Tests
GET USER1 EXTRA_AREA 2.105 s Teapot-Tests
GET USER2 EXTRA_AREA 2.127 s Teapot-Tests
GET NO TOKEN EXTRA_AREA 0.010 s Teapot-Tests
GET INVALID TOKEN EXTRA_AREA 0.010 s Teapot-Tests
PUT REQUEST INVALID TOKEN EXTRA_AREA 0.009 s Teapot-Tests
PUT REQUEST NO TOKEN EXTRA_AREA 0.009 s Teapot-Tests
PUT REQUEST USER1 EXTRA_AREA 2.118 s Teapot-Tests
PUT REQUEST USER2 EXTRA_AREA 2.132 s Teapot-Tests
GET FILE USER1 EXTRA_AREA 3.176 s Teapot-Tests
GET FILE USER2 EXTRA_AREA 3.174 s Teapot-Tests
GET FILE NO TOKEN EXTRA_AREA 0.011 s Teapot-Tests
GET FILE INVALID TOKEN EXTRA_AREA 0.009 s Teapot-Tests
DELETE REQUEST USER1 EXTRA_AREA 2.112 s Teapot-Tests
DELETE REQUEST USER2 EXTRA_AREA 2.103 s Teapot-Tests
DELETE REQUEST INVALID TOKEN EXTRA_AREA 0.011 s Teapot-Tests
DELETE REQUEST NO TOKEN EXTRA_AREA 0.010 s Teapot-Tests

Please sign in to comment.