Skip to content

Commit

Permalink
Test sentinel file against public S3 origin
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphall committed Dec 3, 2024
1 parent 5943ed4 commit fcd86de
Showing 1 changed file with 80 additions and 12 deletions.
92 changes: 80 additions & 12 deletions xrootd/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,7 @@ func TestMultiExportOrigin(t *testing.T) {
require.True(t, ok)
}

func runS3Test(t *testing.T, bucketName, urlStyle, objectName string) {
ctx, cancel, egrp := test_utils.TestContext(context.Background(), t)
defer func() { require.NoError(t, egrp.Wait()) }()
defer cancel()

server_utils.ResetTestState()

defer server_utils.ResetTestState()

federationPrefix := "/test"
func mockupS3Origin(ctx context.Context, egrp *errgroup.Group, t *testing.T, federationPrefix, bucketName, urlStyle string) context.CancelFunc {
regionName := "us-east-1"
serviceUrl := "https://s3.amazonaws.com"
viper.Set("Origin.FederationPrefix", federationPrefix)
Expand All @@ -260,7 +251,19 @@ func runS3Test(t *testing.T, bucketName, urlStyle, objectName string) {
viper.Set("Server.WebPort", 0)
viper.Set("TLSSkipVerify", true)

mockupCancel := originMockup(ctx, egrp, t)
return originMockup(ctx, egrp, t)
}

func runS3Test(t *testing.T, bucketName, urlStyle, objectName string) {
ctx, cancel, egrp := test_utils.TestContext(context.Background(), t)
defer func() { require.NoError(t, egrp.Wait()) }()
defer cancel()
server_utils.ResetTestState()
defer server_utils.ResetTestState()

federationPrefix := "/test"

mockupCancel := mockupS3Origin(ctx, egrp, t, federationPrefix, bucketName, urlStyle)
defer mockupCancel()

originEndpoint := param.Origin_Url.GetString()
Expand Down Expand Up @@ -305,7 +308,67 @@ func TestS3OriginConfig(t *testing.T) {
})
}

func TestOriginWithSentinel(t *testing.T) {
func TestS3OriginWithSentinel(t *testing.T) {
ctx, cancel, egrp := test_utils.TestContext(context.Background(), t)
defer func() { require.NoError(t, egrp.Wait()) }()
defer cancel()
server_utils.ResetTestState()
defer server_utils.ResetTestState()

federationPrefix := "/test"
bucketName := "noaa-wod-pds"

mockupCancel := mockupS3Origin(ctx, egrp, t, federationPrefix, bucketName, "path")
defer mockupCancel()

mockExportValidStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
SentinelLocation: "MD5SUMS",
}

originEndpoint := param.Origin_Url.GetString()
// At this point, a 403 means the server is running, which means its ready to grab objects from
err := server_utils.WaitUntilWorking(ctx, "GET", originEndpoint, "xrootd", 403, true)
if err != nil {
t.Fatalf("Unsuccessful test: Server encountered an error: %v", err)
}

// mock export with no sentinel
mockExportNoStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
}

// mock export with an invalid sentinel
mockExportInvalidStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
SentinelLocation: "MD5SUMS_dne",
}

t.Run("valid-sentinel-return-ok", func(t *testing.T) {
ok, err := server_utils.CheckOriginSentinelLocations([]server_utils.OriginExport{mockExportValidStn})
require.NoError(t, err)
require.True(t, ok)
})
t.Run("empty-sentinel-return-ok", func(t *testing.T) {
ok, err := server_utils.CheckOriginSentinelLocations([]server_utils.OriginExport{mockExportNoStn})
require.NoError(t, err)
require.True(t, ok)
})

t.Run("invalid-sentinel-return-error", func(t *testing.T) {
ok, err := server_utils.CheckOriginSentinelLocations([]server_utils.OriginExport{mockExportInvalidStn})
require.Error(t, err)
require.False(t, ok)
})
}

func TestPosixOriginWithSentinel(t *testing.T) {
ctx, cancel, egrp := test_utils.TestContext(context.Background(), t)
defer func() { require.NoError(t, egrp.Wait()) }()
defer cancel()
Expand All @@ -314,6 +377,7 @@ func TestOriginWithSentinel(t *testing.T) {

defer server_utils.ResetTestState()

// Create a test temp dir, ensure it's readable by XRootD
tmpPathPattern := "XRD-Tst_Orgn*"
tmpPath, err := os.MkdirTemp("", tmpPathPattern)
require.NoError(t, err)
Expand All @@ -335,24 +399,28 @@ func TestOriginWithSentinel(t *testing.T) {
mockupCancel := originMockup(ctx, egrp, t)
defer mockupCancel()

// mock export with a valid sentinel
mockExportValidStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
SentinelLocation: "mock_sentinel",
}
// mock export with no sentinel
mockExportNoStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
}
// mock export with an invalid sentinel
mockExportInvalidStn := server_utils.OriginExport{
StoragePrefix: viper.GetString("Origin.StoragePrefix"),
FederationPrefix: viper.GetString("Origin.FederationPrefix"),
Capabilities: server_structs.Capabilities{Reads: true},
SentinelLocation: "sentinel_dne",
}

// Create a sentinel file, ensure it's readable by XRootD
tempStn := filepath.Join(mockExportValidStn.StoragePrefix, mockExportValidStn.SentinelLocation)
file, err := os.Create(tempStn)
require.NoError(t, err)
Expand Down

0 comments on commit fcd86de

Please sign in to comment.