Comment 0 for bug 1407842

Revision history for this message
Hao Li (lihaosz) wrote :

I have read cloudbase-init source code, I found it will work until "HKEY_LOCAL_MACHINE\\SYSTEM\\Setup\\Status\\SysprepStatus" is 7. This may be cause some problem:

sysprep process:
 finish making image,then run sysprep.exe /oobe /generalize /shutdown /unattend:path-------->boot instance from this image----->sysprep will work(find device,and install device driver,then set SysprepStatus 7)------------>sysprep do other things,then reboot vm--------->finish user settings------->login interface

because I have installed cloudbase-init, it start when SysprepStatus is 7, In this moment, sysprep is working and cloudbase-init is working too, when cloudbase-init finish running sethostname plugin, it will reboot vm, but this moment, sysprep is doing important system setting. So the VM will crash.

I propose a way to solve this problem, set a flag in a flag_file, if flag_file is not exist or the content is 0, cloudbase-init should not run. set the flag 1, and cloudbase-init stop. if flag is 1, It can work. I have modify the source code:
def wait_for_boot_complete(self):
        path = CONF.sysprep_status_path
        print path

        is_exist = os.path.exists(path)
        if not is_exist:
            try:
                fp = os.open(path, os.O_CREAT | os.O_RDWR)
                os.write(fp, "1")
            except Exception, e:
                LOG.warning(e)
            finally:
                os.close(fp)
            return -1
        else:
            try:
                fp = os.open(path, os.O_RDWR)
                data = os.read(fp, 1)
            except Exception, e:
                LOG.warning(e)
                return -1

            if data == "0":
                os.lseek(fp,0,0)
                os.write(fp, "1")
                os.close(fp)
                return -1
            else:
                os.close(fp)