def create_kvm_job(self, filename, validate=False): """ Custom function to allow for extra exception handling. """ job_ctx = { "arch": "amd64", "no_kvm": True, } # override to allow unit tests on all types of systems (data, device_dict) = self.create_device("kvm01.jinja2", job_ctx) device = NewDevice(yaml_safe_load(data)) print("####### Device configuration #######") print(data) print("#######") self.validate_data("hi6220-hikey-01", device_dict) kvm_yaml = os.path.join(os.path.dirname(__file__), filename) parser = JobParser() job_data = "" with open(kvm_yaml) as sample_job_data: job_data = yaml_safe_load(sample_job_data.read()) print("########## Test Job Submission validation #######") if validate: validate_job(job_data, strict=False) try: job = parser.parse(yaml_safe_dump(job_data), device, 4212, None, "") job.logger = DummyLogger() except LAVAError as exc: print(exc) return None return job
def create_custom_job(self, template, job_data, job_ctx=None, validate=True): if validate: validate_job(job_data, strict=False) if job_ctx: job_data["context"] = job_ctx else: job_ctx = job_data.get("context") (data, device_dict) = self.create_device(template, job_ctx) device = NewDevice(yaml_safe_load(data)) print("####### Device configuration #######") print(data) print("#######") try: parser = JobParser() job = parser.parse(yaml_safe_dump(job_data), device, 4999, None, "") except (ConfigurationError, TypeError) as exc: print("####### Parser exception ########") print(device) print("#######") raise ConfigurationError("Invalid device: %s" % exc) job.logger = DummyLogger() return job
def check_job(data, options, prefix=""): try: data = yaml.safe_load(data) except yaml.YAMLError as exc: print("%sinvalid job definition:" % prefix) print("%sinvalid yaml" % prefix) return 1 try: validate_job(data, options.strict, options.context) except v.Invalid as exc: print("%sinvalid job definition:" % prefix) print("%skey: %s" % (prefix, exc.path)) print("%smgs: %s" % (prefix, exc.msg)) return 1 return 0