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 Aug 22, 2024
1 parent 4d4c73e commit 287b468
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 16 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 }}"
2 changes: 1 addition & 1 deletion cmd/subcommands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func addCompilationOptions(cmd *cobra.Command) *compilation.Options {
cmd.Flags().StringVarP(&options.ResourceGroupID, "resource-group-id", "", "", "Identifier of a Cloud resource group to contain the instance(s)")
//Todo: allow selecting existing ssh key?
cmd.Flags().StringVarP(&options.SSHKeyType, "ssh-key-type", "", "rsa", "SSH key type [rsa, ed25519]")
cmd.Flags().StringVarP(&options.PublicSSHKey, "public-ssh-key", "", "", "An existing or new SSH public key to identify user on the instance")
cmd.Flags().StringArrayVarP(&options.PublicSSHKey, "public-ssh-key", "", []string{}, "An existing or new SSH public key to identify user on the instance")
cmd.Flags().StringVarP(&options.Zone, "zone", "", "", "A location to host the instance")
cmd.Flags().StringVarP(&options.Profile, "profile", "", "bx2-8x32", "An instance profile type to choose size and capability of the instance")
//TODO: make public image as default
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 @@ -6,5 +6,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
4 changes: 2 additions & 2 deletions pkg/be/ibmcloud/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func createVPC(vpcService *vpcv1.VpcV1, name string, resourceGroupID string) (st
return *vpc.ID, nil
}

func createAndInitVM(vpcService *vpcv1.VpcV1, name string, ir llir.LLIR, resourceGroupID string, keyType string, publicKey string, zone string, profile string, imageID string, verbose bool) error {
func createAndInitVM(vpcService *vpcv1.VpcV1, name string, ir llir.LLIR, resourceGroupID string, keyType string, publicKey []string, zone string, profile string, imageID string, verbose bool) error {
t1s := time.Now()
vpcID, err := createVPC(vpcService, name, resourceGroupID)
if err != nil {
Expand All @@ -263,7 +263,7 @@ func createAndInitVM(vpcService *vpcv1.VpcV1, name string, ir llir.LLIR, resourc
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 @@ -17,7 +17,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 @@ -14,6 +14,11 @@ set -o pipefail
# e.g. see test7/init.sh
export RUNNING_CODEFLARE_TESTS=1

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

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

Expand Down
9 changes: 9 additions & 0 deletions tests/bin/deploy-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ 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

appname="${4-$1}"
TARGET="$TOP"/builds/test/$appname
rm -rf "$TARGET"
Expand Down Expand Up @@ -95,6 +102,8 @@ fi

$testapp up \
-v \
$IC_TARGET \
$IC_UP_ARGS \
$QUEUE \
$APP \
$GPU \
Expand Down
7 changes: 5 additions & 2 deletions tests/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,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
9 changes: 7 additions & 2 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 All @@ -23,10 +28,10 @@ echo "$(tput setaf 2)Uninstalling test Runs for testdir=$1 appname=$appname$(tpu
if [[ -d "$TOP"/builds/test ]]
then
if [[ -n "$appname" ]] && [[ -f "$TOP"/builds/test/"$appname"/test ]]
then "$TOP"/builds/test/"$appname"/test down -v
then "$TOP"/builds/test/"$appname"/test down -v $IC_TARGET
else
for dir in $(ls -t "$TOP"/builds/test)
do "$TOP"/builds/test/"$dir"/test down -v &
do "$TOP"/builds/test/"$dir"/test down -v $IC_TARGET &
done

wait
Expand Down

0 comments on commit 287b468

Please sign in to comment.