Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rator into test/ssh-integration
  • Loading branch information
yanksyoon committed Jan 18, 2024
2 parents 0e07706 + 0c28442 commit e430336
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 336 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
EOF
- name: Cache github-runner Charm
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-charm
with:
path: github-runner_ubuntu-22.04-amd64.charm
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju2.9
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner", "test_charm_with_proxy", "test_charm_with_juju_storage", "test_debug_ssh"]'
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics_success", "test_charm_metrics_failure", "test_self_hosted_runner", "test_charm_with_proxy", "test_charm_with_juju_storage", "test_debug_ssh"]'
integration-tests-juju3:
name: Integration test with juju 3.1
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
Expand All @@ -23,4 +23,4 @@ jobs:
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju3.1
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner", "test_charm_with_proxy", "test_charm_with_juju_storage", "test_debug_ssh"]'
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics_success", "test_charm_metrics_failure", "test_self_hosted_runner", "test_charm_with_proxy", "test_charm_with_juju_storage", "test_debug_ssh"]'
2 changes: 1 addition & 1 deletion .github/workflows/workflow_dispatch_ssh_debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
steps:
- name: Setup tmate session
uses: canonical/action-tmate@chore/env_var_change
timeout-minutes: 1
timeout-minutes: 5
6 changes: 6 additions & 0 deletions scripts/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ retry '/snap/bin/lxc exec builder -- /usr/bin/nslookup github.com' 'Wait for net
/snap/bin/lxc exec builder -- /usr/bin/apt-get update
/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get upgrade -yq
/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get install linux-generic-hwe-22.04 -yq
# This will remove older version of kernel as HWE is installed now.
/snap/bin/lxc exec builder -- /usr/bin/apt-get autoremove --purge

/snap/bin/lxc restart builder
retry '/snap/bin/lxc exec builder -- /usr/bin/who' 'Wait for lxd agent to be ready' 30
Expand All @@ -107,6 +109,10 @@ fi
/snap/bin/lxc exec builder -- /usr/sbin/usermod -aG docker ubuntu
/snap/bin/lxc exec builder -- /usr/sbin/iptables -I DOCKER-USER -j ACCEPT

# Reduce image size
/snap/bin/lxc exec builder -- /usr/bin/npm cache clean --force
/snap/bin/lxc exec builder -- /usr/bin/apt-get clean

# Download and verify checksum of yq
if [[ $(uname -m) == 'aarch64' ]]; then
YQ_ARCH="arm64"
Expand Down
3 changes: 2 additions & 1 deletion src-docs/event_timer.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Construct the timer manager.

---

<a href="../src/event_timer.py#L99"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/event_timer.py#L105"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `disable_event_timer`

Expand Down Expand Up @@ -96,6 +96,7 @@ The timeout is the number of seconds before an event is timed out. If not set or

- <b>`event_name`</b>: Name of the juju event to schedule.
- <b>`interval`</b>: Number of minutes between emitting each event.
- <b>`timeout`</b>: Timeout for each event handle in minutes.



Expand Down
5 changes: 3 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def __init__(self, *args, **kargs) -> None:
path=self.config["path"], # for detecting changes
token=self.config["token"], # for detecting changes
runner_bin_url=None,
runner_image_url=None,
)

self.proxies: ProxySetting = {}
Expand Down Expand Up @@ -503,7 +502,9 @@ def _on_config_changed(self, _event: ConfigChangedEvent) -> None:
self._refresh_firewall()
try:
self._event_timer.ensure_event_timer(
"reconcile-runners", self.config["reconcile-interval"]
event_name="reconcile-runners",
interval=int(self.config["reconcile-interval"]),
timeout=int(self.config["reconcile-interval"]) - 1,
)
except TimerEnableError as ex:
logger.exception("Failed to start the event timer")
Expand Down
8 changes: 7 additions & 1 deletion src/event_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ def ensure_event_timer(self, event_name: str, interval: int, timeout: Optional[i
Args:
event_name: Name of the juju event to schedule.
interval: Number of minutes between emitting each event.
timeout: Timeout for each event handle in minutes.
Raises:
TimerEnableError: Timer cannot be started. Events will be not emitted.
"""
if timeout is not None:
timeout_in_secs = timeout * 60
else:
timeout_in_secs = interval * 30

context: EventConfig = {
"event": event_name,
"interval": interval,
"random_delay": interval // 4,
"timeout": timeout or (interval * 30),
"timeout": timeout_in_secs,
"unit": self.unit_name,
}
self._render_event_template("service", event_name, context)
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
Loading

0 comments on commit e430336

Please sign in to comment.