Skip to content

Commit c8a9227

Browse files
committed
Adding machine interface
This adds a machine interface that can be used to mock operations of machine. This interface is subject to change as it reflects the Machine structure. Signed-off-by: xibz <[email protected]>
1 parent b704cc3 commit c8a9227

File tree

8 files changed

+91
-14
lines changed

8 files changed

+91
-14
lines changed

client_transports.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package firecracker
215

316
import (

client_transports_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package firecracker
215

316
import (

handlers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ func NewSetMetadataHandler(metadata interface{}) Handler {
173173
return Handler{
174174
Name: SetMetadataHandlerName,
175175
Fn: func(ctx context.Context, m *Machine) error {
176-
return m.SetMetadata(ctx, metadata)
176+
if _, err := m.client.PutMmds(ctx, metadata); err != nil {
177+
m.logger.Errorf("Setting metadata: %s", err)
178+
return err
179+
}
180+
181+
m.logger.Printf("SetMetadata successful")
182+
return nil
177183
},
178184
}
179185
}

machine.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -588,22 +588,12 @@ func (m *Machine) sendCtrlAltDel(ctx context.Context) error {
588588
return err
589589
}
590590

591-
// EnableMetadata will append or replace the metadata handler.
591+
// EnableMetadata will append or replace the metadata handler and only will be
592+
// called when calling the Machine Start operation.
592593
func (m *Machine) EnableMetadata(metadata interface{}) {
593594
m.Handlers.FcInit = m.Handlers.FcInit.Swappend(NewSetMetadataHandler(metadata))
594595
}
595596

596-
// SetMetadata sets the machine's metadata for MDDS
597-
func (m *Machine) SetMetadata(ctx context.Context, metadata interface{}) error {
598-
if _, err := m.client.PutMmds(ctx, metadata); err != nil {
599-
m.logger.Errorf("Setting metadata: %s", err)
600-
return err
601-
}
602-
603-
m.logger.Printf("SetMetadata successful")
604-
return nil
605-
}
606-
607597
// UpdateGuestDrive will modify the current guest drive of ID index with the new
608598
// parameters of the partialDrive.
609599
func (m *Machine) UpdateGuestDrive(ctx context.Context, driveID, pathOnHost string, opts ...PatchGuestDriveByIDOpt) error {

machine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func TestWaitForSocket(t *testing.T) {
637637

638638
func testSetMetadata(ctx context.Context, t *testing.T, m *Machine) {
639639
metadata := map[string]string{"key": "value"}
640-
err := m.SetMetadata(ctx, metadata)
640+
_, err := m.client.PutMmds(ctx, metadata)
641641
if err != nil {
642642
t.Errorf("failed to set metadata: %s", err)
643643
}

machineiface.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package firecracker
15+
16+
import (
17+
"context"
18+
)
19+
20+
// MachineIface can be used for mocking and testing of the Machine. The Machine
21+
// is subject to change, meaning this interface would change.
22+
type MachineIface interface {
23+
Start(context.Context) error
24+
StopVMM() error
25+
Shutdown(context.Context) error
26+
Wait(context.Context) error
27+
EnableMetadata(interface{})
28+
UpdateGuestDrive(context.Context, string, string, ...PatchGuestDriveByIDOpt) error
29+
}

rate_limiter.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package firecracker
215

316
import (

rate_limiter_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package firecracker_test
215

316
import (

0 commit comments

Comments
 (0)