def buildname(self):
return self.test_plc.options.buildname
- def areaname (self):
+ def nodedir (self):
if self.is_qemu():
return "qemu-%s"%self.name()
else:
# Do most of the stuff locally - will be pushed on host_box - *not* the plc - later if needed
def prepare_area(self):
- utils.system("rm -rf %s"%self.areaname())
- utils.system("mkdir %s"%self.areaname())
+ utils.system("rm -rf %s"%self.nodedir())
+ utils.system("mkdir %s"%self.nodedir())
#create the tar log file
utils.system("rm -rf nodeslogs && mkdir nodeslogs")
if self.is_qemu():
- utils.system("rsync -v -a --exclude .svn template-qemu/ %s/"%self.areaname())
+ utils.system("rsync -v -a --exclude .svn template-qemu/ %s/"%self.nodedir())
def create_boot_cd(self):
utils.header("Calling GetBootMedium for %s"%self.name())
if (encoded == ''):
raise Exception, 'GetBootmedium failed'
- filename="%s/%s.iso"%(self.areaname(),self.name())
+ filename="%s/%s.iso"%(self.nodedir(),self.name())
utils.header('Storing boot medium into %s'%filename)
file(filename,'w').write(base64.b64decode(encoded))
return
mac=self.node_spec['network_fields']['mac']
hostname=self.node_spec['node_fields']['hostname']
- conf_filename="%s/qemu.conf"%(self.areaname())
+ conf_filename="%s/qemu.conf"%(self.nodedir())
utils.header('Storing qemu config for %s in %s'%(self.name(),conf_filename))
file=open(conf_filename,'w')
file.write('MACADDR=%s\n'%mac)
# if relevant, push the qemu area onto the host box
if ( not self.test_box().is_local()):
utils.header ("Transferring configuration files for node %s onto %s"%(self.name(),self.host_box()))
- self.test_box().clean_dir(self.buildname())
- self.test_box().mkdir(self.buildname())
+# self.test_box().clean_dir(self.buildname())
self.test_box().mkdir("nodeslogs")
- self.test_box().copy(self.areaname(),recursive=True)
+ self.test_box().copy(self.nodedir(),recursive=True)
def start_node (self,options):
# step methods must take (self, options) and return a boolean
def standby(minutes):
- utils.header('Entering StandBy for %d mn'%minutes)
- time.sleep(60*minutes)
- return True
+ utils.header('Entering StandBy for %d mn'%minutes)
+ time.sleep(60*minutes)
+ return True
def standby_generic (func):
def actual(self,options):
class TestPlc:
- def __init__ (self,plc_spec):
+ def __init__ (self,plc_spec,options):
self.plc_spec=plc_spec
- self.path=os.path.dirname(sys.argv[0])
- self.test_ssh=TestSsh(self.plc_spec['hostname'],self.path)
+ self.options=options
+ self.test_ssh=TestSsh(self.plc_spec['hostname'],self.options.buildname)
try:
self.vserverip=plc_spec['vserverip']
self.vservername=plc_spec['vservername']
def connect (self):
pass
- def full_command(self,command):
- return self.test_ssh.to_host(self.host_to_guest(command))
-
def run_in_guest (self,command):
- return utils.system(self.full_command(command))
+ return self.test_ssh.run(self.host_to_guest(command))
def run_in_host (self,command):
- return utils.system(self.test_ssh.to_host(command))
+ return self.test_ssh.run_in_buildname(command)
#command gets run in the chroot/vserver
def host_to_guest(self,command):
# xxx quick n dirty
def run_in_guest_piped (self,local,remote):
- return utils.system(local+" | "+self.full_command(remote))
-
+ return utils.system(local+" | "+self.test_ssh.actual_command(self.host_to_guest(remote)))
def auth_root (self):
return {'Username':self.plc_spec['PLC_ROOT_USER'],
##### Clean up the /plc directory
self.run_in_host('rm -rf /plc/data')
##### stop any running vservers
- self.run_in_host('for vserver in $(ls /vservers/* | sed -e s,/vservers/,,) ; do vserver $vserver stop ; done')
+ self.run_in_host('for vserver in $(ls -d /vservers/* | sed -e s,/vservers/,,) ; do case $vserver in vtest*) echo Shutting down vserver $vserver ; vserver $vserver stop ;; esac ; done')
return True
def uninstall_vserver(self,options):
# we need build dir for vtest-init-vserver
if self.is_local():
# a full path for the local calls
- build_dir=self.path+"/build"
+ build_dir=os.path(sys.argv[0])+"/build"
else:
# use a standard name - will be relative to HOME
build_dir="options.buildname"
return self.install_chroot(options)
### install_rpm
- def cache_rpm(self,url):
- self.run_in_host('rm -rf *.rpm')
- utils.header('Curling rpm from %s'%url)
- id= self.run_in_host('curl -O '+url)
+ def cache_rpm(self,url,rpm):
+ cache_fetch="pwd;if [ -f %(rpm)s ] ; then echo Using cached rpm %(rpm)s ; else echo Fetching %(url)s ; curl -O %(url)s; fi"%locals()
+ id = self.run_in_host(cache_fetch)
if (id != 0):
- raise Exception,"Could not get rpm from %s"%url
- return False
- return True
+ raise Exception,"Could not get rpm from %s"%url
def install_rpm_chroot(self,options):
- rpm = os.path.basename(options.myplc_url)
- if (not os.path.isfile(rpm)):
- self.cache_rpm(options.myplc_url)
+ url = self.options.myplc_url
+ rpm = os.path.basename(url)
+ self.cache_rpm(url,rpm)
utils.header('Installing the : %s'%rpm)
self.run_in_host('rpm -Uvh '+rpm)
self.run_in_host('service plc mount')
return True
def clean_keys(self, options):
- utils.system("rm -rf %s/keys/"%self.path)
+ utils.system("rm -rf %s/keys/"%os.path(sys.argv[0]))
def sites (self,options):
return self.do_sites(options)
test_node.configure_qemu()
return True
- def do_check_intiscripts(self):
+ def do_check_initscripts(self):
for site_spec in self.plc_spec['sites']:
test_site = TestSite (self,site_spec)
test_node = TestNode (self,test_site,site_spec['nodes'])
return init_status
def check_initscripts(self, options):
- return self.do_check_intiscripts()
+ return self.do_check_initscripts()
def initscripts (self, options):
for initscript in self.plc_spec['initscripts']:
return True
def check_tcp (self, options):
- #we just need to create a sliver object nothing else
- test_sliver=TestSliver(self,
- TestNode(self, TestSite(self,self.plc_spec['sites'][0]),
- self.plc_spec['sites'][0]['nodes'][0]),
- TestSlice(self,TestSite(self,self.plc_spec['sites'][0]),
- self.plc_spec['slices']))
- return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options)
+ # we just need to create a sliver object nothing else
+ test_sliver=TestSliver(self,
+ TestNode(self, TestSite(self,self.plc_spec['sites'][0]),
+ self.plc_spec['sites'][0]['nodes'][0]),
+ TestSlice(self,TestSite(self,self.plc_spec['sites'][0]),
+ self.plc_spec['slices']))
+ return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options)
# returns the filename to use for sql dump/restore, using options.dbname if set
def dbfile (self, database, options):
self.buildname=buildname
self.key=key
-
def is_local(self):
return TestSsh.is_local_hostname(self.hostname)
+ std_options="-o StrictHostKeyChecking=no -o BatchMode=yes "
+
+ def key_part (self):
+ if not self.key:
+ return ""
+ return "-i %s.rsa "%self.key
+
# command gets run on the right box
- def to_host(self,command):
+ def actual_command (self, command):
if self.is_local():
return command
- else:
- return "ssh %s %s"%(self.hostname,TestSsh.backslash_shell_specials(command))
+ ssh_command = "ssh "
+ ssh_command += TestSsh.std_options
+ ssh_command += self.key_part()
+ ssh_command += "%s %s" %(self.hostname,TestSsh.backslash_shell_specials(command))
+ return ssh_command
+
+ def run(self, command):
+ return utils.system(self.actual_command(command))
def clean_dir (self,dirname):
if self.is_local():
return 0
- return utils.system(self.to_host("rm -rf %s"%dirname))
+ return self.run("rm -rf %s"%dirname)
- def mkdir (self,dirname):
+ def mkdir (self,dirname=None):
if self.is_local():
+ if dirname:
+ return os.path.mkdir(dirname)
return 0
- return utils.system(self.to_host("mkdir %s"%dirname))
+ if dirname:
+ dirname="%s/%s"%(self.buildname,dirname)
+ else:
+ dirname=self.buildname
+ return self.run("mkdir %s"%dirname)
+
+ def create_buildname_once (self):
+ if self.is_local():
+ return
+ # create remote buildname on demand
+ try:
+ self.buildname_created
+ except:
+ self.mkdir()
+ self.buildname_created=True
def run_in_buildname (self,command):
if self.is_local():
return utils.system(command)
- ssh_command="ssh -o StrictHostKeyChecking=no -o BatchMode=yes "
- if self.key:
- ssh_command += "-i %s.rsa "%(self.key)
- ssh_command += "%s %s/%s"%(self.hostname,self.buildname,TestSsh.backslash_shell_specials(command))
- return utils.system(ssh_command)
+ self.create_buildname_once()
+ return self.run("cd %s ; %s"%(self.buildname,command))
def copy (self,local_file,recursive=False):
if self.is_local():
return 0
- command="scp "
- if recursive: command += "-r "
- if self.key:
- command += "-i %s.rsa "
- command +="%s %s:%s/%s"%(local_file,self.hostname,self.buildname,
- os.path.basename(local_file) or ".")
- return utils.system(command)
+ self.create_buildname_once()
+ scp_command="scp "
+ if recursive: scp_command += "-r "
+ scp_command += self.key_part()
+ scp_command += "%s %s:%s/%s"%(local_file,self.hostname,self.buildname,
+ os.path.basename(local_file) or ".")
+ return utils.system(scp_command)