Commit b3c23e5d authored by Timothy Stack's avatar Timothy Stack

Fix a couple of things I missed in my last checkin.

	* event/program-agent/program-agent.c: Setup of the user
	environment variables wasn't ordered correctly.

	* event/sched/event-sched.c, event/sched/rpc.h,
	event/sched/rpc.cc: Setup the expected user environment variables,
	just like in program-agent.

	* event/sched/simulator-agent.cc: Rename the old feedback data so
	we don't lose it in case the vnode remapping modify fails.

	* xmlrpc/emulabserver.py.in: Add virt_user_environment table data
	to the result of the experiment.metadata method, so the
	event-scheduler can get it.
parent 8e0fccf9
......@@ -207,6 +207,7 @@ static void signal_program(struct proginfo *pinfo, char *args);
* @return Zero on success, -1 otherwise.
*/
static int parse_configfile(char *filename);
static int parse_configfile_env(char *filename);
/**
* Callback triggered when a program executes passed its timeout value.
......@@ -585,6 +586,12 @@ main(int argc, char **argv)
setenv("NODEIP", inet_ntoa(ia), 1);
}
/* XXX Need to eval the ENV parts of the config file after we've
* setup the environment.
*/
if (parse_configfile_env(configfile) != 0)
exit(1);
/*
* Change to the temp directory, this will be inherited by any children
* that do not have their own directory setting.
......@@ -1395,6 +1402,38 @@ parse_configfile(char *filename)
proginfos = pinfo;
continue;
}
if (!strncmp(buf, "ENV ", 4)) {
continue;
}
error("parse_configfile: malformed: %s\n", buf);
goto bad;
}
fclose(fp);
return 0;
bad:
fclose(fp);
return -1;
}
static int
parse_configfile_env(char *filename)
{
FILE *fp;
char buf[BUFSIZ];
assert(filename != NULL);
assert(strlen(filename) > 0);
if ((fp = fopen(filename, "r")) == NULL) {
errorc("could not open configfile %s", filename);
return -1;
}
while (fgets(buf, sizeof(buf), fp)) {
int cc = strlen(buf);
if (buf[cc-1] == '\n')
buf[cc-1] = (char) NULL;
if (!strncmp(buf, "ENV ", 4)) {
FILE *file;
......@@ -1417,14 +1456,10 @@ parse_configfile(char *filename)
}
continue;
}
error("parse_configfile: malformed: %s\n", buf);
goto bad;
}
fclose(fp);
return 0;
bad:
fclose(fp);
return -1;
}
static int
......
......@@ -196,18 +196,14 @@ main(int argc, char *argv[])
fatal("could not connect to rpc server");
}
if (RPC_exppath(pid, eid, buf, sizeof(buf))) {
fatal("could not get experiment metadata");
}
if (chdir(buf) < 0) {
fatal("could not chdir to experiment directory: %s", buf);
}
setenv("EXPDIR", buf, 1);
setenv("LOGDIR", LOGDIR, 1);
setenv("PID", pid, 1);
setenv("EID", eid, 1);
if (RPC_metadata(pid, eid)) {
fatal("could not get experiment metadata");
}
/*
* Okay this is more complicated than it probably needs to be. We do
* not want to run anything on ops that is linked against the event
......@@ -743,6 +739,44 @@ dequeue(event_handle_t handle)
sched_event_free(handle, &next_event);
}
}
int
SetExpPath(const char *path)
{
setenv("EXPDIR", path, 1);
return chdir(path);
}
int
AddUserEnv(char *name, char *path)
{
int retval = 0;
FILE *file;
/* XXX Kind of a stupid way to eval any variables. */
if ((file = popenf("echo %s=%s", "r", name, path)) == NULL) {
retval = -1;
}
else {
char buf[BUFSIZ];
if (fgets(buf, sizeof(buf), file) != NULL) {
char *idx;
if ((idx = strchr(buf, '\n')) != NULL)
*idx = '\0';
if ((idx = strchr(buf, '=')) != NULL) {
*idx = '\0';
retval = setenv(strdup(buf), idx + 1, 1);
}
}
pclose(file);
file = NULL;
}
return 0;
}
/*
* Stuff to get the event list.
*/
......
......@@ -264,24 +264,43 @@ RPC_invoke(char *pid, char *eid, char *method, emulab::EmulabResponse *er)
}
int
RPC_exppath(char *pid, char *eid, char *path_out, size_t path_size)
RPC_metadata(char *pid, char *eid)
{
emulab::EmulabResponse er;
int retval;
assert(pid != NULL);
assert(eid != NULL);
assert(path_out != NULL);
assert(path_size > 0);
if ((retval = RPC_invoke(pid, eid, "experiment.metadata", &er)) == 0) {
ulxr::RpcString path;
ulxr::Array userenv;
ulxr::Struct md;
md = (ulxr::Struct)er.getValue();
path = md.getMember(ULXR_PCHAR("path"));
strncpy(path_out, path.getString().c_str(), path_size);
path_out[path_size - 1] = '\0';
SetExpPath(path.getString().c_str());
userenv = md.getMember(ULXR_PCHAR("user_environment"));
if (userenv.size() > 0) {
int lpc;
for (lpc = 0; lpc < userenv.size(); lpc++) {
ulxr::RpcString tmp;
char *name, *value;
ulxr::Struct ue;
ue = (ulxr::Struct)userenv.getItem(lpc);
tmp = ue.getMember("name");
name = (char *)tmp.getString().c_str();
ue = (ulxr::Struct)userenv.getItem(lpc);
tmp = ue.getMember("value");
value = (char *)tmp.getString().c_str();
if ((retval = AddUserEnv(name, value)) != 0)
return retval;
}
}
}
return retval;
......
......@@ -56,7 +56,7 @@ int RPC_init(const char *certpath, const char *host, unsigned short port);
int RPC_grab(void);
void RPC_drop(void);
int RPC_exppath(char *pid, char *eid, char *path_out, size_t path_size);
int RPC_metadata(char *pid, char *eid);
int RPC_waitforrobots(event_handle_t handle, char *pid, char *eid);
int RPC_waitforactive(char *pid, char *eid);
int RPC_notifystart(char *pid, char *eid, char *timeline, int set_or_clear);
......@@ -66,6 +66,9 @@ int RPC_eventlist(char *pid, char *eid,
event_handle_t handle, address_tuple_t tuple,
long basetime);
extern int SetExpPath(const char *path);
extern int AddUserEnv(char *name, char *value);
extern int AddAgent(event_handle_t handle,
char *vname, char *vnode, char *nodeid,
char *ipaddr, char *type);
......
......@@ -157,8 +157,6 @@ static int remap_experiment(simulator_agent_t sa, int token)
EmulabResponse er;
int retval;
rename("tbdata/feedback_data.tcl",
"tbdata/feedback_data_old.tcl");
snprintf(nsfile, sizeof(nsfile),
"/proj/%s/exp/%s/tbdata/%s-modify.ns",
pid, eid, eid);
......@@ -169,14 +167,14 @@ static int remap_experiment(simulator_agent_t sa, int token)
}
RPC_grab();
retval = RPC_invoke("experiment.modify",
&er,
SPA_String, "proj", pid,
SPA_String, "exp", eid,
SPA_Boolean, "wait", true,
SPA_Boolean, "reboot", true,
SPA_Boolean, "restart_eventsys", true,
SPA_String, "nsfilepath", nsfile,
SPA_TAG_DONE);
&er,
SPA_String, "proj", pid,
SPA_String, "exp", eid,
SPA_Boolean, "wait", true,
SPA_Boolean, "reboot", true,
SPA_Boolean, "restart_eventsys", true,
SPA_String, "nsfilepath", nsfile,
SPA_TAG_DONE);
RPC_drop();
if (retval != 0) {
......@@ -201,6 +199,8 @@ static int do_modify(simulator_agent_t sa, int token, char *args)
error("no mode specified\n");
}
else if (strncasecmp("stabilize", mode, rc) == 0) {
rename("tbdata/feedback_data.tcl",
"tbdata/feedback_data_old.tcl");
if (systemf("loghole --port=%d --quiet sync",
DEFAULT_RPC_PORT) != 0) {
error("failed to sync log holes\n");
......
......@@ -1345,6 +1345,13 @@ class experiment:
"elab_in_elab"
])
vue = DBQueryFatal("SELECT name,value FROM virt_user_environment "
"WHERE pid=%s and eid=%s order by idx",
(argdict["proj"], argdict["exp"]),
True)
res["user_environment"] = vue
return EmulabResponse(RESPONSE_SUCCESS, value=res, output=str(res))
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment