Blob Blame History Raw
From 8575535c25a5e25f7352275326d291f404ef5feb Mon Sep 17 00:00:00 2001
From: Eduardo Otubo <otubo@redhat.com>
Date: Fri, 13 Apr 2018 10:14:36 +0200
Subject: [PATCH] Add -show-configuration option

RH-Author: Eduardo Otubo <otubo@redhat.com>
Message-id: <20180413101436.9118-1-otubo@redhat.com>
Patchwork-id: 79602
O-Subject: [RHEL-7 WALinuxAgent PATCH] Add -show-configuration option
Bugzilla: 1508340
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>

   commit d7fe940b27955b0bac5143474beee26ccb546842
   Author: Christopher Boumenot <chrboum@microsoft.com>
   Date:   Mon Nov 27 17:18:32 2017 -0800

       Add -show-configuration option

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 azurelinuxagent/agent.py | 15 ++++++++-------
 tests/test_agent.py      | 21 +++++++++++++++++++--
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/azurelinuxagent/agent.py b/azurelinuxagent/agent.py
index e99f7be..87ab3c1 100644
--- a/azurelinuxagent/agent.py
+++ b/azurelinuxagent/agent.py
@@ -144,7 +144,7 @@ def main(args=[]):
     if command == "version":
         version()
     elif command == "help":
-        usage()
+        print(usage())
     elif command == "start":
         start(conf_file_path=conf_file_path)
     else:
@@ -228,15 +228,16 @@ def version():
 
 def usage():
     """
-    Show agent usage
+    Return agent usage message
     """
-    print("")
-    print((("usage: {0} [-verbose] [-force] [-help] "
+    s  = "\n"
+    s += ("usage: {0} [-verbose] [-force] [-help] "
            "-configuration-path:<path to configuration file>"
            "-deprovision[+user]|-register-service|-version|-daemon|-start|"
-           "-run-exthandlers]"
-           "").format(sys.argv[0])))
-    print("")
+           "-run-exthandlers|-show-configuration]"
+           "").format(sys.argv[0])
+    s += "\n"
+    return s
 
 def start(conf_file_path=None):
     """
diff --git a/tests/test_agent.py b/tests/test_agent.py
index 42edda2..2cb95f9 100644
--- a/tests/test_agent.py
+++ b/tests/test_agent.py
@@ -15,9 +15,7 @@
 # Requires Python 2.4+ and Openssl 1.0+
 #
 
-import mock
 import os.path
-import sys
 
 from azurelinuxagent.agent import *
 from azurelinuxagent.common.conf import *
@@ -167,3 +165,22 @@ class TestAgent(AgentTestCase):
         for k in sorted(configuration.keys()):
             actual_configuration.append("{0} = {1}".format(k, configuration[k]))
         self.assertEqual(EXPECTED_CONFIGURATION, actual_configuration)
+
+    def test_agent_usage_message(self):
+        message = usage()
+
+        # Python 2.6 does not have assertIn()
+        self.assertTrue("-verbose" in message)
+        self.assertTrue("-force" in message)
+        self.assertTrue("-help" in message)
+        self.assertTrue("-configuration-path" in message)
+        self.assertTrue("-deprovision" in message)
+        self.assertTrue("-register-service" in message)
+        self.assertTrue("-version" in message)
+        self.assertTrue("-daemon" in message)
+        self.assertTrue("-start" in message)
+        self.assertTrue("-run-exthandlers" in message)
+        self.assertTrue("-show-configuration" in message)
+
+        # sanity check
+        self.assertFalse("-not-a-valid-option" in message)
-- 
1.8.3.1