Skip to content

Commit

Permalink
fix(ci): minor fixes
Browse files Browse the repository at this point in the history
fix utils communicate to use bytes instead of str. Move shell scripts to respective components
  • Loading branch information
BrianLusina committed Jun 1, 2020
1 parent a699368 commit bd2decd
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 37 deletions.
9 changes: 3 additions & 6 deletions ci/dispatcher/dispatcher_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ class DispatcherHandler(socketserver.BaseRequestHandler):
command_re = re.compile(r"(\w+)(:.+)*")
BUF_SIZE = 1024

def __init__(self):
super().__init__()
def handle(self):
self.data = self.request.recv(self.BUF_SIZE).strip()
self.command_groups = self.command_re.match(self.data)
self.commands = {
"status": self.check_status,
"register": self.register,
"dispatch": self.dispatch,
"results": self.results,
}

def handle(self):
self.data = self.request.recv(self.BUF_SIZE).strip()
self.command_groups = self.command_re.match(self.data)

if not self.command_groups:
self.invalid_command()
return
Expand Down
6 changes: 3 additions & 3 deletions ci/repo_observer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def observer(dispatcher_host, dispatcher_port, repo, poll, branch):
# for changes. If there's a change, it will drop a .commit_id file
# with the latest commit in the current working directory
logger.info(f"cloning repo {repo}")
subprocess.check_output(["./scripts/update_repo.sh", repo, branch])
subprocess.check_output(["./update_repo.sh", repo, branch])
except subprocess.CalledProcessError as e:
logger.error(f"Failed to update & check repo {repo}, err: {e.output}")
raise RepoObserverError(
f"Could not update & check repository. Err: {e.output}"
)

if os.path.isfile("files/.commit_id"):
if os.path.isfile(".commit_id"):
# great, we have a change! let's execute the tests
# First, check the status of the dispatcher server to see
# if we can send the tests
Expand All @@ -57,7 +57,7 @@ def observer(dispatcher_host, dispatcher_port, repo, poll, branch):
# Dispatcher is available
commit = ""

with open("files/.commit_id") as commit_file:
with open(".commit_id") as commit_file:
commit = commit_file.readline

response = communicate(
Expand Down
13 changes: 11 additions & 2 deletions scripts/update_repo.sh → ci/repo_observer/update_repo.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/bin/bash

source ./scripts/run_or_fail.sh
# helper method for providing error messages for a command
run_or_fail() {
local explanation=$1
shift 1
"$@"
if [ $? != 0 ]; then
echo $explanation 1>&2
exit 1
fi
}

# delete previous id
rm -f files/.commit_id
rm -f .commit_id

# go to repo and update it to given commit
run_or_fail "Repository folder not found!" pushd $1 1> /dev/null
Expand Down
2 changes: 1 addition & 1 deletion ci/test_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_runner_server(host, port, repo, dispatcher_host, dispatcher_port):

runner_host = host
runner_port = None
tries = 100
tries = 0

if not port:
runner_port = range_start
Expand Down
5 changes: 1 addition & 4 deletions ci/test_runner/test_runner_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ class TestRunnerHandler(BaseRequestHandler):

command_re = re.compile(r"(\w+)(:.+)*")

def __init__(self):
super().__init__()
self.commands = {"ping": self.health_check, "runtest": self.runtest}

def handle(self):
self.data = self.request.recv(1024).strip()
self.command_groups = self.command_re.match(self.data)
self.commands = {"ping": self.health_check, "runtest": self.runtest}
command = command_groups.group(1)

# Handle commands, if none match, handle invalid command
Expand Down
Empty file modified ci/test_runner/test_runner_script.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion ci/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def communicate(host, port, request):
"""
s = socket()
s.connect((host, port))
s.send(request)
s.send(bytes(request, "utf-8"))
response = s.recv(1024)
s.close()
return response
Empty file removed files/.gitkeep
Empty file.
10 changes: 0 additions & 10 deletions scripts/run_or_fail.sh

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/test_runner.sh

This file was deleted.

0 comments on commit bd2decd

Please sign in to comment.