Пример #1
0
    def test_resolve_upgrade_and_steps_with_resolution_disabled(
            self, upgrade_planer: UpgradePlaner, catalog):
        upgrade_planer.config['solve_dependencies'] = False
        upgrade_planer.build_catalog = mock.Mock(return_value=catalog)
        upgrade_planer.dependency_solver.solve_dependencies = mock.Mock(
            return_value={
                "results": [],
                "errors": [],
                "anomalies": []
            })
        bp = Phase(
            [PhasePin(catalog[1], "1.0.16"),
             PhasePin(catalog[0], "1.0.16")])
        upgrade_planer.get_latest_phase = mock.Mock(
            return_value={
                catalog[1]['name']: "1.0.16",
                catalog[0]['name']: "1.0.16"
            })
        upgrade_planer.solve_best_phase = mock.Mock(return_value=(bp, 1))
        upgrade_planer.build_steps = mock.Mock()

        res = upgrade_planer.resolve_upgrade_and_steps()

        upgrade_planer.solve_best_phase.assert_called_with([bp])
        upgrade_planer.build_steps.assert_called_with(bp)
        upgrade_planer.dependency_solver.solve_dependencies.assert_not_called()

        assert res['result']['best_phase'] == bp
Пример #2
0
    def test_resolve_upgrade_and_steps_with_goal(self,
                                                 upgrade_planer: UpgradePlaner,
                                                 catalog):
        upgrade_planer.build_catalog = mock.Mock(return_value=catalog)
        upgrade_planer.dependency_solver.solve_dependencies = mock.Mock(
            return_value={
                "results": [{
                    "producer": "1.0.16",
                    "consumer": "1.0.16"
                }],
                "errors": [],
                "anomalies": []
            })
        bp = Phase(
            [PhasePin(catalog[1], "1.0.16"),
             PhasePin(catalog[0], "1.0.16")])
        upgrade_planer.solve_best_phase = mock.Mock(return_value=(bp, 1))
        upgrade_planer.build_steps = mock.Mock()

        res = upgrade_planer.resolve_upgrade_and_steps()

        upgrade_planer.solve_best_phase.assert_called_with([bp])
        upgrade_planer.build_steps.assert_called_with(bp)

        assert res['result']['best_phase'] == bp
Пример #3
0
 def test_build_catalog_beta_versions(self, upgrade_planer: UpgradePlaner,
                                      service):
     service['consumer']['image']['image_info']['version'] = '1.0.16b'
     service['producer']['image']['image_info']['version'] = '1.0.16b'
     upgrade_planer.mongo.catalog.find.return_value = [{
         "name":
         "consumer",
         "service":
         service['consumer'],
         "versions_list": [{
             "version": "1.0.16b",
             "dependencies": {
                 "require": ["producer:rpc:echo"]
             }
         }],
         "version":
         service['consumer']['image']['image_info']['version'],
     }, {
         "name":
         "producer",
         "service":
         service['producer'],
         "versions_list": [{
             "version": "1.0.16b",
             "dependencies": {
                 "provide": {
                     "producer:rpc:echo": 1
                 }
             }
         }],
         "version":
         service['producer']['image']['image_info']['version'],
     }]
     c = upgrade_planer.build_catalog()
     assert c == [{
         "name": "consumer",
         "versions": {
             "1.0.16b": {
                 "provide": {},
                 "require": ["producer:rpc:echo"]
             },
         }
     }, {
         "name": "producer",
         "versions": {
             "1.0.16b": {
                 "provide": {
                     "producer:rpc:echo": 1
                 },
                 "require": []
             },
         }
     }]
Пример #4
0
    def test_sample1_build_catalog(self, upgrade_planer: UpgradePlaner):
        upgrade_planer.mongo.catalog.find.return_value = self.load_sample(
            'sample1.json')['catalog']
        catalog = upgrade_planer.build_catalog()

        total = reduce(lambda a, b: a * b,
                       (len(service['versions']) for service in catalog), 1)
        assert total == 8640
        reduced = upgrade_planer.reduce_catalog(catalog)
        total_reduced = reduce(lambda a, b: a * b, (len(service['versions'])
                                                    for service in reduced), 1)
        assert total_reduced == 32
Пример #5
0
    def test_resolve_upgrade_and_steps_with_error(
            self, upgrade_planer: UpgradePlaner, catalog):
        upgrade_planer.build_catalog = mock.Mock(return_value=catalog)
        upgrade_planer.dependency_solver.solve_dependencies = mock.Mock(
            return_value={
                "results": [],
                "errors": ["ceci est une erreur"],
                "anomalies": []
            })

        res = upgrade_planer.resolve_upgrade_and_steps()

        print(res)
        assert res == {
            'result': None,
            'errors': {
                'step': 'dependency_solve',
                'error': ['ceci est une erreur'],
                'catalog': catalog
            }
        }
Пример #6
0
 def test_build_catalog_no_solution(self, upgrade_planer: UpgradePlaner,
                                    service):
     upgrade_planer.mongo.catalog.find.return_value = [{
         "name":
         "consumer",
         "service":
         service['consumer'],
         "versions_list": [{
             "version": "1.0.15",
             "dependencies": {
                 "require": ["producer:rpc:echo"]
             }
         }],
         "version":
         service['consumer']['image']['image_info']['version']
     }, {
         "name":
         "producer",
         "service":
         service['producer'],
         "versions_list": [{
             "version": "1.0.15",
             "dependencies": {
                 "provide": {
                     "producer:rpc:echo": 1
                 }
             }
         }],
         "version":
         service['producer']['image']['image_info']['version'],
     }]
     c = upgrade_planer.build_catalog(NO_DOWNGRADE)
     assert c == [{
         "name": "consumer",
         "versions": {}
     }, {
         "name": "producer",
         "versions": {}
     }]