def run(self, *args, **kwargs): if not args: self.parser.error('One or more systems must be specified') dryrun = kwargs.get('dryrun') xml = kwargs.get('xml') prettyxml = kwargs.get('prettyxml') wait = kwargs.get('wait') self.set_hub(**kwargs) requests_session = self.requests_session() submitted_jobs = [] failed = False for fqdn in args: res = requests_session.post('jobs/+inventory', json={ 'fqdn': fqdn, 'dryrun': dryrun }) try: res.raise_for_status() except HTTPError as e: sys.stderr.write('HTTP error: %s, %s\n' % (fqdn, e)) content_type, _ = cgi.parse_header( e.response.headers.get('Content-Type', '')) if content_type == 'text/plain': sys.stderr.write('\t' + e.response.content.rstrip('\n') + '\n') failed = True else: res_data = res.json() if xml: print(res_data['job_xml']) if prettyxml: print( parseString( res_data['job_xml']).toprettyxml(encoding='utf8')) if not dryrun: submitted_jobs.append(res_data['job_id']) if not dryrun: print("Submitted: %s" % submitted_jobs) if wait: failed |= watch_tasks(self.hub, submitted_jobs) sys.exit(failed)
class Update_Inventory(BeakerCommand): """Submits a Inventory job""" enabled = True def options(self): self.parser.usage = "%%prog %s <fqdn>.." % self.normalized_name self.parser.add_option( '--dry-run', '--dryrun', default=False, action='store_true', dest='dryrun', help='Do not submit an inventory job', ) self.parser.add_option( '--xml', default=False, action='store_true', help='Print the generated Job XML', ) self.parser.add_option( '--pretty-xml', '--prettyxml', dest='prettyxml', default=False, action='store_true', help='Pretty print the generated Job XML', ) self.parser.add_option( '--wait', default=False, action='store_true', help='Wait on job completion', ) def run(self, *args, **kwargs): if not args: self.parser.error('One or more systems must be specified') dryrun = kwargs.get('dryrun') xml = kwargs.get('xml') prettyxml = kwargs.get('prettyxml') wait = kwargs.get('wait') self.set_hub(**kwargs) requests_session = self.requests_session() submitted_jobs = [] failed = False for fqdn in args: res = requests_session.post('jobs/+inventory', json={'fqdn':fqdn, 'dryrun':dryrun}) try: res.raise_for_status() except HTTPError, e: sys.stderr.write('HTTP error: %s, %s\n' % (fqdn, e)) content_type, _ = cgi.parse_header(e.response.headers.get( 'Content-Type', '')) if content_type == 'text/plain': sys.stderr.write('\t' + e.response.content.rstrip('\n') + '\n') failed = True else: res_data = res.json() if xml: print res_data['job_xml'] if prettyxml: print parseString(res_data['job_xml']).toprettyxml(encoding='utf8') if not dryrun: submitted_jobs.append(res_data['job_id']) if not dryrun: print "Submitted: %s" % submitted_jobs if wait: failed |= watch_tasks(self.hub, submitted_jobs) sys.exit(failed)
def provision(self, *args, **kwargs): """ provision resources in Beaker """ # Break down kwargs for debug, dryrun, wait, recipesets, and whiteboard debug = kwargs.get("debug", False) dryrun = kwargs.get("dryrun", False) wait = kwargs.get("wait", False) recipesets = kwargs.get("recipesets", []) # Create Job job = BeakerJob(*args, **kwargs) # Add All Host Requirements for recipeset in recipesets: kwargs = self.create_recipesets(recipeset, **kwargs) family = kwargs.get("family", None) distro = kwargs.get("distro", None) task_params = kwargs.get("taskparam", []) arch = kwargs.get("arch", None) ks_meta = kwargs.get("ks_meta", "") method = kwargs.get("method", "nfs") priority = kwargs.get("priority", "Normal") hostrequires = kwargs.get("hostrequires", []) # Tasks and harnesses if 'harness' in ks_meta: # Disable report plugins task_params.append("RSTRNT_DISABLED=01_dmesg_check " "10_avc_check") # Reserve the system after its installed kwargs.update({"reserve": True}) # We don't need to run a task but beaker needs one. requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}] # if no repos are defined but with no value use default repo # This default will not work for Fedora repos = kwargs.get("repos", [ "http://file.bos.redhat.com/~bpeck/restraint/rhel" "$releasever" ]) kwargs.update({'repo': repos}) else: requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}, {'arches': [], 'name': '/distribution/reservesys'}] # Update defaults kwargs.update({"suppress_install_task": True}) kwargs.update({"method": method}) kwargs.update({"priority": priority}) # Must have family or distro if not family and not distro and not arch: sys.stderr.write("No Family or Distro and arch specified\n") sys.exit(1) if not requested_tasks: sys.stderr.write("You must specify a task to run\n") sys.exit(1) # Create Workflow wrkflow = BeakerWorkflow('BeakerWorkflow') # Create Base Recipe recipe_template = BeakerRecipe(*args, **kwargs) # Add Host Requirements if 'force' in hostrequires: # hostRequires element is created by BeakerRecipe, use it hostrequires_node = recipe_template.node.getElementsByTagName( 'hostRequires')[0] # noqa E501 # all other filters are ignored if the hostname is forced, # so the use of 'force' is mutually exclusive with the use # of any other 'hostRequires' filters hostrequires_node.setAttribute('force', hostrequires['force']) else: for requirement in hostrequires: # If force is not used, a requirement can be any number # of differently formatted XML elements, each with their # own combination of element name and valid attrs. So, # the best we can do is generate XML based on the input, # and only the "tag" key is required. tag_name = requirement.pop('tag') requirement_node = self.doc.createElement(tag_name) for attr, value in requirement.items(): # Force all values to str, which the XML writer expects. requirement_node.setAttribute(attr, str(value)) # use the BeakerRecipe API to add the element recipe_template.addHostRequires(requirement_node) # Add Distro Requirements recipe_template.addBaseRequires(*args, **kwargs) arch_node = self.doc.createElement('distro_arch') arch_node.setAttribute('op', '=') arch_node.setAttribute('value', arch) recipe_set = BeakerRecipeSet(**kwargs) if wrkflow.multi_host: for i in range(self.n_servers): recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='SERVERS', **kwargs)) for i in range(self.n_clients): recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='CLIENTS', **kwargs)) else: recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, **kwargs)) job.addRecipeSet(recipe_set) # jobxml jobxml = job.toxml(**kwargs) if debug: LOG.debug(jobxml) self.submitted_jobs = [] is_failed = False if not dryrun: try: self.submitted_jobs.append(self.hub.jobs.upload(jobxml)) LOG.info("Submitted: %s" % self.submitted_jobs) return self.submitted_jobs except (KeyboardInterrupt, SystemExit): raise except Exception, ex: is_failed = True sys.stderr.write('Exception: %s\n' % ex) if wait: is_failed |= watch_tasks(self.hub, self.submitted_jobs)
def run(self, *args, **kwargs): self.set_hub(**kwargs) debug = kwargs.pop('debug', False) dryrun = kwargs.pop('dryrun', False) wait = kwargs.pop('wait', False) taskParams = kwargs.pop('taskparam', []) families = kwargs.pop('family', []) kwargs.pop('variant', None) kwargs.pop('arch', None) if not kwargs.get('whiteboard'): kwargs['whiteboard'] = 'Test harness installation' if not families: families = self.get_os_majors(**kwargs) # filter out any junky old distros with no family families = [f for f in families if f] fva = set() # all family-variant-arch combinations for family in families: dts = self.hub.distrotrees.filter({'family': family}) for dt in dts: fva.add((family, dt['variant'] or '', dt['arch'])) # if this family has any variants, discard combinations which have blank variant if any(f == family and v for f, v, a in fva): fva.difference_update([(f, v, a) for f, v, a in fva if f == family and not v]) job = BeakerJob(**kwargs) for family, variant, arch in sorted(fva): requestedTasks = self.get_tasks(family=family, **kwargs) recipe = BeakerRecipe() recipe.add_base_requires(family=family, variant=variant, arch=arch, **kwargs) arch_node = self.doc.createElement('distro_arch') arch_node.setAttribute('op', '=') arch_node.setAttribute('value', arch) recipe = self.process_template(recipe, requestedTasks, taskParams=taskParams, distroRequires=arch_node, arch=arch, family=family, allow_empty_recipe=True, **kwargs) recipe.whiteboard = ' '.join([family, variant, arch]) recipeset = BeakerRecipeSet(**kwargs) recipeset.add_recipe(recipe) job.add_recipe_set(recipeset) jobxml = job.toxml(**kwargs) if debug: print(jobxml) submitted_jobs = [] failed = False if not dryrun: try: submitted_jobs.append(self.hub.jobs.upload(jobxml)) print("Submitted: %s" % submitted_jobs) except (KeyboardInterrupt, SystemError): raise except Exception as ex: failed = True sys.stderr.write('Exception: %s\n' % ex) if wait: failed |= watch_tasks(self.hub, submitted_jobs) sys.exit(failed)
def provision(self, *args, **kwargs): """ provision resources in Beaker """ # Break down kwargs for debug, dryrun, wait, and recipesets debug = kwargs.get("debug", False) dryrun = kwargs.get("dryrun", False) wait = kwargs.get("wait", False) recipesets = kwargs.get("recipesets", []) # Create Job job = BeakerJob(*args, **kwargs) # Add All Host Requirements for recipeset in recipesets: kwargs = self.create_recipesets(recipeset, **kwargs) family = kwargs.get("family", None) distro = kwargs.get("distro", None) task_params = kwargs.get("taskparam", []) arch = kwargs.get("arch", None) ks_meta = kwargs.get("ks_meta", "") method = kwargs.get("method", "nfs") priority = kwargs.get("priority", "Normal") # Tasks and harnesses if 'harness' in ks_meta: # Disable report plugins task_params.append("RSTRNT_DISABLED=01_dmesg_check " "10_avc_check") # Reserve the system after its installed kwargs.update({"reserve": True}) # We don't need to run a task but beaker needs one. requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}] # if no repos are defined but with no value use default repo # This default will not work for Fedora repos = kwargs.get( "repos", ["http://file.bos.redhat.com/~bpeck/restraint/rhel" "$releasever"] ) kwargs.update({'repo': repos}) else: requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}, {'arches': [], 'name': '/distribution/reservesys'}] # Update defaults kwargs.update({"suppress_install_task": True}) kwargs.update({"method": method}) kwargs.update({"priority": priority}) # Must have family or distro if not family and not distro and not arch: sys.stderr.write("No Family or Distro and arch specified\n") sys.exit(1) if not requested_tasks: sys.stderr.write("You must specify a task to run\n") sys.exit(1) # Create Workflow wrkflow = BeakerWorkflow('BeakerWorkflow') # Create Base Recipe recipe_template = BeakerRecipe(*args, **kwargs) # Add Distro Requirements recipe_template.addBaseRequires(*args, **kwargs) arch_node = self.doc.createElement('distro_arch') arch_node.setAttribute('op', '=') arch_node.setAttribute('value', arch) recipe_set = BeakerRecipeSet(**kwargs) if wrkflow.multi_host: for i in range(self.n_servers): recipe_set.addRecipe(wrkflow.processTemplate( recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='SERVERS', **kwargs)) for i in range(self.n_clients): recipe_set.addRecipe(wrkflow.processTemplate( recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='CLIENTS', **kwargs)) else: recipe_set.addRecipe(wrkflow.processTemplate( recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, **kwargs)) job.addRecipeSet(recipe_set) # jobxml jobxml = job.toxml(**kwargs) if debug: LOG.debug(jobxml) self.submitted_jobs = [] is_failed = False if not dryrun: try: self.submitted_jobs.append(self.hub.jobs.upload(jobxml)) LOG.info("Submitted: %s" % self.submitted_jobs) return self.submitted_jobs except (KeyboardInterrupt, SystemExit): raise except Exception, ex: is_failed = True sys.stderr.write('Exception: %s\n' % ex) if wait: is_failed |= watch_tasks(self.hub, self.submitted_jobs)
def provision(self, *args, **kwargs): """ provision resources in Beaker """ # Break down kwargs for debug, dryrun, wait, and recipesets debug = kwargs.get("debug", False) dryrun = kwargs.get("dryrun", False) wait = kwargs.get("wait", False) recipesets = kwargs.get("recipesets", []) # Create Job job = BeakerJob(*args, **kwargs) # Add All Host Requirements for recipeset in recipesets: kwargs = self.create_recipesets(recipeset, **kwargs) family = kwargs.get("family", None) distro = kwargs.get("distro", None) task_params = kwargs.get("taskparam", []) arch = kwargs.get("arch", None) ks_meta = kwargs.get("ks_meta", "") method = kwargs.get("method", "nfs") priority = kwargs.get("priority", "Normal") # Tasks and harnesses if 'harness' in ks_meta: # Disable report plugins task_params.append("RSTRNT_DISABLED=01_dmesg_check " "10_avc_check") # Reserve the system after its installed kwargs.update({"reserve": True}) # We don't need to run a task but beaker needs one. requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}] # if no repos are defined but with no value use default repo # This default will not work for Fedora repos = kwargs.get("repos", [ "http://file.bos.redhat.com/~bpeck/restraint/rhel" "$releasever" ]) kwargs.update({'repo': repos}) else: requested_tasks = \ [{'arches': [], 'name': '/distribution/dummy'}, {'arches': [], 'name': '/distribution/reservesys'}] # Update defaults kwargs.update({"suppress_install_task": True}) kwargs.update({"method": method}) kwargs.update({"priority": priority}) # Must have family or distro if not family and not distro and not arch: sys.stderr.write("No Family or Distro and arch specified\n") sys.exit(1) if not requested_tasks: sys.stderr.write("You must specify a task to run\n") sys.exit(1) # Create Workflow wrkflow = BeakerWorkflow('BeakerWorkflow') # Create Base Recipe recipe_template = BeakerRecipe(*args, **kwargs) # Add Distro Requirements recipe_template.addBaseRequires(*args, **kwargs) arch_node = self.doc.createElement('distro_arch') arch_node.setAttribute('op', '=') arch_node.setAttribute('value', arch) recipe_set = BeakerRecipeSet(**kwargs) if wrkflow.multi_host: for i in range(self.n_servers): recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='SERVERS', **kwargs)) for i in range(self.n_clients): recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, role='CLIENTS', **kwargs)) else: recipe_set.addRecipe( wrkflow.processTemplate(recipe_template, requested_tasks, taskParams=task_params, distroRequires=arch_node, **kwargs)) job.addRecipeSet(recipe_set) # jobxml jobxml = job.toxml(**kwargs) if debug: LOG.debug(jobxml) self.submitted_jobs = [] is_failed = False if not dryrun: try: self.submitted_jobs.append(self.hub.jobs.upload(jobxml)) LOG.info("Submitted: %s" % self.submitted_jobs) return self.submitted_jobs except (KeyboardInterrupt, SystemExit): raise except Exception, ex: is_failed = True sys.stderr.write('Exception: %s\n' % ex) if wait: is_failed |= watch_tasks(self.hub, self.submitted_jobs)
class Harness_Test(BeakerWorkflow): """Workflow for testing harness installation""" enabled = True def options(self): super(Harness_Test, self).options() self.parser.remove_option("--family") self.parser.remove_option("--clients") self.parser.remove_option("--servers") self.parser.remove_option("--distro") self.parser.remove_option("--variant") self.parser.remove_option("--arch") # Re-add option Family with append options self.parser.add_option('--family', action='append', default=[], help='Test harness only on this family') def run(self, *args, **kwargs): self.set_hub(**kwargs) debug = kwargs.pop('debug', False) dryrun = kwargs.pop('dryrun', False) wait = kwargs.pop('wait', False) taskParams = kwargs.pop('taskparam', []) families = kwargs.pop('family', []) kwargs.pop('variant', None) kwargs.pop('arch', None) if not kwargs.get('whiteboard'): kwargs['whiteboard'] = 'Test harness installation' if not families: families = self.getOsMajors(**kwargs) # filter out any junky old distros with no family families = [f for f in families if f] fva = set() # all family-variant-arch combinations for family in families: dts = self.hub.distrotrees.filter({'family': family}) for dt in dts: fva.add((family, dt['variant'] or '', dt['arch'])) # if this family has any variants, discard combinations which have blank variant if any(f == family and v for f, v, a in fva): fva.difference_update([(f, v, a) for f, v, a in fva if f == family and not v]) job = BeakerJob(**kwargs) for family, variant, arch in sorted(fva): requestedTasks = self.getTasks(family=family, **kwargs) recipe = BeakerRecipe() recipe.addBaseRequires(family=family, variant=variant, arch=arch, **kwargs) arch_node = self.doc.createElement('distro_arch') arch_node.setAttribute('op', '=') arch_node.setAttribute('value', arch) recipe = self.processTemplate(recipe, requestedTasks, taskParams=taskParams, distroRequires=arch_node, arch=arch, family=family, allow_empty_recipe=True, **kwargs) recipe.whiteboard = ' '.join([family, variant, arch]) recipeset = BeakerRecipeSet(**kwargs) recipeset.addRecipe(recipe) job.addRecipeSet(recipeset) jobxml = job.toxml(**kwargs) if debug: print jobxml submitted_jobs = [] failed = False if not dryrun: try: submitted_jobs.append(self.hub.jobs.upload(jobxml)) except Exception, ex: failed = True print >> sys.stderr, ex if not dryrun: print "Submitted: %s" % submitted_jobs if wait: watch_tasks(self.hub, submitted_jobs) if failed: sys.exit(1)