~bladernr/maas-cert-server/mcs-install-curtin_userdata-by-packaging

« back to all changes in this revision

Viewing changes to preseed/curtin_userdata_custom_cert

  • Committer: Jeff Lane
  • Author(s): Rod Smith
  • Date: 2016-04-20 19:45:28 UTC
  • mfrom: (53.1.1 015-fix-network-naming)
  • Revision ID: jeff_lane-20160420194528-7rh7p6oh8033eqsc
Instead of using one preseed file for both standard MAAS and custom images, create two files. The standard MAAS preseed file does not attempt to adjust /etc/network/interfaces; only the custom-image preseed does that. This should enable MAAS to set the networking the way it wants to. The cost is that it might not bring up eth1 and above, but at least it won't fail to deploy.

This change also includes a tweak to maniacs-setup to install the correct preseed files. Users will need to run "sudo maniacs-setup -p" to replace their old preseed files with the new ones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Get maas version
 
2
{{py:
 
3
from subprocess import check_output
 
4
from shlex import split
 
5
maas_version = ""
 
6
cache_output = check_output(['apt-cache', 'policy', 'maas']).decode('utf-8')
 
7
for line in cache_output.splitlines():
 
8
    line = line.strip()
 
9
    if ':' in line and line.split(':')[0] == 'Installed':
 
10
        maas_version = line.split(':')[1].strip()
 
11
        break
 
12
try:
 
13
    f = open('/etc/maas-cert-server/iperf.conf', 'r')
 
14
    test_target_iperf = f.readline().rstrip()
 
15
    f.close()
 
16
except IOError:
 
17
    test_target_iperf = "gateway"
 
18
}}
 
19
#cloud-config
 
20
debconf_selections:
 
21
 maas: |
 
22
  {{for line in str(curtin_preseed).splitlines()}}
 
23
  {{line}}
 
24
  {{endfor}}
 
25
{{if third_party_drivers and driver}}
 
26
early_commands:
 
27
  {{py: key_string = ''.join(['\\x%x' % x for x in map(ord, driver['key_binary'])])}}
 
28
  driver_00_get_key: /bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg
 
29
  driver_01_add_key: ["apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
 
30
  driver_02_add: ["add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
 
31
  driver_03_update_install: ["sh", "-c", "apt-get update --quiet && apt-get --assume-yes install {{driver['package']}}"]
 
32
  driver_04_load: ["sh", "-c", "depmod && modprobe {{driver['module']}}"]
 
33
{{endif}}
 
34
 
 
35
anchor_bucket:
 
36
  - &sudoers |
 
37
      #!/bin/sh
 
38
      echo "Setting up sudoers...";
 
39
      echo "ubuntu ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/maas ;  chmod 0440 /etc/sudoers.d/maas;
 
40
      echo "Done.";
 
41
 
 
42
  - &installcert
 
43
      #!/bin/sh
 
44
      echo "Installing certfication tools...";
 
45
      echo " Add cert source list...";
 
46
      . /etc/lsb-release;
 
47
      if [ -z "`grep DISTRIB_DESCRIPTION /etc/lsb-release | grep development`" ] ; then
 
48
          echo deb http://ppa.launchpad.net/hardware-certification/public/ubuntu $DISTRIB_CODENAME main >> /etc/apt/sources.list.d/certification.list;
 
49
      else
 
50
          echo deb http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu $DISTRIB_CODENAME main >> /etc/apt/sources.list.d/certification.list;
 
51
      fi;
 
52
      echo deb http://ppa.launchpad.net/firmware-testing-team/ppa-fwts-stable/ubuntu $DISTRIB_CODENAME main >> /etc/apt/sources.list.d/certification.list;
 
53
      echo " Getting GPG Keys...";
 
54
      apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 1FEADE10;
 
55
      echo " Running apt-get update...";
 
56
      apt-get update;
 
57
      echo " Installing checkbox certification...";
 
58
      apt-get install -y --force-yes canonical-certification-server;
 
59
      sleep 60;
 
60
      maas_ip=$(/sbin/ip route | awk '/default/ { print $3 }');
 
61
      wget -nc -P /usr/bin http://$maas_ip/canonical-certification-precheck;
 
62
      chmod a+x /usr/bin/canonical-certification-precheck;
 
63
      echo "Done.";
 
64
 
 
65
  - &iperf
 
66
      #!/bin/sh
 
67
      echo "Setting up iperf...";
 
68
      /bin/sed -i '/^#TEST_TARGET_FTP /s/^#//' /etc/xdg/canonical-certification.conf;
 
69
      /bin/sed -i '/^#TEST_USER /s/^#//' /etc/xdg/canonical-certification.conf;
 
70
      /bin/sed -i '/^#TEST_PASS /s/^#//' /etc/xdg/canonical-certification.conf;
 
71
      /bin/sed -i '/^#TEST_TARGET_IPERF /s/^#//' /etc/xdg/canonical-certification.conf;
 
72
      if [ "{{test_target_iperf}}" = "gateway" ] ; then
 
73
          maas_ip=$(/sbin/ip route | awk '/default/ { print $3 }');
 
74
          sed -i 's/ your-iperf-server.example.com/'"$maas_ip"'/g' /etc/xdg/canonical-certification.conf;
 
75
      else
 
76
          sed -i 's/ your-iperf-server.example.com/{{test_target_iperf}}/g' /etc/xdg/canonical-certification.conf;
 
77
      fi;
 
78
      echo "Done.";
 
79
 
 
80
  - &networkinterfaces |
 
81
      #!/bin/sh
 
82
      echo "Setting all network interfaces to auto...";
 
83
      echo $(ls -l /etc/network/interfaces);
 
84
      echo "# This file created by maas-cert-server curtin preseed script" > /etc/network/interfaces;
 
85
      echo "auto lo" >> /etc/network/interfaces;
 
86
      echo "iface lo inet loopback\n" >> /etc/network/interfaces;
 
87
      for i in `ls /sys/class/net|sort |grep -v -E '(lo|wlan)'`; do
 
88
        if [ `cat /sys/class/net/$i/operstate` != "up" ] ; then
 
89
          dhclient -nw $i ;
 
90
          sleep 15 ;
 
91
          if [ `cat /sys/class/net/$i/operstate` != "up" ] ; then
 
92
            echo "# $i available but inoperative; check its cabling and DHCP server!" >> /etc/network/interfaces ;
 
93
            echo -n "#" >> /etc/network/interfaces ;
 
94
          fi;
 
95
          dhclient -r $i ;
 
96
        fi;
 
97
        echo "auto $i" >> /etc/network/interfaces ;
 
98
        echo "iface $i inet dhcp\n" >> /etc/network/interfaces ;
 
99
      done;
 
100
      echo "Done.";
 
101
 
 
102
  - &setubuntupass |
 
103
      #!/bin/sh
 
104
      echo "Setting ubuntu password..."
 
105
      echo "#cloud-config\nsystem_info:\n default_user:\n  lock_passwd: False\n  plain_text_passwd: 'ubuntu'" > /etc/cloud/cloud.cfg.d/ubuntu-user-defaults.cfg
 
106
      echo "Done.";
 
107
 
 
108
late_commands:
 
109
  maas: [wget, '--no-proxy', '{{node_disable_pxe_url|escape.shell}}', '--post-data', '{{node_disable_pxe_data|escape.shell}}', '-O', '/dev/null']
 
110
{{if third_party_drivers and driver}}
 
111
  driver_00_key_get: curtin in-target -- sh -c "/bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg"
 
112
  driver_02_key_add: ["curtin", "in-target", "--", "apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
 
113
  driver_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
 
114
  driver_04_update_install: ["curtin", "in-target", "--", "apt-get", "update", "--quiet"]
 
115
  driver_05_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{driver['package']}}"]
 
116
  driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
 
117
  driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
 
118
{{endif}}
 
119
  # inject maas version into /etc/installed-with-maas and install cert tools
 
120
  set_maas_version: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo {{maas_version}} > /etc/installed-by-maas"]
 
121
  # Install certification suite
 
122
  zv_cert_install:  ['curtin', 'in-target', '--', 'sh', '-c', *sudoers ]
 
123
  zw_cert_install:  ['curtin', 'in-target', '--', 'sh', '-c', *installcert ]
 
124
  zx_cert_install:  ['curtin', 'in-target', '--', 'sh', '-c', *iperf ]
 
125
  zy_cert_install:  ['curtin', 'in-target', '--', 'sh', '-c', *networkinterfaces]
 
126
  zz_cert_install:  ['curtin', 'in-target', '--', 'sh', '-c', *setubuntupass]
 
127
 
 
128
 
 
129
power_state:
 
130
  mode: reboot
 
131
 
 
132
{{if node.split_arch()[0] in {'i386', 'amd64'} }}
 
133
apt_mirrors:
 
134
  ubuntu_archive: http://{{main_archive_hostname}}/{{main_archive_directory}}
 
135
  ubuntu_security: http://{{main_archive_hostname}}/{{main_archive_directory}}
 
136
{{else}}
 
137
apt_mirrors:
 
138
  ubuntu_archive: http://{{ports_archive_hostname}}/{{ports_archive_directory}}
 
139
  ubuntu_security: http://{{ports_archive_hostname}}/{{ports_archive_directory}}
 
140
{{endif}}
 
141
 
 
142
{{if http_proxy }}
 
143
apt_proxy: {{http_proxy}}
 
144
{{else}}
 
145
apt_proxy: http://{{server_host}}:8000/
 
146
{{endif}}