當前位置: 首頁>>代碼示例>>Python>>正文


Python base.ResourceRegistrar類代碼示例

本文整理匯總了Python中st2common.bootstrap.base.ResourceRegistrar的典型用法代碼示例。如果您正苦於以下問題:Python ResourceRegistrar類的具體用法?Python ResourceRegistrar怎麽用?Python ResourceRegistrar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ResourceRegistrar類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _register_packs

    def _register_packs(self):
        """
        Register all the packs inside the fixtures directory.
        """

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar.register_packs(base_dirs=get_packs_base_paths())
開發者ID:AlexeyDeyneko,項目名稱:st2,代碼行數:7,代碼來源:base.py

示例2: test_register_packs

    def test_register_packs(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_schema_dbs = ConfigSchema.get_all()

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

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_1': PACK_PATH_1}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Verify pack and schema have been registered
        pack_dbs = Pack.get_all()
        config_schema_dbs = ConfigSchema.get_all()

        self.assertEqual(len(pack_dbs), 1)
        self.assertEqual(len(config_schema_dbs), 1)

        self.assertEqual(pack_dbs[0].name, 'dummy_pack_1')
        self.assertEqual(len(pack_dbs[0].contributors), 2)
        self.assertEqual(pack_dbs[0].contributors[0], 'John Doe1 <[email protected]>')
        self.assertEqual(pack_dbs[0].contributors[1], 'John Doe2 <[email protected]>')
        self.assertTrue('api_key' in config_schema_dbs[0].attributes)
        self.assertTrue('api_secret' in config_schema_dbs[0].attributes)
開發者ID:Pulsant,項目名稱:st2,代碼行數:27,代碼來源:test_resource_registrar.py

示例3: test_register_pack_pack_stackstorm_version_and_future_parameters

    def test_register_pack_pack_stackstorm_version_and_future_parameters(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_9': PACK_PATH_9}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Dependencies, stackstorm_version and future values
        pack_db = Pack.get_by_name('dummy_pack_9_deps')
        self.assertEqual(pack_db.dependencies, ['core=0.2.0'])
        self.assertEqual(pack_db.stackstorm_version, '>=1.6.0, <2.2.0')
        self.assertEqual(pack_db.system, {'centos': {'foo': '>= 1.0'}})
        self.assertEqual(pack_db.python_versions, ['2', '3'])

        # Note: We only store parameters which are defined in the schema, all other custom user
        # defined attributes are ignored
        self.assertTrue(not hasattr(pack_db, 'future'))
        self.assertTrue(not hasattr(pack_db, 'this'))

        # Wrong characters in the required st2 version
        expected_msg = "'wrongstackstormversion' does not match"
        self.assertRaisesRegexp(ValidationError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_10)
開發者ID:nzlosh,項目名稱:st2,代碼行數:27,代碼來源:test_resource_registrar.py

示例4: test_register_pack_pack_ref

    def test_register_pack_pack_ref(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()

        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_1': PACK_PATH_1,
            'dummy_pack_6': PACK_PATH_6
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_6')
        self.assertEqual(pack_db.ref, 'dummy_pack_6_ref')
        self.assertEqual(len(pack_db.contributors), 0)

        # Ref is not provided, directory name should be used
        pack_db = Pack.get_by_name('dummy_pack_1')
        self.assertEqual(pack_db.ref, 'dummy_pack_1')

        # "ref" is not provided, but "name" is
        registrar._register_pack_db(pack_name=None, pack_dir=PACK_PATH_7)

        pack_db = Pack.get_by_name('dummy_pack_7_name')
        self.assertEqual(pack_db.ref, 'dummy_pack_7_name')

        # "ref" is not provided and "name" contains invalid characters
        expected_msg = 'contains invalid characters'
        self.assertRaisesRegexp(ValueError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_8)
開發者ID:nzlosh,項目名稱:st2,代碼行數:34,代碼來源:test_resource_registrar.py

示例5: setup_virtualenvs

def setup_virtualenvs():
    """
    Setup Python virtual environments for all the registered or the provided pack.
    """
    pack_dir = cfg.CONF.register.pack
    fail_on_failure = cfg.CONF.register.fail_on_failure

    if pack_dir:
        pack_name = os.path.basename(pack_dir)
        pack_names = [pack_name]
    else:
        registrar = ResourceRegistrar()
        pack_names = registrar.get_registered_packs()

    setup_count = 0
    for pack_name in pack_names:
        try:
            setup_pack_virtualenv(pack_name=pack_name, update=True, logger=LOG)
        except Exception as e:
            exc_info = not fail_on_failure
            LOG.warning('Failed to setup virtualenv for pack "%s": %s', pack_name, e,
                        exc_info=exc_info)

            if fail_on_failure:
                raise e
        else:
            setup_count += 1

    LOG.info('Setup virtualenv for %s pack.' % (setup_count))
開發者ID:AlexeyDeyneko,項目名稱:st2,代碼行數:29,代碼來源:bootstrap.py

示例6: test_register_pack_old_style_non_semver_version_is_normalized_to_valid_version

    def test_register_pack_old_style_non_semver_version_is_normalized_to_valid_version(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_11': PACK_PATH_11}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Non-semver valid version 0.2 should be normalize to 0.2.0
        pack_db = Pack.get_by_name('dummy_pack_11')
        self.assertEqual(pack_db.version, '0.2.0')
開發者ID:peak6,項目名稱:st2,代碼行數:14,代碼來源:test_resource_registrar.py

示例7: test_register_pack_arbitrary_properties_are_allowed

    def test_register_pack_arbitrary_properties_are_allowed(self):
        # Test registering a pack which has "arbitrary" properties in pack.yaml
        # We support this use-case (ignore properties which are not defined on the PackAPI model)
        # so we can add new attributes in a new version without breaking existing installations.
        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_20': PACK_PATH_20,
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_20')
        self.assertEqual(pack_db.ref, 'dummy_pack_20_ref')
        self.assertEqual(len(pack_db.contributors), 0)
開發者ID:nzlosh,項目名稱:st2,代碼行數:16,代碼來源:test_resource_registrar.py

示例8: test_register_packs

    def test_register_packs(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        config_schema_dbs = ConfigSchema.get_all()

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

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_1': PACK_PATH_1}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Verify pack and schema have been registered
        pack_dbs = Pack.get_all()
        config_schema_dbs = ConfigSchema.get_all()

        self.assertEqual(len(pack_dbs), 1)
        self.assertEqual(len(config_schema_dbs), 1)

        pack_db = pack_dbs[0]
        config_schema_db = config_schema_dbs[0]

        self.assertEqual(pack_db.name, 'dummy_pack_1')
        self.assertEqual(len(pack_db.contributors), 2)
        self.assertEqual(pack_db.contributors[0], 'John Doe1 <[email protected]>')
        self.assertEqual(pack_db.contributors[1], 'John Doe2 <[email protected]>')
        self.assertTrue('api_key' in config_schema_db.attributes)
        self.assertTrue('api_secret' in config_schema_db.attributes)

        # Verify pack_db.files is correct and doesn't contain excluded files (*.pyc, .git/*, etc.)
        # Note: We can't test that .git/* files are excluded since git doesn't allow you to add
        # .git directory to existing repo index :/
        excluded_files = [
            '__init__.pyc',
            'actions/dummy1.pyc',
            'actions/dummy2.pyc',
        ]

        for excluded_file in excluded_files:
            self.assertTrue(excluded_file not in pack_db.files)
開發者ID:nzlosh,項目名稱:st2,代碼行數:42,代碼來源:test_resource_registrar.py

示例9: test_register_pack_invalid_ref_name_friendly_error_message

    def test_register_pack_invalid_ref_name_friendly_error_message(self):
        registrar = ResourceRegistrar(use_pack_cache=False)

        # Invalid ref
        expected_msg = (r'Pack ref / name can only contain valid word characters .*?,'
                        ' dashes are not allowed.')
        self.assertRaisesRegexp(ValidationError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_13)

        try:
            registrar._register_pack_db(pack_name=None, pack_dir=PACK_PATH_13)
        except ValidationError as e:
            self.assertTrue("'invalid-has-dash' does not match '^[a-z0-9_]+$'" in six.text_type(e))
        else:
            self.fail('Exception not thrown')

        # Pack ref not provided and name doesn't contain valid characters
        expected_msg = (r'Pack name "dummy pack 14" contains invalid characters and "ref" '
                        'attribute is not available. You either need to add')
        self.assertRaisesRegexp(ValueError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_14)
開發者ID:nzlosh,項目名稱:st2,代碼行數:21,代碼來源:test_resource_registrar.py

示例10: setup_virtualenvs

def setup_virtualenvs():
    """
    Setup Python virtual environments for all the registered or the provided pack.
    """

    LOG.info('=========================================================')
    LOG.info('########### Setting up virtual environments #############')
    LOG.info('=========================================================')

    pack_dir = cfg.CONF.register.pack
    fail_on_failure = cfg.CONF.register.fail_on_failure

    registrar = ResourceRegistrar()

    if pack_dir:
        pack_name = os.path.basename(pack_dir)
        pack_names = [pack_name]

        # 1. Register pack
        registrar.register_pack(pack_name=pack_name, pack_dir=pack_dir)
    else:
        # 1. Register pack
        base_dirs = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=base_dirs)

        # 2. Retrieve available packs (aka packs which have been registered)
        pack_names = registrar.get_registered_packs()

    setup_count = 0
    for pack_name in pack_names:
        try:
            setup_pack_virtualenv(pack_name=pack_name, update=True, logger=LOG)
        except Exception as e:
            exc_info = not fail_on_failure
            LOG.warning('Failed to setup virtualenv for pack "%s": %s', pack_name, e,
                        exc_info=exc_info)

            if fail_on_failure:
                raise e
        else:
            setup_count += 1

    LOG.info('Setup virtualenv for %s pack(s).' % (setup_count))
開發者ID:acm1,項目名稱:st2,代碼行數:43,代碼來源:bootstrap.py

示例11: ResourceRegistrar

from st2common.constants.pack import DEFAULT_PACK_NAME
from st2common.content.loader import ContentPackLoader
from st2common.content.loader import MetaLoader
from st2common.bootstrap.base import ResourceRegistrar
import st2common.content.utils as content_utils
from st2common.models.api.action import ActionAPI
from st2common.models.api.sensor import SensorTypeAPI
from st2common.models.api.rule import RuleAPI
from st2common.models.db import db_setup
from st2common.models.db import db_teardown
from st2common.models.system.common import ResourceReference
from st2common.persistence.rule import Rule
from st2common.persistence.sensor import SensorType
from st2common.persistence.action import Action

registrar = ResourceRegistrar()
registrar.ALLOWED_EXTENSIONS = [".yaml", ".yml", ".json"]

meta_loader = MetaLoader()

API_MODELS_ARTIFACT_TYPES = {"actions": ActionAPI, "sensors": SensorTypeAPI, "rules": RuleAPI}

API_MODELS_PERSISTENT_MODELS = {Action: ActionAPI, SensorType: SensorTypeAPI, Rule: RuleAPI}


def do_register_cli_opts(opts, ignore_errors=False):
    for opt in opts:
        try:
            cfg.CONF.register_cli_opt(opt)
        except:
            if not ignore_errors:
開發者ID:azamsheriff,項目名稱:st2,代碼行數:31,代碼來源:diff-db-disk.py

示例12: ResourceRegistrar

from st2common.constants.pack import DEFAULT_PACK_NAME
from st2common.content.loader import ContentPackLoader
from st2common.content.loader import MetaLoader
from st2common.bootstrap.base import ResourceRegistrar
import st2common.content.utils as content_utils
from st2common.models.api.action import ActionAPI
from st2common.models.api.sensor import SensorTypeAPI
from st2common.models.api.rule import RuleAPI
from st2common.service_setup import db_setup
from st2common.service_setup import db_teardown
from st2common.models.system.common import ResourceReference
from st2common.persistence.rule import Rule
from st2common.persistence.sensor import SensorType
from st2common.persistence.action import Action

registrar = ResourceRegistrar()
registrar.ALLOWED_EXTENSIONS = ['.yaml', '.yml', '.json']

meta_loader = MetaLoader()

API_MODELS_ARTIFACT_TYPES = {
    'actions': ActionAPI,
    'sensors': SensorTypeAPI,
    'rules': RuleAPI
}

API_MODELS_PERSISTENT_MODELS = {
    Action: ActionAPI,
    SensorType: SensorTypeAPI,
    Rule: RuleAPI
}
開發者ID:lyandut,項目名稱:st2,代碼行數:31,代碼來源:diff-db-disk.py


注:本文中的st2common.bootstrap.base.ResourceRegistrar類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。