Exemplo n.º 1
0
 def test_no_exception_for_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     user_specified_unit_criteria = {
         'rpm': {
             "filters": {
                 "name": {
                     "$in": ['zsh']
                 }
             }
         },
         'xxx': {
             "filters": {
                 "name": {
                     "$in": ['abc']
                 }
             }
         }
     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA,
                                            self.REPO_CRITERIA,
                                            unit_criteria)
     self.assertTrue(result == {})
Exemplo n.º 2
0
 def test_profiler_no_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.find_applicable_units = Mock(side_effect=KeyError)
     # Test
     user_specified_unit_criteria = {
         'rpm': {
             "filters": {
                 "name": {
                     "$in": ['zsh', 'ksh']
                 }
             }
         },
         'mock-type': {
             "filters": {
                 "name": {
                     "$in": ['abc', 'def']
                 }
             }
         }
     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA,
                                            self.REPO_CRITERIA,
                                            unit_criteria)
     self.assertTrue(result == {})
Exemplo n.º 3
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        unit_criteria = {}
        if units:
            for type_id, criteria in units.items():
                # process if criteria is not empty
                if criteria:
                    unit_criteria[type_id] = Criteria.from_client_input(criteria)
                else:
                    unit_criteria[type_id] = criteria

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria, repo_criteria, unit_criteria, override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in applicability_reports]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [serialization.consumer.applicability_report(r) for r in report_list]

        return self.ok(report)
Exemplo n.º 4
0
 def test_no_exception_for_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     units = {'rpm': [{'name':'zsh'}],
              'xxx': [{'name':'abc'}]
             }
     manager = factory.consumer_applicability_manager()
     result = manager.units_applicable(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, units)
     self.assertTrue('test-1' in result.keys())
     self.assertTrue('test-2' in result.keys())
Exemplo n.º 5
0
 def test_no_exception_for_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     user_specified_unit_criteria = {'rpm': {"filters": {"name": {"$in":['zsh']}}},
                      'xxx': {"filters": {"name": {"$in":['abc']}}}
                     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, unit_criteria)
     self.assertTrue(result == {})
Exemplo n.º 6
0
 def test_A(self):
     env = TestEnv()
     self.populate(env)
     manager = managers.consumer_applicability_manager()
     units = [TEST_UNIT,]
     criteria = self.criteria()
     print 'Testing applicability ....'
     timer = Timer()
     timer.start()
     applicable = manager.units_applicable(criteria, units)
     timer.stop()
     print 'Finished: [%s] in: %s' % (env, timer)
     for id, report in applicable.items():
         self.assertTrue(report[0].applicable)
Exemplo n.º 7
0
 def test_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     units = [
         {'type_id':'rpm', 'unit_key':{'name':'zsh'}},
         {'type_id':'xxx', 'unit_key':{'name':'abc'}}
     ]
     manager = factory.consumer_applicability_manager()
     self.assertRaises(
         PulpExecutionException,
         manager.units_applicable,
         self.CRITERIA,
         units)
Exemplo n.º 8
0
 def test_profiler_no_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.units_applicable = Mock(side_effect=KeyError)
     # Test
     units = {'rpm': [{'name':'zsh'},
                      {'name':'ksh'}],
              'mock-type': [{'name':'abc'},
                            {'name':'def'}]
             }
     manager = factory.consumer_applicability_manager()
     result = manager.units_applicable(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, units)
     self.assertTrue('test-1' in result.keys())
     self.assertTrue('test-2' in result.keys())
Exemplo n.º 9
0
 def test_profiler_no_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.find_applicable_units = Mock(side_effect=KeyError)
     # Test
     user_specified_unit_criteria = {'rpm': {"filters": {"name": {"$in":['zsh','ksh']}}},
                                     'mock-type': {"filters": {"name": {"$in":['abc','def']}}}
                                     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, unit_criteria)
     self.assertTrue(result == {})
Exemplo n.º 10
0
 def test_profiler_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.unit_applicable = Mock(side_effect=KeyError)
     # Test
     units = [
         {'type_id':'rpm', 'unit_key':{'name':'zsh'}},
         {'type_id':'rpm', 'unit_key':{'name':'ksh'}},
         {'type_id':'mock-type', 'unit_key':{'name':'abc'}},
         {'type_id':'mock-type', 'unit_key':{'name':'def'}}
     ]
     manager = factory.consumer_applicability_manager()
     self.assertRaises(
         PulpExecutionException,
         manager.units_applicable,
         self.CRITERIA,
         units)
Exemplo n.º 11
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        units: {<type_id1> : [{<unit1>}, {<unit2}, ..]
                <type_id2> : [{<unit1>}, {<unit2}, ..]} or None
        }

        :return: A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }
                
        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('units', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.units_applicable(consumer_criteria, repo_criteria, units)

        for consumer_report in report.values():
            for unit_type_id, report_list in consumer_report.items():
                consumer_report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in report_list]
        return self.ok(report)
Exemplo n.º 12
0
 def test_applicability(self):
     # Setup
     self.populate()
     # Test
     units = [
         {'type_id':'rpm', 'unit_key':{'name':'zsh'}},
         {'type_id':'rpm', 'unit_key':{'name':'ksh'}},
         {'type_id':'mock-type', 'unit_key':{'name':'abc'}},
         {'type_id':'mock-type', 'unit_key':{'name':'def'}}
     ]
     manager = factory.consumer_applicability_manager()
     applicability = manager.units_applicable(self.CRITERIA, units)
     # verify
     self.assertEquals(len(applicability), 2)
     for id in self.CONSUMER_IDS:
         for report in applicability[id]:
             if report.unit in units[1:2]:
                 self.assertTrue(report.applicable)
                 self.assertEquals(report.summary, 'mysummary')
                 self.assertEquals(report.details, 'mydetails')
                 continue
             if report.unit in units[2:3]:
                 self.assertFalse(report.applicable)
                 self.assertEquals(report.summary, 'mocked')
                 self.assertEquals(report.details, None)
                 continue
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     call = 0
     args = [c[0] for c in profiler.unit_applicable.call_args_list]
     for id in self.CONSUMER_IDS:
         for unit in units[0:2]:
             self.assertEquals(args[call][0].id, id)
             self.assertEquals(args[call][0].profiles, {'rpm':self.PROFILE})
             self.assertEquals(args[call][1], unit)
             self.assertEquals(args[call][2], cfg)
             self.assertEquals(args[call][3].__class__, ProfilerConduit)
             call += 1
Exemplo n.º 13
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        # If unit_criteria is not specified, consider all units of all types
        if not units:
            units = {}
            all_unit_type_ids = content_types_db.all_type_ids()
            for unit_type_id in all_unit_type_ids:
                units[unit_type_id] = {}
        # Validate user defined criteria and convert them to Criteria objects
        unit_criteria = {}
        for type_id, criteria in units.items():
            if criteria is None:
                criteria = {}
            unit_criteria[type_id] = Criteria.from_client_input(criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria, repo_criteria, unit_criteria, override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in applicability_reports]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [serialization.consumer.applicability_report(r) for r in report_list]

        return self.ok(report)
Exemplo n.º 14
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        # If unit_criteria is not specified, consider all units of all types
        if not units:
            units = {}
            all_unit_type_ids = content_types_db.all_type_ids()
            for unit_type_id in all_unit_type_ids:
                units[unit_type_id] = {}
        # Validate user defined criteria and convert them to Criteria objects
        unit_criteria = {}
        for type_id, criteria in units.items():
            if criteria is None:
                criteria = {}
            unit_criteria[type_id] = Criteria.from_client_input(criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria,
                                               repo_criteria, unit_criteria,
                                               override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [
                    serialization.consumer.applicability_report(r)
                    for r in applicability_reports
                ]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [
                        serialization.consumer.applicability_report(r)
                        for r in report_list
                    ]

        return self.ok(report)