Beispiel #1
0
    def test_get_system_info_no_number_of_enabled_core(self):
        """
        Tests get_system_info when there is no `NumberOfEnabledCore` property in
        the WMI Class Win32_Processor. Older versions of Windows are missing
        this property
        """

        # Create a mock processor class that does not have the
        # NumberOfCoresEnabled property
        class MockWMIProcessor:
            """
            Mock WMI Win32_Processor Class
            """
            def __init__(self):
                self.Manufacturer = "Intel"
                self.MaxClockSpeed = 2301
                self.NumberOfLogicalProcessors = 8
                self.NumberOfCores = 4

        with patch(
                "salt.utils.win_system.get_computer_name", MagicMock()), patch(
                    "salt.utils.winapi.Com", MagicMock()), patch.object(
                        self.WMI,
                        "Win32_OperatingSystem",
                        return_value=[
                            MockWMI_OperatingSystem()
                        ]), patch.object(
                            self.WMI,
                            "Win32_ComputerSystem",
                            return_value=[
                                MockWMI_ComputerSystem()
                            ]), patch.object(
                                self.WMI,
                                "Win32_ComputerSystemProduct",
                                return_value=[MockWMI_ComputerSystemProduct()],
                            ), patch.object(
                                self.WMI,
                                "Win32_Processor",
                                return_value=[
                                    MockWMIProcessor(),
                                    MockWMIProcessor()
                                ],
                            ), patch.object(
                                self.WMI,
                                "Win32_BIOS",
                                return_value=[MockWMI_BIOS()]), patch.object(
                                    wmi, "WMI", Mock(return_value=self.WMI)):
            ret = win_system.get_system_info()
            self.assertIn("processors", ret)
            self.assertIn("processors_logical", ret)
            self.assertIn("processor_cores", ret)
            self.assertIn("processor_manufacturer", ret)
            self.assertIn("processor_max_clock_speed", ret)
            self.assertNotIn("processor_cores_enabled", ret)
Beispiel #2
0
 def test_get_system_info(self):
     fields = [
         'bios_caption', 'bios_description', 'bios_details',
         'bios_manufacturer', 'bios_version', 'bootup_state', 'caption',
         'chassis_bootup_state', 'chassis_sku_number', 'description',
         'dns_hostname', 'domain', 'domain_role', 'hardware_manufacturer',
         'hardware_model', 'hardware_serial', 'install_date', 'last_boot',
         'name', 'network_server_mode_enabled', 'organization',
         'os_architecture', 'os_manufacturer', 'os_name', 'os_type',
         'os_version', 'part_of_domain', 'pc_system_type', 'power_state',
         'primary', 'processor_cores', 'processor_cores_enabled',
         'processor_manufacturer', 'processor_max_clock_speed',
         'processors', 'processors_logical', 'registered_user', 'status',
         'system_directory', 'system_drive', 'system_type', 'thermal_state',
         'total_physical_memory', 'total_physical_memory_raw', 'users',
         'windows_directory', 'workgroup'
     ]
     with patch('salt.utils', Mockwinapi), \
             patch('salt.utils.winapi.Com', MagicMock()), \
             patch.object(self.WMI, 'Win32_OperatingSystem',
                          return_value=[MockWMI_OperatingSystem()]), \
             patch.object(self.WMI, 'Win32_ComputerSystem',
                          return_value=[MockWMI_ComputerSystem()]), \
             patch.object(self.WMI, 'Win32_Processor',
                          return_value=[MockWMI_Processor(),
                                        MockWMI_Processor()]), \
             patch.object(self.WMI, 'Win32_BIOS',
                          return_value=[MockWMI_BIOS()]), \
             patch.object(wmi, 'WMI', Mock(return_value=self.WMI)):
         ret = win_system.get_system_info()
     # Make sure all the fields are in the return
     for field in fields:
         self.assertIn(field, ret)
     # os_type
     os_types = ['Work Station', 'Domain Controller', 'Server']
     self.assertIn(ret['os_type'], os_types)
     domain_roles = [
         'Standalone Workstation', 'Member Workstation',
         'Standalone Server', 'Member Server', 'Backup Domain Controller',
         'Primary Domain Controller'
     ]
     self.assertIn(ret['domain_role'], domain_roles)
     system_types = [
         'Unspecified', 'Desktop', 'Mobile', 'Workstation',
         'Enterprise Server', 'SOHO Server', 'Appliance PC',
         'Performance Server', 'Slate', 'Maximum'
     ]
     self.assertIn(ret['pc_system_type'], system_types)
     warning_states = [
         'Other', 'Unknown', 'Safe', 'Warning', 'Critical',
         'Non-recoverable'
     ]
     self.assertIn(ret['chassis_bootup_state'], warning_states)
     self.assertIn(ret['thermal_state'], warning_states)
Beispiel #3
0
 def test_get_system_info(self):
     fields = [
         "bios_caption",
         "bios_description",
         "bios_details",
         "bios_manufacturer",
         "bios_version",
         "bootup_state",
         "caption",
         "chassis_bootup_state",
         "chassis_sku_number",
         "description",
         "dns_hostname",
         "domain",
         "domain_role",
         "hardware_manufacturer",
         "hardware_model",
         "hardware_serial",
         "install_date",
         "last_boot",
         "name",
         "network_server_mode_enabled",
         "organization",
         "os_architecture",
         "os_manufacturer",
         "os_name",
         "os_type",
         "os_version",
         "part_of_domain",
         "pc_system_type",
         "power_state",
         "primary",
         "processor_cores",
         "processor_cores_enabled",
         "processor_manufacturer",
         "processor_max_clock_speed",
         "processors",
         "processors_logical",
         "registered_user",
         "status",
         "system_directory",
         "system_drive",
         "system_type",
         "thermal_state",
         "total_physical_memory",
         "total_physical_memory_raw",
         "users",
         "windows_directory",
         "workgroup",
     ]
     with patch(
             "salt.utils.win_system.get_computer_name", MagicMock()), patch(
                 "salt.utils.winapi.Com", MagicMock()), patch.object(
                     self.WMI,
                     "Win32_OperatingSystem",
                     return_value=[
                         MockWMI_OperatingSystem()
                     ]), patch.object(
                         self.WMI,
                         "Win32_ComputerSystem",
                         return_value=[
                             MockWMI_ComputerSystem()
                         ]), patch.object(
                             self.WMI,
                             "Win32_ComputerSystemProduct",
                             return_value=[MockWMI_ComputerSystemProduct()],
                         ), patch.object(
                             self.WMI,
                             "Win32_Processor",
                             return_value=[
                                 MockWMI_Processor(),
                                 MockWMI_Processor()
                             ],
                         ), patch.object(
                             self.WMI,
                             "Win32_BIOS",
                             return_value=[MockWMI_BIOS()]), patch.object(
                                 wmi, "WMI", Mock(return_value=self.WMI)):
         ret = win_system.get_system_info()
     # Make sure all the fields are in the return
     for field in fields:
         self.assertIn(field, ret)
     # os_type
     os_types = ["Work Station", "Domain Controller", "Server"]
     self.assertIn(ret["os_type"], os_types)
     domain_roles = [
         "Standalone Workstation",
         "Member Workstation",
         "Standalone Server",
         "Member Server",
         "Backup Domain Controller",
         "Primary Domain Controller",
     ]
     self.assertIn(ret["domain_role"], domain_roles)
     system_types = [
         "Unspecified",
         "Desktop",
         "Mobile",
         "Workstation",
         "Enterprise Server",
         "SOHO Server",
         "Appliance PC",
         "Performance Server",
         "Slate",
         "Maximum",
     ]
     self.assertIn(ret["pc_system_type"], system_types)
     warning_states = [
         "Other",
         "Unknown",
         "Safe",
         "Warning",
         "Critical",
         "Non-recoverable",
     ]
     self.assertIn(ret["chassis_bootup_state"], warning_states)
     self.assertIn(ret["thermal_state"], warning_states)