Skip to content

Commit

Permalink
Rename UploadFloppyImage -> MountFloppyImage
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Oct 31, 2023
1 parent 35b0e0f commit 7932b1c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions bmc/floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,7 +37,7 @@ func uploadFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUplo
return metadata, err

Check warning on line 37 in bmc/floppy.go

View check run for this annotation

Codecov / codecov/patch

bmc/floppy.go#L37

Added line #L37 was not covered by tests
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

Check warning on line 43 in bmc/floppy.go

View check run for this annotation

Codecov / codecov/patch

bmc/floppy.go#L42-L43

Added lines #L42 - L43 were not covered by tests
Expand All @@ -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"))

Check warning on line 51 in bmc/floppy.go

View check run for this annotation

Codecov / codecov/patch

bmc/floppy.go#L51

Added line #L51 was not covered by tests
}

// 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))
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func unmountFloppyImage(ctx context.Context, p []floppyImageUnmounterProvider) (
return metadataLocal, multierror.Append(err, errors.New("failed to unmount floppy image"))

Check warning on line 121 in bmc/floppy.go

View check run for this annotation

Codecov / codecov/patch

bmc/floppy.go#L121

Added line #L121 was not covered by tests
}

// 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 {
Expand Down
12 changes: 6 additions & 6 deletions bmc/floppy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ func (c *Client) ClearSystemEventLog(ctx context.Context) (err error) {
return err

Check warning on line 454 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L454

Added line #L454 was not covered by tests
}

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)

Check warning on line 459 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L457-L459

Added lines #L457 - L459 were not covered by tests

return err

Check warning on line 461 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L461

Added line #L461 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion examples/floppy-image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion providers/supermicro/floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *Client) floppyImageMounted(ctx context.Context) (bool, error) {
return false, nil

Check warning on line 38 in providers/supermicro/floppy.go

View check run for this annotation

Codecov / codecov/patch

providers/supermicro/floppy.go#L38

Added line #L38 was not covered by tests
}

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

Check warning on line 44 in providers/supermicro/floppy.go

View check run for this annotation

Codecov / codecov/patch

providers/supermicro/floppy.go#L41-L44

Added lines #L41 - L44 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
providers.FeatureScreenshot,
providers.FeatureFirmwareInstall,
providers.FeatureFirmwareInstallStatus,
providers.FeatureUploadFloppyImage,
providers.FeatureMountFloppyImage,
providers.FeatureUnmountFloppyImage,
}
)
Expand Down

0 comments on commit 7932b1c

Please sign in to comment.