Fix purging unattended-upgrades in template generator

Change-Id: Idbf7bdc4237eaab36cf2bfebb5c5105378775875
diff --git a/tcp_tests/templates/cookied-model-generator/underlay--user-data-cfg01.yaml b/tcp_tests/templates/cookied-model-generator/underlay--user-data-cfg01.yaml
index ba4ee4e..7bd7a02 100644
--- a/tcp_tests/templates/cookied-model-generator/underlay--user-data-cfg01.yaml
+++ b/tcp_tests/templates/cookied-model-generator/underlay--user-data-cfg01.yaml
@@ -19,10 +19,12 @@
 
   bootcmd:
    # Block access to SSH while node is preparing
-   - cloud-init-per once sudo iptables -A INPUT -p tcp --dport 22 -j DROP
+   #- cloud-init-per once sudo iptables -A INPUT -p tcp --dport 22 -j DROP
+   - cloud-init-per once sudo ifdown ens4
+
    # Enable root access
-   - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
-   - service sshd restart
+   - cloud-init-per once sudo sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
+   - cloud-init-per once sudo service sshd restart
 
   output:
     all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
@@ -30,9 +32,19 @@
   runcmd:
    # Prepare network connection
    - sudo ifdown ens3
-   #- sudo ifup ens3
+   - sudo ifup ens3
    #- sudo route add default gw {gateway} {interface_name}
 
+   # Purge the unattended-upgrades package (Workaround for PROD-17904, PROD-18736)"
+   - echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt
+   - echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt
+   - echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt
+   - apt-get -y purge unattended-upgrades
+   # Stop currently running apt-daily service, source: https://unix.stackexchange.com/a/315517
+   - systemctl stop apt-daily.service
+   - systemctl kill --kill-who=all apt-daily.service
+   - while ! (systemctl list-units --all apt-daily.service | fgrep -q dead); do sleep 1; done
+
    # Configure dhclient
    - sudo echo "nameserver {gateway}" >> /etc/resolvconf/resolv.conf.d/base
    - sudo resolvconf -u
@@ -65,16 +77,11 @@
 
    ########################################################
    # Node is ready, allow SSH access
-   - echo "Allow SSH access ..."
-   - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
+   #- echo "Allow SSH access ..."
+   #- sudo iptables -D INPUT -p tcp --dport 22 -j DROP
+   - sudo ifup ens4
    ########################################################
 
-   # Purge the unattended-upgrades package (Workaround for PROD-17904, PROD-18736)"
-   - echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt
-   - echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt
-   - echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt
-   - apt-get -y purge unattended-upgrades
-   - reboot
 
   write_files:
    - path: /etc/default/grub.d/97-enable-grub-menu.cfg
@@ -87,6 +94,8 @@
      content: |
           auto ens3
           iface ens3 inet dhcp
+          auto ens4
+          iface ens4 inet dhcp
 
    - path: /root/.ssh/config
      owner: root:root