summaryrefslogtreecommitdiff
path: root/qa/src/test_pcp_getopts.python
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
commit47e6e7c84f008a53061e661f31ae96629bc694ef (patch)
tree648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/src/test_pcp_getopts.python
downloadpcp-debian/3.9.10.tar.gz
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/test_pcp_getopts.python')
-rwxr-xr-xqa/src/test_pcp_getopts.python113
1 files changed, 113 insertions, 0 deletions
diff --git a/qa/src/test_pcp_getopts.python b/qa/src/test_pcp_getopts.python
new file mode 100755
index 0000000..776aa92
--- /dev/null
+++ b/qa/src/test_pcp_getopts.python
@@ -0,0 +1,113 @@
+#
+# Copyright (C) 2014 Red Hat.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+
+import sys as system
+from pcp import pmapi
+import cpmapi as c_api
+
+""" Create an options object and set/get everything possible """
+
+options = pmapi.pmOptions("a:bfl:D:h:H:K:LS:T:O:A:s:t:VZ:z?")
+options.pmSetOptionFlags(c_api.PM_OPTFLAG_BOUNDARIES)
+options.pmSetOptionFlags(c_api.PM_OPTFLAG_MULTI)
+options.pmSetOptionFlags(c_api.PM_OPTFLAG_MIXED)
+
+options.pmSetLongOptionHeader("General Options")
+options.pmSetLongOptionAlign()
+options.pmSetLongOptionArchive()
+options.pmSetLongOptionDebug()
+options.pmSetLongOptionGuiMode()
+options.pmSetLongOptionHost()
+options.pmSetLongOptionHostsFile()
+options.pmSetLongOptionSpecLocal()
+options.pmSetLongOptionLocalPMDA()
+options.pmSetLongOptionOrigin()
+options.pmSetLongOptionGuiPort()
+options.pmSetLongOptionStart()
+options.pmSetLongOptionSamples()
+options.pmSetLongOptionFinish()
+options.pmSetLongOptionInterval()
+options.pmSetLongOptionVersion()
+options.pmSetLongOptionTimeZone()
+options.pmSetLongOptionHostZone()
+options.pmSetLongOptionHelp()
+
+# extract any options we can (many are consumed internally) & dump 'em;
+# this test variant focusses on context creation and using time windows.
+
+ctx = c_api.PM_ERR_NOCONTEXT
+try:
+ ctx = pmapi.pmContext.fromOptions(options, system.argv)
+except pmapi.pmUsageErr as usage:
+ usage.message()
+ system.exit(1)
+except pmapi.pmErr as error:
+ print(error)
+
+nonoptions = options.pmNonOptionsFromList(system.argv)
+if nonoptions != None:
+ print("Non-option arguments: %s" % nonoptions)
+
+# for host and archive lists exercise the creation of multiple contexts
+hosts = options.pmGetOptionHosts()
+if hosts != None:
+ print("Host list: %s" % hosts)
+ print("Host %s pmcd.hostname: %s" % (hosts[0], ctx.pmGetContextHostName()))
+ if len(hosts) > 1:
+ typed = c_api.PM_CONTEXT_HOST
+ for index in range(1, len(hosts)):
+ try:
+ ctx = pmapi.pmContext.fromOptions(options, system.argv, typed, index)
+ print("Host %s pmcd.hostname: %s" % (hosts[index], ctx.pmGetContextHostName()))
+ except pmapi.pmErr as error:
+ print("pmContext failed for host %s - %s" %s (hosts[index], error))
+
+archives = options.pmGetOptionArchives()
+if archives != None:
+ print("Archive list: %s" % archives)
+ print("Archive %s hostname: %s" % (archives[0], ctx.pmGetContextHostName()))
+ if len(archives) > 1:
+ typed = c_api.PM_CONTEXT_ARCHIVE
+ for index in range(1, len(archives)):
+ try:
+ ctx = pmapi.pmContext.fromOptions(options, system.argv, typed, index)
+ print("Archive %s hostname: %s" % (archives[index], ctx.pmGetContextHostName()))
+ except pmapi.pmErr as error:
+ print("pmContext failed for archive %s - %s" % (archives[index], error))
+
+timezone = options.pmGetOptionTimezone()
+if timezone != None:
+ print("Timezone: %s" % timezone)
+
+samples = options.pmGetOptionSamples()
+if samples != None:
+ print("Samples: %d" % samples)
+
+interval = options.pmGetOptionInterval()
+if interval != None:
+ print("Interval: %s" % interval)
+
+start = options.pmGetOptionStart()
+if start != None:
+ print("Start: %s" % start)
+
+finish = options.pmGetOptionFinish()
+if finish != None:
+ print("Finish: %s" % finish)
+
+origin = options.pmGetOptionOrigin()
+if origin != None:
+ print("Origin: %s" % origin)
+
+print("Done!")