Example #1
0
 def test_simple_in_group(self):
     resources_members = ["outer:g1"]
     resources = {
         "d1": self.primitive_fixture("d1", resources_members),
         "d2": self.primitive_fixture("d2", resources_members),
         "g1": RelationEntityDto("g1", "group", ["inner:g1"], {"id": "g1"}),
     }
     relations = {
         "inner:g1":
         RelationEntityDto(
             "inner:g1",
             ResourceRelationType.INNER_RESOURCES,
             ["d1", "d2"],
             {"id": "g1"},
         ),
         "outer:g1":
         RelationEntityDto(
             "outer:g1",
             ResourceRelationType.OUTER_RESOURCE,
             ["g1"],
             {"id": "g1"},
         ),
     }
     expected = dict(
         relation_entity=dto.to_dict(resources["d1"]),
         is_leaf=False,
         members=[
             dict(
                 relation_entity=dto.to_dict(relations["outer:g1"]),
                 is_leaf=False,
                 members=[
                     dict(
                         relation_entity=dto.to_dict(resources["g1"]),
                         is_leaf=False,
                         members=[
                             dict(
                                 relation_entity=dto.to_dict(
                                     relations["inner:g1"]),
                                 is_leaf=False,
                                 members=[
                                     dict(
                                         relation_entity=dto.to_dict(
                                             resources["d2"]),
                                         is_leaf=False,
                                         members=[],
                                     ),
                                 ],
                             ),
                         ],
                     ),
                 ],
             ),
         ],
     )
     self.assertEqual(
         expected,
         dto.to_dict(
             lib.ResourceRelationTreeBuilder(
                 resources, relations).get_tree("d1").to_dto()),
     )
Example #2
0
 def test_simple_order(self):
     resources_members = ["order-d1-d2-mandatory"]
     resources = {
         "d1": self.primitive_fixture("d1", resources_members),
         "d2": self.primitive_fixture("d2", resources_members),
     }
     relations = {
         "order-d1-d2-mandatory":
         RelationEntityDto(
             "order-d1-d2-mandatory",
             ResourceRelationType.ORDER,
             members=["d1", "d2"],
             metadata={
                 "id": "order-d1-d2-mandatory",
                 "first": "d1",
                 "first-action": "start",
                 "then": "d2",
                 "then-action": "start",
                 "kind": "Mandatory",
             },
         ),
     }
     expected = dict(
         relation_entity=dto.to_dict(resources["d2"]),
         is_leaf=False,
         members=[
             dict(
                 relation_entity=dto.to_dict(
                     relations["order-d1-d2-mandatory"]),
                 is_leaf=False,
                 members=[
                     dict(
                         relation_entity=dto.to_dict(resources["d1"]),
                         is_leaf=False,
                         members=[],
                     )
                 ],
             )
         ],
     )
     self.assertEqual(
         expected,
         dto.to_dict(
             lib.ResourceRelationTreeBuilder(
                 resources, relations).get_tree("d2").to_dto()),
     )
Example #3
0
 def test_order_loop(self):
     resources_members = ["order-d1-d2-mandatory", "order-d2-d1-mandatory"]
     resources = {
         "d1": self.primitive_fixture("d1", resources_members),
         "d2": self.primitive_fixture("d2", resources_members),
     }
     order_fixture = lambda r1, r2: RelationEntityDto(
         f"order-{r1}-{r2}-mandatory",
         ResourceRelationType.ORDER,
         members=[r1, r2],
         metadata={
             "id": f"order-{r1}-{r2}-mandatory",
             "first": r1,
             "first-action": "start",
             "then": r2,
             "then-action": "start",
             "kind": "Mandatory",
         },
     )
     relations = {
         "order-d1-d2-mandatory": order_fixture("d1", "d2"),
         "order-d2-d1-mandatory": order_fixture("d2", "d1"),
     }
     expected = dict(
         relation_entity=dto.to_dict(resources["d1"]),
         is_leaf=False,
         members=[
             dict(
                 relation_entity=dto.to_dict(
                     relations["order-d1-d2-mandatory"]),
                 is_leaf=False,
                 members=[
                     dict(
                         relation_entity=dto.to_dict(resources["d2"]),
                         is_leaf=False,
                         members=[
                             dict(
                                 relation_entity=dto.to_dict(
                                     relations["order-d2-d1-mandatory"]),
                                 is_leaf=True,
                                 members=[],
                             ),
                         ],
                     ),
                 ],
             ),
             dict(
                 relation_entity=dto.to_dict(
                     relations["order-d2-d1-mandatory"]),
                 is_leaf=False,
                 members=[
                     dict(
                         relation_entity=dto.to_dict(resources["d2"]),
                         is_leaf=True,
                         members=[],
                     ),
                 ],
             ),
         ],
     )
     self.assertEqual(
         expected,
         dto.to_dict(
             lib.ResourceRelationTreeBuilder(
                 resources, relations).get_tree("d1").to_dto()),
     )
Example #4
0
 def test_simple_order_set(self):
     res_list = ("d1", "d2", "d3", "d4", "d5", "d6")
     resources_members = ["pcs_rsc_order_set_1"]
     resources = {
         _id: self.primitive_fixture(_id, resources_members)
         for _id in res_list
     }
     relations = {
         "pcs_rsc_order_set_1":
         RelationEntityDto(
             "pcs_rsc_order_set_1",
             ResourceRelationType.ORDER_SET,
             members=["d1", "d2", "d3", "d4", "d5", "d6"],
             metadata={
                 "id":
                 "pcs_rsc_order_set_1",
                 "sets": [
                     {
                         "id": "pcs_rsc_set_1",
                         "metadata": {
                             "id": "pcs_rsc_set_1",
                             "sequential": "true",
                             "require-all": "true",
                             "action": "start",
                         },
                         "members": ["d1", "d3", "d2"],
                     },
                     {
                         "id": "pcs_rsc_set_2",
                         "metadata": {
                             "id": "pcs_rsc_set_2",
                             "sequential": "false",
                             "require-all": "false",
                             "action": "stop",
                         },
                         "members": ["d6", "d5", "d4"],
                     },
                 ],
                 "kind":
                 "Serialize",
                 "symmetrical":
                 "true",
             },
         ),
     }
     get_res = lambda _id: dict(
         relation_entity=dto.to_dict(resources[_id]),
         is_leaf=False,
         members=[],
     )
     expected = dict(
         relation_entity=dto.to_dict(resources["d5"]),
         is_leaf=False,
         members=[
             dict(
                 relation_entity=dto.to_dict(
                     relations["pcs_rsc_order_set_1"]),
                 is_leaf=False,
                 members=[
                     get_res(_id) for _id in ("d1", "d2", "d3", "d4", "d6")
                 ],
             )
         ],
     )
     self.assertEqual(
         expected,
         dto.to_dict(
             lib.ResourceRelationTreeBuilder(
                 resources, relations).get_tree("d5").to_dto()),
     )
Example #5
0
 def test_resource_not_present(self):
     with self.assertRaises(AssertionError):
         lib.ResourceRelationTreeBuilder({}, {}).get_tree("not_existing")