mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
[WIP] Support for cloud version (#17)
* Added build-cloud to Makefile * Fix env var key GOOS * Added taskSetReleaseVersion for edgeboxctl version option write into DB * taskGetSystemUptime to run every 5 ticks * Added support for detecting main disk in cloud version * Added missing import * Finding main device in test * Refactored GetDevices and test to use release_version * Added utils.getIP function, set to run as a 60 tick scheduled task * Added taskEnablePublicDashboard and taskDisablePublicDashboard * Added utils.WriteOption and refactor, added enablePublicDashb0oard * Finalizing online support for dashboard, cloud version support * Added task SetupCloudOptions * Added couple of func description comments * Early return statement (thanks @inverse) * Using IsPublicDashboard in DisablePublicDashboard func * Added constants for release version and device types, added diagnostics.GetReleaseVersion * Removed codecov from test action
This commit is contained in:
+35
-15
@@ -6,24 +6,25 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
)
|
||||
|
||||
// Device : Struct representing a storage device in the system
|
||||
type Device struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Size string `json:"size"`
|
||||
InUse bool `json:"in_use"`
|
||||
MainDevice bool `json:"main_device"`
|
||||
MAJ string `json:"maj"`
|
||||
MIN string `json:"min"`
|
||||
RM string `json:"rm"`
|
||||
RO string `json:"ro"`
|
||||
Partitions []Partition `json:"partitions"`
|
||||
Status DeviceStatus `json:"status"`
|
||||
UsageStat UsageStat `json:"usage_stat"`
|
||||
ID DeviceIdentifier `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Size string `json:"size"`
|
||||
InUse bool `json:"in_use"`
|
||||
MainDevice bool `json:"main_device"`
|
||||
MAJ string `json:"maj"`
|
||||
MIN string `json:"min"`
|
||||
RM string `json:"rm"`
|
||||
RO string `json:"ro"`
|
||||
Partitions []Partition `json:"partitions"`
|
||||
Status DeviceStatus `json:"status"`
|
||||
UsageStat UsageStat `json:"usage_stat"`
|
||||
}
|
||||
|
||||
// DeviceStatus : Struct representing possible storage device statuses (code + description)
|
||||
@@ -66,10 +67,27 @@ type Partition struct {
|
||||
UsageStat UsageStat `json:"usage_stat"`
|
||||
}
|
||||
|
||||
const mainDiskID = "mmcblk0"
|
||||
type DeviceIdentifier string
|
||||
|
||||
const (
|
||||
DISK_TYPE_SDA DeviceIdentifier = "sda"
|
||||
DISK_TYPE_MCBLK DeviceIdentifier = "mmcblk0"
|
||||
DISK_TYPE_VDA DeviceIdentifier = "vda"
|
||||
)
|
||||
|
||||
func GetDeviceIdentifier(release_version diagnostics.ReleaseVersion) DeviceIdentifier {
|
||||
switch release_version {
|
||||
case diagnostics.CLOUD_VERSION:
|
||||
return DISK_TYPE_VDA
|
||||
case diagnostics.PROD_VERSION:
|
||||
return DISK_TYPE_MCBLK
|
||||
}
|
||||
|
||||
return DISK_TYPE_SDA
|
||||
}
|
||||
|
||||
// GetDevices : Returns a list of all available sotrage devices in structs filled with information
|
||||
func GetDevices() []Device {
|
||||
func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||
|
||||
var devices []Device
|
||||
|
||||
@@ -82,6 +100,8 @@ func GetDevices() []Device {
|
||||
firstDevice := true
|
||||
currentDeviceInUseFlag := false
|
||||
|
||||
mainDiskID := GetDeviceIdentifier(release_version)
|
||||
|
||||
for scanner.Scan() {
|
||||
// 1 Device is represented here. Extract words in order for filling a Device struct
|
||||
// Example deviceRawInfo: "mmcblk0 179:0 0 29.7G 0 disk"
|
||||
@@ -122,7 +142,7 @@ func GetDevices() []Device {
|
||||
mainDevice := false
|
||||
|
||||
device := Device{
|
||||
ID: deviceRawInfo[0],
|
||||
ID: DeviceIdentifier(deviceRawInfo[0]),
|
||||
Name: deviceRawInfo[0],
|
||||
Size: deviceRawInfo[3],
|
||||
MainDevice: mainDevice,
|
||||
|
||||
@@ -7,25 +7,37 @@ import (
|
||||
)
|
||||
|
||||
func TestGetDevices(t *testing.T) {
|
||||
result := GetDevices()
|
||||
|
||||
if len(result) == 0 {
|
||||
t.Log("Testing with release version dev")
|
||||
assertGetDevices(GetDevices("dev"), t)
|
||||
t.Log("Testing with release version prod")
|
||||
assertGetDevices(GetDevices("prod"), t)
|
||||
t.Log("Testing with release version cloud")
|
||||
assertGetDevices(GetDevices("cloud"), t)
|
||||
|
||||
}
|
||||
|
||||
func assertGetDevices(devices []Device, t *testing.T) {
|
||||
|
||||
if len(devices) == 0 {
|
||||
t.Log("Expecting at least 1 block device, 0 elements found in slice")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
foundDevice := false
|
||||
|
||||
t.Log("Looking for a mmcblk0 or sda device")
|
||||
for _, device := range result {
|
||||
if device.ID == "mmcblk0" || device.ID == "sda" {
|
||||
t.Log("Looking for a mmcblk0, sda or dva device")
|
||||
for _, device := range devices {
|
||||
|
||||
if device.ID == "mmcblk0" || device.ID == "sda" || device.ID == "vda" {
|
||||
t.Log("Found target device", device.ID)
|
||||
foundDevice = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !foundDevice {
|
||||
t.Log("Expected to find device mmcblk0 but did not. Devices:", result)
|
||||
t.Log("Expected to find device mmcblk0, sda or dva but did not. Devices:", devices)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user