You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/11/01 17:46:49 UTC

[trafficcontrol] 05/05: genRoutesConfig.py now supports defaulting blank testing username/password to reference username/password

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit cc3ca2e08987ed53391ff0f62521ababbd9fe54a
Author: ocket8888 <oc...@gmail.com>
AuthorDate: Thu Nov 1 10:58:35 2018 -0600

    genRoutesConfig.py now supports defaulting blank testing username/password to reference username/password
    
    This is as opposed to the existing behaviour which would use the reference username/password _pair_ if the testing pair was not given at all.
    That means that you can, for instance, give it the testing pair 'admin:' to use the testing username 'admin', but default to the password used by the reference user
---
 docs/source/tools/compare.rst                  |  4 ++++
 traffic_ops/testing/compare/genConfigRoutes.py | 21 ++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/docs/source/tools/compare.rst b/docs/source/tools/compare.rst
index a1e9e72..165d7c6 100644
--- a/docs/source/tools/compare.rst
+++ b/docs/source/tools/compare.rst
@@ -82,6 +82,8 @@ usage: genConfigRoutes.py [-h] [-k] [-v] InstanceA InstanceB LoginA [LoginB]
 
 .. note:: If you're using a CDN-in-a-Box environment for testing, it's likely that you'll need the ``-k``/``--insecure`` option if you're outside the Docker network
 
+.. _compare-genConfigRoutes-positional_parameters:
+
 .. table:: Positional Parameters (In Order)
 
 	+-----------+---------------------------------------------------------------------------------------------------------------------------------------+
@@ -97,6 +99,8 @@ usage: genConfigRoutes.py [-h] [-k] [-v] InstanceA InstanceB LoginA [LoginB]
 	|           | If not given, LoginA will be re-used for the second connection (default: None)                                                        |
 	+-----------+---------------------------------------------------------------------------------------------------------------------------------------+
 
+.. note:: The full behaviour of the ``LoginB`` parameter described in :ref:`compare-genConfigRoutes-positional_parameters` is such that supports not only a fully missing authentication credentials pair, but also a blank string for each of the pair members. This means that you can, for instance, give it the testing pair 'admin:' to use the testing username 'admin', but default to the password used by the reference user. Or, another example is that passing ``LoginB`` as simple ``:`` will r [...]
+
 The genConfigRoutes.py script will output list of unique API routes (relative to the desired Traffic Ops URL) that point to generated configuration files for a sample set of servers common to both  Traffic Ops instances. The results are printed to stdout, making the output perfect for piping directly into ``compare`` like so:
 
 .. code-block:: shell
diff --git a/traffic_ops/testing/compare/genConfigRoutes.py b/traffic_ops/testing/compare/genConfigRoutes.py
index 628f770..0725c88 100755
--- a/traffic_ops/testing/compare/genConfigRoutes.py
+++ b/traffic_ops/testing/compare/genConfigRoutes.py
@@ -170,13 +170,24 @@ def main(kwargs:argparse.Namespace) -> int:
 
 	instanceA = kwargs.InstanceA
 	instanceB = kwargs.InstanceB
-	loginA = kwargs.LoginA.split(':')
-	loginA = (loginA[0], ':'.join(loginA[1:]))
+
+	try:
+		loginA = kwargs.LoginA.split(':')
+		loginA = (loginA[0], ':'.join(loginA[1:]))
+	except (KeyError, IndexError) as e:
+		logging.critical("Bad username/password pair: '%s' (hint: try -h/--help)", kwargs.LoginA)
+		return 1
+
 	loginB = loginA
-	if kwargs.LoginB:
-		loginB = kwargs.LoginB.split(':')
-		loginB = (loginB[0], ':'.join(loginB[1:]))
 
+	try:
+		if kwargs.LoginB:
+			loginB = kwargs.LoginB.split(':')
+			loginB = (loginB[0], ':'.join(loginB[1:]))
+			loginB = (loginB[0] if loginB[0] else loginA[0], loginB[1] if loginB[1] else loginA[1])
+	except (KeyError, IndexError) as e:
+		logging.critical("Bad username/password pair: '%s' (hint: try -h/--help)", kwargs.LoginB)
+		return 1
 
 	verify = not kwargs.insecure