Since test_type is not nullable when creating new object we need to specify it; in the previous version we just set the path. Also move up the validation for test type.
Signed-off-by: Julius Gawlas <[email protected]> --- utils/test_importer.py | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-) diff --git a/utils/test_importer.py b/utils/test_importer.py index c1d8d8c..b1b4027 100755 --- a/utils/test_importer.py +++ b/utils/test_importer.py @@ -49,6 +49,9 @@ class TestImporterLoggingConfig(logging_config.LoggingConfig): DRY_RUN = False DEPENDENCIES_NOT_FOUND = set() +test_type = {'client': 1, + 'server': 2, } + def update_all(autotest_dir, add_noncompliant, add_experimental): """ @@ -228,12 +231,20 @@ def update_tests_in_db(tests, dry_run=False, add_experimental=False, '%s not in %s, did you forget to use -z option?' % (test, autotest_dir)) + logging.info("Processing %s", test) + + # create test object, first validate test type + data = tests[test] + if not hasattr(data, 'test_type'): + raise Exception('Test type is required') + if not data.test_type.lower() in test_type: + raise Exception('Incorrect value %s for test_type' % + data.test_type) new_test = models.Test.objects.get_or_create( - path=test.replace(autotest_dir, '').lstrip('/'))[0] - logging.info("Processing %s", new_test.path) + path=test.replace(autotest_dir, '').lstrip('/'), + test_type=test_type[data.test_type.lower()])[0] # Set the test's attributes - data = tests[test] _set_attributes_clean(new_test, data) # Custom Attribute Update @@ -272,12 +283,9 @@ def _set_attributes_clean(test, data): @param test: a test object to be populated for the database. @param data: object with test data from the file system. """ - test_type = { 'client' : 1, - 'server' : 2, } - test_time = { 'short' : 1, - 'medium' : 2, - 'long' : 3, } - + test_time = {'short': 1, + 'medium': 2, + 'long': 3, } string_attributes = ('name', 'author', 'test_class', 'test_category', 'test_category', 'sync_count') @@ -292,23 +300,14 @@ def _set_attributes_clean(test, data): setattr(test, attribute, int(getattr(data, attribute))) try: - test.test_type = int(data.test_type) - if test.test_type != 1 and test.test_type != 2: - raise Exception('Incorrect number %d for test_type' % - test.test_type) - except ValueError: - pass - try: test.test_time = int(data.time) - if test.test_time < 1 or test.time > 3: + if not test.test_time in test_time.values(): raise Exception('Incorrect number %d for time' % test.time) except ValueError: pass if not test.test_time and str == type(data.time): test.test_time = test_time[data.time.lower()] - if not test.test_type and str == type(data.test_type): - test.test_type = test_type[data.test_type.lower()] def add_label_dependencies(test): -- 1.7.7.6 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
