This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 1284417 - Python PMAPI pmSetMode does not allow None timeval
Python PMAPI pmSetMode does not allow None timeval
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: pcp (Show other bugs)
23
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Nathan Scott
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-11-23 05:03 EST by Marko Myllynen
Modified: 2016-04-06 10:55 EDT (History)
7 users (show)

See Also:
Fixed In Version: pcp-3.10.9-1.fc23 pcp-3.10.9-1.fc22 pcp-3.11.1-1.el5
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-04-06 10:55:24 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
test.tar.gz (1.44 KB, application/x-gzip)
2015-11-24 11:05 EST, Marko Myllynen
no flags Details

  None (edit)
Description Marko Myllynen 2015-11-23 05:03:22 EST
Description of problem:
From pmSetMode(1):

...
       int pmSetMode(int mode, const struct timeval *when, int delta);
...
       As  a  special  case, if when is NULL then the mode and delta arguments
       are used as described above, but the current time in the archive is not
       altered.
...

But the Python pmSetMode does not allow this:

...
    def pmSetMode(self, mode, timeVal, delta):
        """PMAPI - set interpolation mode for reading archive files
        code = pmSetMode(c_api.PM_MODE_INTERP, timeval, 0)
        """
        status = LIBPCP.pmUseContext(self.ctx)
        if status < 0:
            raise pmErr(status)
        status = LIBPCP.pmSetMode(mode, pointer(timeVal), delta)
        if status < 0:
            raise pmErr(status)
        return status
...
Comment 1 Nathan Scott 2015-11-23 19:35:51 EST
If I'm reading the ctypes docs correctly, the patch below should work ... could you try it out Marko, if you have a use-case for this already?

cheers.


diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py
index f9805a7..b3f126b 100644
--- a/src/python/pcp/pmapi.py
+++ b/src/python/pcp/pmapi.py
@@ -1551,7 +1551,10 @@ class pmContext(object):
         status = LIBPCP.pmUseContext(self.ctx)
         if status < 0:
             raise pmErr(status)
-        status = LIBPCP.pmSetMode(mode, pointer(timeVal), delta)
+        when = None
+        if timeVal != None:
+            when = pointer(timeVal)
+        status = LIBPCP.pmSetMode(mode, when, delta)
         if status < 0:
             raise pmErr(status)
         return status
Comment 2 Marko Myllynen 2015-11-24 11:04:55 EST
Thanks, I tested the change and it seems to work in that sense that my test code runs. I see only one in-tree user pmSetMode(PM_MODE_FORW, NULL, 0) (src/pmlogreduce/scan.c) but I'm not yet sure would this be useful elsewhere.

However, there's also one case where the man pages could be clarified a bit:

The pmSetMode(1) man page states:

...
       As  a  special  case, if when is NULL then the mode and delta arguments
       are used as described above, but the current time in the archive is not
       altered.
...

The pmFetchArchive(1) man page states:

...
       The result is instantiated with all of the metrics (and instances) from
       the next archive record, consequently there is no notion of a  list  of
       desired  metrics,  and  the  instance  profile  of the PMAPI context is
       ignored.
...

But with code like:

...
        self.context.pmSetMode(c_api.PM_MODE_FORW, None, 0)
        while self.context.type == c_api.PM_CONTEXT_ARCHIVE and True:
            result = self.context.pmFetchArchive()
            print "Fetch @ " + str(result.contents.timestamp)
...

I see:

...
$ python ~/pmapi-test.py -a pVZ3Sj.localhost
Fetch @ 1448379062.065
Fetch @ 1448379064.064
Fetch @ 1448379066.065
...

Based on the above quotes from pmSetMode(1) and pmFetchArchive(1) I was perhaps expecting 1448379062.065 being printed repeatedly here.

I'll attach the test archive and the crude test script just in case (I see the same behaviour with both pmFetch() pmFetchArchive()).

Thanks.
Comment 3 Marko Myllynen 2015-11-24 11:05 EST
Created attachment 1098255 [details]
test.tar.gz
Comment 4 Marko Myllynen 2015-11-30 10:48:37 EST
(In reply to Marko Myllynen from comment #2)
> 
> However, there's also one case where the man pages could be clarified a bit:
> 
> Based on the above quotes from pmSetMode(1) and pmFetchArchive(1) I was
> perhaps expecting 1448379062.065 being printed repeatedly here.

Err, nevermind, I completely misunderstood/misread the pages; pmSetMode with NULL timeval doesn't alter the time during pmSetMode() call, of course pmFetchArchive() then moves it to the next record according to the mode set earlier by pmSetMode().

So no additional changes needed here.

Thanks.
Comment 5 Nathan Scott 2015-12-02 23:29:58 EST
Fixed upstream, will be in pcp-3.10.9.
Comment 6 Fedora Update System 2015-12-16 20:54:33 EST
pcp-3.10.9-1.fc22 has been submitted as an update to Fedora 22. https://bodhi.fedoraproject.org/updates/FEDORA-2015-d08245c076
Comment 7 Fedora Update System 2015-12-16 20:55:16 EST
pcp-3.10.9-1.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2015-2b40815137
Comment 8 Fedora Update System 2015-12-16 21:18:04 EST
pcp-3.10.9-1.el5 has been submitted as an update to Fedora EPEL 5. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2015-2ac90519bc
Comment 9 Fedora Update System 2015-12-17 05:26:31 EST
pcp-3.10.9-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'dnf --enablerepo=updates-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-2b40815137
Comment 10 Fedora Update System 2015-12-17 05:26:50 EST
pcp-3.10.9-1.fc22 has been pushed to the Fedora 22 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'dnf --enablerepo=updates-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-d08245c076
Comment 11 Fedora Update System 2015-12-17 07:48:55 EST
pcp-3.10.9-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'yum --enablerepo=epel-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2015-2ac90519bc
Comment 12 Fedora Update System 2016-01-05 16:57:47 EST
pcp-3.10.9-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.
Comment 13 Fedora Update System 2016-01-05 17:54:23 EST
pcp-3.10.9-1.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.
Comment 14 Fedora Update System 2016-02-02 22:56:41 EST
pcp-3.11.0-1.el5 has been submitted as an update to Fedora EPEL 5. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-57b7efb2d7
Comment 15 Fedora Update System 2016-02-03 17:17:18 EST
pcp-3.11.0-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-57b7efb2d7
Comment 16 Fedora Update System 2016-03-21 20:17:38 EDT
pcp-3.11.1-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-5b519318e0
Comment 17 Fedora Update System 2016-04-06 10:53:52 EDT
pcp-3.11.1-1.el5 has been pushed to the Fedora EPEL 5 stable repository. If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.