Ejemplo n.º 1
0
def register_policy_types(module):
    registered_count = 0
    mod_path = os.path.dirname(os.path.realpath(sys.modules[module.__name__].__file__))
    path = '%s/policies/meta' % mod_path

    files = []
    for ext in ALLOWED_EXTS:
        exp = '%s/*%s' % (path, ext)
        files += glob.glob(exp)

    for f in files:
        try:
            LOG.debug('Loading policy type from "%s".', f)
            content = loader.load_meta_file(f)
            policy_type_api = PolicyTypeAPI(**content)
            policy_type_db = PolicyTypeAPI.to_model(policy_type_api)

            try:
                existing_entry = PolicyType.get_by_ref(policy_type_db.ref)
                if existing_entry:
                    policy_type_db.id = existing_entry.id
            except ValueError:
                LOG.debug('Policy type "%s" is not found. Creating new entry.',
                          policy_type_db.ref)

            policy_type_db = PolicyType.add_or_update(policy_type_db)
            extra = {'policy_type_db': policy_type_db}
            LOG.audit('Policy type "%s" is updated.', policy_type_db.ref, extra=extra)

            registered_count += 1
        except:
            LOG.exception('Unable to register policy type from "%s".', f)

    return registered_count
Ejemplo n.º 2
0
def register_policy_types(module):
    registered_count = 0
    mod_path = os.path.dirname(os.path.realpath(sys.modules[module.__name__].__file__))
    path = os.path.join(mod_path, 'policies/meta')

    files = []
    for ext in ALLOWED_EXTS:
        exp = '%s/*%s' % (path, ext)
        files += glob.glob(exp)

    for f in files:
        try:
            LOG.debug('Loading policy type from "%s".', f)
            content = loader.load_meta_file(f)
            policy_type_api = PolicyTypeAPI(**content)
            policy_type_db = PolicyTypeAPI.to_model(policy_type_api)

            try:
                existing_entry = PolicyType.get_by_ref(policy_type_db.ref)
                if existing_entry:
                    policy_type_db.id = existing_entry.id
            except StackStormDBObjectNotFoundError:
                LOG.debug('Policy type "%s" is not found. Creating new entry.',
                          policy_type_db.ref)

            policy_type_db = PolicyType.add_or_update(policy_type_db)
            extra = {'policy_type_db': policy_type_db}
            LOG.audit('Policy type "%s" is updated.', policy_type_db.ref, extra=extra)

            registered_count += 1
        except:
            LOG.exception('Unable to register policy type from "%s".', f)

    return registered_count
Ejemplo n.º 3
0
    def setUpClass(cls):
        super(PolicyTypeControllerTestCase, cls).setUpClass()

        cls.policy_type_dbs = []

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            policy_type_db = PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))
            cls.policy_type_dbs.append(policy_type_db)
Ejemplo n.º 4
0
    def setUpClass(cls):
        super(PolicyTypeControllerTestCase, cls).setUpClass()

        cls.policy_type_dbs = []

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            policy_type_db = PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))
            cls.policy_type_dbs.append(policy_type_db)
Ejemplo n.º 5
0
    def setUpClass(cls):
        super(PolicyControllerTest, cls).setUpClass()

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 6
0
    def setUpClass(cls):
        super(PolicyControllerTest, cls).setUpClass()

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 7
0
    def setUpClass(cls):
        super(SchedulingPolicyTest, cls).setUpClass()

        # Register runners
        runners_registrar.register_runners()

        for _, fixture in six.iteritems(FIXTURES['actions']):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 8
0
    def setUpClass(cls):
        super(SchedulingPolicyTest, cls).setUpClass()

        # Register runners
        runners_registrar.register_runners()

        for _, fixture in six.iteritems(FIXTURES['actions']):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 9
0
    def setUpClass(cls):
        super(PolicyTest, cls).setUpClass()

        for _, fixture in six.iteritems(FIXTURES['runners']):
            instance = RunnerTypeAPI(**fixture)
            RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['actions']):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 10
0
    def setUpClass(cls):
        super(PolicyTest, cls).setUpClass()

        for _, fixture in six.iteritems(FIXTURES['runners']):
            instance = RunnerTypeAPI(**fixture)
            RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['actions']):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 11
0
    def setUp(self):
        EventletTestCase.setUpClass()
        DbTestCase.setUpClass()

        for _, fixture in six.iteritems(FIXTURES['runners']):
            instance = RunnerTypeAPI(**fixture)
            RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['actions']):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policytypes']):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES['policies']):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))
Ejemplo n.º 12
0
    def setUp(self):
        EventletTestCase.setUpClass()
        DbTestCase.setUpClass()

        for _, fixture in six.iteritems(FIXTURES["runners"]):
            instance = RunnerTypeAPI(**fixture)
            RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES["actions"]):
            instance = ActionAPI(**fixture)
            Action.add_or_update(ActionAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES["policytypes"]):
            instance = PolicyTypeAPI(**fixture)
            PolicyType.add_or_update(PolicyTypeAPI.to_model(instance))

        for _, fixture in six.iteritems(FIXTURES["policies"]):
            instance = PolicyAPI(**fixture)
            Policy.add_or_update(PolicyAPI.to_model(instance))