Skip to content

Commit

Permalink
nfs admin: create directories used by nfs tests
Browse files Browse the repository at this point in the history
Recent changes to ceph check that a directory exists in cephfs before it
will allow an NFS export of the dir to be created. It was a pretty shaky
practice of ours to create NFS exports without dirs backing them anyhow.
This change ensures the dirs exist before the test cases are run and
clean them up afterwards.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
  • Loading branch information
phlogistonjohn authored and mergify[bot] committed Apr 4, 2023
1 parent 3d47f9d commit 66ffbfa
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion common/admin/nfs/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import (
"github.com/stretchr/testify/assert"
tsuite "github.com/stretchr/testify/suite"

"github.com/ceph/go-ceph/cephfs"
"github.com/ceph/go-ceph/internal/admintest"
"github.com/ceph/go-ceph/internal/commands"
"github.com/ceph/go-ceph/rados"
)

var radosConnector = admintest.NewConnector()
var (
radosConnector = admintest.NewConnector()
usableDirNames = []string{"january", "february", "march", "sept"}
)

func TestNFSAdmin(t *testing.T) {
tsuite.Run(t, new(NFSAdminSuite))
Expand Down Expand Up @@ -51,6 +55,11 @@ func (suite *NFSAdminSuite) SetupSuite() {
if suite.mockConfig {
suite.setupMockNFSConfig()
}
suite.setupDirs()
}

func (suite *NFSAdminSuite) TearDownSuite() {
suite.removeDirs()
}

func (suite *NFSAdminSuite) setupMockNFSConfig() {
Expand All @@ -74,6 +83,48 @@ func (suite *NFSAdminSuite) setupMockNFSConfig() {
require.NoError(err)
}

func (suite *NFSAdminSuite) setupDirs() {
require := suite.Require()
conn := radosConnector.GetConn(suite.T())
fs, err := cephfs.CreateFromRados(conn)
require.NoError(err)
defer func() {
require.NoError(fs.Release())
}()
err = fs.Mount()
require.NoError(err)
defer func() {
require.NoError(fs.Unmount())
}()

// establish a "random" list of dir names to work with
for _, name := range usableDirNames {
err = fs.MakeDir(name, 0777)
require.NoError(err, "failed to make dir "+name)
}
}

func (suite *NFSAdminSuite) removeDirs() {
require := suite.Require()
conn := radosConnector.GetConn(suite.T())
fs, err := cephfs.CreateFromRados(conn)
require.NoError(err)
defer func() {
require.NoError(fs.Release())
}()
err = fs.Mount()
require.NoError(err)
defer func() {
require.NoError(fs.Unmount())
}()

// establish a "random" list of dir names to work with
for _, name := range usableDirNames {
err = fs.RemoveDir(name)
require.NoError(err, "failed to remove dir "+name)
}
}

func (suite *NFSAdminSuite) TestCreateDeleteCephFSExport() {
require := suite.Require()
ra := radosConnector.Get(suite.T())
Expand Down

0 comments on commit 66ffbfa

Please sign in to comment.