Skip to content

Commit 507b743

Browse files
authored
test: Separate applying calico rules to different job; add job to apply cfw after integration tests are executed; update test_invalid_file test case (#663)
Co-authored-by: Youjung Kim <126618609+ykim-1@users.noreply.github.com>
1 parent 19ee0b7 commit 507b743

File tree

4 files changed

+141
-37
lines changed

4 files changed

+141
-37
lines changed

.github/workflows/e2e-suite-windows.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,60 @@ jobs:
103103
conclusion: process.env.conclusion
104104
});
105105
return result;
106+
107+
apply-calico-rules:
108+
runs-on: ubuntu-latest
109+
needs: [integration-fork-windows]
110+
if: ${{ success() || failure() }}
111+
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
with:
116+
fetch-depth: 0
117+
submodules: 'recursive'
118+
119+
- name: Download kubectl and calicoctl for LKE clusters
120+
run: |
121+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
122+
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
123+
chmod +x calicoctl-linux-amd64 kubectl
124+
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
125+
mv kubectl /usr/local/bin/kubectl
126+
127+
- name: Apply Calico Rules to LKE
128+
run: |
129+
cd e2e_scripts/cloud_security_scripts/lke_calico_rules/ && ./lke_calico_rules_e2e.sh
130+
env:
131+
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN_2 }}
132+
133+
add-fw-to-remaining-instances:
134+
runs-on: ubuntu-latest
135+
needs: [integration-fork-windows]
136+
if: ${{ success() || failure() }}
137+
138+
steps:
139+
- name: Set up Python
140+
uses: actions/setup-python@v5
141+
with:
142+
python-version: '3.x'
143+
144+
- name: Install Linode CLI
145+
run: |
146+
pip install linode-cli
147+
148+
- name: Create Firewall and Attach to Instances
149+
run: |
150+
FIREWALL_ID=$(linode-cli firewalls create --label "e2e-fw-$(date +%s)" --rules.inbound_policy "DROP" --rules.outbound_policy "ACCEPT" --text --format=id --no-headers)
151+
echo "Created Firewall with ID: $FIREWALL_ID"
152+
153+
for instance_id in $(linode-cli linodes list --format "id" --text --no-header); do
154+
echo "Attaching firewall to instance: $instance_id"
155+
if linode-cli firewalls device-create "$FIREWALL_ID" --id "$instance_id" --type linode; then
156+
echo "Firewall attached to instance $instance_id successfully."
157+
else
158+
echo "An error occurred while attaching firewall to instance $instance_id. Skipping..."
159+
fi
160+
done
161+
env:
162+
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN_2 }}

.github/workflows/e2e-suite.yml

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ on:
77
description: 'Use minimal test account'
88
required: false
99
default: 'false'
10-
test_path:
11-
description: "The path from 'test/integration' to the target to be tested, e.g. 'cli'"
10+
module:
11+
description: "The module from 'test/integration' to the target to be tested, e.g. 'cli, domains, events, etc'"
1212
required: false
1313
sha:
1414
description: 'The hash value of the commit.'
15-
required: false
15+
required: true
1616
default: ''
1717
pull_request_number:
1818
description: 'The number of the PR. Ensure sha value is provided'
@@ -28,15 +28,6 @@ jobs:
2828
runs-on: ubuntu-latest
2929
if: github.event_name == 'workflow_dispatch' && inputs.sha != '' || github.event_name == 'push' || github.event_name == 'pull_request'
3030
steps:
31-
- name: Validate Test Path
32-
uses: actions-ecosystem/action-regex-match@v2
33-
id: validate-tests
34-
if: ${{ inputs.test_path != '' }}
35-
with:
36-
text: ${{ inputs.test_path }}
37-
regex: '[^a-z0-9-:.\/_]' # Tests validation
38-
flags: gi
39-
4031
- name: Checkout Repository with SHA
4132
if: ${{ inputs.sha != '' }}
4233
uses: actions/checkout@v4
@@ -91,14 +82,6 @@ jobs:
9182
pip install certifi -U && \
9283
pip install .[obj,dev]
9384
94-
- name: Download kubectl and calicoctl for LKE clusters
95-
run: |
96-
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
97-
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
98-
chmod +x calicoctl-linux-amd64 kubectl
99-
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
100-
mv kubectl /usr/local/bin/kubectl
101-
10285
- name: Install Package
10386
run: make install
10487
env:
@@ -112,18 +95,10 @@ jobs:
11295
run: |
11396
timestamp=$(date +'%Y%m%d%H%M')
11497
report_filename="${timestamp}_cli_test_report.xml"
115-
make testint TEST_ARGS="--junitxml=${report_filename}"
116-
if: ${{ steps.validate-tests.outputs.match == '' || inputs.test_path == '' }}
98+
make testint TEST_ARGS="--junitxml=${report_filename}" MODULE="${{ inputs.module }}"
11799
env:
118100
LINODE_CLI_TOKEN: ${{ env.LINODE_CLI_TOKEN }}
119101

120-
- name: Apply Calico Rules to LKE
121-
if: always()
122-
run: |
123-
cd scripts && ./lke_calico_rules_e2e.sh
124-
env:
125-
LINODE_TOKEN: ${{ env.LINODE_CLI_TOKEN }}
126-
127102
- name: Upload test results
128103
if: always()
129104
run: |
@@ -168,10 +143,75 @@ jobs:
168143
});
169144
return result;
170145
146+
apply-calico-rules:
147+
runs-on: ubuntu-latest
148+
needs: [integration_tests]
149+
if: ${{ success() || failure() }}
150+
151+
steps:
152+
- name: Checkout code
153+
uses: actions/checkout@v4
154+
with:
155+
fetch-depth: 0
156+
submodules: 'recursive'
157+
158+
- name: Set LINODE_CLI_TOKEN
159+
run: |
160+
echo "LINODE_CLI_TOKEN=${{ secrets[inputs.use_minimal_test_account == 'true' && 'MINIMAL_LINODE_TOKEN' || 'LINODE_TOKEN'] }}" >> $GITHUB_ENV
161+
162+
- name: Download kubectl and calicoctl for LKE clusters
163+
run: |
164+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
165+
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
166+
chmod +x calicoctl-linux-amd64 kubectl
167+
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
168+
mv kubectl /usr/local/bin/kubectl
169+
170+
- name: Apply Calico Rules to LKE
171+
run: |
172+
cd e2e_scripts/cloud_security_scripts/lke_calico_rules/ && ./lke_calico_rules_e2e.sh
173+
env:
174+
LINODE_TOKEN: ${{ env.LINODE_CLI_TOKEN }}
175+
176+
add-fw-to-remaining-instances:
177+
runs-on: ubuntu-latest
178+
needs: [integration_tests]
179+
if: ${{ success() || failure() }}
180+
181+
steps:
182+
- name: Set up Python
183+
uses: actions/setup-python@v5
184+
with:
185+
python-version: '3.x'
186+
187+
- name: Install Linode CLI
188+
run: |
189+
pip install linode-cli
190+
191+
- name: Set LINODE_CLI_TOKEN
192+
run: |
193+
echo "LINODE_CLI_TOKEN=${{ secrets[inputs.use_minimal_test_account == 'true' && 'MINIMAL_LINODE_TOKEN' || 'LINODE_TOKEN'] }}" >> $GITHUB_ENV
194+
195+
- name: Create Firewall and Attach to Instances
196+
run: |
197+
FIREWALL_ID=$(linode-cli firewalls create --label "e2e-fw-$(date +%s)" --rules.inbound_policy "DROP" --rules.outbound_policy "ACCEPT" --text --format=id --no-headers)
198+
echo "Created Firewall with ID: $FIREWALL_ID"
199+
200+
for instance_id in $(linode-cli linodes list --format "id" --text --no-header); do
201+
echo "Attaching firewall to instance: $instance_id"
202+
if linode-cli firewalls device-create "$FIREWALL_ID" --id "$instance_id" --type linode; then
203+
echo "Firewall attached to instance $instance_id successfully."
204+
else
205+
echo "An error occurred while attaching firewall to instance $instance_id. Skipping..."
206+
fi
207+
done
208+
env:
209+
LINODE_CLI_TOKEN: ${{ env.LINODE_CLI_TOKEN }}
210+
171211
notify-slack:
172212
runs-on: ubuntu-latest
173213
needs: [integration_tests]
174-
if: always() && github.repository == 'linode/linode-cli' # Run even if integration tests fail and only on main repository
214+
if: ${{ (success() || failure()) && github.repository == 'linode/linode-cli' }} # Run even if integration tests fail and only on main repository
175215

176216
steps:
177217
- name: Notify Slack

tests/integration/image/test_plugin_image_upload.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
import pytest
1010

11-
from tests.integration.helpers import assert_headers_in_lines, get_random_text
11+
from tests.integration.helpers import (
12+
assert_headers_in_lines,
13+
exec_failing_test_command,
14+
get_random_text,
15+
)
1216

1317
REGION = "us-iad"
1418
BASE_CMD = ["linode-cli", "image-upload", "--region", REGION]
@@ -52,13 +56,13 @@ def test_invalid_file(
5256
fake_image_file,
5357
):
5458
file_path = fake_image_file + "_fake"
55-
process = exec_test_command(
56-
BASE_CMD + ["--label", "notimportant", file_path]
59+
process = exec_failing_test_command(
60+
BASE_CMD + ["--label", "notimportant", file_path], expected_code=8
5761
)
58-
output = process.stdout.decode()
62+
error_output = process.stderr.decode()
5963

6064
assert process.returncode == 8
61-
assert f"No file at {file_path}" in output
65+
assert f"No file at {file_path}" in error_output
6266

6367

6468
@pytest.mark.smoke

tests/integration/ssh/test_plugin_ssh.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from tests.integration.helpers import (
99
COMMAND_JSON_OUTPUT,
10+
exec_failing_test_command,
1011
get_random_text,
1112
wait_for_condition,
1213
)
@@ -83,9 +84,11 @@ def test_help():
8384

8485
@pytest.mark.skipif(platform == "win32", reason="Test N/A on Windows")
8586
def test_ssh_instance_provisioning(target_instance: Dict[str, Any]):
86-
process = exec_test_command(BASE_CMD + ["root@" + target_instance["label"]])
87+
process = exec_failing_test_command(
88+
BASE_CMD + ["root@" + target_instance["label"]], expected_code=2
89+
)
8790
assert process.returncode == 2
88-
output = process.stdout.decode()
91+
output = process.stderr.decode()
8992

9093
assert "is not running" in output
9194

0 commit comments

Comments
 (0)