def _assert_move_last_from_cloned_group(self, clone_type): # pylint: disable=no-self-use cib_before = f""" <resources> <group id="G"> <primitive id="RG1" /> <primitive id="RG2" /> <primitive id="RG3" /> </group> <{clone_type} id="X-{clone_type}"> <group id="X"> <primitive id="R1" /> </group> </{clone_type}> <primitive id="R3" /> </resources> """ cib_after = """ <resources> <group id="G"> <primitive id="RG1" /> <primitive id="RG2" /> <primitive id="RG3" /> <primitive id="R1" /> </group> <primitive id="R3" /> </resources> """ cib = etree.fromstring(cib_before) hierarchy.move_resources_to_group( _resource(cib, "G"), _resources(cib, "R1"), ) assert_xml_equal(cib_after, etree_to_str(cib))
def test_no_adjacent(self): cib_before = self.cib_resources cib_after = """ <resources> <group id="G"> <primitive id="RG1" /> <primitive id="RG2" /> <primitive id="RG3" /> <primitive id="R3" /> <primitive id="R1" /> </group> <primitive id="R2" /> </resources> """ cib = etree.fromstring(cib_before) hierarchy.move_resources_to_group(_resource(cib, "G"), _resources(cib, "R3", "R1")) assert_xml_equal(cib_after, etree_to_str(cib))
def test_move_from_another_group(self): # pylint: disable=no-self-use cib_before = """ <resources> <group id="G"> <primitive id="RG1" /> <primitive id="RG2" /> <primitive id="RG3" /> </group> <group id="X"> <primitive id="R1" /> <primitive id="R2" /> </group> <primitive id="R3" /> </resources> """ cib_after = """ <resources> <group id="G"> <primitive id="RG1" /> <primitive id="RG2" /> <primitive id="RG3" /> <primitive id="R2" /> </group> <group id="X"> <primitive id="R1" /> </group> <primitive id="R3" /> </resources> """ cib = etree.fromstring(cib_before) hierarchy.move_resources_to_group( _resource(cib, "G"), _resources(cib, "R2"), ) assert_xml_equal(cib_after, etree_to_str(cib))
def create_in_cluster( env: LibraryEnvironment, ip: str, instance_name: Optional[str] = None, allow_absent_resource_agent: bool = False, ): """ Create group with ip resource and booth resource env -- provides all for communication with externals ip -- float ip address for the operation of the booth instance_name -- booth instance name allow_absent_resource_agent -- allowing creating booth resource even if its agent is not installed """ report_processor = env.report_processor booth_env = env.get_booth_env(instance_name) # Booth config path goes to CIB. Working with a mocked booth configs would # not work coorectly as the path would point to a mock file (the path to a # mock file is unknown to us in the lib anyway) # It makes sense to work with a mocked CIB, though. Users can do other # changes to the CIB and push them to the cluster at once. _ensure_live_booth_env(booth_env) resources_section = get_resources(env.get_cib()) id_provider = IdProvider(resources_section) instance_name = booth_env.instance_name # validate if resource.find_for_config(resources_section, booth_env.config_path): report_processor.report( ReportItem.error(reports.messages.BoothAlreadyInCib(instance_name)) ) # verify the config exists and is readable try: booth_env.config.raw_file.read() except RawFileError as e: report_processor.report(raw_file_error_report(e)) if report_processor.has_errors: raise LibraryError() # validation done create_id = partial( resource.create_resource_id, resources_section, instance_name ) create_primitive = partial( primitive.create, env.report_processor, resources_section, id_provider ) agent_factory = ResourceAgentFacadeFactory( env.cmd_runner(), report_processor ) # Group id validation is not needed since create_id creates a new unique # booth group identifier hierarchy.move_resources_to_group( group.append_new(resources_section, create_id("group")), [ create_primitive( create_id("ip"), _get_agent_facade( env.report_processor, agent_factory, allow_absent_resource_agent, ResourceAgentName("ocf", "heartbeat", "IPaddr2"), ), instance_attributes={"ip": ip}, ), create_primitive( create_id("service"), _get_agent_facade( env.report_processor, agent_factory, allow_absent_resource_agent, ResourceAgentName("ocf", "pacemaker", "booth-site"), ), instance_attributes={"config": booth_env.config_path}, ), ], ) env.push_cib()