+++ /dev/null
-import traceback
-import time
-from qa.Test import Test
-from qa import utils
-
-class access_slice(Test):
- """
- Repeatedly attempt to use the specified users credentials to
- access the specified node on the specified slice.
- """
-
- def call(self, email, slice_name, hostname, timeout=3):
- api = self.config.api
- auth = self.config.auth
- email_parts = email.split("@")
- keys_filename = email_parts[0]
- keys_path = self.config.KEYS_PATH
- private_key_path = keys_path + os.sep + keys_filename
- public_key_path = private_key_path + ".pub"
-
- # Validate slice
- slices = api.GetSlices(auth, [slice_name], ['name', 'slice_id', 'node_ids'])
- if not slices:
- raise Exception, "No such slice %(slice_name)s" % locals()
- slice = slices[0]
-
- # Validate node
- nodes = api.GetNodes(auth, [hostname], ['hostname', 'node_id', 'slice_ids'])
- if not nodes:
- raise Exception, "No such node %(hostname)s" % locals()
- node = nodes[0]
- if slice['slice_id'] not in node['slice_ids']:
- raise Exception, "%(slice_name)s not on %(hostname)s" % locals()
-
- # Validate user
- persons = api.GetPersons(auth, ['email'], ['person_id', 'key_ids', 'slice_ids'])
- if not persons:
- raise Exception, "No such person %(email)s" % locals()
- person = persons[0]
- if slice['slice_id'] not in person['slice_ids']:
- raise Exception, "%(email)s not in slice %(slice_name)s" % locals()
-
- # get keys
- if not os.path.isfile(private_key_path) or \
- not os.path.isfile(public_key_path):
- # keys dont exist, call api.sync_user_key()
- from qa.modules.api.sync_user_key import sync_user_key
- sync_user_key()(email)
-
- # attempt to access slice
- start_time = time.time()
- end_time = start_time + timeout*60
- sleep = 30
- while time.time() < endtime:
- if self.config.verbose:
- utils.header("Trying to connect to %(slice_name)s@%(hostname)s" % locals())
- ssh_command = "ssh -i %(private_key_path)s %(slice_name)s@%(hostname)s" % locals()
- host_check = os.system(ssh_command + " hostname ")
- if host_check == 0:
- if self.config.verbose:
- utils.header("connecteed to %(slice_name)s@%(hostname)s" % locals())
- return 1
- else:
- if self.config.verbose:
- utils.header("failed to connect to %(slice_name)s@%(hostname)s" % locals())
- time.sleep(sleep)
-
- return 0
+++ /dev/null
-import os,sys
-import base64
-from qa.Test import Test
-from qa import utils
-
-image_types = ['node-iso', 'node-usb', 'generic-iso', 'generic-usb']
-
-class boot_node(Test):
- """
- Attempts to boot the specified node using qemu.
- """
-
- def call(self, hostname, image_type = 'node-iso', disk_size="4G"):
- api = self.config.api
- auth = self.config.auth
- self.tdir = "/tmp/"
-
- # validate hostname
- nodes = api.GetNodes(auth, [hostname], ['hostname'])
- if not nodes:
- raise Exception, "No such node %(hostname)s" % locals()
-
- bootimage = api.GetBootMedium(auth, hostname, image_type, '')
- bootimage_path = '/%(tdir)s/%(hostname)s-bootcd.iso' % locals()
-
- if self.config.verbose:
- utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())
- # Create a temporary bootcd file
- file = open(bootimage_path, 'w')
- file.write(base64.b64decode(bootimage))
- file.close()
-
- # Create a temporary disk image
- diskimage_path = "/%(tdir)s/%(hostname)s-hda.img" % locals()
- qemu_img_cmd = "qemu-img create -f qcow2 %(diskimage_path)s %(disk_size)s" % locals()
- (stdin, stdout, stderr) = os.popen3(qemu_img_cmd)
- self.errors = stderr.readlines()
- if self.errors:
- raise Exception, "Unable to create disk image\n" + \
- "\n".join(self.errors)
-
- if self.config.verbose:
- utils.header("Booting %(hostname)s" % locals())
- # Attempt to boot this node image
- bootcmd = "qemu -hda %(diskimage_path)s -cdrom %(bootimage_path)s -smp 1 -m 256 -monitor stdio" % \
- locals()
- (stdin, stdout, stderr) = os.popen3(bootcmd)
- self.errors = stderr.readlines()
- if self.errors:
- raise Exception, "Unable to boot node image\n" + \
- "\n".join(self.errors)
-
- return 1
-
- def get_image_medium(self, hostname, image_type, path):
- api = self.config.api
- auth = self.config.auth
-
- file = open(path, 'w')
- if image-type in ['node-floppy', 'node-iso', 'node-usb', 'generic-iso', 'generic-usb']:
- image = api.GetBootMedium(auth, hostname, image_type, '')
-
-
-
-
-
+++ /dev/null
-import time
-
-from qa import utils
-from qa.Test import Test
-
-class check_boot_state(Test):
- """
- Continually checks the boot_state of the specified node until
- either the node reaches boot, the node reaches debug or the
- timeout is reached.
-
- Timeout represents the ammout of time (in minutes) we should
- continue trying before quitting.
-
- Sleep represnet the ammount of time (in seconds) to wait in
- between checks.
-
- Returns the boot state of the node.
- """
- def call(self, hostname, timeout = 5, sleep = 30):
- exit = False
- api = self.config.api
- auth = self.config.auth
-
- # Validate hostname
- nodes = api.GetNodes(auth, [hostname], ['hostname'])
- if not nodes:
- raise Exception, "No such hostname %(hostname)s" % locals()
-
- start_time = time.time()
- end_time = start_time + (timeout * 60)
-
- while not exit:
- nodes = api.GetNodes(auth, [hostname], ['boot_state'])
- node = nodes[0]
- boot_state = node['boot_state']
- if self.config.verbose:
- utils.header("%(hostname)s boot_state is %(boot_state)s" % locals())
-
- if boot_state in ['boot', 'debug']:
- exit = True
- elif time.time() < end_time:
- time.sleep(sleep)
- else:
- exit = True
-
-
- if self.config.verbose:
- if boot_state in ['boot']:
- utils.header("%(hostname)s correctly installed and booted" % locals())
- else:
- utils.header("%(hostname)s not fully booted" % locals())
-
- return boot_state
+++ /dev/null
-
-import os, sys
-import traceback
-from qa.Test import Test
-from qa import utils
-
-class configure(Test):
- """
- Configure the myplc from config options in config file
- """
-
- def call(self, system_type, root_dir):
- tmpname = '/tmp/plc-cinfig-tty-%d' % os.getpid()
- fileconf = open(tmpname, 'w')
- for var in [ 'PLC_NAME',
- 'PLC_ROOT_PASSWORD',
- 'PLC_ROOT_USER',
- 'PLC_MAIL_ENABLED',
- 'PLC_MAIL_SUPPORT_ADDRESS',
- 'PLC_DB_HOST',
- 'PLC_API_HOST',
- 'PLC_WWW_HOST',
- 'PLC_BOOT_HOST',
- 'PLC_NET_DNS1',
- 'PLC_NET_DNS2']:
- fileconf.write('e %s\n%s\n' % (var, getattr(self.config, var)))
- fileconf.write('w\nq\n')
- fileconf.close()
-
- mount_command = "/sbin/service plc mount"
- full_command = ""
- if system_type in ['vserv', 'vserver']:
- full_command += " vserver %(root_dir)s exec " % locals()
- elif system_type in ['chroot']:
- full_command += " chroot %(root_dir)s " % locals()
- else:
- raise Exception, "Invalid system type %(sytem_type)s" % locals()
-
- full_command += " plc-config-tty < %(tmpname)s" % locals()
- commands = [mount_command, full_command]
- for command in commands:
- if self.config.verbose:
- utils.header(command)
- (stdout, stderr) = utils.popen(command)
- (stdout, stderr) = utils.popen("rm %s" % tmpname)
-
- return 1
+++ /dev/null
-import time
-
-from qa import utils
-from qa.Test import Test
-
-class get_boot_state(Test):
- """
- Continually checks the boot_state of the specified node until
- either the node reaches boot, the node reaches debug or the
- timeout is reached.
-
- Timeout represents the ammout of time (in minutes) we should
- continue trying before quitting.
-
- Sleep represnet the ammount of time (in seconds) to wait in
- between checks.
-
- Returns the boot state of the node.
- """
- def call(self, hostname, timeout = 5, sleep = 30):
- exit = False
- api = self.config.api
- auth = self.config.auth
-
- # Validate hostname
- nodes = api.GetNodes(auth, [hostname], ['hostname'])
- if not nodes:
- raise Exception, "No such hostname %(hostname)s" % locals()
-
- start_time = time.time()
- end_time = start_time + (timeout * 60)
-
- while not exit:
- nodes = api.GetNodes(auth, [hostname], ['boot_state'])
- node = nodes[0]
- boot_state = node['boot_state']
- if self.config.verbose:
- utils.header("%(hostname)s boot_state is %(boot_state)s" % locals())
-
- if boot_state in ['boot', 'debug']:
- exit = True
- elif time.time() < end_time:
- time.sleep(sleep)
- else:
- exit = True
-
-
- if self.config.verbose:
- if boot_state in ['boot']:
- utils.header("%(hostname)s correctly installed and booted" % locals())
- else:
- utils.header("%(hostname)s not fully booted" % locals())
-
- return boot_state
+++ /dev/null
-
-import os, sys
-import traceback
-from qa import utils
-from qa.Test import Test
-
-class install(Test):
- """
- Installs a myplc
- """
-
- def call(self, system_type, root_dir, url=None):
-
- url_path = self.config.path
- # Determine url
- if not url:
- try:
-
- url_file = open("%s/URL" % url_path)
- url = url_file.read().strip()
- url_file.close()
- except IOError:
- pass
- if not url:
- print "URL not specified"
- sys.exit(1)
-
- # Save url
- if self.config.verbose:
- utils.header('Saving current myplc url into %s/URL' % url_path)
- fsave=open('%s/URL' % url_path, "w")
- fsave.write(url+'\n')
- fsave.close()
-
- # Instal myplc from url
- if self.config.verbose:
- utils.header('Installing myplc from url %s' % url)
-
- # build command
- full_command = ""
- install_command = " rpm -Uvh %(url)s "
- if system_type in ['vserv', 'vserver']:
- full_command += " vserver %(root_dir)s exec "
- elif system_type in ['chroot']:
- pass
- else:
- raise Exception, "Invalid system type %(system_type)s" % locals()
-
- full_command += install_command % locals()
- (stdout, stderr) = utils.popen(full_command)
- if self.config.verbose:
- utils.header("\n".join(stdout))
-
- return 1
+++ /dev/null
-import os
-from qa.Test import Test
-from qa import utils
-
-class remote_call(Test):
- """
- Attempt to connect to a node using the plc root key and
- issue a command.
- """
-
- def call(self, root_key_path, hostname, command):
- if not os.path.isfile(root_key_path):
- raise Exception, "no such private key file %(root_key_path)s" % locals()
-
- full_command = "ssh -i %(root_key_path)s root@%(hostname)s %(command)s" % locals()
- if self.config.verbose:
- utils.header(full_command)
- (stdout, stderr) = utils.popen(full_command)
- if self.config.verbose:
- utils.header("\n".join(stdout))
-
-
- return 1
+++ /dev/null
-import traceback
-from qa.Test import Test
-from qa import utils
-
-class start(Test):
- """
- Starts the myplc service
- """
-
- def call(self, system_type, root_dir):
-
- start_command = " /sbin/service plc start "
- full_command = ""
-
- if system_type in ['vserv', 'vserver']:
- full_command += " vserver %(root_dir)s exec "
- elif system_type in ['chroot']:
- pass
- else:
- raise Exception, "Invalid system type %(system_type)s" % locals()
-
- full_command += start_command % locals()
-
- if self.config.verbose:
- utils.header(full_command)
-
- (stdout, stderr) = utils.popen(full_command)
-
- if self.config.verbose:
- utils.header("".join(stdout))
-
- return 1
+++ /dev/null
-import os, sys
-import traceback
-from qa.Test import Test
-from qa import utils
-
-class stop(Test):
- """
- Installs a myplc
- """
-
- def call(self, system_type, root_dir):
-
- stop_command = " /sbin/service plc stop "
- full_command = ""
- if system_type in ['vserv', 'vserver']:
- full_command += " vserver %(root_dir)s exec "
- elif system_type in ['chroot']:
- pass
- else:
- raise Exception, "Invalid system type %(system_type)s" % locals()
-
- full_command += stop_command % locals()
-
- if self.config.verbose:
- utils.header(full_command)
-
- (stdout, stderr) = utils.popen(full_command)
-
- if self.config.verbose:
- utils.header("\n".join(stdout))
-
- return 1
+++ /dev/null
-import os, sys
-import traceback
-from qa.Test import Test
-from qa import utils
-
-class uninstall(Test):
- """
- Completely removes the installed myplc
- """
-
- def call(self, system_type, root_dir):
-
- remove_command = " rpm -e myplc "
- full_command = ""
-
- if system_type in ['vserv', 'vserver']:
- full_command += " vserver %(root_dir)s exec "
- elif system_type in ['chroot']:
- pass
- else:
- raise Exception, "Invalid system type %(system_type)s" % locals()
-
- if self.config.verbose:
- utils.header("Removing myplc")
-
- full_command = full_command % locals()
- (stdout, stderr) = utils.popen(full_command + "/sbin/service plc safestop")
- if self.config.verbose:
- utils.header("\n".join(stdout))
-
- (stdout, stderr) = utils.popen(full_command + remove_command)
- if self.config.verbose:
- utils.header("\n".join(stdout))
-
- (stdout, stderr) = utils.popen(full_command + " rm -rf /plc/data")
- if self.config.verbose:
- utiils.header("\n".join(stdout))
-
- return 1