Skip to content

Commit

Permalink
Merge branch 'main' into update-sample-config
Browse files Browse the repository at this point in the history
  • Loading branch information
coulof authored Nov 9, 2023
2 parents 0714c37 + bd7e2ac commit 748f04f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 23 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ integration-test:
unit-test:
( cd test/unit-test; sh run.sh )

.PHONY: download-csm-common
download-csm-common:
curl -O -L https://raw.githubusercontent.com/dell/csm/main/config/csm-common.mk

#
# Docker-related tasks
#
# Generates the docker container (but does not push)
podman-build: go-build
sh build.sh
podman-build: download-csm-common go-build
$(eval include csm-common.mk)
sh build.sh --baseubi $(DEFAULT_BASEIMAGE)

podman-push: go-build
sh build.sh -p
podman-push: download-csm-common go-build
$(eval include csm-common.mk)
sh build.sh --baseubi $(DEFAULT_BASEIMAGE) --push

#
# Docker-related tasks
Expand Down
23 changes: 14 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function git_version {
echo Target Version=$VERSION
}


function build_image {
# Tag corresponding to digest sha256:630cf7bdef807f048cadfe7180d6c27eb3aaa99323ffc3628811da230ed3322a for ubi9 micro is 9.2-13
bash build_ubi_micro.sh registry.access.redhat.com/ubi9/ubi-micro@sha256:630cf7bdef807f048cadfe7180d6c27eb3aaa99323ffc3628811da230ed3322a
echo ${BASE_UBI_IMAGE}
bash build_ubi_micro.sh ${BASE_UBI_IMAGE}
echo $BUILDCMD build -t ${IMAGE_NAME}:${IMAGE_TAG} .
(cd .. && $BUILDCMD build -t ${IMAGE_NAME}:${IMAGE_TAG} --build-arg GOPROXY=$GOPROXY -f csi-unity/Dockerfile.podman . --format=docker)
echo $BUILDCMD tag ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_REPO}/${IMAGE_REPO_NAMESPACE}/${IMAGE_NAME}:${IMAGE_TAG}
Expand All @@ -52,13 +53,17 @@ IMAGE_REPO_NAMESPACE=csi-unity
IMAGE_TAG=${VERSION}

# Read options
while getopts 'ph' flag; do
case "${flag}" in
p) PUSH_IMAGE='true' ;;
h) git_version
exit 0 ;;
*) git_version
exit 0 ;;
for param in $*; do
case $param in
"--baseubi")
shift
BASE_UBI_IMAGE=$1
shift
;;
"--push")
shift
PUSH_IMAGE='true'
;;
esac
done

Expand Down
29 changes: 19 additions & 10 deletions service/mount.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2019 Dell Inc. or its subsidiaries. All Rights Reserved.
Copyright © 2019-2023 Dell Inc. or its subsidiaries. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,9 @@ package service

import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -729,18 +731,25 @@ func createDirIfNotExist(ctx context.Context, path, arrayID string) error {
func mkdir(ctx context.Context, path string) (bool, error) {
log := utils.GetRunidLogger(ctx)
st, err := os.Stat(path)
if os.IsNotExist(err) {
if err := os.MkdirAll(path, 0o750); err != nil {
log.WithField("dir", path).WithError(err).Error("Unable to create dir")
return false, err
if err == nil {
if !st.IsDir() {
return false, fmt.Errorf("existing path is not a directory")
}
log.WithField("path", path).Debug("created directory")
return true, nil
return false, nil
}
if !st.IsDir() {
return false, fmt.Errorf("existing path is not a directory")
if !errors.Is(err, fs.ErrNotExist) {
log.WithField("dir", path).WithError(err).Error("Unable to stat dir")
return false, err
}
return false, nil

// Case when there is error and the error is fs.ErrNotExists.
if err := os.MkdirAll(path, 0o750); err != nil {
log.WithField("dir", path).WithError(err).Error("Unable to create dir")
return false, err
}

log.WithField("path", path).Debug("created directory")
return true, nil
}

// mkfile creates a file specified by the path
Expand Down
85 changes: 85 additions & 0 deletions service/mount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright © 2019-2023 Dell Inc. or its subsidiaries. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package service

import (
"context"
"os"
"testing"

"github.com/dell/csi-unity/service/utils"
"github.com/stretchr/testify/assert"
)

// Split TestMkdir into separate tests to test each case
func TestMkdirCreateDir(t *testing.T) {
log := utils.GetLogger()
ctx := context.Background()
entry := log.WithField(utils.RUNID, "1111")
ctx = context.WithValue(ctx, utils.UnityLogger, entry)

// Make temp directory to use for testing
basepath, err := os.MkdirTemp("/tmp", "*")
defer os.RemoveAll(basepath)
path := basepath + "/test"

// Test creating a directory
created, err := mkdir(ctx, path)
assert.NoError(t, err)
assert.True(t, created)
}

func TestMkdirExistingDir(t *testing.T) {
log := utils.GetLogger()
ctx := context.Background()
entry := log.WithField(utils.RUNID, "1111")
ctx = context.WithValue(ctx, utils.UnityLogger, entry)

// Make temp directory to use for testing
basepath, err := os.MkdirTemp("/tmp", "*")
defer os.RemoveAll(basepath)

path := basepath + "/test"

// Pre-create the directory
err = os.Mkdir(path, 0o755)
assert.NoError(t, err)

// Test creating an existing directory
created, err := mkdir(ctx, path)
assert.NoError(t, err)
assert.False(t, created)
}

func TestMkdirExistingFile(t *testing.T) {
log := utils.GetLogger()
ctx := context.Background()
entry := log.WithField(utils.RUNID, "1111")
ctx = context.WithValue(ctx, utils.UnityLogger, entry)

// Make temp directory to use for testing
basepath, err := os.MkdirTemp("/tmp", "*")
defer os.RemoveAll(basepath)

path := basepath + "/file"
file, err := os.Create(path)
assert.NoError(t, err)
file.Close()

// Test creating a directory with an existing file path
created, err := mkdir(ctx, path)
assert.Error(t, err)
assert.False(t, created)
}

0 comments on commit 748f04f

Please sign in to comment.