From 7c719262b6be5736dfc6089b59ac02770770404e Mon Sep 17 00:00:00 2001 From: Tee Ngo Date: Mon, 24 Jun 2019 10:46:18 -0400 Subject: [PATCH] Switch to using sysinv URL and Address validators In this commit the bootstrap playbook is updated to make use of sysinv URL and Address validators to ensure a) consistent user experience and b) future validation updates will be done in one spot. Note: Currently, sysinv Address validator does not accept CIDR notation as the current docker engine does not support CIDR in NO_PROXY list. Ref: https://github.com/docker/docker.github.io/issues/8191. Change-Id: I433303dde93801f3e45cd7d10935eb1de28b9090 Closes-Bug: 1833710 Depends-On: Ic5a450ede0390529e795ca0120200a0f7bbf52ce Signed-off-by: Tee Ngo --- playbookconfig/centos/build_srpm.data | 2 +- playbookconfig/centos/playbookconfig.spec | 6 +++--- .../validate-config/tasks/validate_address.yml | 14 +++++--------- .../roles/validate-config/tasks/validate_url.yml | 8 +++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/playbookconfig/centos/build_srpm.data b/playbookconfig/centos/build_srpm.data index 24a1597f1..a9e6da284 100644 --- a/playbookconfig/centos/build_srpm.data +++ b/playbookconfig/centos/build_srpm.data @@ -1,2 +1,2 @@ SRC_DIR="playbookconfig" -TIS_PATCH_VER=2 +TIS_PATCH_VER=3 diff --git a/playbookconfig/centos/playbookconfig.spec b/playbookconfig/centos/playbookconfig.spec index ae270c5a1..1235cec10 100644 --- a/playbookconfig/centos/playbookconfig.spec +++ b/playbookconfig/centos/playbookconfig.spec @@ -8,13 +8,13 @@ License: Apache-2.0 URL: unknown Source0: %{name}-%{version}.tar.gz +Requires: ansible Requires: python Requires: python-netaddr -Requires: sshpass Requires: python2-ptyprocess Requires: python2-pexpect -Requires: python2-django -Requires: ansible +Requires: sshpass +Requires: sysinv %description This package contains playbooks used for configuring StarlingX. diff --git a/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_address.yml b/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_address.yml index d51a9da04..67b39747c 100644 --- a/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_address.yml +++ b/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_address.yml @@ -11,21 +11,17 @@ - name: Check if the supplied address is a valid domain name or ip address vars: script_content: | - # Use this utility to be consistent with the current config_controller - # though the underlying regex used is not flexible. - from controllerconfig.utils import is_valid_domain_or_ip + # Make use of sysinv Address Validator + from sysinv.common.utils import is_valid_domain_or_ip if not is_valid_domain_or_ip( "{{ input_address }}" ): - raise Exception("Invalid domain name!") + raise Exception("Invalid address format!") shell: "{{ script_content }}" args: executable: /usr/bin/python failed_when: false register: domain_name_ip_check -# Do the final catch-all check using Ansible ipaddr filter to pick up -# addresses with CIDR notation and whatever future valid formats will be. - name: Fail if the supplied address is not a valid domain name or ip address fail: - msg: "{{ input_address }} is an invalid address!." - when: (domain_name_ip_check.rc != 0) and - (input_address | ipaddr == false) + msg: "{{ input_address }} is an invalid address." + when: domain_name_ip_check.rc != 0 diff --git a/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_url.yml b/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_url.yml index afd323d60..d695e3472 100644 --- a/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_url.yml +++ b/playbookconfig/playbookconfig/playbooks/bootstrap/roles/validate-config/tasks/validate_url.yml @@ -12,11 +12,9 @@ - name: Check if the supplied proxy is a valid URL vars: script_content: | - # Make use of django URL Validator - from django.core.validators import URLValidator - try: - URLValidator()( "{{ input_url }}" ) - except Exception: + # Make use of sysinv URL Validator + from sysinv.common.utils import is_url + if not is_url( "{{ input_url }}" ): raise Exception("Invalid url format!") shell: "{{ script_content }}" args: