7481 Remove use of site-specific option, GrubMenu, from AI setup
authorClay Baenziger <ClayB@OpenSolaris.ORG>
Wed, 21 Apr 2010 10:47:14 -0600
changeset 813 5d94238d153f
parent 812 3b46b38c25e1
child 815 a7f52b124d5b
7481 Remove use of site-specific option, GrubMenu, from AI setup 15531 installadm build_136 creates bad macro for X86 service 15588 installadm_common: run_cmd() should raise OSError if non-existent command is attempted 15593 create-client: needs to quote dhtadm macro strings again
usr/src/cmd/installadm/create_client.py
usr/src/cmd/installadm/installadm_common.py
usr/src/cmd/installadm/setup-dhcp.sh
--- a/usr/src/cmd/installadm/create_client.py	Mon Apr 19 12:10:22 2010 -0700
+++ b/usr/src/cmd/installadm/create_client.py	Wed Apr 21 10:47:14 2010 -0600
@@ -190,17 +190,31 @@
                             MACAddress class)
               arch - architecture to setup for ("SPARC" or "X86")
     Returns: Nothing
-    Raises: SystemExit if command fails
+    Raises: SystemExit if command fails,
+            AssertionError if an unrecognized architecture is passed in
+            (recognized are SPARC and X86)
     """
+    # normalize architecutre case
+    arch=arch.upper()
     # create a DHCP client-identifier (01 + MAC ADDRESS)
     client_id = "01" + mac_address
+
     # get the host IP address (this only gets the IP of the host's nodename not
     # all interface IP addresses)
     server_ip = socket.gethostbyname(socket.gethostname())
-    http_port = "5555"
-    cgibin_wanboot_cgi = "/cgi-bin/wanboot-cgi"
-    boot_file = "http://" + server_ip + ":" + http_port + cgibin_wanboot_cgi
-    cmd = {"cmd": ["/usr/lib/installadm/setup-dhcp", "client", arch, server_ip,
+    # setup the boot file correctly per architecture
+    if arch == "SPARC":
+        http_port = "5555"
+        cgibin_wanboot_cgi = "/cgi-bin/wanboot-cgi"
+        boot_file = "http://" + server_ip + ":" + http_port + cgibin_wanboot_cgi
+    elif arch == "X86":
+        boot_file = client_id
+    else:
+        raise AssertionError("Architecture unrecognized!")
+
+    # run setup-dhcp shell script
+    # architecture needs be lower case for setup-dhcp.sh 
+    cmd = {"cmd": ["/usr/lib/installadm/setup-dhcp", "client", arch.lower(), server_ip,
                    client_id, boot_file]}
     try:
         cmd = com.run_cmd(cmd)
--- a/usr/src/cmd/installadm/installadm_common.py	Mon Apr 19 12:10:22 2010 -0700
+++ b/usr/src/cmd/installadm/installadm_common.py	Wed Apr 21 10:47:14 2010 -0600
@@ -1,3 +1,4 @@
+#!/bin/python2.6
 #
 # CDDL HEADER START
 #
@@ -1106,12 +1107,50 @@
 #
 
 def run_cmd(data):
-    """
+    r"""
     Run a command given by a dictionary and run the command, check for stderr
     output, return code, and populate stdout and stderr. One can check the
     return code, if catching SystemExit, via data["subproc"].returncode.
     Raises: SystemExit if command errors in any way (i.e. a non-zero return
-            code or anything in standard error).
+            code or anything in standard error). OSError if command is not
+            found or cannot be executed.
+    >>> test={"cmd": ["/bin/true"]}
+    >>> test=run_cmd(test)
+    >>> test={"cmd": ["/bin/pgrep", "python"]}
+    >>> run_cmd(test) # doctest:+ELLIPSIS, +NORMALIZE_WHITESPACE
+    {'cmd': ['/bin/pgrep', 'python'],
+     'subproc': <subprocess.Popen object at 0x...>,
+     'err': '',
+     'out': '...\n'}
+    >>> import gettext
+    >>> gettext.install("")
+    >>> test={"cmd": ["/bin/false"]}
+    >>> try:
+    ...  run_cmd(test)
+    ... except SystemExit, msg:
+    ...  print msg
+    ... 
+    Failure running subcommand /bin/false result 255
+    <BLANKLINE>
+    >>> test={"cmd": ["/bin/ksh","-c", "print -nu2 foo"]}
+    >>> gettext.install("")
+    >>> try:
+    ...  run_cmd(test)
+    ... except SystemExit, msg:
+    ...  print msg
+    ... 
+    Failure running subcommand /bin/ksh -c print -nu2 foo.
+    Got output:
+    foo
+    >>> test['err']
+    'foo'
+    >>> gettext.install("")
+    >>> run_cmd({"cmd": ["/does_not_exist"]}) # doctest:+ELLIPSIS
+    Traceback (most recent call last):
+                    ...
+    OSError: Failure executing subcommand /does_not_exist:
+    [Errno 2] No such file or directory
+    <BLANKLINE>
     """
     try:
         data["subproc"] = subprocess.Popen(data["cmd"],
@@ -1119,7 +1158,7 @@
                                            stderr=subprocess.PIPE)
     # unable to find command will result in an OSError
     except OSError, e:
-        raise SystemExit (_("Failure running subcommand %s:\n%s\n") %
+        raise OSError (_("Failure executing subcommand %s:\n%s\n") %
                            (" ".join(data["cmd"]), str(e)))
 
     # fill data["out"] with stdout and data["err"] with stderr
@@ -1193,3 +1232,7 @@
             basedir = defaultbasedir
 
     return basedir
+
+if __name__ == "__main__":
+    import doctest
+    doctest.testmod()
--- a/usr/src/cmd/installadm/setup-dhcp.sh	Mon Apr 19 12:10:22 2010 -0700
+++ b/usr/src/cmd/installadm/setup-dhcp.sh	Wed Apr 21 10:47:14 2010 -0600
@@ -46,7 +46,6 @@
 BOOTSRVA="BootSrvA"
 BOOTFILE="BootFile"
 INCLUDE="Include"
-GRUBMENU="GrubMenu"
 
 #
 # DHCP options should be built and given to dhtadm in a single command
@@ -108,19 +107,10 @@
 	echo "named ${macro} with:"
 	echo "   Boot server IP (BootSrvA) : ${svr_ipaddr}"
 	echo "   Boot file      (BootFile) : ${bootfile}"
-	if [ ! "$sparc" -a "${caller}" != "client" ]; then
-		echo "   GRUB Menu      (GrubMenu) : ${menu_lst_file}"
-	fi
 
 	echo "If you are running the Solaris DHCP Server, use the following"
 	echo "command to add the DHCP macro, ${macro}:"
 	echo "   $DHTADM -A -m ${macro} -d ${macvalue}"
-	if [ ! "$sparc" -a "${caller}" != "client" ]; then
-		echo ""
-		echo "Additionally, if the site specific symbol GrubMenu"
-		echo "is not present, please add it as follows:"
-		echo "   $DHTADM -A -s GrubMenu -d Site,150,ASCII,1,0"
-	fi
 	echo ""
 	echo "Note: Be sure to assign client IP address(es) if needed"
 	echo "(e.g., if running the Solaris DHCP Server, run pntadm(1M))."
@@ -130,9 +120,8 @@
 #
 # Set up the dhcp macro
 #    Both sparc/x86 use boot server address and boot file, but contents of
-#    boot file differs between sparc/x86. In addition, x86 uses dhcp macro
-#    symbol GrubMenu, which is defined by GRUBMENU.
-# 
+#    boot file differs between sparc/x86.
+#
 setup_dhcp_macro()
 {
 	caller=$1
@@ -176,10 +165,6 @@
 	fi
 	mvalue=`update_macro_value ${BOOTSRVA} ${svr_ipaddr} ${mvalue}`
 	mvalue=`update_macro_value ${BOOTFILE} ${bootfile} ${mvalue}`
-	if [ ! "$sparc" ]; then
-		mvalue=`update_macro_value ${GRUBMENU} ${menu_lst_file} \
-			${mvalue}`
-	fi
 
 	if [ $dhtstatus -ne 0 ]; then
 		# Tell user how to setup dhcp macro
@@ -238,11 +223,6 @@
 	# At this point, either a DHCP server previously existed, or
 	# one has been successfully created.
 
-	# Add the site specific option 150 to specify a
-	# menu.lst other than default one based on
-	# MAC adddress
-	$DHTADM -A -s GrubMenu -d Site,150,ASCII,1,0
-
 	# If the router found is for the network being configured,
 	# configure the network in DHCP with that router.  Otherwise
 	# don't use it.