Skip to content

Commit

Permalink
working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Human Capitalist committed May 8, 2021
1 parent b3b5443 commit ac35c2e
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 49 deletions.
4 changes: 2 additions & 2 deletions lib/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def to_s
end

def self.to_strings
all.select(&:by_serial).sort_by{|d| d.type_sort_order * 100000000 + d.connection_sort_order * 10000000 + d.capacity_gb}.map(&:to_s)
all.sort_by{|d| d.type_sort_order * 100000000 + d.connection_sort_order * 10000000 + d.capacity_gb}.map(&:to_s)
end

def self.to_string_list
Expand All @@ -35,7 +35,7 @@ def self.load
log.debug "-----------------------------------------"
log.debug " "
end
disks
disks.select(&:by_serial)
end

def id
Expand Down
56 changes: 32 additions & 24 deletions lib/root_installer/questions/boot_type.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
class RootInstaller::Questions::BootType < Question

attr_reader :boot_type, :efi_partition
attr_reader :boot_type, :efi_partition, :efi_choice_dialog, :efi_advisory_dialog,
:mbr_advisory_dialog, :mbr_error_dialog, :efi_partition_dialog

def ask
File.directory?("/sys/firmware/efi") ? ask_efi : ask_legacy
self.class.efi_support? ? ask_efi : ask_legacy
end

def self.efi_support?
@efi_support ||= File.directory?("/sys/firmware/efi")
end

def ask_efi
if has_512k
new_dialog.tap do |d|
d.title = "Boot Type"
d.yes_label = "EFI\\ Boot"
d.no_label = "Legacy\\ MBR\\ Boot"
if d.yesno("\\nThis machine supports both EFI and legacy MBR booting. What boot type would you like?", 8, 50)
@boot_type = :efi
else
@boot_type = :mbr
ask_efi_partition
end
@efi_choice_dialog = new_dialog
@efi_choice_dialog.title = "Boot Type"
@efi_choice_dialog.yes_label = "EFI\\ Boot"
@efi_choice_dialog.no_label = "Legacy\\ MBR\\ Boot"
if @efi_choice_dialog.yesno("\\nThis machine supports both EFI and legacy MBR booting. What boot type would you like?", 8, 50)
@boot_type = :efi
else
@boot_type = :mbr
ask_efi_partition
end
else
new_dialog.tap do |d|
d.title = "Boot Pool - select disks"
d.msgbox("\\nThis machine only has 4Kn type disks, so it will be configured for UEFI boot.", 8, 50)
end
@efi_advisory_dialog = new_dialog
@efi_advisory_dialog.title = "Boot Type"
@efi_advisory_dialog.msgbox("\\nThis machine only has 4Kn type disks, so it will be configured for UEFI boot.", 8, 50)
@boot_type = :efi
end
end

def ask_legacy
new_dialog.tap do |d|
d.title = "Boot Type"
d.msgbox("\\nThis machine does not support UEFI booting, so legacy MBR booting will be configured.", 8, 50)
if has_512k
@mbr_advisory_dialog = new_dialog
@mbr_advisory_dialog.title = "Boot Type"
@mbr_advisory_dialog.msgbox("\\nThis machine does not support UEFI booting, so legacy MBR booting will be configured.", 8, 50)
ask_efi_partition
else
@mbr_error_dialog = new_dialog
@mbr_error_dialog.title = "Boot Type"
@mbr_error_dialog.msgbox('This machine does not support UEFI booting, But none of its disks is reporting 512K sectors that support legacy MBR Boot. This installer cannot work on this machine. Please see https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html#root-on-zfs for manual install instructions.', 10, 70)
quit 1
end
ask_efi_partition
end

def ask_efi_partition
new_dialog.tap do |d|
d.title = "Create EFI Partition for future use?"
@efi_partition = d.yesno("\\nLegacy MBR Boot has been selected. Would you also like to create an unused EFI partition in case you need UEFI boot in future?", 9, 50)
end
@efi_partition_dialog = new_dialog
@efi_partition_dialog.title = "Create EFI Partition for future use?"
@efi_partition = @efi_partition_dialog.yesno("\\nLegacy MBR Boot has been selected. Would you also like to create an unused EFI partition in case you need UEFI boot in future?", 9, 50)
end


Expand Down
6 changes: 3 additions & 3 deletions runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ if [ -z "$1" ]
then
echo " "
echo " "
echo "usage: ./runtest.sh <test file name relative to ./test directory, including file extension>"
echo "eg: ./runtest.sh test_question.rb"
echo "usage: ./runtest.sh <test file name relative to current directory, including file extension>"
echo "eg: ./runtest.sh test/test_question.rb"
echo " "
echo " "
exit
fi
ruby -Ilib:test test/$1
ruby -Ilib:test $1
File renamed without changes.
237 changes: 237 additions & 0 deletions test/data/largesector-disks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
16: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: 7tlP.Fxp0d3BezAE
SysFS ID: /class/block/ram2
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram2
Device Number: block 1:2
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

17: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: CWFH.Fxp0d3BezAE
SysFS ID: /class/block/ram0
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram0
Device Number: block 1:0
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

18: IDE 100.0: 10600 Disk
[Created at block.245]
Unique ID: WZeP.ltDB2H9Ht5E
Parent ID: w7Y8.9yUVNR9J1l9
SysFS ID: /class/block/sdb
SysFS BusID: 1:0:0:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0
Hardware Class: disk
Model: "ST2000NM0033-9ZM"
Device: "ST2000NM0033-9ZM"
Revision: "SN07"
Serial ID: "Z1X0TX8R"
Driver: "ahci", "sd"
Driver Modules: "ahci", "sd_mod"
Device File: /dev/sdb
Device Files: /dev/sdb, /dev/disk/by-id/ata-ST2000NM0033-9ZM175_Z1X0TX8R, /dev/disk/by-path/pci-0000:00:1f.2-ata-2, /dev/disk/by-id/wwn-0x5000c50064b2a291
Device Number: block 8:16-8:31
Geometry (Logical): CHS 243201/255/63
Size: 488378646 sectors a 4096 bytes
Capacity: 1863 GB (2000398934016 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #3 (SATA controller)

19: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: XOSI.Fxp0d3BezAE
SysFS ID: /class/block/ram9
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram9
Device Number: block 1:9
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

20: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: s19p.Fxp0d3BezAE
SysFS ID: /class/block/ram14
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram14
Device Number: block 1:14
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

21: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: d1y9.Fxp0d3BezAE
SysFS ID: /class/block/ram7
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram7
Device Number: block 1:7
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

22: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: ygeg.Fxp0d3BezAE
SysFS ID: /class/block/ram12
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram12
Device Number: block 1:12
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

23: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: UPWc.Fxp0d3BezAE
SysFS ID: /class/block/ram5
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram5
Device Number: block 1:5
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

24: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: 2K8Y.Fxp0d3BezAE
SysFS ID: /class/block/ram10
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram10
Device Number: block 1:10
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

25: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: a20U.Fxp0d3BezAE
SysFS ID: /class/block/ram3
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram3
Device Number: block 1:3
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

26: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: ghVL.Fxp0d3BezAE
SysFS ID: /class/block/ram1
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram1
Device Number: block 1:1
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

27: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: JDPt.Fxp0d3BezAE
SysFS ID: /class/block/ram15
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram15
Device Number: block 1:15
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

28: IDE 00.0: 10600 Disk
[Created at block.245]
Unique ID: 3OOL.eZgOVl+pmnA
Parent ID: w7Y8.9yUVNR9J1l9
SysFS ID: /class/block/sda
SysFS BusID: 0:0:0:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0
Hardware Class: disk
Model: "ST2000NM0033-9ZM"
Device: "ST2000NM0033-9ZM"
Revision: "SN07"
Serial ID: "Z1X0TY02"
Driver: "ahci", "sd"
Driver Modules: "ahci", "sd_mod"
Device File: /dev/sda
Device Files: /dev/sda, /dev/disk/by-path/pci-0000:00:1f.2-ata-1, /dev/disk/by-id/wwn-0x5000c50064b2518e, /dev/disk/by-id/ata-ST2000NM0033-9ZM175_Z1X0TY02
Device Number: block 8:0-8:15
Geometry (Logical): CHS 243201/255/63
Size: 488378646 sectors a 4096 bytes
Capacity: 1863 GB (2000398934016 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #3 (SATA controller)

29: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: 4DCE.Fxp0d3BezAE
SysFS ID: /class/block/ram8
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram8
Device Number: block 1:8
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

30: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: Psuk.Fxp0d3BezAE
SysFS ID: /class/block/ram13
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram13
Device Number: block 1:13
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

31: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: xamg.Fxp0d3BezAE
SysFS ID: /class/block/ram6
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram6
Device Number: block 1:6
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

32: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: VVOc.Fxp0d3BezAE
SysFS ID: /class/block/ram11
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram11
Device Number: block 1:11
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown

33: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: 1EGY.Fxp0d3BezAE
SysFS ID: /class/block/ram4
Hardware Class: disk
Model: "Disk"
Device File: /dev/ram4
Device Number: block 1:4
Size: 131072 sectors a 512 bytes
Capacity: 0 GB (67108864 bytes)
Config Status: cfg=new, avail=yes, need=no, active=unknown
File renamed without changes.
1 change: 1 addition & 0 deletions test/data/root_installer/test_boot_type.test_efi_4k.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\\nThis machine only has 4Kn type disks, so it will be configured for UEFI boot.", 8, 50]

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions test/data/test_disk.test_string_list_with_hpe_disks.txt

This file was deleted.

2 changes: 0 additions & 2 deletions test/data/test_disk.test_string_list_with_rescue_disks.txt

This file was deleted.

6 changes: 0 additions & 6 deletions test/data/test_disk.test_string_list_with_usb_disks.txt

This file was deleted.

Loading

0 comments on commit ac35c2e

Please sign in to comment.