From 1bfd3229ee628c79274f7eb5b362d493a4725cec Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Tue, 31 Oct 2023 10:47:41 +0100 Subject: [PATCH] Rename UploadFloppyImage -> MountFloppyImage --- bmc/floppy.go | 32 +++++++++++++++--------------- bmc/floppy_test.go | 12 +++++------ client.go | 4 ++-- examples/floppy-image/main.go | 2 +- providers/providers.go | 4 ++-- providers/supermicro/floppy.go | 2 +- providers/supermicro/supermicro.go | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/bmc/floppy.go b/bmc/floppy.go index 2cbb4e69..891a1131 100644 --- a/bmc/floppy.go +++ b/bmc/floppy.go @@ -10,19 +10,19 @@ import ( "github.com/pkg/errors" ) -// FloppyImageUploader defines methods to upload a floppy image -type FloppyImageUploader interface { - UploadFloppyImage(ctx context.Context, image io.Reader) (err error) +// FloppyImageMounter defines methods to upload a floppy image +type FloppyImageMounter interface { + MountFloppyImage(ctx context.Context, image io.Reader) (err error) } // floppyImageUploaderProvider is an internal struct to correlate an implementation/provider and its name type floppyImageUploaderProvider struct { name string - impl FloppyImageUploader + impl FloppyImageMounter } -// uploadFloppyImage is a wrapper method to invoke methods for the FloppyImageUploader interface -func uploadFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUploaderProvider) (metadata Metadata, err error) { +// mountFloppyImage is a wrapper method to invoke methods for the FloppyImageMounter interface +func mountFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUploaderProvider) (metadata Metadata, err error) { var metadataLocal Metadata for _, elem := range p { @@ -37,7 +37,7 @@ func uploadFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUplo return metadata, err default: metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name) - uploadErr := elem.impl.UploadFloppyImage(ctx, image) + uploadErr := elem.impl.MountFloppyImage(ctx, image) if uploadErr != nil { err = multierror.Append(err, errors.WithMessagef(uploadErr, "provider: %v", elem.name)) continue @@ -48,20 +48,20 @@ func uploadFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUplo } } - return metadataLocal, multierror.Append(err, errors.New("failed to upload floppy image")) + return metadataLocal, multierror.Append(err, errors.New("failed to mount floppy image")) } -// UploadFloppyImageFromInterfaces identifies implementations of the FloppyImageUploader interface and passes the found implementations to the uploadFloppyImage() wrapper -func UploadFloppyImageFromInterfaces(ctx context.Context, image io.Reader, p []interface{}) (metadata Metadata, err error) { +// MountFloppyImageFromInterfaces identifies implementations of the FloppyImageMounter interface and passes the found implementations to the mountFloppyImage() wrapper +func MountFloppyImageFromInterfaces(ctx context.Context, image io.Reader, p []interface{}) (metadata Metadata, err error) { providers := make([]floppyImageUploaderProvider, 0) for _, elem := range p { temp := floppyImageUploaderProvider{name: getProviderName(elem)} switch p := elem.(type) { - case FloppyImageUploader: + case FloppyImageMounter: temp.impl = p providers = append(providers, temp) default: - e := fmt.Sprintf("not a FloppyImageUploader implementation: %T", p) + e := fmt.Sprintf("not a FloppyImageMounter implementation: %T", p) err = multierror.Append(err, errors.New(e)) } } @@ -71,16 +71,16 @@ func UploadFloppyImageFromInterfaces(ctx context.Context, image io.Reader, p []i err, errors.Wrap( bmclibErrs.ErrProviderImplementation, - "no FloppyImageUploader implementations found", + "no FloppyImageMounter implementations found", ), ) } - return uploadFloppyImage(ctx, image, providers) + return mountFloppyImage(ctx, image, providers) } -// FloppyImageUploader defines methods to unmount a floppy image +// FloppyImageMounter defines methods to unmount a floppy image type FloppyImageUnmounter interface { UnmountFloppyImage(ctx context.Context) (err error) } @@ -121,7 +121,7 @@ func unmountFloppyImage(ctx context.Context, p []floppyImageUnmounterProvider) ( return metadataLocal, multierror.Append(err, errors.New("failed to unmount floppy image")) } -// UploadFloppyImageFromInterfaces identifies implementations of the FloppyImageUnmounter interface and passes the found implementations to the unmountFloppyImage() wrapper +// MountFloppyImageFromInterfaces identifies implementations of the FloppyImageUnmounter interface and passes the found implementations to the unmountFloppyImage() wrapper func UnmountFloppyImageFromInterfaces(ctx context.Context, p []interface{}) (metadata Metadata, err error) { providers := make([]floppyImageUnmounterProvider, 0) for _, elem := range p { diff --git a/bmc/floppy_test.go b/bmc/floppy_test.go index bbb413e2..3107b8c9 100644 --- a/bmc/floppy_test.go +++ b/bmc/floppy_test.go @@ -10,19 +10,19 @@ import ( "github.com/stretchr/testify/assert" ) -type uploadFloppyImageTester struct { +type mountFloppyImageTester struct { returnError error } -func (p *uploadFloppyImageTester) UploadFloppyImage(ctx context.Context, reader io.Reader) (err error) { +func (p *mountFloppyImageTester) MountFloppyImage(ctx context.Context, reader io.Reader) (err error) { return p.returnError } -func (p *uploadFloppyImageTester) Name() string { +func (p *mountFloppyImageTester) Name() string { return "foo" } -func TestUploadFloppyFromInterfaces(t *testing.T) { +func TestMountFloppyFromInterfaces(t *testing.T) { testCases := []struct { testName string image io.Reader @@ -43,10 +43,10 @@ func TestUploadFloppyFromInterfaces(t *testing.T) { badImplementation := struct{}{} generic = []interface{}{&badImplementation} } else { - testImplementation := &uploadFloppyImageTester{returnError: tc.returnError} + testImplementation := &mountFloppyImageTester{returnError: tc.returnError} generic = []interface{}{testImplementation} } - metadata, err := UploadFloppyImageFromInterfaces(context.Background(), tc.image, generic) + metadata, err := MountFloppyImageFromInterfaces(context.Background(), tc.image, generic) if tc.returnError != nil { assert.ErrorContains(t, err, tc.returnError.Error()) return diff --git a/client.go b/client.go index e0c9e5a0..4f62e6ad 100644 --- a/client.go +++ b/client.go @@ -454,8 +454,8 @@ func (c *Client) ClearSystemEventLog(ctx context.Context) (err error) { return err } -func (c *Client) UploadFloppyImage(ctx context.Context, image io.Reader) (err error) { - metadata, err := bmc.UploadFloppyImageFromInterfaces(ctx, image, c.registry().GetDriverInterfaces()) +func (c *Client) MountFloppyImage(ctx context.Context, image io.Reader) (err error) { + metadata, err := bmc.MountFloppyImageFromInterfaces(ctx, image, c.registry().GetDriverInterfaces()) c.setMetadata(metadata) return err diff --git a/examples/floppy-image/main.go b/examples/floppy-image/main.go index d7a25374..60eb29e0 100644 --- a/examples/floppy-image/main.go +++ b/examples/floppy-image/main.go @@ -70,7 +70,7 @@ func main() { } defer fh.Close() - err = cl.UploadFloppyImage(ctx, fh) + err = cl.MountFloppyImage(ctx, fh) if err != nil { l.Fatal(err) } diff --git a/providers/providers.go b/providers/providers.go index fd558b63..b32749b4 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -23,10 +23,10 @@ const ( FeatureBootDeviceSet registrar.Feature = "bootdeviceset" // FeaturesVirtualMedia means an implementation can manage virtual media devices FeatureVirtualMedia registrar.Feature = "virtualmedia" - // FeatureUploadFloppyImage means an implementation uploads a floppy image for mounting as virtual media. + // FeatureMountFloppyImage means an implementation uploads a floppy image for mounting as virtual media. // // note: This is differs from FeatureVirtualMedia which is limited to accepting a URL to download the image from. - FeatureUploadFloppyImage registrar.Feature = "uploadFloppyImage" + FeatureMountFloppyImage registrar.Feature = "mountFloppyImage" // FeatureUnmountFloppyImage means an implementation removes a floppy image that was previously uploaded. FeatureUnmountFloppyImage registrar.Feature = "unmountFloppyImage" // FeatureFirmwareInstall means an implementation that initiates the firmware install process diff --git a/providers/supermicro/floppy.go b/providers/supermicro/floppy.go index 72ee8434..3cd3dceb 100644 --- a/providers/supermicro/floppy.go +++ b/providers/supermicro/floppy.go @@ -38,7 +38,7 @@ func (c *Client) floppyImageMounted(ctx context.Context) (bool, error) { return false, nil } -func (c *Client) UploadFloppyImage(ctx context.Context, image io.Reader) error { +func (c *Client) MountFloppyImage(ctx context.Context, image io.Reader) error { mounted, err := c.floppyImageMounted(ctx) if err != nil { return err diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index ca03fc86..29e235a0 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -41,7 +41,7 @@ var ( providers.FeatureScreenshot, providers.FeatureFirmwareInstall, providers.FeatureFirmwareInstallStatus, - providers.FeatureUploadFloppyImage, + providers.FeatureMountFloppyImage, providers.FeatureUnmountFloppyImage, } )