Exemplo n.º 1
0
 def testParse_noHostConfigs(self):
     """Test config file with cluster but no host_configs."""
     # No host_configs is fine.
     config_path = GetTestFilePath('valid/config_without_host_configs.yaml')
     with open(config_path, 'r') as f:
         lab_config_pb = lab_config.Parse(f)
     self.assertEqual(0, len(lab_config_pb.cluster_configs[0].host_configs))
Exemplo n.º 2
0
 def testParse_multipleClusterConfigs(self):
     """Test config file with multiple cluster_configs section."""
     # Config with multiple cluster_configs will only keep the last one.
     config_path = GetTestFilePath(
         'invalid/config_multiple_cluster_configs.yaml')
     with self.assertRaisesRegex(
             lab_config.ConfigError,
             r".*Duplicate key 'cluster_configs' found.*"):
         with open(config_path, 'r') as f:
             lab_config.Parse(f)
Exemplo n.º 3
0
 def testParse_emptyHostConfigs(self):
     """Test config file with cluster but empty host_configs."""
     # Has host_configs field but the field is empty is invalid.
     # This can not be pased by java's yaml lib.
     config_path = GetTestFilePath('invalid/config_empty_host_configs.yaml')
     with self.assertRaisesRegex(
             lab_config.ConfigError,
             r'when expecting a sequence\nfound a blank string'):
         with open(config_path, 'r') as f:
             lab_config.Parse(f)
Exemplo n.º 4
0
def GetLabConfigFromGCS(lab_config_path):
  """Get lab config from GCS.

  Args:
    lab_config_path: a string of the file path on Google Cloud Storage.
  Returns:
    a lab config proto
  """
  try:
    return lab_config_util.Parse(file_storage.OpenFile(lab_config_path))
  except file_storage.ObjectNotFoundError:
    logging.exception('Cannot open lab config file: %s', lab_config_path)
  except lab_config_util.ConfigError:
    logging.exception('Fail to parse file: %s', lab_config_path)
Exemplo n.º 5
0
    def testParse(self):
        """Test parse a normal config."""
        config_path = GetTestFilePath('valid/config.yaml')
        lab_config_pb = None
        with open(config_path, 'r') as f:
            lab_config_pb = lab_config.Parse(f)

        self.assertEqual('lab1', lab_config_pb.lab_name)
        self.assertEqual('lab_user1', lab_config_pb.host_login_name)
        self.assertEqual(['lab_user1', 'user1'], lab_config_pb.owners)
        self.assertEqual('tfc_url', lab_config_pb.control_server_url)
        self.assertEqual('lab_docker_image', lab_config_pb.docker_image)
        self.assertEqual('docker_server_1', lab_config_pb.docker_server)
        self.assertEqual('AStringToRepresentApiKey',
                         lab_config_pb.engprod_api_key)
        self.assertTrue(lab_config_pb.enable_stackdriver)
        self.assertTrue(lab_config_pb.enable_autoupdate)
        self.assertTrue(lab_config_pb.enable_ui_update)
        self.assertEqual(lab_config_pb2.ON_PREMISE,
                         lab_config_pb.operation_mode)
        self.assertEqual('path/to/key.json',
                         lab_config_pb.service_account_json_key_path)
        self.assertEqual('lab_sv_key',
                         lab_config_pb.service_account_key_secret_id)
        self.assertEqual('secret_project_id', lab_config_pb.secret_project_id)
        self.assertEqual('*****@*****.**',
                         lab_config_pb.service_account)
        self.assertEqual(
            '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
            '-F /path/to/ssh/config -C', lab_config_pb.ssh_arg)
        self.assertEqual(2, len(lab_config_pb.cluster_configs))
        cluster = lab_config_pb.cluster_configs[0]
        self.assertEqual('cluster1', cluster.cluster_name)
        self.assertEqual('user1', cluster.host_login_name)
        self.assertEqual(['user1', 'user2'], cluster.owners)
        self.assertEqual('path/to/config.xml', cluster.tf_global_config_path)
        self.assertEqual('tfc_url', cluster.control_server_url)
        self.assertTrue(cluster.graceful_shutdown)
        self.assertEqual(600, cluster.shutdown_timeout_sec)
        self.assertTrue(cluster.enable_stackdriver)
        self.assertTrue(cluster.enable_autoupdate)
        self.assertEqual(['--arg1', 'value1'], cluster.extra_docker_args)
        self.assertEqual('gcr.io/dockerized-tradefed/tradefed:golden',
                         cluster.docker_image)
        self.assertEqual('docker_server_2', cluster.docker_server)
        self.assertEqual(2, len(cluster.tmpfs_configs))
        self.assertEqual('/atmpfs', cluster.tmpfs_configs[0].path)
        self.assertEqual(1000, cluster.tmpfs_configs[0].size)
        self.assertEqual('/btmpfs', cluster.tmpfs_configs[1].path)
        self.assertEqual(3, len(cluster.host_configs))
        host = cluster.host_configs[0]
        self.assertEqual('host1', host.hostname)
        self.assertEqual(5, host.max_local_virtual_devices)
        self.assertEqual(1, len(host.tmpfs_configs))
        self.assertEqual('/atmpfs', host.tmpfs_configs[0].path)
        self.assertEqual(2000, host.tmpfs_configs[0].size)
        self.assertEqual('750', host.tmpfs_configs[0].mode)
        host = cluster.host_configs[1]
        self.assertEqual('host2', host.hostname)
        self.assertTrue(host.enable_ui_update)
        host = cluster.host_configs[2]
        self.assertEqual('host3', host.hostname)
        self.assertEqual('path/to/new/config.xml', host.tf_global_config_path)

        cluster = lab_config_pb.cluster_configs[1]
        self.assertEqual('cluster2', cluster.cluster_name)
        self.assertEqual('path/to/config.xml', cluster.tf_global_config_path)
        self.assertEqual(0, len(list(cluster.extra_docker_args)))
        self.assertEqual(2, len(cluster.host_configs))
        self.assertEqual('host4', cluster.host_configs[0].hostname)
        self.assertEqual('host5', cluster.host_configs[1].hostname)
        self.assertEqual(3600, cluster.shutdown_timeout_sec)
        self.assertTrue(cluster.enable_ui_update)
Exemplo n.º 6
0
 def testParse_invalidKey(self):
     """Test config file with invalid key."""
     config_path = GetTestFilePath('invalid/config_invalid_key.yaml')
     with self.assertRaises(lab_config.ConfigError):
         with open(config_path, 'r') as f:
             lab_config.Parse(f)
Exemplo n.º 7
0
 def testParse_extraLines(self):
     """Test config file not used lines."""
     config_path = GetTestFilePath('invalid/config_extra_lines.yaml')
     with self.assertRaises(lab_config.ConfigError):
         with open(config_path, 'r') as f:
             lab_config.Parse(f)
Exemplo n.º 8
0
 def testParse_noClusters(self):
     """Test config file with no 'cluster_configs'."""
     config_path = GetTestFilePath('invalid/config_no_clusters.yaml')
     with self.assertRaises(lab_config.ConfigError):
         with open(config_path, 'r') as f:
             lab_config.Parse(f)