From: Dan Mick Date: Wed, 9 Aug 2023 02:05:25 +0000 (-0700) Subject: Standardize on "label" name for parameter X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F2157%2Fhead;p=ceph-build.git Standardize on "label" name for parameter The Jenkins UI (or at least the Python binding) uses "label", not "labels" (for reconfig only, because it uses XML, and the XML contains the tag 'label'. Sadly that's not true for create.) Avoid the confusion that wasted my time. Signed-off-by: Dan Mick --- diff --git a/ansible/examples/builder.yml b/ansible/examples/builder.yml index b6a7019b7..a1e099e92 100644 --- a/ansible/examples/builder.yml +++ b/ansible/examples/builder.yml @@ -17,7 +17,7 @@ - api_uri: 'https://jenkins.ceph.com' - jenkins_credentials_uuid: 'jenkins-build' - nodename: '{{ nodename }}' - - labels: "{{ jenkins_labels[inventory_hostname] }}" + - label: "{{ jenkins_labels[inventory_hostname] }}" - grant_sudo: true - osc_user: 'username' - osc_pass: 'password' @@ -896,7 +896,7 @@ # mapping from Jenkins back to whatever service created the current # node name: "{{ ansible_default_ipv4.address }}+{{ nodename }}" - labels: "{{ labels | default('') }}" + label: "{{ label | default('') }}" host: "{{ ansible_default_ipv4.address }}" credentialsId: "{{ jenkins_credentials_uuid }}" remoteFS: '/home/{{ jenkins_user }}/build' @@ -916,7 +916,7 @@ # mapping from Jenkins back to whatever service created the current # node name: "{{ ansible_default_ipv4.address }}+{{ ansible_hostname }}" - labels: "{{ labels }}" + label: "{{ label }}" host: "{{ ansible_default_ipv4.address }}" credentialsId: "{{ jenkins_credentials_uuid }}" launcher: 'hudson.slaves.JNLPLauncher' diff --git a/ansible/library/jenkins_node b/ansible/library/jenkins_node index e20c9d2ce..5a3a84016 100644 --- a/ansible/library/jenkins_node +++ b/ansible/library/jenkins_node @@ -48,9 +48,9 @@ options: required: false default: null - labels: + label: description: - - Labels to associate with a node, like "amd64" or "python" + - List of labels in a string, space-separated, to associate with a node, like "amd64" or "python" required: false default: null @@ -144,9 +144,6 @@ def maybe_convert_string_to_list(v): def sanitize_update_params(kw): - def translate_labels(labels): - return 'label', ' '.join(labels) - # this list may be smaller than it needs to be, but these are # the only ones I want to support for now VALID_UPDATE_PARAMS = { @@ -154,12 +151,11 @@ def sanitize_update_params(kw): 'name': None, 'remoteFS': None, 'numExecutors': None, - 'labels': translate_labels, + 'label': None, } update_kws = dict() invalid = list() for k, v in kw.items(): - v = maybe_convert_string_to_list(v) if k not in VALID_UPDATE_PARAMS: invalid.append(k) else: @@ -191,6 +187,9 @@ def create_or_modify(uri, user, password, name, **kw): j.reconfig_node(name, new_xconfig) else: + if 'label' in params: + params['labels'] = params['label'] + params.pop('label') j.create_node(name, launcher_params=launcher_params, **params) if not j.node_exists(name): return False, "Failed to create node '%s'." % name @@ -234,7 +233,7 @@ def main(): name=dict(required=True), executors=dict(required=False, default=2), description=dict(required=False, default=None), - labels=dict(required=False, default=None), + label=dict(required=False, default=None), host=dict(required=False, default=None), credentialsId=dict(required=False, default=None), launcher=dict(required=False, default='hudson.plugins.sshslaves.SSHLauncher'), @@ -254,7 +253,7 @@ def main(): name = module.params['name'] executors = module.params['executors'] description = module.params.get('description') - labels = module.params.get('labels') + label = module.params.get('label') exclusive = module.params.get('exclusive', False) host = module.params.get('host') remoteFS = module.params.get('remoteFS') @@ -284,7 +283,7 @@ def main(): name, executors=executors, description=description, - labels=labels, + label=label, exclusive=exclusive, host=host, credentialsId=credentialsId,