nfs admin: create directories used by nfs tests

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>
This commit is contained in:
John Mulligan 2023-04-03 16:59:17 -04:00 committed by mergify[bot]
parent 3d47f9da6c
commit 66ffbfa633
1 changed files with 52 additions and 1 deletions

View File

@ -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))
@ -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() {
@ -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())