示例#1
0
 def testLabelParam(self):
     good_labels = [('genre', 'jazz'), ('underscores_are', 'totally_ok'),
                    ('dashes-are', 'also-ok'), ('num_123', 'good_456'),
                    ('final_underscore_', 'ok_too_'),
                    ('final-dash', 'no-problem-'), ('optional_value', ''),
                    ('a' * 63, 'not_too_long')]
     for name, value in good_labels:
         label_param = param_util.LabelParam(name, value)
         self.assertEqual(name, label_param.name)
         self.assertEqual(value, label_param.value)
     bad_labels = [('WHATS', 'updog'), ('1', 'initial_number'),
                   ('initial_number', '1'), ('-', 'initial_dash'),
                   ('initial_dash', '-'), ('spaces bad', ''),
                   ('midCaps', 'bad'), ('bad', 'midCaps'),
                   ('a' * 64, 'too_long'), ('', 'name_required'),
                   ('too_long', 'a' * 64)]
     for name, value in bad_labels:
         with self.assertRaises(ValueError):
             param_util.LabelParam(name, value)
示例#2
0
def dstat_get_jobs(statuses=None,
                   job_ids=None,
                   task_ids=None,
                   labels=None,
                   create_time_min=None,
                   create_time_max=None):
    statuses = statuses or {'*'}
    labels = labels or {}
    labels['test-token'] = test_setup.TEST_TOKEN
    labels_set = {param_util.LabelParam(k, v) for (k, v) in labels.items()}

    return dstat.dstat_job_producer(provider=get_dsub_provider(),
                                    statuses=statuses,
                                    job_ids=job_ids,
                                    task_ids=task_ids,
                                    labels=labels_set,
                                    create_time_min=create_time_min,
                                    create_time_max=create_time_max,
                                    full_output=True).next()
示例#3
0
 def test_bad_labels(self, unused_name, name, value):
     del unused_name
     with self.assertRaises(ValueError):
         param_util.LabelParam(name, value)
示例#4
0
 def test_good_labels(self, unused_name, name, value):
     del unused_name
     label_param = param_util.LabelParam(name, value)
     self.assertEqual(name, label_param.name)
     self.assertEqual(value, label_param.value)
示例#5
0
def dsub_start_job(command,
                   name=None,
                   envs=None,
                   labels=None,
                   inputs=None,
                   inputs_recursive=None,
                   outputs=None,
                   outputs_recursive=None,
                   wait=False):

    envs = envs or {}
    labels = labels or {}
    inputs = inputs or {}
    inputs_recursive = inputs_recursive or {}
    outputs = outputs or {}
    outputs_recursive = outputs_recursive or {}

    labels['test-token'] = test_setup.TEST_TOKEN

    logging = param_util.build_logging_param(test.LOGGING)
    job_resources = job_util.JobResources(image='ubuntu',
                                          logging=logging,
                                          zones=['us-central1-*'])

    env_data = {param_util.EnvParam(k, v) for (k, v) in envs.items()}
    label_data = {param_util.LabelParam(k, v) for (k, v) in labels.items()}

    input_file_param_util = param_util.InputFileParamUtil('input')
    input_data = set()
    for (recursive, items) in ((False, inputs.items()),
                               (True, inputs_recursive.items())):
        for (name, value) in items:
            name = input_file_param_util.get_variable_name(name)
            input_data.add(
                input_file_param_util.make_param(name, value, recursive))

    output_file_param_util = param_util.OutputFileParamUtil('output')
    output_data = set()
    for (recursive, items) in ((False, outputs.items()),
                               (True, outputs_recursive.items())):
        for (name, value) in items:
            name = output_file_param_util.get_variable_name(name)
            output_data.add(
                output_file_param_util.make_param(name, value, recursive))

    job_data = {
        'envs': env_data,
        'inputs': input_data,
        'outputs': output_data,
        'labels': label_data,
    }
    all_task_data = [{
        'envs': env_data,
        'labels': label_data,
        'inputs': input_data,
        'outputs': output_data,
    }]

    return dsub.run(get_dsub_provider(),
                    job_resources,
                    job_data,
                    all_task_data,
                    name=name,
                    command=command,
                    wait=wait,
                    disable_warning=True)