当前位置: 首页>>代码示例>>Python>>正文


Python GlobalCommandHookRegistry.setup方法代码示例

本文整理汇总了Python中apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry.setup方法的典型用法代码示例。如果您正苦于以下问题:Python GlobalCommandHookRegistry.setup方法的具体用法?Python GlobalCommandHookRegistry.setup怎么用?Python GlobalCommandHookRegistry.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry的用法示例。


在下文中一共展示了GlobalCommandHookRegistry.setup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_skip_hooks_in_create

# 需要导入模块: from apache.aurora.client.cli.command_hooks import GlobalCommandHookRegistry [as 别名]
# 或者: from apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry import setup [as 别名]
  def test_skip_hooks_in_create(self):
    """Run a test of create, with a hook that should forbid running create, but
    with a user who's covered by one of the hook skip exception rules - so it
    should succeed.
    """

    GlobalCommandHookRegistry.reset()
    command_hook = HookForTesting(True)
    GlobalCommandHookRegistry.register_command_hook(command_hook)
    command_hook_two = SecondHookForTesting(False)
    GlobalCommandHookRegistry.register_command_hook(command_hook_two)
    mock_response = Mock()
    mock_context = FakeAuroraCommandContext()

    with contextlib.nested(
        patch("apache.aurora.client.cli.jobs.Job.create_context", return_value=mock_context),
        patch("requests.get", return_value=mock_response),
        patch("getpass.getuser", return_value="bozo")):
      mock_response.json.return_value = {
        "a": {
          "users": ["bozo", "clown"],
          "commands": {"job": ["killall", "create"]},
          "hooks": ["test_hook", "second"]
        },
        "b": {
          "commands": {"user": ["kick"]},
        }
      }

      mock_query = self.create_mock_query()
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.INIT))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      mock_context.get_api("west").check_status.side_effect = (
        lambda x: self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      api = mock_context.get_api("west")
      api.create_job.return_value = self.get_createjob_response()
      GlobalCommandHookRegistry.setup("http://foo.bar")

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(["job", "create", "--skip-hooks=second", "--wait-until=RUNNING",
            "west/bozo/test/hello", fp.name])
        assert result == 0
        self.assert_create_job_called(api)
        self.assert_scheduler_called(api, mock_query, 1)
        assert command_hook.ran_pre
        assert command_hook.ran_post
开发者ID:kevints,项目名称:aurora,代码行数:53,代码来源:test_command_hooks.py

示例2: test_cannot_skip_hooks_in_create

# 需要导入模块: from apache.aurora.client.cli.command_hooks import GlobalCommandHookRegistry [as 别名]
# 或者: from apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry import setup [as 别名]
  def test_cannot_skip_hooks_in_create(self):
    """This time, the hook shouldn't be skippable, because we use a username
    who isn't allowed by the hook exception rule.
    """
    GlobalCommandHookRegistry.reset()
    command_hook = HookForTesting(True)
    GlobalCommandHookRegistry.register_command_hook(command_hook)
    command_hook_two = SecondHookForTesting(False)
    GlobalCommandHookRegistry.register_command_hook(command_hook_two)
    mock_response = Mock()
    mock_context = FakeAuroraCommandContext()

    with contextlib.nested(
        patch("apache.aurora.client.cli.jobs.Job.create_context", return_value=mock_context),
        patch("requests.get", return_value=mock_response),
        patch("getpass.getuser", return_value="beezus")):
      mock_response.json.return_value = {
        "a": {
          "users": ["bozo", "clown"],
          "commands": {"job": ["killall", "create"]},
          "hooks": ["test_hook", "second"]
        },
        "b": {
          "commands": {"user": ["kick"]},
        }
      }

      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.INIT))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      api = mock_context.get_api("west")
      api.create_job.return_value = self.get_createjob_response()
      GlobalCommandHookRegistry.setup("http://foo.bar")

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(["job", "create", "--skip-hooks=second", "--wait-until=RUNNING",
            "west/bozo/test/hello", fp.name])
        # Check that it returns the right error code, and that create_job didn't get called.
        assert result == EXIT_PERMISSION_VIOLATION
        assert api.create_job.call_count == 0
开发者ID:bhuvan,项目名称:incubator-aurora,代码行数:46,代码来源:test_command_hooks.py

示例3: test_json_skip_rules

# 需要导入模块: from apache.aurora.client.cli.command_hooks import GlobalCommandHookRegistry [as 别名]
# 或者: from apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry import setup [as 别名]
 def test_json_skip_rules(self):
   """Load up a set of skips, specified in JSON, and then check a bunch of different
   cases to see that the skip rules work correctly.
   """
   mock_response = Mock()
   mock_context = FakeAuroraCommandContext()
   with patch("requests.get", return_value=mock_response):
     mock_response.json.return_value = {
       "a": {
         "users": ["bozo", "clown"],
         "commands": {"job": ["killall"]},
         "hooks": ["test_hook", "second"]
       },
       "b": {
         "commands": {"user": ["kick"]},
       }
     }
     GlobalCommandHookRegistry.reset()
     GlobalCommandHookRegistry.setup("http://foo.bar")
     command_hook_one = HookForTesting(False)
     GlobalCommandHookRegistry.register_command_hook(command_hook_one)
     command_hook_two = SecondHookForTesting(True)
     GlobalCommandHookRegistry.register_command_hook(command_hook_two)
     assert len(GlobalCommandHookRegistry.SKIP_HOOK_RULES) == 2
     # Should not be allowed: no skip rule permitting skipping hooks on job kill
     self.assert_skip_forbidden(mock_context, "all", "beezus", "job", "kill", ["a", "b", "c"])
     # Should not be allowed: there are hooks on "job killall", and beezus doesn't satisfy
     # their exception rules
     self.assert_skip_forbidden(mock_context, "all", "beezus", "job", "kill", ["a", "b", "c"])
     # Should be allowed: there's a rule allowing bozo to skip test_hook on job killall.
     self.assert_skip_allowed(mock_context, "test_hook", "bozo", "job", "killall", ["a", "b", "c"])
     # Should be allowed: since there's only one hook on killall, this is equivalent to
     # the previous.
     self.assert_skip_allowed(mock_context, "all", "bozo", "job", "killall", ["a", "b", "c"])
     # Should be allowed: there's a rule allowing anyone to skip any hook on "user kick".
     self.assert_skip_allowed(mock_context, "test_hook,something_else", "nobody", "user",
         "kick", ["a", "b", "c"])
     # should be allowed: there are no hooks in place for "user kick", so all is acceptable.
     self.assert_skip_allowed(mock_context, "all", "nobody", "user", "kick", ["a", "b", "c"])
开发者ID:bhuvan,项目名称:incubator-aurora,代码行数:41,代码来源:test_command_hooks.py


注:本文中的apache.aurora.client.cli.command_hooks.GlobalCommandHookRegistry.setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。