コード例 #1
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    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
コード例 #2
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
 def test_update_catalog_existing_version(self, event_payload,
                                          upgrade_planer: UpgradePlaner):
     upgrade_planer.mongo.catalog.find_one.return_value = {
         "name":
         "producer",
         "service":
         event_payload['service'],
         "versions_list": [{
             "version":
             "1.0.1",
             "dependencies":
             event_payload['scale_config']['dependencies'],
             "image_info": {
                 'digest':
                 'sha256:d2a8219e9b3bdc4da656d32c4ac9ad4e54312946a10ac9244967d4373bc3ce6d',
                 'image': 'maiev',
                 'repository': 'localhost:5000',
                 'species': 'producer',
                 'tag': 'producer-1.0.1',
                 'version': '1.0.1'
             },
             "available":
             True
         }],
     }
     upgrade_planer.on_new_version(event_payload)
     upgrade_planer.dispatch.assert_not_called()
コード例 #3
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    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
コード例 #4
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
 def test_sort_version(self, upgrade_planer: UpgradePlaner):
     versions = ['1.1.4-108b', '1.3.0-110b', '1.3.0-114b', '1.3.0-119b']
     sorted_v = upgrade_planer.sort_versions(
         self.build_catalog("producer", versions))
     assert sorted_v == [
         '1.3.0-119b', '1.3.0-114b', '1.3.0-110b', '1.1.4-108b'
     ]
コード例 #5
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    def test_get_latest_phase_beta_real(self, upgrade_planer: UpgradePlaner):
        upgrade_planer.mongo.catalog.find.return_value = [
            {
                "name":
                "producer",
                "versions_list":
                self.build_catalog("producer", [
                    '1.1-93b', '1.1-79b', '1.1-73b', '1.1-77b', '1.1-78b',
                    '1.1-71b', '1.1-87b', '1.1-64b', '1.1-89b', '1.1-84b',
                    '1.1-86b', '1.1-65b', '1.1-88b', '1.1-96b', '1.1-97b',
                    '1.1-98b', '1.1-99b', '1.1-100b', '1.1-101b', '1.1-103b',
                    '1.1-104b', '1.1-106b', '1.1-107b', '1.1-108b',
                    '1.3.0-110b', '1.3.0-114b', '1.3.0-119b'
                ])
            },
            {
                "name":
                "consumer",
                "versions_list":
                self.build_catalog("consumer", ["1.0.5", "1.0-17b"])
            },
        ]

        s = upgrade_planer.get_latest_phase()
        assert {"producer": "1.3.0-119b", "consumer": "1.0.5"} == s
コード例 #6
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    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
            }
        }
コード例 #7
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
 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": []
             },
         }
     }]
コード例 #8
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    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
コード例 #9
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
def upgrade_planer():
    service = UpgradePlaner()
    service.config = {}
    service.mongo = mock.Mock()
    service.dispatch = mock.Mock()
    service.dependency_solver = mock.Mock()
    return service
コード例 #10
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    def test_build_steps(self, upgrade_planer: UpgradePlaner):
        goal = Phase((
            PhasePin({
                "name": "producer",
            }, "1.0.17"),
            PhasePin({
                "name": "consumer",
            }, "1.0.17"),
        ))
        upgrade_planer.mongo.catalog.find.return_value = [{
            "name": "producer",
            "version": "1.0.16"
        }, {
            "name": "consumer",
            "version": "1.0.1"
        }]

        upgrade_planer.explain_phase = mock.Mock(return_value={'results': 0})
        s = upgrade_planer.build_steps(goal)
        assert 2 == len(s)
        assert [('producer', '1.0.16', '1.0.17'),
                ('consumer', '1.0.1', '1.0.17')] == s
コード例 #11
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
 def test_sample1_get_latest(self, upgrade_planer: UpgradePlaner):
     upgrade_planer.mongo.catalog.find.return_value = self.load_sample(
         'sample1.json')['catalog']
     s = upgrade_planer.get_latest_phase()
     assert s == {
         'http_to_rpc': '0.1.24',
         'joboffer_algolia_publisher': '0.1.24',
         'joboffer_fetcher': '0.1.24',
         'joboffer_xml_publisher': '0.1.24',
         'maiev': '1.3.0',
         'yupeeposting-backend': '0.2.65',
         'yupeeposting-webui': '0.2.64'
     }
コード例 #12
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    def test_best_phase2(self, upgrade_planer: UpgradePlaner):
        phases = [
            [[{
                "name": "producer",
            }, "1.0.1"], [{
                "name": "consumer",
            }, "1.0.1"]],
            [[{
                "name": "producer",
            }, "1.0.1"], [{
                "name": "consumer",
            }, "1.0.17"]],
            [[{
                "name": "producer",
            }, "1.0.16"], [{
                "name": "consumer",
            }, "1.0.1"]],
            [[{
                "name": "producer",
            }, "1.0.17"], [{
                "name": "consumer",
            }, "1.0.1"]],
        ]
        upgrade_planer.mongo.catalog.find.return_value = [
            {
                "name":
                "producer",
                "versions_list":
                self.build_catalog("producer", ["1.0.1", "1.0.16", "1.0.17"])
            },
            {
                "name":
                "consumer",
                "versions_list":
                self.build_catalog("consumer", ["1.0.1", "1.0.17"])
            },
        ]

        s = upgrade_planer.solve_best_phase(phases)
        assert 2 == len(s)
        goal, rank = s
        assert 1 == rank
        assert goal == [[{
            "name": "producer",
        }, "1.0.17"], [{
            "name": "consumer",
        }, "1.0.1"]]
コード例 #13
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    def test_get_latest_phase_beta(self, upgrade_planer: UpgradePlaner):
        upgrade_planer.mongo.catalog.find.return_value = [
            {
                "name":
                "producer",
                "versions_list":
                self.build_catalog("producer", ["1.0.5", "1.0.16b", "1.0.17"])
            },
            {
                "name":
                "consumer",
                "versions_list":
                self.build_catalog("consumer", ["1.0.5", "1.0.17b"])
            },
        ]

        s = upgrade_planer.get_latest_phase()
        assert {"producer": "1.0.17", "consumer": "1.0.17b"} == s
コード例 #14
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
 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": {}
     }]
コード例 #15
0
ファイル: test_upgrade_planer.py プロジェクト: Yupeek/maiev
    def test_best_phase_rc_version(self, upgrade_planer: UpgradePlaner):
        phases = [
            Phase([
                PhasePin({
                    "name": "producer",
                }, "1.0.1rc1"),
                PhasePin({
                    "name": "consumer",
                }, "1.0.1rc1")
            ]),
            Phase([
                PhasePin({
                    "name": "producer",
                }, "1.0.1rc1"),
                PhasePin({
                    "name": "consumer",
                }, "1.0.1rc17")
            ]),
            Phase([
                PhasePin({
                    "name": "producer",
                }, "1.0.1rc16"),
                PhasePin({
                    "name": "consumer",
                }, "1.0.1rc1")
            ]),
            Phase([
                PhasePin({
                    "name": "producer",
                }, "1.0.1rc17"),
                PhasePin({
                    "name": "consumer",
                }, "1.0.1rc1")
            ]),
            Phase([
                PhasePin({
                    "name": "producer",
                }, "1.0.1rc17"),
                PhasePin({
                    "name": "consumer",
                }, "1.0.1rc17")
            ]),
        ]
        upgrade_planer.mongo.catalog.find.return_value = [
            {
                "name":
                "producer",
                "versions_list":
                self.build_catalog("producer",
                                   ["1.0.1rc1", "1.0.1rc16", "1.0.1rc17"])
            },
            {
                "name":
                "consumer",
                "versions_list":
                self.build_catalog("consumer", ["1.0.1rc1", "1.0.1rc17"])
            },
        ]

        s = upgrade_planer.solve_best_phase(phases)
        assert 2 == len(s)
        goal, rank = s
        assert 0 == rank
        assert goal == Phase([
            PhasePin({
                "name": "producer",
            }, "1.0.1rc17"),
            PhasePin({
                "name": "consumer",
            }, "1.0.1rc17")
        ])