mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-19 12:14:11 +00:00
virtcontainers: Remove unused function
While working on the previous commits, some of the functions become non-used. Let's simply remove them. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
0939f5181b
commit
323271403e
@ -11,7 +11,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -50,7 +49,6 @@ const (
|
||||
// MockHypervisor is a mock hypervisor for testing purposes
|
||||
MockHypervisor HypervisorType = "mock"
|
||||
|
||||
procMemInfo = "/proc/meminfo"
|
||||
procCPUInfo = "/proc/cpuinfo"
|
||||
|
||||
defaultVCPUs = 1
|
||||
@ -799,39 +797,6 @@ func DeserializeParams(parameters []string) []Param {
|
||||
return params
|
||||
}
|
||||
|
||||
func GetHostMemorySizeKb(memInfoPath string) (uint64, error) {
|
||||
f, err := os.Open(memInfoPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
// Expected format: ["MemTotal:", "1234", "kB"]
|
||||
parts := strings.Fields(scanner.Text())
|
||||
|
||||
// Sanity checks: Skip malformed entries.
|
||||
if len(parts) < 3 || parts[0] != "MemTotal:" || parts[2] != "kB" {
|
||||
continue
|
||||
}
|
||||
|
||||
sizeKb, err := strconv.ParseUint(parts[1], 0, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
return sizeKb, nil
|
||||
}
|
||||
|
||||
// Handle errors that may have occurred during the reading of the file.
|
||||
if err := scanner.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("unable get MemTotal from %s", memInfoPath)
|
||||
}
|
||||
|
||||
// CheckCmdline checks whether an option or parameter is present in the kernel command line.
|
||||
// Search is case-insensitive.
|
||||
// Takes path to file that contains the kernel command line, desired option, and permitted values
|
||||
|
@ -8,7 +8,6 @@ package virtcontainers
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
|
||||
@ -372,55 +371,6 @@ func TestAddKernelParamInvalid(t *testing.T) {
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestGetHostMemorySizeKb(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
type testData struct {
|
||||
contents string
|
||||
expectedResult int
|
||||
expectError bool
|
||||
}
|
||||
|
||||
data := []testData{
|
||||
{
|
||||
`
|
||||
MemTotal: 1 kB
|
||||
MemFree: 2 kB
|
||||
SwapTotal: 3 kB
|
||||
SwapFree: 4 kB
|
||||
`,
|
||||
1024,
|
||||
false,
|
||||
},
|
||||
{
|
||||
`
|
||||
MemFree: 2 kB
|
||||
SwapTotal: 3 kB
|
||||
SwapFree: 4 kB
|
||||
`,
|
||||
0,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
file := filepath.Join(dir, "meminfo")
|
||||
_, err := GetHostMemorySizeKb(file)
|
||||
assert.Error(err)
|
||||
|
||||
for _, d := range data {
|
||||
err = os.WriteFile(file, []byte(d.contents), os.FileMode(0640))
|
||||
assert.NoError(err)
|
||||
defer os.Remove(file)
|
||||
|
||||
hostMemKb, err := GetHostMemorySizeKb(file)
|
||||
|
||||
assert.False((d.expectError && err == nil))
|
||||
assert.False((!d.expectError && err != nil))
|
||||
assert.NotEqual(hostMemKb, d.expectedResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckCmdline(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
@ -302,18 +302,6 @@ func (q *qemu) cpuTopology() govmmQemu.SMP {
|
||||
return q.arch.cpuTopology(q.config.NumVCPUs, q.config.DefaultMaxVCPUs)
|
||||
}
|
||||
|
||||
func (q *qemu) hostMemMB() (uint64, error) {
|
||||
hostMemKb, err := GetHostMemorySizeKb(procMemInfo)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Unable to read memory info: %s", err)
|
||||
}
|
||||
if hostMemKb == 0 {
|
||||
return 0, fmt.Errorf("Error host memory size 0")
|
||||
}
|
||||
|
||||
return hostMemKb / 1024, nil
|
||||
}
|
||||
|
||||
func (q *qemu) memoryTopology() (govmmQemu.Memory, error) {
|
||||
hostMemMb := q.config.DefaultMaxMemorySize
|
||||
memMb := uint64(q.config.MemorySize)
|
||||
|
Loading…
Reference in New Issue
Block a user