def restart_workers(name, wait_time_min=1): """ Restarts workers by their name. Args: name: Name of the worker. Multiple workers can have the same name. Name is matched with `in` Returns: bool whether the restart succeeded. """ table = Table("//div[@id='records_div']/table[@class='style3']") sel.force_navigate("cfg_diagnostics_server_workers") def get_all_pids(worker_name): return {row.pid.text for row in table.rows() if worker_name in row.name.text} reload_func = partial(tb.select, "Reload current workers display") pids = get_all_pids(name) # Initiate the restart for pid in pids: table.click_cell("pid", pid) tb.select("Configuration", "Restart selected worker", invokes_alert=True) sel.handle_alert(cancel=False) reload_func() # Check they have finished def _check_all_workers_finished(): for pid in pids: if table.click_cell("pid", pid): # If could not click, it is no longer present return False # If clicked, it is still there so unsuccess return True # Wait for all original workers to be gone try: wait_for( _check_all_workers_finished, fail_func=reload_func, num_sec=wait_time_min * 60 ) except TimedOutError: return False # And now check whether the same number of workers is back online try: wait_for( lambda: len(pids) == len(get_all_pids(name)), fail_func=reload_func, num_sec=wait_time_min * 60, message="wait_workers_back_online" ) return True except TimedOutError: return False
'infrastructure_pxe_template': [ lambda ctx: template_tree(ctx.pxe_template.image_type, ctx. pxe_template.name), { 'infrastructure_pxe_template_edit': lambda _: cfg_btn('Edit this Customization Template') } ] } ], 'infrastructure_pxe_image_types': [ lambda _: image_tree(), { 'infrastructure_pxe_image_type_new': lambda _: cfg_btn('Add a new System Image Type'), 'infrastructure_pxe_image_type': [ lambda ctx: image_table.click_cell( 'name', ctx.pxe_image_type.name), { 'infrastructure_pxe_image_type_edit': lambda _: cfg_btn('Edit this System Image Type') } ] } ], 'infrastructure_iso_datastores': [ lambda _: iso_tree(), { 'infrastructure_iso_datastore_new': lambda _: cfg_btn('Add a New ISO Datastore'), 'infrastructure_iso_datastore': lambda ctx: iso_tree(ctx.pxe_iso_datastore.provider) } ] })
{'infrastructure_pxe_server_edit': lambda _: cfg_btn('Edit this PXE Server')}]}], 'infrastructure_pxe_templates': [lambda _: template_tree(), {'infrastructure_pxe_template_new': lambda _: cfg_btn('Add a New Customization Template'), 'infrastructure_pxe_template': [lambda ctx: template_tree(ctx.pxe_template.image_type, ctx.pxe_template.name), {'infrastructure_pxe_template_edit': lambda _: cfg_btn('Edit this Customization Template')}]}], 'infrastructure_pxe_image_types': [lambda _: image_tree(), {'infrastructure_pxe_image_type_new': lambda _: cfg_btn('Add a new System Image Type'), 'infrastructure_pxe_image_type': [lambda ctx: image_table.click_cell('name', ctx.pxe_image_type.name), {'infrastructure_pxe_image_type_edit': lambda _: cfg_btn('Edit this System Image Type')}]}], 'infrastructure_iso_datastores': [lambda _: iso_tree(), {'infrastructure_iso_datastore_new': lambda _: cfg_btn('Add a New ISO Datastore'), 'infrastructure_iso_datastore': lambda ctx: iso_tree(ctx.pxe_iso_datastore.provider)}]}) class PXEServer(Updateable, Pretty): """Model of a PXE Server object in CFME Args: name: Name of PXE server.
details_page = Region(infoblock_type="detail") cfg_btn = partial(tb.select, "Configuration") timeprofile_table = Table("//div[@id='main_div']//table") nav.add_branch( "my_settings", { "my_settings_time_profiles": [ lambda _: tabs.select_tab("Time Profiles"), { "timeprofile_new": lambda _: cfg_btn("Add a new Time Profile"), "timeprofile_edit": lambda ctx: timeprofile_table.click_cell( "description", ctx.timeprofile.description ), }, ], "my_settings_visual": [lambda _: tabs.select_tab("Visual"), {}], "my_settings_default_filters": [lambda _: tabs.select_tab("Default Filters"), {}], "my_settings_default_views": [lambda _: tabs.select_tab("Default Views"), {}], }, ) class Timeprofile(Updateable): timeprofile_form = Form( fields=[ ("description", Input("description")), ("scope", Select("select#profile_type")),
{'infrastructure_pxe_server_edit': lambda _: cfg_btn('Edit this PXE Server')}]}], 'infrastructure_pxe_templates': [lambda _: template_tree(), {'infrastructure_pxe_template_new': lambda _: cfg_btn('Add a New Customization Template'), 'infrastructure_pxe_template': [lambda ctx: template_tree(ctx.image_type, ctx.name), {'infrastructure_pxe_template_edit': lambda _: cfg_btn('Edit this Customization Template')}]}], 'infrastructure_pxe_image_types': [lambda _: image_tree(), {'infrastructure_pxe_image_type_new': lambda _: cfg_btn('Add a new System Image Type'), 'infrastructure_pxe_image_type': [lambda ctx: image_table.click_cell('name', ctx.name), {'infrastructure_pxe_image_type_edit': lambda _: cfg_btn('Edit this System Image Type')}]}], 'infrastructure_iso_datastores': [lambda _: iso_tree(), {'infrastructure_iso_datastore_new': lambda _: cfg_btn('Add a New ISO Datastore'), 'infrastructure_iso_datastore': lambda ctx: iso_tree(ctx.provider)}]}) class PXEServer(Updateable): """Model of a PXE Server object in CFME Args: name: Name of PXE server.
"infrastructure_pxe_templates": [ lambda _: template_tree(), { "infrastructure_pxe_template_new": lambda _: cfg_btn("Add a New Customization Template"), "infrastructure_pxe_template": [ lambda ctx: template_tree(ctx.pxe_template.image_type, ctx.pxe_template.name), {"infrastructure_pxe_template_edit": lambda _: cfg_btn("Edit this Customization Template")}, ], }, ], "infrastructure_pxe_image_types": [ lambda _: image_tree(), { "infrastructure_pxe_image_type_new": lambda _: cfg_btn("Add a new System Image Type"), "infrastructure_pxe_image_type": [ lambda ctx: image_table.click_cell("name", ctx.pxe_image_type.name), {"infrastructure_pxe_image_type_edit": lambda _: cfg_btn("Edit this System Image Type")}, ], }, ], "infrastructure_iso_datastores": [ lambda _: iso_tree(), { "infrastructure_iso_datastore_new": lambda _: cfg_btn("Add a New ISO Datastore"), "infrastructure_iso_datastore": lambda ctx: iso_tree(ctx.pxe_iso_datastore.provider), }, ], }, )
[ lambda _: accordion.click("Settings"), { "cfg_settings_region": lambda _: settings_tree.click_path("Region: Region"), "cfg_settings_defaultzone": lambda _: settings_tree.click_path("Region: Region", "Zones", "Default Zone"), "cfg_settings_schedules": [ lambda _: settings_tree.click_path("Region: Region", "Schedules"), { "cfg_settings_schedule": [ lambda ctx: records_table.click_cell("name", ctx["schedule_name"]), { "cfg_settings_schedule_edit": lambda _: tb.select("Configuration", "Edit this Schedule") } ] } ], "cfg_settings_currentserver": [ lambda _: settings_tree.click_path("Region: Region", "Zones", "Default Zone", "(current)"), {
from utils.pretty import Pretty from utils.update import Updateable details_page = Region(infoblock_type='detail') cfg_btn = partial(tb.select, 'Configuration') timeprofile_table = Table("//div[@id='main_div']//table") nav.add_branch( 'my_settings', { 'my_settings_time_profiles': [ lambda _: tabs.select_tab("Time Profiles"), { "timeprofile_new": lambda _: cfg_btn('Add a new Time Profile'), "timeprofile_edit": lambda ctx: timeprofile_table.click_cell( "description", ctx.timeprofile.description), } ], 'my_settings_visual': [lambda _: tabs.select_tab("Visual"), {}], 'my_settings_default_filters': [lambda _: tabs.select_tab("Default Filters"), {}], 'my_settings_default_views': [lambda _: tabs.select_tab("Default Views"), {}], }) class Timeprofile(Updateable): timeprofile_form = Form(fields=[ ("description", Input("description")), ("scope", { version.LOWEST: Select("select#profile_type"),