Ejemplo n.º 1
0
 def test_get_system_with_running_hardware_scan_recipe(self):
     # The bug was a circular reference from system -> recipe -> system
     # which caused JSON serialization to fail.
     with session.begin():
         Job.inventory_system_job(data_setup.create_distro_tree(), owner=self.owner, system=self.system)
         recipe = self.system.find_current_hardware_scan_recipe()
         data_setup.mark_recipe_running(recipe, system=self.system)
     response = requests.get(
         get_server_base() + "/systems/%s/" % self.system.fqdn, headers={"Accept": "application/json"}
     )
     response.raise_for_status()
     in_progress_scan = response.json()["in_progress_scan"]
     self.assertEquals(in_progress_scan["recipe_id"], recipe.id)
     self.assertEquals(in_progress_scan["status"], u"Running")
     self.assertEquals(in_progress_scan["job_id"], recipe.recipeset.job.t_id)
Ejemplo n.º 2
0
 def test_get_system_with_running_hardware_scan_recipe(self):
     # The bug was a circular reference from system -> recipe -> system
     # which caused JSON serialization to fail.
     with session.begin():
         Job.inventory_system_job(data_setup.create_distro_tree(),
                                  owner=self.owner,
                                  system=self.system)
         recipe = self.system.find_current_hardware_scan_recipe()
         data_setup.mark_recipe_running(recipe, system=self.system)
     response = requests.get(get_server_base() +
                             '/systems/%s/' % self.system.fqdn,
                             headers={'Accept': 'application/json'})
     response.raise_for_status()
     in_progress_scan = response.json()['in_progress_scan']
     self.assertEquals(in_progress_scan['recipe_id'], recipe.id)
     self.assertEquals(in_progress_scan['status'], u'Running')
     self.assertEquals(in_progress_scan['job_id'],
                       recipe.recipeset.job.t_id)
Ejemplo n.º 3
0
def submit_inventory_job():
    """
    Submit a inventory job with the most suitable distro selected automatically.

    Returns a dictionary consisting of the job_id, recipe_id, status (recipe status) 
    and the job XML. If ``dryrun`` is set to ``True`` in the request, the first three 
    are set to ``None``.

    :jsonparam string fqdn: Fully-qualified domain name for the system.
    :jsonparam bool dryrun: If True, do not submit the job
    """
    if 'fqdn' not in request.json:
        raise BadRequest400('Missing the fqdn parameter')
    fqdn = request.json['fqdn']
    if 'dryrun' in request.json:
        dryrun = request.json['dryrun']
    else:
        dryrun = False
    try:
        system = System.by_fqdn(fqdn, identity.current.user)
    except NoResultFound:
        raise BadRequest400('System not found: %s' % fqdn)
    if system.find_current_hardware_scan_recipe():
        raise Conflict409('Hardware scanning already in progress')
    distro = system.distro_tree_for_inventory()
    if not distro:
        raise BadRequest400(
            'Could not find a compatible distro for hardware scanning available to this system'
        )
    job_details = {}
    job_details['system'] = system
    job_details['whiteboard'] = 'Update Inventory for %s' % fqdn
    with convert_internal_errors():
        job_xml = Job.inventory_system_job(distro,
                                           dryrun=dryrun,
                                           **job_details)
    r = {}
    if not dryrun:
        r = system.find_current_hardware_scan_recipe().__json__()
    else:
        r = {
            'recipe_id': None,
            'status': None,
            'job_id': None,
        }
    r['job_xml'] = job_xml
    r = jsonify(r)
    return r
Ejemplo n.º 4
0
def submit_inventory_job():
    """
    Submit a inventory job with the most suitable distro selected automatically.

    Returns a dictionary consisting of the job_id, recipe_id, status (recipe status) 
    and the job XML. If ``dryrun`` is set to ``True`` in the request, the first three 
    are set to ``None``.

    :jsonparam string fqdn: Fully-qualified domain name for the system.
    :jsonparam bool dryrun: If True, do not submit the job
    """
    if 'fqdn' not in request.json:
        raise BadRequest400('Missing the fqdn parameter')
    fqdn = request.json['fqdn']
    if 'dryrun' in request.json:
        dryrun = request.json['dryrun']
    else:
        dryrun = False
    try:
        system = System.by_fqdn(fqdn, identity.current.user)
    except NoResultFound:
        raise BadRequest400('System not found: %s' % fqdn)
    if system.find_current_hardware_scan_recipe():
        raise Conflict409('Hardware scanning already in progress')
    distro = system.distro_tree_for_inventory()
    if not distro:
        raise BadRequest400('Could not find a compatible distro for hardware scanning available to this system')
    job_details = {}
    job_details['system'] = system
    job_details['whiteboard'] = 'Update Inventory for %s' % fqdn
    with convert_internal_errors():
        job_xml = Job.inventory_system_job(distro, dryrun=dryrun, **job_details)
    r = {}
    if not dryrun:
        r = system.find_current_hardware_scan_recipe().__json__()
    else:
        r = {'recipe_id': None,
             'status': None,
             'job_id': None,
        }
    r['job_xml'] = job_xml
    r = jsonify(r)
    return r