File tree Expand file tree Collapse file tree 5 files changed +63
-37
lines changed Expand file tree Collapse file tree 5 files changed +63
-37
lines changed Original file line number Diff line number Diff line change 3434 pip install -r test_requirements.txt
3535 - name : Pre-commit checks
3636 run : pre-commit run --all-files
37- - name : Write SSH keys
38- env :
39- # These were generated with:
40- # ssh-keygen -t ecdsa -m PEM ''
41- # and then installed as a read-only deploy key on the buildrunner repository
42- #
43- # Since this is a public repository and the key provides the same rights that even anonymous users have,
44- # this key is rather worthless and can be stored safely in code here. This *could* be used as a secret,
45- # but since secrets are not available to forks, we cannot test SSH functionality in PRs which defeats
46- # the purpose somewhat.
47- #
48- # Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa
49- DEPLOY_SSH_KEY : " -----BEGIN OPENSSH PRIVATE KEY-----\n b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\n QyNTUxOQAAACBasvUoRzAAdHZ5nFWtDR/5DQU+FWtDYNXD0xPGSdjKtwAAAJiLXobki16G\n 5AAAAAtzc2gtZWQyNTUxOQAAACBasvUoRzAAdHZ5nFWtDR/5DQU+FWtDYNXD0xPGSdjKtw\n AAAEBcRwB1PEnUHF5aK6q3JYyuOlT+adQ0mcRrIxsmJiiq1Vqy9ShHMAB0dnmcVa0NH/kN\n BT4Va0Ng1cPTE8ZJ2Mq3AAAAEWJ1aWxkcnVubmVyQGFkb2JlAQIDBA==\n -----END OPENSSH PRIVATE KEY-----"
50- DEPLOY_SSH_KEY_PUB : " ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFqy9ShHMAB0dnmcVa0NH/kNBT4Va0Ng1cPTE8ZJ2Mq3 buildrunner@adobe"
51- run : |
52- mkdir -p ~/.ssh
53- printf -- "$DEPLOY_SSH_KEY" > ~/.ssh/buildrunner-deploy-id_rsa
54- printf -- "$DEPLOY_SSH_KEY_PUB" > ~/.ssh/buildrunner-deploy-id_rsa.pub
55- chmod 700 ~/.ssh
56- chmod 600 ~/.ssh/buildrunner-deploy-*
5737 - name : Test with pytest
5838 run : |
5939 pytest -v -m "not serial" --numprocesses=auto --junitxml=test-reports/non-serial-test-results.xml
Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ ssh-keys:
1111 aliases :
1212 - ' adobe-github'
1313 - ' adobe-dma'
14- - file : ~/.ssh/buildrunner-deploy-id_rsa
14+ # This should match what is in the test_buildrunner_files.py file and is generated before the tests are run
15+ - file : /tmp/buildrunner-test-id_rsa
1516 aliases :
16- - ' buildrunner-deploy '
17+ - ' buildrunner-test-ssh '
1718
1819local-files :
1920 tests : ./tests
Original file line number Diff line number Diff line change 1- # Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa
2- # Look in the .github/workflows/build.yaml file for the SSH private key
31use-legacy-builder : False
42steps :
53 clone :
86 FROM {{ DOCKER_REGISTRY }}/rockylinux:8.5
97 RUN yum install -y git-core openssh-clients && yum clean all
108 run :
11- ssh-keys : ['buildrunner-deploy']
9+ # This key is generated automatically by the test runner
10+ ssh-keys : ['buildrunner-test-ssh']
11+ services :
12+ ssh-service :
13+ image : {{ DOCKER_REGISTRY }}/linuxserver/openssh-server:latest
14+ wait_for :
15+ - 2222
16+ env :
17+ # This is set in the test_buildrunner_files.py file
18+ PUBLIC_KEY : " {{ BUILDRUNNER_TEST_SSH_PUB_KEY }}"
19+ LOG_STDOUT : " true"
1220 cmds :
1321 - mkdir ~/.ssh
14- - ssh-keyscan github.com > ~/.ssh/known_hosts
22+ - ssh-keyscan -p 2222 ssh-service > ~/.ssh/known_hosts
1523 - chmod 700 ~/.ssh
1624 - chmod 600 ~/.ssh/known_hosts
17- # Clone into temp directory since the "buildrunner" directory may already exist
18- - rm -rf /tmp/test-clone
19- -
git clone [email protected] :adobe/buildrunner.git /tmp/test-clone 25+ - if [ "$(ssh -p 2222 linuxserver.io@ssh-service 'whoami')" != "linuxserver.io" ]; then exit 1; fi
Original file line number Diff line number Diff line change 1- # Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa.
2- # Look in the .github/workflows/build.yaml file for the SSH private key.
31steps :
4- clone :
2+ ssh-test :
53 build :
64 dockerfile : |
75 FROM {{ DOCKER_REGISTRY }}/rockylinux:8.5
86 RUN yum install -y git-core openssh-clients && yum clean all
97 run :
10- ssh-keys : ['buildrunner-deploy']
8+ # This key is generated automatically by the test runner
9+ ssh-keys : ['buildrunner-test-ssh']
10+ services :
11+ ssh-service :
12+ image : {{ DOCKER_REGISTRY }}/linuxserver/openssh-server:latest
13+ wait_for :
14+ - 2222
15+ env :
16+ # This is set in the test_buildrunner_files.py file
17+ PUBLIC_KEY : " {{ BUILDRUNNER_TEST_SSH_PUB_KEY }}"
18+ LOG_STDOUT : " true"
1119 cmds :
1220 - mkdir ~/.ssh
13- - ssh-keyscan github.com > ~/.ssh/known_hosts
21+ - ssh-keyscan -p 2222 ssh-service > ~/.ssh/known_hosts
1422 - chmod 700 ~/.ssh
1523 - chmod 600 ~/.ssh/known_hosts
16- # Clone into temp directory since the "buildrunner" directory may already exist
17- - rm -rf /tmp/test-clone
18- -
git clone [email protected] :adobe/buildrunner.git /tmp/test-clone 24+ - if [ "$(ssh -p 2222 linuxserver.io@ssh-service 'whoami')" != "linuxserver.io" ]; then exit 1; fi
Original file line number Diff line number Diff line change 11import os
22import pytest
33import platform
4+ import subprocess
45import tempfile
6+ from pathlib import Path
57from typing import List , Optional , Tuple
68
79from tests import test_runner
810
11+ # This should match what is in the dot-buildrunner.yaml file
12+ TEST_SSH_KEY_FILE = "/tmp/buildrunner-test-id_rsa"
13+
914test_dir_path = os .path .realpath (os .path .dirname (__file__ ))
1015TEST_DIR = os .path .dirname (__file__ )
1116top_dir_path = os .path .realpath (os .path .dirname (test_dir_path ))
1823]
1924
2025
26+ @pytest .fixture (autouse = True , scope = "session" )
27+ def setup_buildrunner_test_ssh_key ():
28+ key_file_path = Path (TEST_SSH_KEY_FILE )
29+ key_file_path .unlink (missing_ok = True )
30+ subprocess .run (
31+ [
32+ "ssh-keygen" ,
33+ "-t" ,
34+ "ecdsa" ,
35+ "-m" ,
36+ "PEM" ,
37+ "-N" ,
38+ "" ,
39+ "-f" ,
40+ TEST_SSH_KEY_FILE ,
41+ ],
42+ check = True ,
43+ )
44+ # Set the public key in an environment variable to use in the test buildrunner files
45+ os .environ ["BUILDRUNNER_TEST_SSH_PUB_KEY" ] = (
46+ Path (f"{ TEST_SSH_KEY_FILE } .pub" ).read_text ().strip ()
47+ )
48+ yield
49+ # Cleanup
50+ del os .environ ["BUILDRUNNER_TEST_SSH_PUB_KEY" ]
51+ key_file_path .unlink ()
52+
53+
2154def _get_test_args (file_name : str ) -> Optional [List [str ]]:
2255 if file_name == "test-timeout.yaml" :
2356 # Set a short timeout here for the timeout test
You can’t perform that action at this time.
0 commit comments