def update_labels(self, labels): data = copy.deepcopy(self.minimal_data) sanitized_labels = { k: sanitize_strings_for_openshift(v) for k, v in labels.items() } data['metadata']['labels'] = sanitized_labels response = self.os.patch( self.pipeline_run_url, data=json.dumps(data), headers={ "Content-Type": "application/merge-patch+json", "Accept": "application/json", }, ) msg = f"update labels on pipeline run '{self.pipeline_run_name}'" exc_msg = f"Can't update labels on pipeline run '{self.pipeline_run_name}', " \ f"because it doesn't exist" response_json = self._check_response(response, msg) if not response_json: raise OsbsException(exc_msg) return response_json
def start_pipeline_run(self): if not self.input_data: raise OsbsException( "No input data provided for pipeline run to start") run_name = self.input_data.get('metadata', {}).get('name') labels = self.input_data.get('metadata', {}).get('labels', {}) if labels: sanitized_labels = { k: sanitize_strings_for_openshift(v) for k, v in labels.items() } self.input_data['metadata']['labels'] = sanitized_labels if run_name != self.pipeline_run_name: msg = f"Pipeline run name provided '{self.pipeline_run_name}' is different " \ f"than in input data '{run_name}'" raise OsbsException(msg) url = self.os.build_url(self.api_path, self.api_version, "pipelineruns") response = self.os.post( url, data=json.dumps(self.input_data), headers={ "Content-Type": "application/json", "Accept": "application/json" }, ) return response.json()
def test_sanitize_string(str1, str2, limit, separator, label, expected): sanitized = sanitize_strings_for_openshift(str1, str2, limit, separator, label) assert sanitized == expected valid = re.compile(BC_LABEL_REGEX) if label else re.compile(BC_NAME_REGEX) assert valid.match(sanitized)
def set_label(self, name, value): if not value: value = '' self.template['metadata'].setdefault('labels', {}) value = sanitize_strings_for_openshift(value) self.template['metadata']['labels'][name] = value