Skip to content

Commit

Permalink
Add nested lxc test to fully test the lxc_ssh.py plugin from ssh to lxc
Browse files Browse the repository at this point in the history
Co-authored-by: David Parrish <daveparrish@tutanota.com>
Co-authored-by: AnvithLobo <64419387+AnvithLobo@users.noreply.github.com>
  • Loading branch information
dmp1ce and AnvithLobo committed Jun 11, 2021
1 parent d421553 commit 76e6b52
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
44 changes: 39 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ defaults:


jobs:
pr-test:
name: Check the PR
pr-test-ubuntu-user:
name: Check the PR (ubuntu user)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -100,11 +100,12 @@ jobs:


# create an actual container, and configure it
# Enable container nesting
- name: Create container
run: sudo lxc launch images:ubuntu/${{ matrix.guest }} test-container
run: sudo lxc launch images:ubuntu/${{ matrix.guest }} test-container -c security.nesting=true

- name: Wait for container to start
run: sleep 30
run: sleep 10

- name: Show container
run: sudo lxc list
Expand Down Expand Up @@ -261,6 +262,9 @@ jobs:
- name: Python3
run: sudo lxc exec test-container --env DEBIAN_FRONTEND=noninteractive -- apt-get -y install -y python3

# Install LXD inside cotnainer its missing inside container
- name: Install LXD inside container
run: sudo lxc exec test-container --env DEBIAN_FRONTEND=noninteractive -- sudo apt-get install -y lxd lxd-client lxd-tools iptables

# container is ready

Expand Down Expand Up @@ -289,5 +293,35 @@ jobs:
- name: Show test directory
run: bash -c "ls -ld $GITHUB_WORKSPACE/tests/*"

# nested LXD configuration
- name: Init LXD inside container
run: sudo lxc exec test-container -- sudo lxd init --preseed < $GITHUB_WORKSPACE/.github/resources/lxd4-init.yml

# Create a nested container for lxc_ssh tests
- name: Create a nested container
run: sudo lxc exec test-container -- sudo lxc launch images:ubuntu/${{ matrix.guest }} nested-container

- name: add container user to lxd group
run: sudo lxc exec test-container -- sudo adduser ubuntu lxd

- name: Wait for container to start
run: sleep 10

- name: Generate ansible inventory
run: |
cat <<EOF > $GITHUB_WORKSPACE/tests/inventory.yml
---
all:
hosts:
testhost:
ansible_host: ${{ steps.test_container_ipv4.outputs.IPv4 }}
ansible_user: 'ubuntu'
lxc_host: "nested-container"
ansible_connection: lxc_ssh
EOF
- name: Show inventory file
run: cat $GITHUB_WORKSPACE/tests/inventory.yml

- name: Run test
run: ANSIBLE_CONFIG=$GITHUB_WORKSPACE/tests/ cd tests && ansible-playbook -i ${{ steps.test_container_ipv4.outputs.IPv4 }}, $GITHUB_WORKSPACE/tests/test-lxc_ssh.yml
run: ANSIBLE_CONFIG=$GITHUB_WORKSPACE/tests/ cd tests && ansible-playbook -i $GITHUB_WORKSPACE/tests/inventory.yml $GITHUB_WORKSPACE/tests/test-lxc_ssh.yml
4 changes: 0 additions & 4 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ fact_caching = jsonfile
fact_caching_connection = facts.json
fact_caching_timeout = 86400


remote_user=ubuntu


[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=900s -o PreferredAuthentications=publickey
pipelining = true
2 changes: 1 addition & 1 deletion tests/test-lxc_ssh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
include_tasks:
file: "test-command.yml"
vars:
expect_user: "ubuntu"
expect_user: "root"

- name: Test template
include_tasks:
Expand Down

0 comments on commit 76e6b52

Please sign in to comment.