Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Jun 19, 2023
1 parent 6f6bcd3 commit 5bfec9c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 138 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/build_charm.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Upload github-runner Charm
uses: actions/upload-artifact@v3
with:
name: github-runner_ubuntu-22.04-amd64.charm
name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm
path: github-runner_ubuntu-22.04-amd64.charm

run-id:
Expand All @@ -74,18 +74,15 @@ jobs:
runs-on: ubuntu-latest
needs: [ build-charm, run-id ]
steps:
- name: Enable Kernel Modules
run: |
for m in ip_tables ip6_tables nf_nat overlay br_netfilter; do
sudo modprobe $m;
done
- name: Setup Lxd Juju Controller
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: 3.1/stable
provider: lxd

- name: Install GitHub Cli
run: which gh || sudo apt install gh -y

- name: Create Testing Juju Model
run: juju add-model testing

Expand All @@ -101,7 +98,7 @@ jobs:
- name: Download github-runner Charm
uses: actions/download-artifact@v3
with:
name: github-runner_ubuntu-22.04-amd64.charm
name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm

- name: Deploy github-runner Charm
run: |
Expand All @@ -112,14 +109,11 @@ jobs:
--config path=${{ secrets.E2E_TESTING_REPO }} \
--config token=${{ secrets.E2E_TESTING_TOKEN }} \
--config virtual-machines=1 \
--force
- name: Install GitHub Cli
run: which gh || sudo apt install gh -y
- name: Watch github-runner
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 30
run: |
juju debug-log --replay --tail &
Expand Down
67 changes: 0 additions & 67 deletions .github/workflows/end_to_end_test.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Tests

on: {}
# pull_request:
on:
pull_request: { }

jobs:
unit-tests:
Expand Down
6 changes: 4 additions & 2 deletions src/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ def mk_dir(self, dir_name: str) -> None:
"--",
"/usr/bin/mkdir",
"-p",
dir_name
dir_name,
]
try:
execute_command(lxc_command)
except SubprocessError as err:
logger.exception("Failed to create directory")
raise LxdError(f"Unable to create directory in LXD instance {self.instance.name}") from err
raise LxdError(
f"Unable to create directory in LXD instance {self.instance.name}"
) from err

def push_file(self, source: str, destination: str, mode: Optional[str] = None) -> None:
"""Push a file to the LXD instance.
Expand Down
30 changes: 16 additions & 14 deletions src/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class Runner:
pre_job_script = runner_application / "pre-job.sh"

def __init__(
self,
clients: RunnerClients,
runner_config: RunnerConfig,
runner_status: RunnerStatus,
instance: Optional[LxdInstance] = None,
self,
clients: RunnerClients,
runner_config: RunnerConfig,
runner_status: RunnerStatus,
instance: Optional[LxdInstance] = None,
):
"""Construct the runner instance.
Expand All @@ -80,11 +80,11 @@ def __init__(
self.instance = instance

def create(
self,
image: str,
resources: VirtualMachineResources,
binary_path: Path,
registration_token: str,
self,
image: str,
resources: VirtualMachineResources,
binary_path: Path,
registration_token: str,
):
"""Create the runner instance on LXD and register it on GitHub.
Expand Down Expand Up @@ -193,7 +193,7 @@ def remove(self, remove_token: str) -> None:

@retry(tries=5, delay=1, local_logger=logger)
def _create_instance(
self, image: str, resources: VirtualMachineResources, ephemeral: bool = True
self, image: str, resources: VirtualMachineResources, ephemeral: bool = True
) -> LxdInstance:
"""Create an instance of runner.
Expand Down Expand Up @@ -318,14 +318,16 @@ def _start_instance(self) -> None:
# Setting `wait=True` only ensure the instance has begin to boot up.
self.instance.start(wait=True)

@retry(tries=120, delay=30, local_logger=logger)
@retry(tries=20, delay=30, local_logger=logger)
def _wait_boot_up(self) -> None:
if self.instance is None:
raise RunnerError("Runner operation called prior to runner creation.")

# Wait for the instance to finish to boot up and network to be up.
assert self.instance.execute(["/usr/bin/who"])[0] == 0
assert self.instance.execute(["/usr/bin/nslookup", "github.com"])[0] == 0
if self.instance.execute(["/usr/bin/who"])[0] != 0:
raise RunnerError("Runner system is not ready")
if self.instance.execute(["/usr/bin/nslookup", "github.com"])[0] != 0:
raise RunnerError("Runner network is not ready")

logger.info("Finished booting up LXD instance for runner: %s", self.config.name)

Expand Down
18 changes: 9 additions & 9 deletions src/runner_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class RunnerManager:
runner_bin_path = Path("/opt/github-runner-app")

def __init__(
self,
app_name: str,
unit: int,
runner_manager_config: RunnerManagerConfig,
proxies: ProxySetting = ProxySetting(),
self,
app_name: str,
unit: int,
runner_manager_config: RunnerManagerConfig,
proxies: ProxySetting = ProxySetting(),
) -> None:
"""Construct RunnerManager object for creating and managing runners.
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(

@retry(tries=5, delay=30, local_logger=logger)
def get_latest_runner_bin_url(
self, os_name: str = "linux", arch_name: str = "x64"
self, os_name: str = "linux", arch_name: str = "x64"
) -> RunnerApplication:
"""Get the URL for the latest runner binary.
Expand Down Expand Up @@ -407,9 +407,9 @@ def _get_runners(self) -> list[Runner]:
"""

def create_runner_info(
name: str,
local_runner: Optional[LxdInstance],
remote_runner: Optional[SelfHostedRunner],
name: str,
local_runner: Optional[LxdInstance],
remote_runner: Optional[SelfHostedRunner],
) -> Runner:
"""Create runner from information from GitHub and LXD."""
logger.debug(
Expand Down

0 comments on commit 5bfec9c

Please sign in to comment.