Various updates for hyperv and machine e2e tests

This PR is a mishmash of updates needed so that the hyperv provider can
begin to passd the machine e2e tests.

Summary as follows:
* Added custom error handling for machine errors so that all providers
  can generate the same formatted error messages.  The ones implemented
  thus far are needed for the basic and init tests.  More will come as
  they are identified.
* Vendored new libhvee for better memory inspection.  The memory type
  changed from uint32 to uint64.
* Some machine e2e tests used linux-specific utilities to check various
  error conditions and messages (like pgrep).  Those were made into
  functions and implemented on an operating system level.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2023-09-19 09:09:53 -05:00
parent cf3b216acb
commit 5b3801776b
16 changed files with 139 additions and 43 deletions

View File

@ -326,13 +326,18 @@ func (vm *VirtualMachine) GetConfig(diskPath string) (*HyperVConfig, error) {
return nil, err
}
diskSize = uint64(diskPathInfo.Size())
mem := MemorySettings{}
if err := vm.getMemorySettings(&mem); err != nil {
return nil, err
}
config := HyperVConfig{
Hardware: HardwareConfig{
// TODO we could implement a getProcessorSettings like we did for memory
CPUs: summary.NumberOfProcessors,
DiskPath: diskPath,
DiskSize: diskSize,
Memory: summary.MemoryAvailable,
Memory: mem.Limit,
},
Status: Statuses{
Created: vm.InstallDate,
@ -403,8 +408,8 @@ func (vmm *VirtualMachineManager) NewVirtualMachine(name string, config *Hardwar
// The API seems to require both of these even
// when not using dynamic memory
ms.Limit = uint64(config.Memory)
ms.VirtualQuantity = uint64(config.Memory)
ms.Limit = config.Memory
ms.VirtualQuantity = config.Memory
}).
PrepareProcessorSettings(func(ps *ProcessorSettings) {
ps.VirtualQuantity = uint64(config.CPUs) // 4 cores
@ -468,6 +473,15 @@ func (vm *VirtualMachine) fetchExistingResourceSettings(service *wmiext.Service,
return service.FindFirstRelatedObject(path, resourceType, resourceSettings)
}
func (vm *VirtualMachine) getMemorySettings(m *MemorySettings) error {
service, err := wmiext.NewLocalService(HyperVNamespace)
if err != nil {
return err
}
defer service.Close()
return vm.fetchExistingResourceSettings(service, "Msvm_MemorySettingData", m)
}
// Update processor and/or mem
func (vm *VirtualMachine) UpdateProcessorMemSettings(updateProcessor func(*ProcessorSettings), updateMemory func(*MemorySettings)) error {
service, err := wmiext.NewLocalService(HyperVNamespace)
@ -496,8 +510,7 @@ func (vm *VirtualMachine) UpdateProcessorMemSettings(updateProcessor func(*Proce
}
if updateMemory != nil {
err = vm.fetchExistingResourceSettings(service, "Msvm_MemorySettingData", mem)
if err != nil {
if err := vm.getMemorySettings(mem); err != nil {
return err
}

View File

@ -97,7 +97,7 @@ type HardwareConfig struct {
// Disk size in gigabytes assigned to the vm
DiskSize uint64
// Memory in megabytes assigned to the vm
Memory int32
Memory uint64
// Network is bool to add a Network Connection to the
// default network switch in Microsoft HyperV
Network bool