Example #1
0
    def test_register_all_configs_with_config_schema_validation_validation_failure_1(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_dbs = Config.get_all()

        self.assertEqual(len(pack_dbs), 0)
        self.assertEqual(len(config_dbs), 0)

        registrar = ConfigsRegistrar(use_pack_cache=False, fail_on_failure=True,
                                     validate_configs=True)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_6': PACK_6_PATH}

        # Register ConfigSchema for pack
        registrar._register_pack_db = mock.Mock()
        registrar._register_pack(pack_name='dummy_pack_5', pack_dir=PACK_6_PATH)
        packs_base_paths = content_utils.get_packs_base_paths()

        if six.PY3:
            expected_msg = ('Failed validating attribute "regions" in config for pack '
                            '"dummy_pack_6" (.*?): 1000 is not of type \'array\'')
        else:
            expected_msg = ('Failed validating attribute "regions" in config for pack '
                            '"dummy_pack_6" (.*?): 1000 is not of type u\'array\'')

        self.assertRaisesRegexp(ValueError, expected_msg,
                                registrar.register_from_packs,
                                base_dirs=packs_base_paths)
Example #2
0
    def test_register_all_configs_with_config_schema_validation_validation_failure(
            self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_dbs = Config.get_all()

        self.assertEqual(len(pack_dbs), 0)
        self.assertEqual(len(config_dbs), 0)

        registrar = ConfigsRegistrar(use_pack_cache=False,
                                     fail_on_failure=True,
                                     validate_configs=True)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_6': PACK_6_PATH
        }

        # Register ConfigSchema for pack
        registrar._register_pack_db = mock.Mock()
        registrar._register_pack(pack_name='dummy_pack_5',
                                 pack_dir=PACK_6_PATH)
        packs_base_paths = content_utils.get_packs_base_paths()

        expected_msg = (
            'Failed validating attribute "regions" in config for pack "dummy_pack_6" '
            '(.*?): 1000 is not of type u\'array\'')
        self.assertRaisesRegexp(ValueError,
                                expected_msg,
                                registrar.register_from_packs,
                                base_dirs=packs_base_paths)
Example #3
0
    def test_register_all_configs_with_config_schema_validation_validation_failure_2(
        self, ):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_dbs = Config.get_all()

        self.assertEqual(len(pack_dbs), 0)
        self.assertEqual(len(config_dbs), 0)

        registrar = ConfigsRegistrar(use_pack_cache=False,
                                     fail_on_failure=True,
                                     validate_configs=True)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            "dummy_pack_19": PACK_19_PATH
        }

        # Register ConfigSchema for pack
        registrar._register_pack_db = mock.Mock()
        registrar._register_pack(pack_name="dummy_pack_19",
                                 pack_dir=PACK_19_PATH)
        packs_base_paths = content_utils.get_packs_base_paths()

        if six.PY3:
            expected_msg = (
                'Failed validating attribute "instances.0.alias" in config for pack '
                "\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
                "'string'")
        else:
            expected_msg = (
                'Failed validating attribute "instances.0.alias" in config for pack '
                "\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
                "u'string'")

        self.assertRaisesRegexp(
            ValueError,
            expected_msg,
            registrar.register_from_packs,
            base_dirs=packs_base_paths,
        )
Example #4
0
    def test_register_all_configs_with_config_schema_validation_validation_failure_4(
        self, ):
        # This test checks for default values containing "decrypt_kv" jinja filter for
        # keys which have "secret: True" set.

        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_dbs = Config.get_all()

        self.assertEqual(len(pack_dbs), 0)
        self.assertEqual(len(config_dbs), 0)

        registrar = ConfigsRegistrar(use_pack_cache=False,
                                     fail_on_failure=True,
                                     validate_configs=True)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            "dummy_pack_22": PACK_22_PATH
        }

        # Register ConfigSchema for pack
        registrar._register_pack_db = mock.Mock()
        registrar._register_pack(pack_name="dummy_pack_22",
                                 pack_dir=PACK_22_PATH)
        packs_base_paths = content_utils.get_packs_base_paths()

        expected_msg = (
            'Values specified as "secret: True" in config schema are automatically '
            'decrypted by default. Use of "decrypt_kv" jinja filter is not allowed '
            "for such values. Please check the specified values in the config or "
            "the default values in the schema.")

        self.assertRaisesRegexp(
            ValueError,
            expected_msg,
            registrar.register_from_packs,
            base_dirs=packs_base_paths,
        )