nfs admin: add mock configuration for test container

Our test container does not support an orchestrator to pre configure
the ".nfs" configuration pool for us. This is something that rook and
cephadm are expected to do before exports are created, etc.
So we support creating a minimal "mock" configuration in rados.
This option can be toggled on and off via the GO_CEPH_TEST_MOCK_NFS
env var. Turning it off can be useful if you want to run the live
suite against a "real" ceph cluster.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2022-03-10 14:45:39 -05:00 committed by mergify[bot]
parent ece889e721
commit e74d868365
1 changed files with 36 additions and 0 deletions

View File

@ -5,6 +5,9 @@ package nfs
import (
"errors"
"fmt"
"os"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
@ -12,6 +15,7 @@ import (
"github.com/ceph/go-ceph/internal/admintest"
"github.com/ceph/go-ceph/internal/commands"
"github.com/ceph/go-ceph/rados"
)
var radosConnector = admintest.NewConnector()
@ -31,11 +35,43 @@ type NFSAdminSuite struct {
fileSystemName string
clusterID string
mockConfig bool
}
func (suite *NFSAdminSuite) SetupSuite() {
suite.fileSystemName = "cephfs"
suite.clusterID = "goceph"
suite.mockConfig = true
mock := os.Getenv("GO_CEPH_TEST_MOCK_NFS")
if ok, err := strconv.ParseBool(mock); err == nil {
suite.mockConfig = ok
}
if suite.mockConfig {
suite.setupMockNFSConfig()
}
}
func (suite *NFSAdminSuite) setupMockNFSConfig() {
require := suite.Require()
conn := radosConnector.GetConn(suite.T())
err := conn.MakePool(".nfs")
if err != nil && !errors.Is(err, rados.ErrObjectExists) {
suite.T().Fatalf("failed to make pool: %v", err)
}
ioctx, err := conn.OpenIOContext(".nfs")
require.NoError(err)
defer ioctx.Destroy()
ioctx.SetNamespace(suite.clusterID)
err = ioctx.Create(
fmt.Sprintf("conf-nfs.%s", suite.clusterID),
rados.CreateIdempotent)
require.NoError(err)
}
func (suite *NFSAdminSuite) TestCreateDeleteCephFSExport() {