コード例 #1
0
 def test__windows_disks_retcode(self):
     '''
     Test grains._windows_disks, retcode 1
     Should return empty lists
     '''
     mock_which = MagicMock(
         return_value='C:\\Windows\\System32\\wbem\\WMIC.exe')
     mock_run_all = MagicMock(return_value={'stdout': '', 'retcode': 1})
     with patch('salt.utils.path.which', mock_which), \
             patch.dict(disks.__salt__, {'cmd.run_all': mock_run_all}):
         result = disks._windows_disks()
         expected = {'SSDs': [], 'disks': []}
         self.assertDictEqual(result, expected)
コード例 #2
0
 def test__windows_disks_retcode(self):
     """
     Test grains._windows_disks, retcode 1
     Should return empty lists
     """
     mock_which = MagicMock(
         return_value="C:\\Windows\\System32\\wbem\\WMIC.exe")
     mock_run_all = MagicMock(return_value={"stdout": "", "retcode": 1})
     with patch("salt.utils.path.which",
                mock_which), patch.dict(disks.__salt__,
                                        {"cmd.run_all": mock_run_all}):
         result = disks._windows_disks()
         expected = {"ssds": [], "disks": []}
         self.assertDictEqual(result, expected)
コード例 #3
0
    def test__windows_disks(self):
        """
        Test grains._windows_disks, normal return
        Should return a populated dictionary
        """
        mock_which = MagicMock(
            return_value="C:\\Windows\\System32\\wbem\\WMIC.exe")
        wmic_result = textwrap.dedent("""
            DeviceId  MediaType
            0         4
            1         0
            2         3
            3         5
        """)
        mock_run_all = MagicMock(return_value={
            "stdout": wmic_result,
            "retcode": 0
        })

        with patch("salt.utils.path.which",
                   mock_which), patch.dict(disks.__salt__,
                                           {"cmd.run_all": mock_run_all}):
            result = disks._windows_disks()
            expected = {
                "ssds": ["\\\\.\\PhysicalDrive0"],
                "disks": [
                    "\\\\.\\PhysicalDrive0",
                    "\\\\.\\PhysicalDrive1",
                    "\\\\.\\PhysicalDrive2",
                    "\\\\.\\PhysicalDrive3",
                ],
            }
            self.assertDictEqual(result, expected)
            cmd = " ".join([
                "C:\\Windows\\System32\\wbem\\WMIC.exe",
                "/namespace:\\\\root\\microsoft\\windows\\storage",
                "path",
                "MSFT_PhysicalDisk",
                "get",
                "DeviceID,MediaType",
                "/format:table",
            ])
            mock_run_all.assert_called_once_with(cmd)
コード例 #4
0
    def test__windows_disks(self):
        '''
        Test grains._windows_disks, normal return
        Should return a populated dictionary
        '''
        mock_which = MagicMock(
            return_value='C:\\Windows\\System32\\wbem\\WMIC.exe')
        wmic_result = textwrap.dedent('''
            DeviceId  MediaType
            0         4
            1         0
            2         3
            3         5
        ''')
        mock_run_all = MagicMock(return_value={
            'stdout': wmic_result,
            'retcode': 0
        })

        with patch('salt.utils.path.which', mock_which), \
                patch.dict(disks.__salt__, {'cmd.run_all': mock_run_all}):
            result = disks._windows_disks()
            expected = {
                'SSDs': ['\\\\.\\PhysicalDrive0'],
                'disks': [
                    '\\\\.\\PhysicalDrive0', '\\\\.\\PhysicalDrive1',
                    '\\\\.\\PhysicalDrive2', '\\\\.\\PhysicalDrive3'
                ]
            }
            self.assertDictEqual(result, expected)
            cmd = ' '.join([
                'C:\\Windows\\System32\\wbem\\WMIC.exe',
                '/namespace:\\\\root\\microsoft\\windows\\storage', 'path',
                'MSFT_PhysicalDisk', 'get', 'DeviceID,MediaType',
                '/format:table'
            ])
            mock_run_all.assert_called_once_with(cmd)