当前位置: 首页>>代码示例>>Python>>正文


Python parser.simple_parse函数代码示例

本文整理汇总了Python中senlin.engine.parser.simple_parse函数的典型用法代码示例。如果您正苦于以下问题:Python simple_parse函数的具体用法?Python simple_parse怎么用?Python simple_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了simple_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_action_get_project_safe

 def test_action_get_project_safe(self):
     parser.simple_parse(shared.sample_action)
     action = _create_action(self.ctx)
     new_ctx = utils.dummy_context(project='another-project')
     retobj = db_api.action_get(new_ctx, action.id, project_safe=True)
     self.assertIsNone(retobj)
     retobj = db_api.action_get(new_ctx, action.id, project_safe=False)
     self.assertIsNotNone(retobj)
开发者ID:jonnary,项目名称:senlin,代码行数:8,代码来源:test_action_api.py

示例2: test_load

    def test_load(self):
        timestamp = timeutils.utcnow()
        spec = parser.simple_parse(sample_trigger)
        db_trigger = self._create_db_trigger('FAKE_ID',
                                             created_time=timestamp,
                                             updated_time=timestamp)

        self.assertIsNotNone(db_trigger)
        res = base.Trigger.load(self.ctx, trigger_id=db_trigger.id)

        self.assertIsInstance(res, base.Trigger)
        self.assertEqual('FAKE_ID', res.id)
        self.assertEqual('test-trigger', res.name)
        self.assertEqual('FakeTriggerType', res.type_name)
        self.assertEqual('blah blah', res.desc)
        self.assertEqual(base.INSUFFICIENT_DATA, res.state)
        self.assertTrue(res.enabled)
        self.assertEqual(base.S_CRITICAL, res.severity)
        self.assertEqual({'alarm_actions': ['http://url1']}, res.links)
        self.assertEqual(timestamp, res.created_time)
        self.assertEqual(timestamp, res.updated_time)
        self.assertIsNone(res.deleted_time)

        self.assertEqual(spec, res.spec)
        self.assertEqual(spec['type'], res.spec_data['type'])
        self.assertEqual(str(spec['version']), res.spec_data['version'])
        self.assertEqual(spec['rule'], res.spec_data['rule'])

        # load trigger via db trigger object
        res = base.Trigger.load(self.ctx, db_trigger=db_trigger)
        self.assertIsInstance(res, base.Trigger)
        self.assertEqual('FAKE_ID', res.id)
开发者ID:KongJustin,项目名称:senlin,代码行数:32,代码来源:test_trigger_base.py

示例3: _create_action

def _create_action(context, action_json=shared.sample_action, **kwargs):
    data = parser.simple_parse(action_json)
    data['user'] = context.user
    data['project'] = context.project
    data['domain'] = context.domain
    data.update(kwargs)
    return db_api.action_create(context, data)
开发者ID:jonnary,项目名称:senlin,代码行数:7,代码来源:test_action_api.py

示例4: test_trigger_list_with_limit_marker

    def test_trigger_list_with_limit_marker(self):
        spec = parser.simple_parse(trigger_spec)
        t1 = self.eng.trigger_create(self.ctx, 't-1', spec)
        t2 = self.eng.trigger_create(self.ctx, 't-2', spec)

        result = self.eng.trigger_list(self.ctx, limit=0)

        self.assertEqual(0, len(result))
        result = self.eng.trigger_list(self.ctx, limit=1)
        self.assertEqual(1, len(result))
        result = self.eng.trigger_list(self.ctx, limit=2)
        self.assertEqual(2, len(result))
        result = self.eng.trigger_list(self.ctx, limit=3)
        self.assertEqual(2, len(result))

        result = self.eng.trigger_list(self.ctx, marker=t1['id'])
        self.assertEqual(1, len(result))
        result = self.eng.trigger_list(self.ctx, marker=t2['id'])
        self.assertEqual(0, len(result))

        self.eng.trigger_create(self.ctx, 't-3', spec)
        result = self.eng.trigger_list(self.ctx, limit=1, marker=t1['id'])
        self.assertEqual(1, len(result))
        result = self.eng.trigger_list(self.ctx, limit=2, marker=t1['id'])
        self.assertEqual(2, len(result))
开发者ID:KongJustin,项目名称:senlin,代码行数:25,代码来源:test_triggers.py

示例5: test_trigger_create_invalid_spec

 def test_trigger_create_invalid_spec(self):
     spec = parser.simple_parse(trigger_spec)
     spec['KEY3'] = 'value3'
     ex = self.assertRaises(rpc.ExpectedException,
                            self.eng.trigger_create,
                            self.ctx, 't-1', spec)
     self.assertEqual(exception.SpecValidationFailed, ex.exc_info[0])
开发者ID:KongJustin,项目名称:senlin,代码行数:7,代码来源:test_triggers.py

示例6: test_profile_create

 def test_profile_create(self):
     data = parser.simple_parse(shared.sample_profile)
     profile = shared.create_profile(self.ctx)
     self.assertIsNotNone(profile.id)
     self.assertEqual(data['name'], profile.name)
     self.assertEqual(data['type'], profile.type)
     self.assertEqual(data['spec'], profile.spec)
开发者ID:jonnary,项目名称:senlin,代码行数:7,代码来源:test_profile_api.py

示例7: test_trigger_list_with_sort_keys

    def test_trigger_list_with_sort_keys(self):
        spec = parser.simple_parse(trigger_spec)
        t1 = self.eng.trigger_create(self.ctx, 'TB', spec, severity='low')
        t2 = self.eng.trigger_create(self.ctx, 'TA', spec, severity='low')
        t3 = self.eng.trigger_create(self.ctx, 'TC', spec, severity='high')

        # default by created_time
        result = self.eng.trigger_list(self.ctx)
        self.assertEqual(t1['id'], result[0]['id'])
        self.assertEqual(t2['id'], result[1]['id'])

        # use name for sorting
        result = self.eng.trigger_list(self.ctx, sort_keys=['name'])
        self.assertEqual(t2['id'], result[0]['id'])
        self.assertEqual(t1['id'], result[1]['id'])

        # use permission for sorting
        result = self.eng.trigger_list(self.ctx, sort_keys=['severity'])
        self.assertEqual(t3['id'], result[0]['id'])

        # use name and permission for sorting
        result = self.eng.trigger_list(self.ctx,
                                       sort_keys=['severity', 'name'])
        self.assertEqual(t3['id'], result[0]['id'])
        self.assertEqual(t2['id'], result[1]['id'])
        self.assertEqual(t1['id'], result[2]['id'])

        # unknown keys will be ignored
        result = self.eng.trigger_list(self.ctx, sort_keys=['duang'])
        self.assertIsNotNone(result)
开发者ID:KongJustin,项目名称:senlin,代码行数:30,代码来源:test_triggers.py

示例8: test_trigger_list_with_sort_dir

    def test_trigger_list_with_sort_dir(self):
        spec = parser.simple_parse(trigger_spec)
        t1 = self.eng.trigger_create(self.ctx, 'TB', spec, severity='low')
        t2 = self.eng.trigger_create(self.ctx, 'TA', spec, severity='low')
        t3 = self.eng.trigger_create(self.ctx, 'TC', spec, severity='high')

        # default by created_time, ascending
        result = self.eng.trigger_list(self.ctx)
        self.assertEqual(t1['id'], result[0]['id'])
        self.assertEqual(t2['id'], result[1]['id'])

        # sort by created_time, descending
        result = self.eng.trigger_list(self.ctx, sort_dir='desc')
        self.assertEqual(t3['id'], result[0]['id'])
        self.assertEqual(t2['id'], result[1]['id'])

        # use name for sorting, descending
        result = self.eng.trigger_list(self.ctx, sort_keys=['name'],
                                       sort_dir='desc')
        self.assertEqual(t3['id'], result[0]['id'])
        self.assertEqual(t1['id'], result[1]['id'])

        ex = self.assertRaises(ValueError,
                               self.eng.trigger_list, self.ctx,
                               sort_dir='Bogus')
        self.assertEqual("Unknown sort direction, must be one of: "
                         "asc-nullsfirst, asc-nullslast, desc-nullsfirst, "
                         "desc-nullslast", six.text_type(ex))
开发者ID:KongJustin,项目名称:senlin,代码行数:28,代码来源:test_triggers.py

示例9: test_to_dict

    def test_to_dict(self):
        spec = parser.simple_parse(sample_trigger)
        trigger = base.Trigger('t1', spec, id='FAKE_ID', desc='DESC',
                               user=self.ctx.user, project=self.ctx.project,
                               domain=self.ctx.domain)

        expected = {
            'id': 'FAKE_ID',
            'name': 't1',
            'type': 'FakeTriggerType',
            'desc': 'DESC',
            'state': base.INSUFFICIENT_DATA,
            'enabled': True,
            'severity': base.S_LOW,
            'links': {},
            'spec': spec,
            'user': self.ctx.user,
            'project': self.ctx.project,
            'domain': self.ctx.domain,
            'created_time': None,
            'updated_time': None,
            'deleted_time': None
        }

        res = trigger.to_dict()

        self.assertEqual(expected, res)
开发者ID:KongJustin,项目名称:senlin,代码行数:27,代码来源:test_trigger_base.py

示例10: create_profile

def create_profile(context, profile=sample_profile, **kwargs):
    data = parser.simple_parse(profile)
    data['user'] = context.user
    data['project'] = context.project
    data['domain'] = context.domain
    data.update(kwargs)
    return db_api.profile_create(context, data)
开发者ID:jonnary,项目名称:senlin,代码行数:7,代码来源:shared.py

示例11: test_trigger_create_type_not_found

 def test_trigger_create_type_not_found(self):
     spec = parser.simple_parse(trigger_spec)
     spec['type'] = 'Bogus'
     ex = self.assertRaises(rpc.ExpectedException,
                            self.eng.trigger_create,
                            self.ctx, 't-1', spec)
     self.assertEqual(exception.TriggerTypeNotFound, ex.exc_info[0])
开发者ID:KongJustin,项目名称:senlin,代码行数:7,代码来源:test_triggers.py

示例12: test_profile_create

 def test_profile_create(self):
     data = parser.simple_parse(shared.sample_profile)
     profile = shared.create_profile(self.ctx)
     self.assertIsNotNone(profile.id)
     self.assertEqual(data["name"], profile.name)
     self.assertEqual(data["type"], profile.type)
     self.assertEqual(data["spec"], profile.spec)
     self.assertEqual(data["permission"], profile.permission)
开发者ID:MountainWei,项目名称:senlin,代码行数:8,代码来源:test_profile_api.py

示例13: test_trigger_create_failed_validation

 def test_trigger_create_failed_validation(self):
     spec = parser.simple_parse(trigger_spec)
     self.patchobject(fakes.TestTrigger, 'validate',
                      side_effect=exception.InvalidSpec(message='BOOM'))
     ex = self.assertRaises(rpc.ExpectedException,
                            self.eng.trigger_create,
                            self.ctx, 't1', spec)
     self.assertEqual(exception.InvalidSpec, ex.exc_info[0])
开发者ID:KongJustin,项目名称:senlin,代码行数:8,代码来源:test_triggers.py

示例14: test_validate_illegal_tc_timezone

    def test_validate_illegal_tc_timezone(self):
        spec = parser.simple_parse(threshold_alarm)
        spec["time_constraints"][0]["timezone"] = "Moon/Back"
        a = alarm.Alarm("A1", spec)

        ex = self.assertRaises(exc.InvalidSpec, a.validate)
        expected = "Invalid timezone value specified for property 'timezone' " "(Moon/Back): 'Moon/Back'"
        self.assertEqual(expected, six.text_type(ex))
开发者ID:KongJustin,项目名称:senlin,代码行数:8,代码来源:test_ceilo_alarm.py

示例15: test_combination_alarm

    def test_combination_alarm(self):
        spec = parser.simple_parse(combination_alarm)
        a = alarm.CombinationAlarm('A1', spec)

        self.assertIsNotNone(a.rule)
        self.assertEqual('combination', a.namespace)
        self.assertEqual('and', a.rule['operator'])
        self.assertIn('alarm_001', a.rule['alarm_ids'])
        self.assertIn('alarm_001', a.rule['alarm_ids'])
开发者ID:Alzon,项目名称:senlin,代码行数:9,代码来源:test_ceilo_alarm.py


注:本文中的senlin.engine.parser.simple_parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。