~milo/lava-tool/lava-165

« back to all changes in this revision

Viewing changes to lava/commands.py

  • Committer: Milo Casagrande
  • Date: 2013-07-17 14:30:42 UTC
  • Revision ID: milo@ubuntu.com-20130717143042-f3xislsmwk7mczld
Reworked the default job tempalte.

    * Remove the UrlListParameter and introduced the TarRepoParameter.
    * Reworked the key of the job templates.
    * Fixed the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
from lava.job.commands import JOB_FILE_EXTENSIONS
54
54
from lava.parameter import (
55
55
    Parameter,
56
 
    ListParameter,
57
 
    UrlListParameter,
 
56
    TarRepoParameter,
 
57
)
 
58
from lava.job.templates import (
 
59
    ACTIONS_ID,
 
60
    PARAMETERS_ID,
 
61
    TESTDEF_REPOS_ID,
 
62
    TESTDEF_REPOS_TAR_REPO,
58
63
)
59
64
from lava.testdef.templates import (
 
65
    DEFAULT_TESTDEF_FILE,
60
66
    DEFAULT_TESTDEF_SCRIPT,
61
67
    DEFAULT_TESTDEF_SCRIPT_CONTENT,
62
68
)
67
73
 
68
74
# Internal parameter ids.
69
75
JOBFILE_ID = "jobfile"
70
 
TESTS_DEF_ID = "test_definitions"
71
76
 
72
77
JOBFILE_PARAMETER = Parameter(JOBFILE_ID)
73
78
JOBFILE_PARAMETER.store = False
74
79
 
75
 
TESTFILES_PARAMETER = ListParameter(TESTS_DEF_ID)
76
 
TESTFILES_PARAMETER.store = False
77
 
 
78
80
INIT_TEMPLATE = {
79
81
    JOBFILE_ID: JOBFILE_PARAMETER,
80
 
    TESTS_DEF_ID: TESTFILES_PARAMETER,
81
82
}
82
83
 
83
84
 
147
148
            # Prompt the user to write the script file.
148
149
            self.edit_file(default_script)
149
150
 
150
 
        test_files = Parameter.deserialize(data[TESTS_DEF_ID])
151
 
 
152
 
        for test in test_files:
153
 
            print >> sys.stdout, ("\nCreating test definition "
154
 
                                  "'{0}':".format(test))
155
 
            self._create_test_file(os.path.join(test_path, test))
 
151
        print >> sys.stdout, ("\nCreating test definition "
 
152
                              "'{0}':".format(DEFAULT_TESTDEF_FILE))
 
153
        self._create_test_file(os.path.join(test_path,
 
154
                                            DEFAULT_TESTDEF_FILE))
156
155
 
157
156
        job = data[JOBFILE_ID]
158
157
        print >> sys.stdout, "\nCreating job file '{0}':".format(job)
267
266
        tests_dir = os.path.join(job_dir, TESTS_DIR)
268
267
 
269
268
        if os.path.isdir(tests_dir):
270
 
            encoded_tests = UrlListParameter.get_encoded_uri(tests_dir)
 
269
            encoded_tests = TarRepoParameter.get_encoded_tar(tests_dir)
271
270
 
272
271
            json_data = None
273
272
            with open(job_file, "r") as json_file:
274
273
                try:
275
274
                    json_data = json.load(json_file)
276
 
                    json_data["actions"][1]["parameters"]["testdef_urls"] = \
 
275
                    # TODO: find a better way to retrieve a key.
 
276
                    json_data[ACTIONS_ID][1][PARAMETERS_ID][TESTDEF_REPOS_ID][TESTDEF_REPOS_TAR_REPO] = \
277
277
                        encoded_tests
278
278
                except Exception:
279
279
                    raise CommandError("Cannot read job file '{0}'.".format(