コード例 #1
0
    def testNamespaceAlreadyExists(self):
        with mock.patch.object(run_subprocess,
                               "GetOutputLines") as mock_get_lines:
            mock_get_lines.return_value = ["namespace/a", "namespace/b"]
            with mock.patch.object(run_subprocess, "Run") as mock_run:

                with kubernetes.KubeNamespace("a"):
                    mock_run.assert_not_called()

                with kubernetes.KubeNamespace("b"):
                    mock_run.assert_not_called()
コード例 #2
0
    def testNamespaceAlreadyExists(self):
        with mock.patch.object(subprocess, "Popen") as popen:
            with mock.patch.object(subprocess, "check_call") as check_call:
                namespaces = six.b("namespace/a\nnamespace/b\n")
                popen.return_value.communicate.return_value = (namespaces,
                                                               None)

                with kubernetes.KubeNamespace("a"):
                    check_call.assert_not_called()

                with kubernetes.KubeNamespace("b"):
                    check_call.assert_not_called()
コード例 #3
0
    def testNamespaceNotExists(self):
        with mock.patch.object(run_subprocess,
                               "GetOutputLines") as mock_get_lines:
            mock_get_lines.return_value = ["namespace/a"]
            with mock.patch.object(run_subprocess, "Run") as mock_run:

                with kubernetes.KubeNamespace("b"):
                    self.assertEqual(
                        mock_run.call_args[0][0],
                        [self.PATH_TO_KUBECTL, "create", "namespace", "b"])

                self.assertEqual(
                    mock_run.call_args_list[1][0][0],
                    [self.PATH_TO_KUBECTL, "delete", "namespace", "b"])
コード例 #4
0
ファイル: dev.py プロジェクト: iofh/QA-System
  def _WithKubeNamespace(namespace_name, context_name):
    """Create and destory a kubernetes namespace if one is specified.

    Args:
      namespace_name: Namespace name.
      context_name: Kubernetes context name.

    Yields:
      None
    """
    if namespace_name:
      with kubernetes.KubeNamespace(namespace_name, context_name):
        yield
    else:
      yield
コード例 #5
0
    def testNamespaceNotExists(self):
        with mock.patch.object(subprocess, "Popen") as popen:
            with mock.patch.object(subprocess, "check_call") as check_call:
                namespaces = six.b("namespace/a")
                popen.return_value.communicate.return_value = (namespaces,
                                                               None)

                with kubernetes.KubeNamespace("b"):
                    self.assertEqual(
                        check_call.call_args[0][0],
                        [self.PATH_TO_KUBECTL, "create", "namespace", "b"])

                self.assertEqual(
                    check_call.call_args_list[1][0][0],
                    [self.PATH_TO_KUBECTL, "delete", "namespace", "b"])
コード例 #6
0
    def testCallWithContext(self):
        with mock.patch.object(run_subprocess,
                               "GetOutputLines") as mock_get_lines:
            mock_get_lines.return_value = ["namespace/a"]
            with mock.patch.object(run_subprocess, "Run") as mock_run, \
             mock.patch.object(run_subprocess, "GetOutputLines") as mock_get_lines:

                with kubernetes.KubeNamespace("b", "my-context"):
                    self.assertEqual(mock_get_lines.call_args[0][0], [
                        self.PATH_TO_KUBECTL, "--context", "my-context", "get",
                        "namespaces", "-o", "name"
                    ])
                    self.assertEqual(mock_run.call_args_list[0][0][0], [
                        self.PATH_TO_KUBECTL, "--context", "my-context",
                        "create", "namespace", "b"
                    ])

                self.assertEqual(mock_run.call_args_list[1][0][0], [
                    self.PATH_TO_KUBECTL, "--context", "my-context", "delete",
                    "namespace", "b"
                ])