Esempio n. 1
0
    def testDriverWIM(self, mkdir, exe, dl, sha, rpath):
        bi = BuildInfo()
        # Setup
        remote = '@Drivers/Lenovo/W54x-Win10-Storage.wim'
        local = r'c:\W54x-Win10-Storage.wim'
        sha_256 = (
            'D30F9DB0698C87901DF6824D11203BDC2D6DAAF0CE14ABD7C0A7B75974936748')
        conf = {
            'data': {
                'driver': [[remote, local, sha_256]]
            },
            'path': ['/autobuild']
        }
        rpath.return_value = '/'

        # Success
        dw = drivers.DriverWIM(conf['data']['driver'], bi)
        dw.Run()
        dl.assert_called_with(mock.ANY,
                              ('https://glazier-server.example.com/'
                               'bin/Drivers/Lenovo/W54x-Win10-Storage.wim'),
                              local,
                              show_progress=True)
        sha.assert_called_with(mock.ANY, local, sha_256)
        cache = drivers.constants.SYS_CACHE
        exe.assert_called_with(
            f'{drivers.constants.WINPE_SYSTEM32}/dism.exe',
            ['/Unmount-Image', f'/MountDir:{cache}\\Drivers\\', '/Discard'],
            shell=True)
        mkdir.assert_called_with('%s\\Drivers\\' % cache)

        # Invalid format
        conf['data']['driver'][0][1] = 'C:\\W54x-Win10-Storage.zip'
        dw = drivers.DriverWIM(conf['data']['driver'], bi)
        self.assertRaises(drivers.ActionError, dw.Run)
        conf['data']['driver'][0][1] = 'C:\\W54x-Win10-Storage.wim'

        # Mount Fail
        exe.side_effect = drivers.execute.Error
        with self.assertRaises(drivers.ActionError):
            dw.Run()
        # Dism Fail
        exe.side_effect = iter([0, drivers.execute.Error])
        with self.assertRaises(drivers.ActionError):
            dw.Run()
        # Unmount Fail
        exe.side_effect = iter([0, 0, drivers.execute.Error])
        with self.assertRaises(drivers.ActionError):
            dw.Run()
Esempio n. 2
0
 def testDriverWIMValidate(self):
   g = drivers.DriverWIM('String', None)
   self.assertRaises(drivers.ValidationError, g.Validate)
   g = drivers.DriverWIM([[1, 2, 3]], None)
   self.assertRaises(drivers.ValidationError, g.Validate)
   g = drivers.DriverWIM([[1, '/tmp/out/path']], None)
   self.assertRaises(drivers.ValidationError, g.Validate)
   g = drivers.DriverWIM([['/tmp/src.zip', 2]], None)
   self.assertRaises(drivers.ValidationError, g.Validate)
   g = drivers.DriverWIM([['https://glazier/bin/src.wim', '/tmp/out/src.zip']],
                         None)
   self.assertRaises(drivers.ValidationError, g.Validate)
   g = drivers.DriverWIM([['https://glazier/bin/src.wim', '/tmp/out/src.wim']],
                         None)
   g.Validate()
   g = drivers.DriverWIM(
       [['https://glazier/bin/src.wim', '/tmp/out/src.wim', '12345']], None)
   g.Validate()
   g = drivers.DriverWIM(
       [['https://glazier/bin/src.zip', '/tmp/out/src.zip', '12345', '67890']],
       None)
   self.assertRaises(drivers.ValidationError, g.Validate)