Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows inspection: Use marketing versions #1391

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
154 changes: 119 additions & 35 deletions cli_tools_tests/module/diskinspect/disk_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ func TestInspectDisk(t *testing.T) {
}

for _, tt := range []struct {
caseName string
imageURI string
expected disk.InspectionResult
}{
{
"projects/opensuse-cloud/global/images/opensuse-leap-15-2-v20200702",
disk.InspectionResult{
imageURI: "projects/opensuse-cloud/global/images/opensuse-leap-15-2-v20200702",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "opensuse",
Major: "15",
Expand All @@ -67,29 +68,22 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: true,
},
}, {
"projects/suse-sap-cloud/global/images/sles-15-sp1-sap-v20200803",
disk.InspectionResult{
imageURI: "projects/suse-sap-cloud/global/images/sles-15-sp1-sap-v20200803",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "sles-sap",
Major: "15",
Minor: "1",
UEFIBootable: true,
BIOSBootableWithHybridMBROrProtectiveMBR: true,
},
}, {
"projects/compute-image-tools-test/global/images/windows-7-ent-x86-nodrivers",
disk.InspectionResult{
Architecture: "x86",
Distro: "windows",
Major: "6",
Minor: "1",
UEFIBootable: false,
BIOSBootableWithHybridMBROrProtectiveMBR: false,
},
}, {
// UEFI inspection test for GPT UEFI
"projects/gce-uefi-images/global/images/rhel-7-v20200403",
disk.InspectionResult{
},

// UEFI
{
caseName: "UEFI inspection test for GPT UEFI",
imageURI: "projects/gce-uefi-images/global/images/rhel-7-v20200403",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "rhel",
Major: "7",
Expand All @@ -98,9 +92,9 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: false,
},
}, {
// UEFI inspection test for MBR-only
"projects/debian-cloud/global/images/debian-9-stretch-v20200714",
disk.InspectionResult{
caseName: "UEFI inspection test for MBR-only",
imageURI: "projects/debian-cloud/global/images/debian-9-stretch-v20200714",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "debian",
Major: "9",
Expand All @@ -109,20 +103,20 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: false,
},
}, {
// UEFI inspection test for GPT UEFI - windows
"projects/gce-uefi-images/global/images/windows-server-2019-dc-core-v20200609",
disk.InspectionResult{
caseName: "UEFI inspection test for GPT UEFI - windows",
imageURI: "projects/gce-uefi-images/global/images/windows-server-2019-dc-core-v20200609",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "10",
Major: "2019",
Minor: "",
UEFIBootable: true,
BIOSBootableWithHybridMBROrProtectiveMBR: false,
},
}, {
// UEFI inspection test for GPT UEFI with BIOS boot
"projects/gce-uefi-images/global/images/ubuntu-1804-bionic-v20200317",
disk.InspectionResult{
caseName: "UEFI inspection test for GPT UEFI with BIOS boot",
imageURI: "projects/gce-uefi-images/global/images/ubuntu-1804-bionic-v20200317",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "ubuntu",
Major: "18",
Expand All @@ -131,9 +125,9 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: true,
},
}, {
// UEFI inspection test for GPT UEFI with hybrid MBR
"projects/compute-image-tools-test/global/images/image-ubuntu-2004-hybrid-mbr",
disk.InspectionResult{
caseName: "UEFI inspection test for GPT UEFI with hybrid MBR",
imageURI: "projects/compute-image-tools-test/global/images/image-ubuntu-2004-hybrid-mbr",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "ubuntu",
Major: "20",
Expand All @@ -142,9 +136,9 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: true,
},
}, {
// UEFI inspection test for MBR-only UEFI
"projects/compute-image-tools-test/global/images/image-uefi-mbr-only",
disk.InspectionResult{
caseName: "UEFI inspection test for MBR-only UEFI",
imageURI: "projects/compute-image-tools-test/global/images/image-uefi-mbr-only",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "ubuntu",
Major: "16",
Expand All @@ -153,11 +147,101 @@ func TestInspectDisk(t *testing.T) {
BIOSBootableWithHybridMBROrProtectiveMBR: false,
},
},

// Windows Server
{
imageURI: "projects/windows-cloud/global/images/windows-server-2008-r2-dc-v20200114",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "2008",
Minor: "r2",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-2012-r2-vmware-import",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "2012",
Minor: "r2",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-2016-import",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "2016",
Minor: "",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-2019",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "2019",
Minor: "",
},
},

// Windows Desktop
{
imageURI: "projects/compute-image-tools-test/global/images/windows-7-ent-x86-nodrivers",
expected: disk.InspectionResult{
Architecture: "x86",
Distro: "windows",
Major: "7",
Minor: "",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-7-import",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "7",
Minor: "",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-8-1-ent-x86-nodrivers",
expected: disk.InspectionResult{
Architecture: "x86",
Distro: "windows",
Major: "8",
Minor: "1",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-8-1-x64",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "8",
Minor: "1",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-10-1909-ent-x86-nodrivers",
expected: disk.InspectionResult{
Architecture: "x86",
Distro: "windows",
Major: "10",
Minor: "",
},
}, {
imageURI: "projects/compute-image-tools-test/global/images/windows-10-1709-import",
expected: disk.InspectionResult{
Architecture: "x64",
Distro: "windows",
Major: "10",
Minor: "",
},
},
} {
// Without this, each parallel test will reference the last tt instance.
// https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
currentTest := tt
t.Run(currentTest.imageURI, func(t *testing.T) {
name := currentTest.caseName
if name == "" {
name = currentTest.imageURI
}
t.Run(name, func(t *testing.T) {
t.Parallel()
inspector, err := disk.NewInspector(daisycommon.WorkflowAttributes{
Project: project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,34 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re

from boot_inspect import model

# Matched against the output of guestfs.inspect_get_product_variant.
# This is required since desktop and server use the same NT versions.
# For example, NT 6.3 is either Windows 2012r2 or Windows 8.1.
_server_pattern = re.compile('server', re.IGNORECASE)
_client_pattern = re.compile('client', re.IGNORECASE)

# Mappings of NT version to marketing versions.
# Source: https://wikipedia.org/wiki/List_of_Microsoft_Windows_versions
_server_versions = {
(6, 0): ('2008', ''),
(6, 1): ('2008', 'r2'),
(6, 2): ('2012', ''),
(6, 3): ('2012', 'r2'),
# (10,0) is resolved in code since, since it's used for
# both Windows 2016 and Windows 2019.
}
_client_versions = {
(6, 0): ('Vista', ''),
(6, 1): ('7', ''),
(6, 2): ('8', ''),
(6, 3): ('8', '1'),
(10, 0): ('10', ''),
}


class Inspector:

Expand All @@ -29,17 +54,36 @@ def __init__(self, g, root: str):
self._root = root

def inspect(self) -> model.OperatingSystem:
if self._is_windows():
return model.OperatingSystem(
model.Distro.WINDOWS,
self._get_version(),
distro = self._g.inspect_get_distro(self._root)
if isinstance(distro, str) and 'windows' in distro.lower():
return _from_nt_version(
major_nt=self._g.inspect_get_major_version(self._root),
minor_nt=self._g.inspect_get_minor_version(self._root),
variant=self._g.inspect_get_product_variant(self._root),
product_name=self._g.inspect_get_product_name(self._root)
)

def _get_version(self) -> model.Version:
major = self._g.inspect_get_major_version(self._root)
minor = self._g.inspect_get_minor_version(self._root)
return model.Version(major, minor)

def _is_windows(self) -> bool:
inspected = self._g.inspect_get_distro(self._root)
return model.distro_for(inspected) == model.Distro.WINDOWS
def _from_nt_version(
variant: str,
major_nt: int,
minor_nt: int,
product_name: str) -> model.OperatingSystem:
major, minor = None, None
nt_version = major_nt, minor_nt
if _client_pattern.search(variant):
major, minor = _client_versions.get(nt_version, (None, None))
elif _server_pattern.search(variant):
if nt_version in _server_versions:
major, minor = _server_versions.get(nt_version, (None, None))
elif nt_version == (10, 0):
if '2016' in product_name:
major, minor = '2016', ''
elif '2019' in product_name:
major, minor = '2019', ''

if major is not None and minor is not None:
return model.OperatingSystem(
model.Distro.WINDOWS,
model.Version(major, minor)
)
4 changes: 2 additions & 2 deletions daisy_workflows/image_import/inspection/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_happy_case(self):
device="/dev/sdb",
os=model.OperatingSystem(
distro=model.Distro.WINDOWS,
version=model.Version(major="6", minor="1"),
version=model.Version(major="8", minor="1"),
),
architecture=model.Architecture.x86,
)
Expand All @@ -80,7 +80,7 @@ def test_happy_case(self):
"os": {
"distro": "windows",
"version": {
"major": "6",
"major": "8",
"minor": "1",
}
},
Expand Down