Skip to content

Commit

Permalink
test: add test coverage for ibmcloud be
Browse files Browse the repository at this point in the history
Signed-off-by: aavarghese <[email protected]>
  • Loading branch information
aavarghese committed Sep 17, 2024
1 parent 83cdfff commit 1a23d9b
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 12 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/tests_ibmcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI Tests for IBM Cloud backend

# cancel any prior runs for this workflow and this PR (or branch)
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
ci:
runs-on: ${{ matrix.os }}

strategy:
matrix:
SCRIPT:
- ./tests/bin/ci.sh -i 'test7f.*'
- ./tests/bin/go.sh
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4

- name: Check Docker
run: docker version && podman version

- name: Run Test with args ${{ matrix.ARGS }}
env:
TERM: xterm-256color
IC_API_KEY: ${{ secrets.IC_API_KEY }}
RESOURCE_GROUP_ID: ${{ secrets.RESOURCE_GROUP_ID }}
SSH_KEY_PUB: ${{ secrets.SSH_KEY_PUB }}
run: bash -c "${{matrix.SCRIPT}} ${{matrix.ARGS }}"
1 change: 1 addition & 0 deletions cmd/subcommands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package subcommands

import (
"context"

"github.com/spf13/cobra"

"lunchpail.io/cmd/options"
Expand Down
2 changes: 1 addition & 1 deletion pkg/be/ibmcloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type Backend struct {
config ibmConfig
vpcService *vpcv1.VpcV1
sshKeyType string
sshPublicKey string
sshPublicKey []string
}
2 changes: 1 addition & 1 deletion pkg/be/ibmcloud/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Authenticator(apiKey string, config ibmConfig) (*vpcv1.VpcV1, error) {
Authenticator: auth,
})
if err != nil {
return nil, errors.New("Error creating VPC Service with apikey" + apiKey)
return nil, errors.New("Error creating VPC Service with apikey " + apiKey)
}
fmt.Printf("Accessing the VPC service via %s\n", method)

Expand Down
2 changes: 1 addition & 1 deletion pkg/be/ibmcloud/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func createAndInitVM(ctx context.Context, vpcService *vpcv1.VpcV1, name string,
t1e := time.Now()

t2s := t1e
keyID, err := createSSHKey(vpcService, name, resourceGroupID, keyType, publicKey)
keyID, err := createSSHKey(vpcService, name, resourceGroupID, keyType, strings.Join(publicKey, " "))
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/be/ibmcloud/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ func getRandomizedZone(config ibmConfig, vpcService *vpcv1.VpcV1) (string, error

// Retrieve public key from user's ssh dir, if exists
// Looks for two ssh key types: “rsa” and “ed25519" (ibmcloud supported)
func loadPublicKey(config ibmConfig, aopts compilation.Options) (string, string, error) {
func loadPublicKey(config ibmConfig, aopts compilation.Options) (string, []string, error) {
homedir, err := os.UserHomeDir()
if err != nil {
return "", "", err
return "", []string{}, err
}

var bytes []byte
if aopts.PublicSSHKey != "" {
if len(aopts.PublicSSHKey) != 0 {
return aopts.SSHKeyType, aopts.PublicSSHKey, nil
} else if bytes, err = os.ReadFile(filepath.Join(homedir, ".ssh", "id_rsa.pub")); err == nil && bytes != nil {
pKeyComps := strings.Split(string(bytes), " ")
if len(pKeyComps) >= 2 && strings.Trim(pKeyComps[0], " ") == ssh.KeyAlgoRSA {
return "rsa", string(bytes), nil
return "rsa", []string{string(bytes)}, nil
}
} else if bytes, err = os.ReadFile(filepath.Join(homedir, ".ssh", "id_ed25519.pub")); err == nil && bytes != nil {
pKeyComps := strings.Split(string(bytes), " ")
if len(pKeyComps) >= 2 && strings.Trim(pKeyComps[0], " ") == ssh.KeyAlgoED25519 {
return "ed25519", string(bytes), nil
return "ed25519", []string{string(bytes)}, nil
}
}

return "", "", nil
return "", []string{}, nil
}
2 changes: 1 addition & 1 deletion pkg/compilation/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Options struct {
ApiKey string `yaml:"apiKey,omitempty"`
ResourceGroupID string `yaml:"resourceGroupID,omitempty"`
SSHKeyType string `yaml:"SSHKeyType,omitempty"`
PublicSSHKey string `yaml:"publicSSHKey,omitempty"`
PublicSSHKey []string `yaml:"publicSSHKey,omitempty"`
Zone string `yaml:"zone,omitempty"`
Profile string `yaml:"profile,omitempty"`
ImageID string `yaml:"imageID,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions tests/bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ set -eo pipefail
# e.g. see test7/init.sh
export RUNNING_LUNCHPAIL_TESTS=1

if [[ -n "$IC_API_KEY" ]]
then
export TEST_IBMCLOUD=1
fi

SCRIPTDIR=$(cd $(dirname "$0") && pwd)
TOP="$SCRIPTDIR"/../..

Expand Down
7 changes: 5 additions & 2 deletions tests/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ then
TEST_NAME=$testname "$1"/init.sh $namespace
fi

${handler-waitForIt} ${deployname:-$testname} ${namespace} $api "${expected[@]}"
EC=$?
if [[ -z "$TEST_IBMCLOUD" ]]
then
${handler-waitForIt} ${deployname:-$testname} ${namespace} $api "${expected[@]}"
EC=$?
fi
undeploy $testname $deployname

if [[ $EC != 0 ]]
Expand Down
5 changes: 5 additions & 0 deletions tests/bin/undeploy-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ set -o pipefail
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
TOP="$SCRIPTDIR"/../../

if [[ -n "$TEST_IBMCLOUD" ]]
then
IC_TARGET="--target=ibmcloud --api-key=$IC_API_KEY" #TODO: needs runname
fi

appname="${2-$1}"

# retry once after failure; this may help to cope with `etcdserver:
Expand Down
9 changes: 9 additions & 0 deletions tests/bin/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ if which lspci && lspci | grep -iq nvidia; then
GPU="--set supportsGpu=true"
fi

if [[ -n "$TEST_IBMCLOUD" ]]
then
IC_TARGET="--target ibmcloud --api-key $IC_API_KEY"
IC_UP_ARGS="--resource-group-id $RESOURCE_GROUP_ID --zone us-south-1 --image-id r006-1169e41d-d654-45d5-bdd5-89e2dc6e8a68 --profile bx2-8x32"
#--public-ssh-key=${SSH_KEY_PUB} \ #TODO: include it in IC_UP_ARGS string
fi

echo "Calling up using target=${LUNCHPAIL_TARGET:-kubernetes}"
$testapp up \
-v \
$IC_TARGET \
$IC_UP_ARGS \
$QUEUE \
$APP \
$GPU \
Expand Down

0 comments on commit 1a23d9b

Please sign in to comment.