Beispiel #1
0
 def test_with_members(self):
     ent0 = self.entity_fixture("0")
     ent1 = self.entity_fixture("1")
     ent2 = self.entity_fixture("2")
     ent3 = self.entity_fixture("3")
     obj = lib.ResourceRelationNode(ent0)
     obj.add_member(lib.ResourceRelationNode(ent1))
     member = lib.ResourceRelationNode(ent2)
     member.add_member(lib.ResourceRelationNode(ent3))
     obj.add_member(member)
     self.assert_dto_equal(
         ResourceRelationDto(
             ent0,
             [
                 ResourceRelationDto(ent1, [], False),
                 ResourceRelationDto(
                     ent2,
                     [
                         ResourceRelationDto(ent3, [], False),
                     ],
                     False,
                 ),
             ],
             False,
         ),
         obj.to_dto(),
     )
Beispiel #2
0
 def test_add_member(self):
     ent0 = self.entity_fixture("0")
     ent1 = self.entity_fixture("1")
     obj = lib.ResourceRelationNode(ent0)
     obj.add_member(lib.ResourceRelationNode(ent1))
     self.assertEqual(
         ResourceRelationDto(
             ent0, [ResourceRelationDto(ent1, [], False)], False,
         ).to_dict(),
         obj.to_dto().to_dict(),
     )
Beispiel #3
0
 def test_from_dto(self):
     dto = ResourceRelationDto(self.order_entity, [
         ResourceRelationDto(D2_PRIMITIVE, [], True),
         ResourceRelationDto(D1_PRIMITIVE, [], True),
     ], False)
     obj = relations.RelationPrintableNode.from_dto(dto)
     self.assertEqual(self.order_entity, obj.relation_entity)
     self.assertEqual(False, obj.is_leaf)
     self.assertEqual(2, len(obj.members))
     self.assert_member(obj.members[0], D1_PRIMITIVE)
     self.assert_member(obj.members[1], D2_PRIMITIVE)
Beispiel #4
0
 def test_add_member_already_in_branch(self):
     ent0 = self.entity_fixture("0")
     ent1 = self.entity_fixture("1")
     obj0 = lib.ResourceRelationNode(ent0)
     obj1 = lib.ResourceRelationNode(ent1)
     obj0.add_member(obj1)
     obj1.add_member(obj0)
     self.assert_dto_equal(
         ResourceRelationDto(ent0, [ResourceRelationDto(ent1, [], False)],
                             False),
         obj0.to_dto(),
     )
Beispiel #5
0
 def test_success(self, mock_print):
     self.lib_call.return_value = ResourceRelationDto(
         RelationEntityDto("d1", "primitive", [], {
             "class": "ocf",
             "provider": "pacemaker",
             "type": "Dummy",
         }),
         [
             ResourceRelationDto(
                 RelationEntityDto(
                     "order1", ResourceRelationType.ORDER, [], {
                         "first-action": "start",
                         "first": "d1",
                         "then-action": "start",
                         "then": "d2",
                         "kind": "Mandatory",
                         "symmetrical": "true",
                     }), [
                         ResourceRelationDto(
                             RelationEntityDto(
                                 "d2", "primitive", [], {
                                     "class": "ocf",
                                     "provider": "heartbeat",
                                     "type": "Dummy",
                                 }), [], False),
                     ], False),
             ResourceRelationDto(
                 RelationEntityDto(
                     "inner:g1", ResourceRelationType.INNER_RESOURCES, [],
                     {}), [
                         ResourceRelationDto(
                             RelationEntityDto("g1", "group", [], {}),
                             [],
                             True,
                         ),
                     ], False)
         ],
         False,
     ).to_dict()
     relations.show_resource_relations_cmd(self.lib, ["d1"],
                                           dict_to_modifiers({}))
     self.lib_call.assert_called_once_with("d1")
     self.assertEqual([
         mock.call("d1 (resource: ocf:pacemaker:Dummy)"),
         mock.call("|- inner resource(s) (None)"),
         mock.call("|  `- g1 (resource: group) [displayed elsewhere]"),
         mock.call("`- order (None)"),
         mock.call("   |  start d1 then start d2"),
         mock.call("   |  kind=Mandatory symmetrical=true"),
         mock.call("   `- d2 (resource: ocf:heartbeat:Dummy)"),
     ], mock_print.call_args_list)
Beispiel #6
0
    def test_from_dto(self):
        inner_ent = RelationEntityDto("inner:g1",
                                      ResourceRelationType.INNER_RESOURCES, [],
                                      {})
        outer_ent = RelationEntityDto("outer:g1",
                                      ResourceRelationType.OUTER_RESOURCE, [],
                                      {})
        order_ent1 = RelationEntityDto("order1", ResourceRelationType.ORDER,
                                       [], {})
        order_ent2 = RelationEntityDto("order2", ResourceRelationType.ORDER,
                                       [], {})
        order_set_ent = RelationEntityDto("order_set",
                                          ResourceRelationType.ORDER_SET, [],
                                          {})

        dto = ResourceRelationDto(
            D1_PRIMITIVE,
            [
                _fixture_res_rel_dto(order_set_ent),
                _fixture_res_rel_dto(order_ent2),
                _fixture_res_rel_dto(outer_ent),
                _fixture_res_rel_dto(inner_ent),
                _fixture_res_rel_dto(order_ent1),
            ],
            False,
        )
        obj = relations.ResourcePrintableNode.from_dto(dto)
        self.assertEqual(D1_PRIMITIVE, obj.relation_entity)
        self.assertEqual(False, obj.is_leaf)
        expected_members = (inner_ent, outer_ent, order_ent1, order_ent2,
                            order_set_ent)
        self.assertEqual(len(expected_members), len(obj.members))
        for i, member in enumerate(obj.members):
            self.assert_member(member, expected_members[i])
Beispiel #7
0
 def test_no_members(self):
     ent = self.entity_fixture("0")
     obj = lib.ResourceRelationNode(ent)
     self.assertEqual(
         ResourceRelationDto(ent, [], False).to_dict(),
         obj.to_dto().to_dict(),
     )
Beispiel #8
0
 def test_add_member_already_in_different_branch(self):
     ent0 = self.entity_fixture("0")
     ent1 = self.entity_fixture("1")
     obj0 = lib.ResourceRelationNode(ent0)
     obj0.add_member(lib.ResourceRelationNode(ent1))
     obj0.add_member(lib.ResourceRelationNode(ent1))
     self.assertEqual(
         ResourceRelationDto(
             ent0, [
                 ResourceRelationDto(ent1, [], False),
                 ResourceRelationDto(ent1, [], False),
             ],
             False,
         ).to_dict(),
         obj0.to_dto().to_dict(),
     )
Beispiel #9
0
 def test_stop(self):
     ent = self.entity_fixture("0")
     obj = lib.ResourceRelationNode(ent)
     obj.stop()
     self.assert_dto_equal(
         ResourceRelationDto(ent, [], True),
         obj.to_dto(),
     )
Beispiel #10
0
 def test_add_member_itself(self):
     ent = self.entity_fixture("0")
     obj = lib.ResourceRelationNode(ent)
     obj.add_member(obj)
     self.assert_dto_equal(
         ResourceRelationDto(ent, [], False),
         obj.to_dto(),
     )
Beispiel #11
0
 def setUp(self):
     self.maxDiff = None
     self.lib_call = mock.Mock()
     self.lib = mock.Mock(spec_set=["resource"])
     self.lib.resource = mock.Mock(spec_set=["get_resource_relations_tree"])
     self.lib.resource.get_resource_relations_tree = self.lib_call
     self.lib_call.return_value = ResourceRelationDto(
         RelationEntityDto("d1", "primitive", [], {
             "class": "ocf",
             "provider": "pacemaker",
             "type": "Dummy",
         }),
         [
             ResourceRelationDto(
                 RelationEntityDto(
                     "order1", ResourceRelationType.ORDER, [], {
                         "first-action": "start",
                         "first": "d1",
                         "then-action": "start",
                         "then": "d2",
                         "kind": "Mandatory",
                         "symmetrical": "true",
                     }), [
                         ResourceRelationDto(
                             RelationEntityDto(
                                 "d2", "primitive", [], {
                                     "class": "ocf",
                                     "provider": "heartbeat",
                                     "type": "Dummy",
                                 }), [], False),
                     ], False),
             ResourceRelationDto(
                 RelationEntityDto(
                     "inner:g1", ResourceRelationType.INNER_RESOURCES, [],
                     {}), [
                         ResourceRelationDto(
                             RelationEntityDto("g1", "group", [], {}),
                             [],
                             True,
                         ),
                     ], False)
         ],
         False,
     ).to_dict()
Beispiel #12
0
def show_resource_relations_cmd(
    lib: Any,
    argv: Sequence[str],
    modifiers: InputModifiers,
) -> None:
    """
    Options:
      * -f - CIB file
    """
    modifiers.ensure_only_supported("-f")
    if len(argv) != 1:
        raise CmdLineInputError()
    tree = ResourcePrintableNode.from_dto(
        ResourceRelationDto.from_dict(
            lib.resource.get_resource_relations_tree(argv[0])))
    for line in tree_to_lines(tree):
        print(line)
Beispiel #13
0
 def to_dto(self) -> ResourceRelationDto:
     return ResourceRelationDto(
         self._obj,
         [member.to_dto() for member in self._members],
         self._is_leaf,
     )
Beispiel #14
0
def _fixture_res_rel_dto(ent):
    return ResourceRelationDto(ent, [], True)