Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
I expect to squash this into an earlier commit once it passes tests
vcsim: support container backing for hosts
  • Loading branch information
hickeng committed Aug 7, 2023
1 parent 2b5c457 commit f636e96
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 43 deletions.
25 changes: 7 additions & 18 deletions simulator/container_host_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,11 @@ import (
"fmt"
"strings"

"github.com/vmware/govmomi/units"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
)

const KiB = 1024
const MiB = 1024 * KiB
const GiB = 1024 * MiB
const TiB = 1024 * GiB
const Pib = 1024 * TiB

const KB = 1000
const MB = 1000 * KB
const GB = 1000 * MB
const TB = 1000 * GB
const PB = 1000 * TB

const (
advOptPrefixPnicToUnderlayPrefix = "RUN.underlay."
advOptContainerBackingImage = "RUN.container"
Expand Down Expand Up @@ -74,8 +63,8 @@ func createSimHostMounts(ctx *Context, containerName string, mounts []types.Host
switch vol := info.Volume.(type) {
case *types.HostVmfsVolume:
vol.BlockSizeMb = 1
vol.BlockSize = KiB
vol.UnmapGranularity = KiB
vol.BlockSize = units.KB
vol.UnmapGranularity = units.KB
vol.UnmapPriority = "low"
vol.MajorVersion = 6
vol.Version = "6.82"
Expand Down Expand Up @@ -309,7 +298,7 @@ var defaultSimVolumes = []types.HostFileSystemMountInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "VMFS",
Name: "datastore1",
Capacity: 1 * TiB,
Capacity: 1 * units.TB,
},
Extent: []types.HostScsiDiskPartition{
{
Expand All @@ -326,7 +315,7 @@ var defaultSimVolumes = []types.HostFileSystemMountInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "OSDATA-%__UUID__%",
Capacity: 128 * GiB,
Capacity: 128 * units.GB,
},
Extent: []types.HostScsiDiskPartition{
{
Expand All @@ -343,7 +332,7 @@ var defaultSimVolumes = []types.HostFileSystemMountInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "BOOTBANK1",
Capacity: 4 * GiB,
Capacity: 4 * units.GB,
},
},
},
Expand All @@ -355,7 +344,7 @@ var defaultSimVolumes = []types.HostFileSystemMountInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "BOOTBANK2",
Capacity: 4 * GiB,
Capacity: 4 * units.GB,
},
},
},
Expand Down
14 changes: 12 additions & 2 deletions simulator/container_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25"
Expand All @@ -39,14 +41,22 @@ import (
// port - the port to forward to the container port 80
func constructNginxBacking(t *testing.T, content string, port int) []types.BaseOptionValue {
dir := t.TempDir()
// experience shows that a parent directory created as part of the TempDir call may not have
// o+rx, preventing use within a container that doesn't have the same uid
for dirpart := dir; dirpart != "/"; dirpart = filepath.Dir(dirpart) {
os.Chmod(dirpart, 0755)
stat, err := os.Stat(dirpart)
require.Nil(t, err, "must be able to check file and directory permissions")
require.NotZero(t, stat.Mode()&0005, "does not have o+rx permissions", dirpart)
}

fpath := filepath.Join(dir, "index.html")
os.WriteFile(fpath, []byte(content), 0644)
err := os.WriteFile(fpath, []byte(content), 0644)
require.Nil(t, err, "Expected to cleanly write content to file: %s", err)

// just in case umask gets in the way
os.Chmod(fpath, 0644)
err = os.Chmod(fpath, 0644)
require.Nil(t, err, "Expected to cleanly set file permissions on content: %s", err)

args := fmt.Sprintf("-v '%s:/usr/share/nginx/html:ro' nginx", dir)

Expand Down
35 changes: 13 additions & 22 deletions simulator/esx/host_config_filesystemvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@ limitations under the License.

package esx

import "github.com/vmware/govmomi/vim25/types"

const KiB = 1024
const MiB = 1024 * KiB
const GiB = 1024 * MiB
const TiB = 1024 * GiB
const Pib = 1024 * TiB

const KB = 1000
const MB = 1000 * KB
const GB = 1000 * MB
const TB = 1000 * GB
const PB = 1000 * TB
import (
"github.com/vmware/govmomi/units"
"github.com/vmware/govmomi/vim25/types"
)

// HostConfigInfo is the default template for the HostSystem config property.
// Capture method:
Expand All @@ -50,14 +41,14 @@ var HostFileSystemVolumeInfo = types.HostFileSystemVolumeInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "VMFS",
Name: "datastore1",
Capacity: 3.5 * TiB,
Capacity: 3.5 * units.TB,
},
BlockSizeMb: 1,
BlockSize: KiB,
UnmapGranularity: KiB,
BlockSize: units.KB,
UnmapGranularity: units.KB,
UnmapPriority: "low",
UnmapBandwidthSpec: (*types.VmfsUnmapBandwidthSpec)(nil),
MaxBlocks: 61 * MiB,
MaxBlocks: 61 * units.MB,
MajorVersion: 6,
Version: "6.82",
Uuid: "deadbeef-01234567-89ab-cdef00000003",
Expand Down Expand Up @@ -88,14 +79,14 @@ var HostFileSystemVolumeInfo = types.HostFileSystemVolumeInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "OSDATA-deadbeef-01234567-89ab-cdef00000002",
Capacity: 128 * GiB,
Capacity: 128 * units.GB,
},
BlockSizeMb: 1,
BlockSize: KiB,
BlockSize: units.KB,
UnmapGranularity: 0,
UnmapPriority: "",
UnmapBandwidthSpec: (*types.VmfsUnmapBandwidthSpec)(nil),
MaxBlocks: 256 * KiB,
MaxBlocks: 256 * units.KB,
MajorVersion: 1,
Version: "1.00",
Uuid: "deadbeef-01234567-89ab-cdef00000002",
Expand Down Expand Up @@ -126,7 +117,7 @@ var HostFileSystemVolumeInfo = types.HostFileSystemVolumeInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "BOOTBANK1",
Capacity: 4 * GiB,
Capacity: 4 * units.GB,
},
},
VStorageSupport: "",
Expand All @@ -144,7 +135,7 @@ var HostFileSystemVolumeInfo = types.HostFileSystemVolumeInfo{
HostFileSystemVolume: types.HostFileSystemVolume{
Type: "OTHER",
Name: "BOOTBANK2",
Capacity: 4 * GiB,
Capacity: 4 * units.GB,
},
},
VStorageSupport: "",
Expand Down
2 changes: 1 addition & 1 deletion simulator/host_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *HostSystem) configureContainerBacking(ctx *Context, image string, mount
Value: image,
}

advOpts := Map.Get(h.ConfigManager.AdvancedOption.Reference()).(*OptionManager)
advOpts := ctx.Map.Get(h.ConfigManager.AdvancedOption.Reference()).(*OptionManager)
fault := advOpts.UpdateOptions(&types.UpdateOptions{ChangedValue: []types.BaseOptionValue{option}}).Fault()
if fault != nil {
panic(fault)
Expand Down

0 comments on commit f636e96

Please sign in to comment.