示例#1
0
 def test_initialize_data_after_merge_db_driver_setup(self):
     doc = {
         "roles": ["db"],
         "additional_ports": {
             "one": 1,
             "two": 2,
             "three": 3
         }
     }
     service = module.Service(doc)
     with patch_mock_db_driver(
             'riptide.config.document.service.db_driver_for_service.get'
     ) as (get, driver):
         driver.collect_additional_ports = MagicMock(return_value={
             "four": 4,
             "five": 5,
             "three": 6
         })
         service._initialize_data_after_merge()
         get.assert_called_once_with(service)
         self.assertEqual(
             {
                 "one": 1,
                 "two": 2,
                 "four": 4,
                 "five": 5,
                 "three": 3
             }, service.doc["additional_ports"])
示例#2
0
    def test_validate_extra_db_driver(self):
        service = module.Service.from_yaml(
            get_fixture_path(FIXTURE_BASE_PATH + 'valid_db_driver.yml'))

        with patch_mock_db_driver(
                'riptide.config.document.service.db_driver_for_service.get'
        ) as (_, driver):
            service._db_driver = driver
            service.validate()
            driver.validate_service.assert_called_once()
示例#3
0
    def test_collect_environment(self):
        service = module.Service(
            {"environment": {
                "key1": "value1",
                "key2": "value2"
            }})

        with patch_mock_db_driver(
                'riptide.config.document.service.db_driver_for_service.get'
        ) as (_, driver):
            service._db_driver = driver
            driver.collect_environment.return_value = {
                'FROM_DB_DRIVER': 'VALUE'
            }

        self.assertEqual(
            {
                "key1": "value1",
                "key2": "value2",
                "FROM_DB_DRIVER": "VALUE"
            }, service.collect_environment())
示例#4
0
    def test_collect_volumes(self, process_additional_volumes_mock: Mock,
                             process_config_mock: Mock, makedirs_mock: Mock,
                             get_logging_path_for_mock: Mock,
                             get_command_logging_container_path_mock: Mock,
                             create_logging_path_mock: Mock):
        config1 = {'to': '/TO_1', 'from': '/FROM_1'}
        config2 = {'to': '/TO_2', 'from': '/FROM_2'}
        config3 = {'to': '/TO_3', 'from': '/FROM_3'}
        service = module.Service({
            "roles": ["src"],
            "config": {
                "config1": config1,
                "config2": config2,
                "config3": config3
            },
            "logging": {
                "stdout": True,
                "stderr": True,
                "paths": {
                    "one": "one_path",
                    "two": "two_path",
                    "three": "three_path"
                },
                "commands": {
                    "four": "not used here"
                }
            },
            "additional_volumes": {
                "one": {
                    "host": "~/hometest",
                    "container": "/vol1",
                    "mode": "rw"
                },
                "2": {
                    "host": "./reltest1",
                    "container": "/vol2",
                    "mode": "rw"
                },
                "three": {
                    "host": "reltest2",
                    "container": "/vol3",
                    "mode": "rw"
                },
                "FOUR": {
                    "host": "reltestc",
                    "container": "reltest_container",
                    "mode": "rw"
                },
                "faive": {
                    "host": "/absolute_with_ro",
                    "container": "/vol4",
                    "mode": "ro"
                },
                "xis": {
                    "host": "/absolute_no_mode",
                    "container": "/vol5"
                }
            }
        })
        expected = OrderedDict({
            # SRC
            ProjectStub.SRC_FOLDER: {
                'bind': CONTAINER_SRC_PATH,
                'mode': 'rw'
            },
            # CONFIG
            'config1~/FROM_1~PROCESSED': {
                'bind': '/TO_1',
                'mode': 'rw'
            },
            'config2~/FROM_2~PROCESSED': {
                'bind': '/TO_2',
                'mode': 'rw'
            },
            'config3~/FROM_3~PROCESSED': {
                'bind': '/TO_3',
                'mode': 'rw'
            },
            # LOGGING
            'stdout~PROCESSED2': {
                'bind': module.LOGGING_CONTAINER_STDOUT,
                'mode': 'rw'
            },
            'stderr~PROCESSED2': {
                'bind': module.LOGGING_CONTAINER_STDERR,
                'mode': 'rw'
            },
            'one~PROCESSED2': {
                'bind': 'one_path',
                'mode': 'rw'
            },
            'two~PROCESSED2': {
                'bind': 'two_path',
                'mode': 'rw'
            },
            'three~PROCESSED2': {
                'bind': 'three_path',
                'mode': 'rw'
            },
            'four~PROCESSED2': {
                'bind': 'four~PROCESSED3',
                'mode': 'rw'
            },
            # DB DRIVER
            'FROM_DB_DRIVER': 'VALUE',
            # ADDITIONAL VOLUMES
            # process_additional_volumes has to be called
            STUB_PAV__KEY: STUB_PAV__VAL
        })

        service.parent_doc = ProjectStub({}, set_parent_to_self=True)

        ## DB DRIVER SETUP
        with patch_mock_db_driver(
                'riptide.config.document.service.db_driver_for_service.get'
        ) as (_, driver):
            service._db_driver = driver
            driver.collect_volumes.return_value = {'FROM_DB_DRIVER': 'VALUE'}

        ## OVERALL ASSERTIONS
        actual = service.collect_volumes()
        self.assertEqual(expected, actual)
        self.assertIsInstance(actual, OrderedDict)

        ## CONFIG ASSERTIONS
        process_config_mock.assert_has_calls([
            call("config1", config1, service),
            call("config2", config2, service),
            call("config3", config3, service),
        ],
                                             any_order=True)

        ## LOGGING ASSERTIONS
        get_logging_path_for_mock.assert_has_calls([
            call(service, "stdout"),
            call(service, "stderr"),
            call(service, "one"),
            call(service, "two"),
            call(service, "three"),
            call(service, "four"),
        ],
                                                   any_order=True)
        get_command_logging_container_path_mock.assert_has_calls(
            [
                call("four"),
            ], any_order=True)
        create_logging_path_mock.assert_called_once()

        ## ADDITIONAL VOLUMES ASSERTIONS
        process_additional_volumes_mock.assert_called_with(
            list(service['additional_volumes'].values()), ProjectStub.FOLDER)

        ## DB DRIVER ASSERTIONS
        makedirs_mock.assert_has_calls(
            [
                # DB DRIVER
                call('FROM_DB_DRIVER', exist_ok=True)
            ],
            any_order=True)