コード例 #1
0
    def test_get_schedulers(self, leaf_scheduler_cls):
        leaf_scheduler = MagicMock()
        leaf_scheduler_cls.return_value = leaf_scheduler

        common.services.register(Host.Iface, MagicMock())
        scheduler_handler = SchedulerHandler()
        common.services.register(Scheduler.Iface, scheduler_handler)
        agent_config = MagicMock()
        agent_config.reboot_required = False
        common.services.register(ServiceName.AGENT_CONFIG, agent_config)
        common.services.register(ServiceName.REQUEST_ID, MagicMock())

        agent_control_handler = AgentControlHandler()
        request = GetSchedulersRequest()
        response = agent_control_handler.get_schedulers(request)

        child_host = ChildInfo(id="foo", address="address", port=12345)

        assert_that(response.schedulers, is_(empty()))
        leaf_scheduler_id = "leaf1"
        scheduler_handler.configure(
            [SchedulerRole(leaf_scheduler_id, "parent1",
                           host_children=[child_host])])
        leaf_scheduler._get_hosts.return_value = [child_host]

        response = agent_control_handler.get_schedulers(request)
        assert_that(response.schedulers, has_length(1))

        scheduler = response.schedulers[0]
        assert_that(scheduler.role.id, is_(leaf_scheduler_id))
        assert_that(scheduler.role.host_children[0], is_(child_host))
        assert_that(len(scheduler.role.host_children), is_(1))
        assert_that(response.result, is_(GetSchedulersResultCode.OK))
コード例 #2
0
	def _parse_section_nodes(para):
		nonlocal next_parser, level, in_child, para_node
		props = _get_para_node_props(para)
		if props:
			if level is None:
				level = props['indent']
			if not matchers.isint(level) or props['indent'] > level:
				success = next_parser(para)
				in_child = in_child or success
				return success
			elif props['indent'] < level:
				# if not handled by a parent parser,
				# but still less than our indent level, then
				# don't know how to handle
				raise Exception('unknown indent for', para['index'], para)
			elif props['indent'] == level:
				para_node = _aaa(dom, 'para', **props)
				next_parser = parse_section_nodes(para_node, NextParser)
				if props['num2']:
					in_child = True
					_merge(para, {'runs': [{'text': lambda t: parens_re.sub('  ', t, 1)}]})
					para['text'] = _para_text_content(para)
					para['richtext'] = _para_rich_text_content(para)
					return next_parser(para)

				in_child = False
				return True

		elif matchers.section_heading(para):
			match = para['text_re']
			if level is None:
				level = match.group('prefix')

			if level == match.group('prefix'):
				heading_node = _aaa(dom, 'para', **match.groupdict())
				next_parser = parse_section_nodes(heading_node, NextParser)
				in_child = True
				return True
			else:
				success = next_parser(para)
				in_child = in_child or success
				return success
		elif not matchers.empty(para):
			if in_child and next_parser(para):
				return True
			elif not matchers.centered(para):
				# lookahead to determine if text belongs to node or its parent
				next_level = _get_next_level(para)
				if para_node is not None and next_level and (not matchers.isint(level) or next_level >= level):
					_make_text(para_node, para['richtext'], para=para['index'])
				else:
					_make_text(dom, para['richtext'], para=para['index'], after=True)
				return True
			else:
				return False
		else:
			return False
コード例 #3
0
 def next_para():
     paras = section['paragraphs']
     next_index = para['index'] - paras[0]['index'] + 1
     if next_index >= len(paras):
         return None
     next_p = prep_para(copy.deepcopy(paras[next_index]))
     if matchers.empty(next_p):
         next_p = next_p['next']()
     return next_p
コード例 #4
0
		def next_para():
			paras = section['paragraphs']
			next_index = para['index'] - paras[0]['index'] + 1
			if next_index >= len(paras):
				return None
			next_p = prep_para(copy.deepcopy(paras[next_index]))
			if matchers.empty(next_p):
				next_p = next_p['next']()
			return next_p
コード例 #5
0
	def _parse_section_text(para):
		nonlocal started
		if matchers.empty(para):
			return True
		elif next_parser(para):
			started = True
			return True
		elif not started:
			_make_text(dom, para['richtext'])
			return True
		else:
			return False
コード例 #6
0
    def test_configure_create_leaf_scheduler(self, leaf_scheduler_cls):
        leaf_scheduler = MagicMock()
        leaf_scheduler_cls.return_value = leaf_scheduler

        handler = SchedulerHandler()
        assert_that(handler._schedulers, is_(empty()))

        handler.configure(
            [SchedulerRole("leaf-scheduler", "parent-id",
                           host_children=[ChildInfo(id="foo")])])
        assert_that(handler._schedulers, has_length(1))

        scheduler = handler._schedulers["leaf-scheduler"]
        assert_that(scheduler.id, is_(leaf_scheduler.id))
        scheduler.configure.assert_called_once_with([ChildInfo(id="foo")])
コード例 #7
0
    def test_configure_create_leaf_scheduler(self, leaf_scheduler_cls):
        leaf_scheduler = MagicMock()
        leaf_scheduler_cls.return_value = leaf_scheduler

        handler = SchedulerHandler()
        assert_that(handler._schedulers, is_(empty()))

        handler.configure([
            SchedulerRole("leaf-scheduler",
                          "parent-id",
                          host_children=[ChildInfo(id="foo")])
        ])
        assert_that(handler._schedulers, has_length(1))

        scheduler = handler._schedulers["leaf-scheduler"]
        assert_that(scheduler.id, is_(leaf_scheduler.id))
        scheduler.configure.assert_called_once_with([ChildInfo(id="foo")])
コード例 #8
0
		def _parse_toc(para):
			nonlocal next_parser, just_started
			if para.get(prefix.lower(), True) and matcher(para):
				match = para['text_re']
				node_data = match.groupdict()
				if node_data['heading']:
					node_data['heading'] = repealed_re.sub('', node_data['heading'])
				toc_node = _aaa(dom, 'container', prefix, para=para['index'], **match.groupdict())
				next_parser = NextParser(toc_node)
				just_started = True
				return True
			elif just_started:
				# skip table of contents
				if matchers.toc_entry(para) or matchers.empty(para):
					return True
				else:
					just_started = False
					return next_parser(para)
			else:
				return next_parser(para)
コード例 #9
0
	def _parse_unit(para):
		nonlocal next_parser, just_started, unit_detected

		if (just_started or unit_detected) and matchers.unit(para):
			match = para['text_re']
			node_data = match.groupdict()
			if node_data['heading']:
				node_data['heading'] = repealed_re.sub('', node_data['heading'])
			toc_node = _aaa(dom, 'container', 'Unit', para=para['index'], **match.groupdict())
			next_parser = NextParser(toc_node)
			unit_detected = True
			just_started = True
			return True
		elif just_started:
			# skip table of contents
			if matchers.toc_entry(para) or matchers.empty(para):
				return True
			else:
				just_started = False
				return next_parser(para)
		elif next_parser:
			return next_parser(para)
		else:
			return False
コード例 #10
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_str(self):
     assert_that('string', is_not(empty()))
コード例 #11
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_list(self):
     assert_that(list(), is_(empty()))
コード例 #12
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_str(self):
     assert_that(str(), is_(empty()))
コード例 #13
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_unicode(self):
     assert_that(u'', is_(empty()))
コード例 #14
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_iterator(self):
     assert_that(iter([1]), is_not(empty()))
コード例 #15
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_generator(self):
     assert_that((a for a in list()), is_(empty()))
コード例 #16
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_tuple(self):
     assert_that(tuple(), is_(empty()))
コード例 #17
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_iterator(self):
     assert_that(iter(list()), is_(empty()))
コード例 #18
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_unicode(self):
     assert_that(u'unicode', is_not(empty()))
コード例 #19
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_set(self):
     assert_that(set(self.tuple), is_not(empty()))
コード例 #20
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_tuple(self):
     assert_that(self.tuple, is_not(empty()))
コード例 #21
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_not_empty_generator(self):
     assert_that((i for i in range(1)), is_not(empty()))
コード例 #22
0
ファイル: test_empty.py プロジェクト: jvrsantacruz/matchers
 def test_empty_dict(self):
     assert_that(dict(), is_(empty()))