Index: fedd/federation/experiment_control.py
===================================================================
--- fedd/federation/experiment_control.py	(revision b535e190b71d388ff10389c7d4d48c7710776d82)
+++ fedd/federation/experiment_control.py	(revision a0c12a6c50a83d5e23391c046cea56625048b8b0)
@@ -589,7 +589,11 @@
 	# return value.  If we successfully parsed a "none" outcome, ignore the
 	# return code.
-	if rv != 0 and state != "none":
+	if rv != 0 and state != 'none':
 	    raise service_error(service_error.internal,
 		    "Cannot get status of segment %s:%s/%s" % (tb, pid, eid))
+
+	if state not in ('active', 'swapped', 'none'):
+	    self.log.debug("[start_segment]:unknown state %s" % state)
+	    return False
 
 	self.log.debug("[start_segment]: %s: %s" % (tb, state))
@@ -611,106 +615,52 @@
 		return False
 	
-	if state == 'active':
-	    # Create the federation config dirs (do not move outside the
-	    # conditional.  Happens later in new expriment creation)
-	    if not self.ssh_cmd(user, host, 
-		    "/bin/sh -c \"'mkdir -p %s'\"" % proj_dir):
+	if state == 'none':
+	    # Create a null copy of the experiment so that we capture any logs
+	    # there if the modify fails.  Emulab software discards the logs
+	    # from a failed startexp
+	    if not self.scp_file("%s/null.tcl" % tmpdir, user, host):
 		return False
-	    # Remote experiment is active.  Modify it.
-	    for f in base_confs:
-		if not self.scp_file("%s/%s" % (tmpdir, f), user, host,
-			"%s/%s" % (proj_dir, f)):
-		    return False
-	    if not self.ship_configs(host, user, "%s/%s" % (tmpdir, tb),
-		    proj_dir):
+	    self.log.info("[start_segment]: Creating %s on %s" % (eid, tb))
+	    if not self.ssh_cmd(user, host,
+		    "/usr/testbed/bin/startexp -i -f -w -p %s -e %s null.tcl" \
+			    % (pid, eid), "startexp"):
 		return False
-	    if os.path.isdir("%s/tarfiles" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/tarfiles" % tmpdir, tarfiles_dir):
-		    return False
-	    if os.path.isdir("%s/rpms" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/rpms" % tmpdir, tarfiles_dir):
-		    return False
-	    self.log.info("[start_segment]: Modifying %s on %s" % (eid, tb))
-	    if not self.ssh_cmd(user, host,
-		    "/usr/testbed/bin/modexp -r -s -w %s %s %s" % \
-			    (pid, eid, tclfile), "modexp"):
+	
+	# Create the federation config dirs
+	if not self.ssh_cmd(user, host, 
+		"/bin/sh -c \"'mkdir -p %s'\"" % proj_dir):
+	    return False
+	for f in base_confs:
+	    if not self.scp_file("%s/%s" % (tmpdir, f), user, host,
+		    "%s/%s" % (proj_dir, f)):
 		return False
-	    return True
-	elif state == "swapped":
-	    # Create the federation config dirs (do not move outside the
-	    # conditional.  Happens later in new expriment creation)
-	    if not self.ssh_cmd(user, host, 
-		    "/bin/sh -c \"'mkdir -p %s'\"" % proj_dir):
+	if not self.ship_configs(host, user, "%s/%s" % (tmpdir, tb),
+		proj_dir):
+	    return False
+	if os.path.isdir("%s/tarfiles" % tmpdir):
+	    if not self.ship_configs(host, user,
+		    "%s/tarfiles" % tmpdir, tarfiles_dir):
 		return False
-	    # Remote experiment swapped out.  Modify it and swap it in.
-	    for f in base_confs:
-		if not self.scp_file("%s/%s" % (tmpdir, f), user, host,
-			"%s/%s" % (proj_dir, f)):
-		    return False
-	    if not self.ship_configs(host, user, "%s/%s" % (tmpdir, tb),
-		    proj_dir):
+	if os.path.isdir("%s/rpms" % tmpdir):
+	    if not self.ship_configs(host, user,
+		    "%s/rpms" % tmpdir, tarfiles_dir):
 		return False
-	    if os.path.isdir("%s/tarfiles" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/tarfiles" % tmpdir, tarfiles_dir):
-		    return False
-	    if os.path.isdir("%s/rpms" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/rpms" % tmpdir, tarfiles_dir):
-		    return False
-	    self.log.info("[start_segment]: Modifying %s on %s" % (eid, tb))
-	    if not self.ssh_cmd(user, host,
-		    "/usr/testbed/bin/modexp -w %s %s %s" % (pid, eid, tclfile),
-		    "modexp"):
-		return False
-	    self.log.info("[start_segment]: Swapping %s in on %s" % (eid, tb))
+	# Stage the new configuration (active experiments will stay swapped in
+	# now)
+	self.log.info("[start_segment]: Modifying %s on %s" % (eid, tb))
+	if not self.ssh_cmd(user, host,
+		"/usr/testbed/bin/modexp -r -s -w %s %s %s" % \
+			(pid, eid, tclfile),
+		"modexp"):
+	    return False
+	# Active experiments are still swapped, this swaps the others in.
+	if state != 'active':
+	    self.log.info("[start_segment]: Swapping %s in on %s" % \
+		    (eid, tb))
 	    if not self.ssh_cmd(user, host,
 		    "/usr/testbed/bin/swapexp -w %s %s in" % (pid, eid),
 		    "swapexp"):
 		return False
-	    return True
-	elif state == "none":
-	    # No remote experiment.  Create one.  We do this in 2 steps so we
-	    # can put the configuration files and scripts into the new
-	    # experiment directories.
-
-	    # Tarfiles must be present for creation to work
-	    if os.path.isdir("%s/tarfiles" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/tarfiles" % tmpdir, tarfiles_dir):
-		    return False
-	    if os.path.isdir("%s/rpms" % tmpdir):
-		if not self.ship_configs(host, user,
-			"%s/rpms" % tmpdir, tarfiles_dir):
-		    return False
-	    self.log.info("[start_segment]: Creating %s on %s" % (eid, tb))
-	    if not self.ssh_cmd(user, host,
-		    "/usr/testbed/bin/startexp -i -f -w -p %s -e %s %s" % \
-			    (pid, eid, tclfile), "startexp"):
-		return False
-	    # Create the federation config dirs (do not move outside the
-	    # conditional.)
-	    if not self.ssh_cmd(user, host, 
-		    "/bin/sh -c \"'mkdir -p %s'\"" % proj_dir):
-		return False
-	    # After startexp the per-experiment directories exist
-	    for f in base_confs:
-		if not self.scp_file("%s/%s" % (tmpdir, f), user, host,
-			"%s/%s" % (proj_dir, f)):
-		    return False
-	    if not self.ship_configs(host, user, "%s/%s" % (tmpdir, tb),
-		    proj_dir):
-		return False
-	    self.log.info("[start_segment]: Swapping %s in on %s" % (eid, tb))
-	    if not self.ssh_cmd(user, host,
-		    "/usr/testbed/bin/swapexp -w %s %s in" % (pid, eid),
-		    "swapexp"):
-		return False
-	    return True
-	else:
-	    self.log.debug("[start_segment]:unknown state %s" % state)
-	    return False
+	return True
 
     def stop_segment(self, tb, eid, tbparams):
@@ -1760,4 +1710,18 @@
 		    self.copy_file(r, "%s/rpms/%s" % \
 			    (tmpdir, os.path.basename(r)))
+		# A null experiment file in case we need to create a remote
+		# experiment from scratch
+		f = open("%s/null.tcl" % tmpdir, "w")
+		print >>f, """
+set ns [new Simulator]
+source tb_compat.tcl
+
+set a [$ns node]
+
+$ns rtproto Session
+$ns run 
+"""
+		f.close()
+
 	    except IOError, e:
 		raise service_error(service_error.internal, 
