/var/lib/pcp/testsuite/src/mergelabelsets.python is in pcp-testsuite 4.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #!/usr/bin/env pmpython
#
# Copyright (C) 2017 Ronak Jain.
#
# 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
import cpmapi as c_api
import argparse
from pcp import pmapi
parser = argparse.ArgumentParser(description='Python test for mergeLabelSets')
# Location Label
locationJSON = "{\"datacenter\":\"torquay\",\"environment\":\"production\"}"
locationLabels = (pmapi.pmLabel * 2)()
locationLabel1 = locationLabels[0]
locationLabel1.name = 2
locationLabel1.namelen = 10
locationLabel1.value = 14
locationLabel1.valuelen = 9
locationLabel1.flags = c_api.PM_LABEL_CONTEXT | c_api.PM_LABEL_OPTIONAL
locationLabel2 = locationLabels[1]
locationLabel2.name = 25
locationLabel2.namelen = 11
locationLabel2.value = 38
locationLabel2.valuelen = 12
locationLabel2.flags = c_api.PM_LABEL_CONTEXT
locationLabelSet = pmapi.pmLabelSet()
locationLabelSet.nlabels = len(locationLabels)
locationLabelSet.json = locationJSON.encode('utf-8')
locationLabelSet.jsonlen = len(locationJSON)
locationLabelSet.labels = locationLabels
#Service Label
serviceJSON = "{\"services\":[\"indexer\",\"database\"]}"
serviceLabels = (pmapi.pmLabel * 1)()
serviceLabel1 = serviceLabels[0]
serviceLabel1.name = 2
serviceLabel1.namelen = 8
serviceLabel1.value = 12
serviceLabel1.valuelen = 22
serviceLabel1.flags = c_api.PM_LABEL_DOMAIN
serviceLabelSet = pmapi.pmLabelSet()
serviceLabelSet.nlabels = len(serviceLabels)
serviceLabelSet.json = serviceJSON.encode('utf-8')
serviceLabelSet.jsonlen = len(serviceJSON)
serviceLabelSet.labels = serviceLabels
#Testing Label
testingJSON = "{\"more\":{\"all\":false,\"none\":true},\"none\":none,\"some\":[1,2,3]}"
testingLabels = (pmapi.pmLabel * 3)()
testingLabel1 = testingLabels[0]
testingLabel1.name = 2
testingLabel1.namelen = 4
testingLabel1.value = 8
testingLabel1.valuelen = 25
testingLabel1.flags = c_api.PM_LABEL_ITEM | c_api.PM_LABEL_OPTIONAL
testingLabel2 = testingLabels[1]
testingLabel2.name = 35
testingLabel2.namelen = 4
testingLabel2.value = 41
testingLabel2.valuelen = 4
testingLabel2.flags = c_api.PM_LABEL_CONTEXT | c_api.PM_LABEL_OPTIONAL
testingLabel3 = testingLabels[2]
testingLabel3.name = 47
testingLabel3.namelen = 4
testingLabel3.value = 53
testingLabel3.valuelen = 7
testingLabel3.flags = c_api.PM_LABEL_CONTEXT | c_api.PM_LABEL_OPTIONAL
testingLabelSet = pmapi.pmLabelSet()
testingLabelSet.nlabels = len(testingLabels)
testingLabelSet.json = testingJSON.encode('utf-8')
testingLabelSet.jsonlen = len(testingJSON)
testingLabelSet.labels = testingLabels
#Empty Label
emptyJSON = "{}"
emptyLabelSet = pmapi.pmLabelSet()
emptyLabelSet.nlabels = 0
emptyLabelSet.json = emptyJSON.encode('utf-8')
emptyLabelSet.jsonlen = len(emptyJSON)
#test1 - Merge all Labelsets without Filter
test_result1 = pmapi.pmContext.pmMergeLabelSets([
locationLabelSet,
serviceLabelSet,
testingLabelSet,
emptyLabelSet ], None, None)
print("Python: Merged testing/services/location (no filter):\n%s\n" % (test_result1))
#test2 - Merge Labelsets with cull optional filter
def cull_optional(label_p, json, arg_p):
if label_p.contents.flags & c_api.PM_LABEL_OPTIONAL:
return 0
return 1
test_result2 = pmapi.pmContext.pmMergeLabelSets([
serviceLabelSet,
locationLabelSet ], cull_optional, None)
print("Python: Merged services/location (cull optional):\n%s\n" % (test_result2))
#test3 - Merge Labelsets with cull none filter
def cull_none(label_p, json, arg_p):
value = label_p.contents.value
if json[value + 1 : value + 5] == "none":
return 1
return 0
test_result3 = pmapi.pmContext.pmMergeLabelSets([
serviceLabelSet,
locationLabelSet,
emptyLabelSet ], cull_none, None)
print("Python: Merged services/location/empty (cull none):\n%s" % (test_result3))
|