Пример #1
0
def _GetMinikubeDockerEnvs(cluster_name):
    """Get the docker environment settings for a given cluster."""
    cmd = [_FindMinikube(), 'docker-env', '-p', cluster_name, '--shell=none']
    lines = run_subprocess.GetOutputLines(cmd, timeout_sec=20)
    return dict(
        line.split('=', 1) for line in lines
        if line and not line.startswith('#'))
Пример #2
0
def _NamespaceExists(namespace, context_name=None):
    cmd = [_FindKubectl()]
    if context_name:
        cmd += ['--context', context_name]
    cmd += ['get', 'namespaces', '-o', 'name']
    namespaces = run_subprocess.GetOutputLines(cmd, show_stderr=False)
    return 'namespace/' + namespace in namespaces
Пример #3
0
 def testCanStripWhitespaceAtEnds(self):
     with cross_platform_temp_file.NamedTempFile(
             '\none\ntwo\n\n') as multi_line_file:
         lines = run_subprocess.GetOutputLines(
             ['cat', multi_line_file.name],
             timeout_sec=10,
             strip_output=True)
         self.assertEqual(lines, ['one', 'two'])
Пример #4
0
def _IsKindClusterUp(cluster_name):
  """Checks if a cluster is running.

  Args:
    cluster_name: Name of the cluster

  Returns:
    True if a cluster with the given name is running.
  """
  cmd = [_FindKind(), 'get', 'clusters']
  clusters = run_subprocess.GetOutputLines(
      cmd, timeout_sec=20, show_stderr=False, strip_output=True)
  return cluster_name in clusters
Пример #5
0
 def testReturnsCommandOutputLines(self):
     with cross_platform_temp_file.NamedTempFile(
             'one\ntwo') as multi_line_file:
         lines = run_subprocess.GetOutputLines(
             ['cat', multi_line_file.name], timeout_sec=10)
         self.assertEqual(lines, ['one', 'two'])
Пример #6
0
 def testReturnsErrorCode(self):
     with self.assertRaises(subprocess.CalledProcessError) as raised:
         run_subprocess.GetOutputLines(['diff', 'nonexist', 'nonexist2'],
                                       timeout_sec=10)
     self.assertEqual(raised.exception.returncode, 2)
Пример #7
0
 def testCanHideStderr(self):
     run_subprocess.GetOutputLines(
         ['bash', '-c', 'echo should not see this in test log >&2'],
         timeout_sec=10,
         show_stderr=False)