-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(e2e): Add barebones E2E test workflow (#818)
- Loading branch information
Showing
5 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: E2E - Run tests | ||
|
||
on: | ||
workflow_dispatch: | ||
# push: | ||
# branches: | ||
# - main | ||
# tags: | ||
# - "*" | ||
# pull_request: | ||
|
||
jobs: | ||
supported-releases: | ||
name: Build matrix for supported ADSys and Ubuntu releases | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-supported-releases.outputs.matrix }} | ||
steps: | ||
- name: Install needed binaries | ||
run: | | ||
sudo apt-get update | ||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y distro-info | ||
- name: Build matrix | ||
id: set-supported-releases | ||
run: | | ||
set -eu | ||
all="$(distro-info --supported-esm) $(distro-info --supported)" | ||
all="$(echo $all | tr ' ' '\n' | sort -u)" | ||
releases="" | ||
for r in ${all}; do | ||
# Filter out unsupported LTS releases | ||
if [ "${r}" = "trusty" -o "${r}" = "xenial" -o "${r}" = "bionic" ]; then | ||
continue | ||
fi | ||
if [ -n "${releases}" ]; then | ||
releases="${releases}, " | ||
fi | ||
releases="${releases}'${r}'" | ||
done | ||
echo matrix="${releases}" >> $GITHUB_OUTPUT | ||
tests: | ||
name: Tests | ||
runs-on: ubuntu-latest | ||
needs: | ||
- supported-releases | ||
strategy: | ||
matrix: | ||
codename: ${{ fromJSON(format('[{0}]', needs.supported-releases.outputs.matrix)) }} | ||
fail-fast: false | ||
env: | ||
AD_PASSWORD: ${{ secrets.AD_PASSWORD }} | ||
steps: | ||
- uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
- name: Set up SSH key | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.AZURE_SSH_KEY }}" > ~/.ssh/id_rsa-e2e | ||
chmod 600 ~/.ssh/id_rsa-e2e | ||
- name: Build adsys deb | ||
run: | | ||
go run ./e2e/cmd/provision_resources/00_build_adsys_deb --codename ${{ matrix.codename }} | ||
- name: Set up VPN connection | ||
uses: ./.github/actions/azure-sstpc-vpn | ||
with: | ||
gateway: ${{ secrets.VPN_GATEWAY }} | ||
ca: ${{ secrets.VPN_CA }} | ||
cert: ${{ secrets.VPN_CERT }} | ||
key: ${{ secrets.VPN_KEY }} | ||
- name: Provision client VM | ||
run: | | ||
go run ./e2e/cmd/provision_resources/01_provision_client --ssh-key ~/.ssh/id_rsa-e2e | ||
- name: Deprovision resources | ||
if: ${{ always() }} | ||
run: | | ||
# Check inventory status to see if we need to deprovision | ||
if [ ! -f inventory.yaml ] || grep -q 'vmid: ""' inventory.yaml; then | ||
echo "Inventory file not found, skipping deprovision" | ||
exit 0 | ||
fi | ||
go run ./e2e/cmd/provision_resources/99_deprovision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Package main provides a script that deprovisions previously created resources. | ||
// This currently consists of leaving the realm and deleting the client VM. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/ubuntu/adsys/e2e/internal/az" | ||
"github.com/ubuntu/adsys/e2e/internal/command" | ||
"github.com/ubuntu/adsys/e2e/internal/inventory" | ||
"github.com/ubuntu/adsys/e2e/internal/remote" | ||
) | ||
|
||
var adPassword string | ||
|
||
func main() { | ||
os.Exit(run()) | ||
} | ||
|
||
func run() int { | ||
cmd := command.New(action, | ||
command.WithValidateFunc(validate), | ||
command.WithStateTransition(inventory.ClientProvisioned, inventory.Deprovisioned), | ||
) | ||
cmd.Usage = fmt.Sprintf(`go run ./%s [options] | ||
Deprovision and destroy previously created resources. | ||
This will leave the realm, delete the computer object from the domain, and | ||
destroy the Azure client VM.`, filepath.Base(os.Args[0])) | ||
|
||
return cmd.Execute(context.Background()) | ||
} | ||
|
||
func validate(_ context.Context, _ *command.Command) error { | ||
adPassword = os.Getenv("AD_PASSWORD") | ||
if adPassword == "" { | ||
return fmt.Errorf("AD_PASSWORD environment variable must be set") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func action(ctx context.Context, cmd *command.Command) error { | ||
ipAddress := cmd.Inventory.IP | ||
sshKey := cmd.Inventory.SSHKeyPath | ||
client, err := remote.NewClient(ipAddress, "root", sshKey) | ||
if err != nil { | ||
return fmt.Errorf("failed to connect to VM: %w", err) | ||
} | ||
defer client.Close() | ||
|
||
// Leave realm and delete computer object | ||
_, err = client.Run(ctx, fmt.Sprintf("realm leave --remove -U localadmin -v --unattended <<<'%s'", adPassword)) | ||
if err != nil { | ||
return fmt.Errorf("failed to leave domain: %w", err) | ||
} | ||
|
||
// Destroy the client VM | ||
log.Infof("Destroying client VM %q", cmd.Inventory.VMName) | ||
_, _, err = az.RunCommand(ctx, "vm", "delete", | ||
"--resource-group", "AD", | ||
"--name", cmd.Inventory.VMName, | ||
"--force-deletion", "true", | ||
"--yes", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters