From 66ffbfa63316a8313cf8399e9861ed2164d30cb7 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 3 Apr 2023 16:59:17 -0400 Subject: [PATCH] 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 --- common/admin/nfs/export_test.go | 53 ++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/common/admin/nfs/export_test.go b/common/admin/nfs/export_test.go index 2d9232d..7269bdd 100644 --- a/common/admin/nfs/export_test.go +++ b/common/admin/nfs/export_test.go @@ -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())