qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / check_import.python
blobb34650989f02439c7a7c56ee3bac6d7daaeb39c5
1 #!/usr/bin/pcp python
2 """ Python test case for Log Import API wrapper module
3 """
5 # Copyright (C) 2012-2014 Red Hat Inc.
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
18 import sys
19 import math
20 import time
21 import cpmapi
22 from pcp import pmi
23 from pcp import pmapi
25 def check_import(archive, hostname, timezone):
26 """ Test body - check many of the Log Import API wrapper interfaces
27 """
28 log = pmi.pmiLogImport(archive)
29 log.pmiSetHostname(hostname)
30 log.pmiSetTimezone(timezone)
32 domain = 60 # Linux kernel
33 pmid = log.pmiID(domain, 2, 0)
34 indom = log.pmiInDom(domain, 2)
35 units = log.pmiUnits(0, 0, 0, 0, 0, 0)
37 # create a metric with no instances (hinv.ncpu)
38 log.pmiAddMetric("hinv.ncpu", cpmapi.PM_ID_NULL, cpmapi.PM_TYPE_U32,
39 cpmapi.PM_INDOM_NULL, cpmapi.PM_SEM_DISCRETE, units)
41 # give it a value
42 log.pmiPutValue("hinv.ncpu", "", "%d" % 42)
44 # create a metric with instances (kernel.all.load)
45 log.pmiAddMetric("kernel.all.load", pmid,
46 cpmapi.PM_TYPE_FLOAT, indom, cpmapi.PM_SEM_INSTANT, units)
47 log.pmiAddInstance(indom, "1 minute", 1)
48 log.pmiAddInstance(indom, "5 minute", 5)
49 log.pmiAddInstance(indom, "15 minute", 15)
51 # give them values
52 log.pmiPutValue("kernel.all.load", "1 minute", "%f" % 0.01)
53 log.pmiPutValue("kernel.all.load", "5 minute", "%f" % 0.05)
54 log.pmiPutValue("kernel.all.load", "15 minute", "%f" % 0.15)
56 timetuple = math.modf(time.time())
57 useconds = int(timetuple[0] * 1000000)
58 seconds = int(timetuple[1])
59 log.pmiWrite(seconds, useconds)
61 del log
63 if __name__ == '__main__':
65 if (len(sys.argv) != 2):
66 print("Usage: " + sys.argv[0] + " <path>")
67 sys.exit(1)
69 check_import(sys.argv[1], "www.abc.com", "EST-10")