setattr(parser.values,option.dest,value.split())
def test_main (self):
+ steps_message="Defaut steps are\n\t%s"%(" ".join(TestMain.default_steps))
+ steps_message += "\nOther useful steps are\n\t %s"%(" ".join(TestMain.other_steps))
usage = """usage: %%prog [options] steps
-myplc-url defaults to the last value used, as stored in MYPLC-URL,
+myplc-url defaults to the last value used, as stored in arg-myplc-url,
no default
-build-url defaults to the last value used, as stored in BUILD-URL,
+build-url defaults to the last value used, as stored in arg-build-url,
or %s
-config defaults to the last value used, as stored in CONFIG,
+config defaults to the last value used, as stored in arg-config,
or %r
-ips defaults to the last value used, as stored in IPS,
+ips defaults to the last value used, as stored in arg-ips,
default is to use IP scanning
-steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_build_url,TestMain.default_config)
- usage += "\n Defaut steps are %r"%TestMain.default_steps
- usage += "\n Other useful steps are %r"%TestMain.other_steps
+steps refer to a method in TestPlc or to a step_* module
+===
+"""%(TestMain.default_build_url,TestMain.default_config)
+ usage += steps_message
parser=OptionParser(usage=usage,version=self.subversion_id)
parser.add_option("-u","--url",action="store", dest="myplc_url",
help="myplc URL - for locating build output")
help="Build URL - for using vtest-init-vserver.sh in native mode")
parser.add_option("-c","--config",action="callback", callback=TestMain.optparse_list, dest="config",
nargs=1,type="string",
- help="config module - can be set multiple times, or use quotes")
+ help="Config module - can be set multiple times, or use quotes")
parser.add_option("-a","--all",action="store_true",dest="all_steps", default=False,
- help="Runs all default steps")
+ help="Run all default steps")
+ parser.add_option("-l","--list",action="store_true",dest="list_steps", default=False,
+ help="List known steps")
parser.add_option("-s","--state",action="store",dest="dbname",default=None,
help="Used by db_dump and db_restore")
parser.add_option("-d","--display", action="store", dest="display", default='bellami.inria.fr:0.0',
- help="set DISPLAY for vmplayer")
+ help="Set DISPLAY for vmplayer")
parser.add_option("-i","--ip",action="callback", callback=TestMain.optparse_list, dest="ips",
nargs=1,type="string",
- help="allows to specify the set of IP addresses to use in vserver mode (disable scanning)")
+ help="Specify the set of IP addresses to use in vserver mode (disable scanning)")
parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
help="Run in verbose mode")
parser.add_option("-n","--dry-run", action="store_true", dest="dry_run", default=False,
self.options.steps=TestMain.default_steps
elif self.options.dry_run:
self.options.steps=TestMain.default_steps
+ elif self.options.list_steps:
+ print steps_message
+ sys.exit(1)
else:
print 'No step found (do you mean -a ? )'
print "Run %s --help for help"%sys.argv[0]
else:
self.options.steps = self.args
- # display display
- utils.header('X11 display : %s'% self.options.display)
-
# handle defaults and option persistence
- for (recname,filename,default) in ( ('myplc_url','MYPLC-URL',"") ,
- ('build_url','BUILD-URL',TestMain.default_build_url) ,
- ('ips','IPS',[]) ,
- ('config','CONFIG',TestMain.default_config) , ) :
+ for (recname,filename,default) in ( ('myplc_url','arg-myplc-url',"") ,
+ ('build_url','arg-build-url',TestMain.default_build_url) ,
+ ('ips','arg-ips',[]) ,
+ ('config','arg-config',TestMain.default_config) , ) :
print 'handling',recname
path="%s/%s"%(self.path,filename)
is_list = isinstance(default,list)
else:
return name+"[chroot]"
+ def is_local (self):
+ return self.plc_spec['hostname'] == 'localhost'
+
# define the API methods on this object through xmlrpc
# would help, but not strictly necessary
def connect (self):
return "chroot /plc/root %s"%command
def ssh_command(self,command):
- if self.plc_spec['hostname'] == "localhost":
+ if self.is_local():
return command
else:
- return "ssh " + self.plc_spec['hostname'] + " " + command
+ return "ssh %s sh -c '\"%s\"'"%(self.plc_spec['hostname'],command)
def full_command(self,command):
return self.ssh_command(self.run_command(command))
# xxx quick n dirty
def run_in_guest_piped (self,local,remote):
- return utils.system(local+" | "+self.full_command(command))
+ return utils.system(local+" | "+self.full_command(remote))
def auth_root (self):
return {'Username':self.plc_spec['PLC_ROOT_USER'],
# xxx this would not work with hostname != localhost as mylc-init-vserver was extracted locally
def install_vserver(self,options):
# we need build dir for vtest-init-vserver
- build_dir=self.path+"/build"
- if not os.path.isdir(build_dir):
- if utils.system("svn checkout %s %s"%(options.build_url,build_dir)) != 0:
- raise Exception,"Cannot checkout build dir"
+ if self.is_local():
+ # a full path for the local calls
+ build_dir=self.path+"/build"
+ else:
+ # use a standard name - will be relative to HOME
+ build_dir="tests-system-build"
+ build_checkout = "svn checkout %s %s"%(options.build_url,build_dir)
+ if self.run_in_host(build_checkout) != 0:
+ raise Exception,"Cannot checkout build dir"
# the repo url is taken from myplc-url
# with the last two steps (i386/myplc...) removed
repo_url = options.myplc_url
repo_url = os.path.dirname(repo_url)
repo_url = os.path.dirname(repo_url)
- command="%s/vtest-init-vserver.sh %s %s -- --interface eth0:%s"%\
+ create_vserver="%s/vtest-init-vserver.sh %s %s -- --interface eth0:%s"%\
(build_dir,self.vservername,repo_url,self.vserverip)
- if utils.system(command) != 0:
+ if self.run_in_host(create_vserver) != 0:
raise Exception,"Could not create vserver for %s"%self.vservername
- # xxx temporary - initialize /etc/sysconfig/network
- network="NETWORKING=yes\nHOSTNAME=%s\n"%self.plc_spec['vserverhostname']
- file("/vservers/%s/etc/sysconfig/network"%self.vservername,"w").write(network)
return True
def install(self,options):
def install_rpm_chroot(self,options):
utils.header('Installing from %s'%options.myplc_url)
url=options.myplc_url
- utils.system('rpm -Uvh '+url)
- utils.system('service plc mount')
+ self.run_in_host('rpm -Uvh '+url)
+ self.run_in_host('service plc mount')
return True
def install_rpm_vserver(self,options):
fileconf.write('q\n')
fileconf.close()
utils.system('cat %s'%tmpname)
- self.run_in_guest('plc-config-tty < %s'%tmpname)
+ self.run_in_guest_piped('cat %s'%tmpname,'plc-config-tty')
utils.system('rm %s'%tmpname)
return True