From fd0e730d954b27f568e31eea378f6a4f924c1a39 Mon Sep 17 00:00:00 2001
From: Nikos Skalkotos <skalkoto@grnet.gr>
Date: Mon, 20 Oct 2014 15:36:07 +0300
Subject: [PATCH] windows: Enable Auto Update if not sysprepped

When we cleanup all the changes made before booting the Windows VM, only
revert the /Microsoft/Windows/CurrentVersion/WindowsUpdate/Auto Update'
changes if the image has not been syspreped. Those values get deleted
during Sysprep.
---
 image_creator/os_type/windows/__init__.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/image_creator/os_type/windows/__init__.py b/image_creator/os_type/windows/__init__.py
index f0114e9..7a41ba9 100644
--- a/image_creator/os_type/windows/__init__.py
+++ b/image_creator/os_type/windows/__init__.py
@@ -523,14 +523,21 @@ class Windows(OSBase):
                 self._add_cleanup('sysprep',
                                   self.registry.update_uac_remote_setting, old)
 
+            def if_not_sysprepped(task, *args):
+                """Only perform this if the image is not syspreped"""
+                if not self.sysprepped:
+                    task(*args)
+
+            # The next 2 registry values get completely removed by Microsoft
+            # Sysprep. They should not be reverted if Sysprep gets executed.
             old = self.registry.update_noautoupdate(1)
             if old != 1:
-                self._add_cleanup('sysprep',
+                self._add_cleanup('sysprep', if_not_sysprepped,
                                   self.registry.update_noautoupdate, old)
 
             old = self.registry.update_auoptions(1)
             if old != 1:
-                self._add_cleanup('sysprep',
+                self._add_cleanup('sysprep', if_not_sysprepped,
                                   self.registry.update_auoptions, old)
 
             # disable the firewalls
-- 
GitLab