コード例 #1
0
ファイル: test_nvpair.py プロジェクト: tomjelinek/pcs
 def test_empty(self):
     resource_element = etree.fromstring("""
         <primitive>
             <meta_attributes/>
         </primitive>
     """)
     self.assertEqual(
         dict(),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )
コード例 #2
0
ファイル: test_nvpair.py プロジェクト: thulyacloud/pcs
 def test_empty(self):
     resource_element = etree.fromstring("""
         <primitive>
             <meta_attributes/>
         </primitive>
     """)
     self.assertEqual(
         dict(),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )
コード例 #3
0
ファイル: test_nvpair.py プロジェクト: thulyacloud/pcs
 def test_non_empty(self):
     resource_element = etree.fromstring("""
         <primitive>
             <meta_attributes>
                 <nvpair id="a" name="attr_name" value="value"/>
                 <nvpair id="b" name="other_name" value="other-value"/>
             </meta_attributes>
         </primitive>
     """)
     self.assertEqual(
         dict(
             attr_name="value",
             other_name="other-value",
         ),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )
コード例 #4
0
ファイル: test_nvpair.py プロジェクト: tomjelinek/pcs
 def test_non_empty(self):
     resource_element = etree.fromstring("""
         <primitive>
             <meta_attributes>
                 <nvpair id="a" name="attr_name" value="value"/>
                 <nvpair id="b" name="other_name" value="other-value"/>
             </meta_attributes>
         </primitive>
     """)
     self.assertEqual(
         dict(
             attr_name="value",
             other_name="other-value",
         ),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )
コード例 #5
0
ファイル: primitive.py プロジェクト: miladalipour99/pcs
def validate_resource_instance_attributes_update(
    resource_agent, instance_attributes, resource_id, resources_section,
    force=False
):
    return (
        resource_agent.validate_parameters_update(
            get_nvset_as_dict(
                "instance_attributes",
                find_element_by_tag_and_id(
                    "primitive", resources_section, resource_id
                )
            ),
            instance_attributes,
            force=force,
        )
        +
        validate_unique_instance_attributes(
            resource_agent, instance_attributes, resources_section,
            resource_id=resource_id, force=force,
        )
    )
コード例 #6
0
ファイル: test_nvpair.py プロジェクト: thulyacloud/pcs
 def test_no_element(self):
     resource_element = etree.fromstring("<primitive/>")
     self.assertEqual(
         dict(),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )
コード例 #7
0
ファイル: primitive.py プロジェクト: mirecheck/pcs
def validate_resource_instance_attributes_update(
    resource_agent: ResourceAgentFacade,
    instance_attributes: Mapping[str, str],
    resource_id: str,
    resources_section: _Element,
    force: bool = False,
) -> reports.ReportItemList:
    # TODO This function currently accepts the updated resource as a string and
    # finds the corresponding xml element by itself. This is needed as the
    # function is called from old pcs code which uses dom while pcs.lib uses
    # lxml. Once resource update command is moved to pcs.lib, this function
    # will be fixed to accept the updated resource as an element instead of a
    # string.
    report_items: reports.ReportItemList = []
    current_instance_attrs = get_nvset_as_dict(
        INSTANCE_ATTRIBUTES_TAG,
        find_element_by_tag_and_id(TAG, resources_section, resource_id),
    )

    if resource_agent.metadata.agent_exists:
        report_items += validate.ValidatorAll(
            resource_agent.get_validators_allowed_parameters(force)
        ).validate(
            # Do not report unknown parameters already set in the CIB. It would
            # be confusing to report an error in an option not actually created
            # now.
            {
                name: value
                for name, value in instance_attributes.items()
                if name not in current_instance_attrs
            }
        )
        report_items += validate.ValidatorAll(
            resource_agent.get_validators_deprecated_parameters()
        ).validate(
            {
                name: value
                for name, value in instance_attributes.items()
                # Allow removing deprecated parameters
                if value != ""
                # we create a custom report for stonith parameter "action"
                and not (
                    resource_agent.metadata.name.is_stonith and name == "action"
                )
            }
        )

        # Check that required parameters have not been removed. This is
        # complicated by two facts:
        # * parameters may by deprecated by other parameters, setting one
        #   required parameter from such group is enough
        # * we only want to report errors related to attributes to be updated
        final_attrs = dict(current_instance_attrs)
        for name, value in instance_attributes.items():
            if value == "":
                final_attrs.pop(name, None)
            else:
                final_attrs[name] = value
        report_items += validate.ValidatorAll(
            # Limit validation only to parameters entered now in an update
            # command. We don't want to report missing parameters not mentioned
            # in a command now, that would be confusing to users.
            resource_agent.get_validators_required_parameters(
                force, only_parameters=instance_attributes.keys()
            )
        ).validate(final_attrs)

    if resource_agent.metadata.name.is_stonith:
        report_items += _validate_stonith_action(instance_attributes, force)

    if resource_agent.metadata.agent_exists:
        report_items += _validate_unique_instance_attributes(
            resource_agent.metadata,
            instance_attributes,
            resources_section,
            resource_id=resource_id,
            force=force,
        )
    return report_items
コード例 #8
0
ファイル: test_nvpair.py プロジェクト: tomjelinek/pcs
 def test_no_element(self):
     resource_element = etree.fromstring("<primitive/>")
     self.assertEqual(
         dict(),
         nvpair.get_nvset_as_dict("meta_attributes", resource_element),
     )