加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
leapp-add-command-no-rhsm_skip.patch 8.25 KB
一键复制 编辑 原始数据 按行查看 历史
崔立昊 提交于 2022-06-01 12:39 . 删除文件 0001-add-checkbaota.patch
From e8aafed7ab22909f8210c98507d141f773554eb2 Mon Sep 17 00:00:00 2001
From: FrankCui713 <FrankCui713@163.com>
Date: Wed, 1 Jun 2022 20:30:08 +0800
Subject: [PATCH] add command no-rhsm_skip
Signed-off-by: FrankCui713 <FrankCui713@163.com>
---
leapp/cli/upgrade/__init__.py | 24 +++++++++++++++++++++---
leapp/workflows/__init__.py | 24 +++++++++++++++++++++++-
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/leapp/cli/upgrade/__init__.py b/leapp/cli/upgrade/__init__.py
index a6a9935..5ae3aec 100644
--- a/leapp/cli/upgrade/__init__.py
+++ b/leapp/cli/upgrade/__init__.py
@@ -150,6 +150,7 @@ def handle_output_level(args):
def prepare_configuration(args):
+ skip_actors = []
"""Returns a configuration dict object while setting a few env vars as a side-effect"""
if args.whitelist_experimental:
args.whitelist_experimental = list(itertools.chain(*[i.split(',') for i in args.whitelist_experimental]))
@@ -161,12 +162,21 @@ def prepare_configuration(args):
os.environ['LEAPP_NO_RHSM'] = '1'
elif os.getenv('LEAPP_NO_RHSM') != '1':
os.environ['LEAPP_NO_RHSM'] = os.getenv('LEAPP_DEVEL_SKIP_RHSM', '0')
+ if args.no_rhsm_skip:
+ os.environ['LEAPP_NO_RHSM'] = '1'
+ args.no_rhsm_skip = list(itertools.chain(*[i.split(',') for i in args.no_rhsm_skip]))
+ # character to lower
+ skip_actors = [skipactor.lower() for skipactor in args.no_rhsm_skip if isinstance(skipactor,str)==True]
+ elif os.getenv('LEAPP_NO_RHSM') != '1':
+ os.environ['LEAPP_NO_RHSM'] = os.getenv('LEAPP_DEVEL_SKIP_RHSM', '0')
if args.enablerepo:
os.environ['LEAPP_ENABLE_REPOS'] = ','.join(args.enablerepo)
+
configuration = {
'debug': os.getenv('LEAPP_DEBUG', '0'),
'verbose': os.getenv('LEAPP_VERBOSE', '0'),
'whitelist_experimental': args.whitelist_experimental or (),
+ 'skip_actor':skip_actors or []
}
return configuration
@@ -187,10 +197,12 @@ def process_whitelist_experimental(repositories, workflow, configuration, logger
@command_opt('resume', is_flag=True, help='Continue the last execution after it was stopped (e.g. after reboot)')
@command_opt('reboot', is_flag=True, help='Automatically performs reboot when requested.')
@command_opt('whitelist-experimental', action='append', metavar='ActorName', help='Enable experimental actors')
+
@command_opt('debug', is_flag=True, help='Enable debug mode', inherit=False)
@command_opt('verbose', is_flag=True, help='Enable verbose logging', inherit=False)
@command_opt('no-rhsm', is_flag=True, help='Use only custom repositories and skip actions'
' with Red Hat Subscription Manager')
+@command_opt('no-rhsm_skip', action='append', metavar='ActorName', help='Enable skip actors with no-rhsm')
@command_opt('enablerepo', action='append', metavar='<repoid>',
help='Enable specified repository. Can be used multiple times.')
def upgrade(args):
@@ -238,7 +250,10 @@ def upgrade(args):
with beautify_actor_exception():
logger.info("Using answerfile at %s", answerfile_path)
workflow.load_answers(answerfile_path, userchoices_path)
- workflow.run(context=context, skip_phases_until=skip_phases_until, skip_dialogs=True)
+ skip_actors = configuration.get('skip_actor')
+ print("The skipped actors will be:")
+ print(skip_actors)
+ workflow.run(context=context, skip_phases_until=skip_phases_until, skip_dialogs=True,skip_actors=skip_actors)
logger.info("Answerfile will be created at %s", answerfile_path)
workflow.save_answers(answerfile_path, userchoices_path)
@@ -259,6 +274,7 @@ def upgrade(args):
@command_opt('verbose', is_flag=True, help='Enable verbose logging', inherit=False)
@command_opt('no-rhsm', is_flag=True, help='Use only custom repositories and skip actions'
' with Red Hat Subscription Manager')
+@command_opt('no-rhsm_skip', action='append', metavar='ActorName', help='Enable skip actors with no-rhsm')
@command_opt('enablerepo', action='append', metavar='<repoid>',
help='Enable specified repository. Can be used multiple times.')
def preupgrade(args):
@@ -276,7 +292,6 @@ def preupgrade(args):
archive_logfiles()
logger = configure_logger('leapp-preupgrade.log')
os.environ['LEAPP_EXECUTION_ID'] = context
-
try:
repositories = load_repositories()
except LeappError as exc:
@@ -288,7 +303,10 @@ def preupgrade(args):
workflow.load_answers(answerfile_path, userchoices_path)
until_phase = 'ReportsPhase'
logger.info('Executing workflow until phase: %s', until_phase)
- workflow.run(context=context, until_phase=until_phase, skip_dialogs=True)
+ skip_actors = configuration.get('skip_actor')
+ print("The skipped actors will be:")
+ print(skip_actors)
+ workflow.run(context=context, until_phase=until_phase, skip_dialogs=True,skip_actors=skip_actors)
logger.info("Answerfile will be created at %s", answerfile_path)
workflow.save_answers(answerfile_path, userchoices_path)
diff --git a/leapp/workflows/__init__.py b/leapp/workflows/__init__.py
index 7d8535e..342637f 100644
--- a/leapp/workflows/__init__.py
+++ b/leapp/workflows/__init__.py
@@ -39,6 +39,17 @@ def phase_names(phase=None):
return (phase[0].__name__.lower(), phase[0].name.lower()) if phase else ()
+def tag_names(tag=None):
+ return (tag.__name__.lower(), tag.name.lower()) if tag else ()
+
+
+def contains_tag(needle_tags, actor_tags):
+ hay = set()
+ for tag in actor_tags:
+ hay.update(tag_names(tag))
+ return bool(hay.intersection([tag.lower() for tag in needle_tags]))
+
+
class WorkflowMeta(type):
"""
Meta class for the registration of workflows
@@ -230,7 +241,8 @@ class Workflow(with_metaclass(WorkflowMeta)):
if phase:
return phase in [name for phs in self._phase_actors for name in phase_names(phs)]
- def run(self, context=None, until_phase=None, until_actor=None, skip_phases_until=None, skip_dialogs=False):
+ def run(self, context=None, until_phase=None, until_actor=None, skip_phases_until=None, skip_dialogs=False,skip_actors=[],
+ only_with_tags=None):
"""
Executes the workflow
@@ -255,6 +267,8 @@ class Workflow(with_metaclass(WorkflowMeta)):
The value of skip_dialogs will be passed to the actors that can theoretically use it for
their purposes.
:type skip_dialogs: bool
+ :param only_with_tags: Executes only actors with the given tag, any other actor is going to get skipped.
+ :type only_with_tags: List[str]
"""
context = context or str(uuid.uuid4())
@@ -273,6 +287,7 @@ class Workflow(with_metaclass(WorkflowMeta)):
needle_phase = needle_phase.lower()
needle_stage = (needle_stage or '').lower()
needle_actor = (until_actor or '').lower()
+
self._errors = get_errors(context)
config_model = type(self).configuration
@@ -303,6 +318,8 @@ class Workflow(with_metaclass(WorkflowMeta)):
for actor in stage.actors:
if early_finish:
return
+ if actor.name in skip_actors: #skip the actor
+ continue
designation = ''
if ExperimentalTag in actor.tags:
designation = '[EXPERIMENTAL]'
@@ -310,6 +327,11 @@ class Workflow(with_metaclass(WorkflowMeta)):
current_logger.info("Skipping experimental actor {actor}".format(actor=actor.name))
continue
+ if only_with_tags and not contains_tag(only_with_tags, actor.tags):
+ current_logger.info(
+ "Actor {actor} does not contain any required tag. Skipping.".format(actor=actor.name))
+ continue
+
display_status_current_actor(actor, designation=designation)
current_logger.info("Executing actor {actor} {designation}".format(designation=designation,
actor=actor.name))
--
1.8.3.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化