OpenIxia / IxNetwork

A central location for IxNetwork sample scripts and utilities. Please also visit http://openixia.com
MIT License
51 stars 59 forks source link

RestPy: CsvSnapshot.update doesn't work #118

Closed matsuda73 closed 4 years ago

matsuda73 commented 4 years ago

The following code worked before, but it doesn't work with the latest RestPy and IxNetwork Web. Am I missing anything?

snippet

    statistics = session.Ixnetwork.Statistics
    csvsnapshot = statistics.CsvSnapshot
    csvsnapshot.update(CsvName='Flow Statistics Snapshot',
                       CsvLocation=statistics.CsvFilePath,
                       SnapshotViewCsvGenerationMode='overwriteCSVFile',
                       SnapshotViewContents='allPages',
                       Views=statistics.View.find(Caption='Flow Statistics'))          ======> *1
    csvsnapshot.TakeCsvSnapshot()
    time.sleep(10)
    print(csvsnapshot)                                                                 ======> *2
    filename = csvsnapshot.CsvName + '.csv'
    remoteFile = os.path.normpath(os.path.join(csvsnapshot.CsvLocation, filename))
    localFile = os.path.normpath(os.path.join(localResultsPath, filename))
    print('Downloading from API server:{} to local:{}'.format(remoteFile, localFile))
    session.Session.DownloadFile(remoteFile, localFile)                                ======> *3

[*1] Script Watch shows that csvSnapshot (on API Server) is updated.

65  127.0.0.1:46646 ixnetwork-restpy    2020-09-07 22:46:21.264 3ms PATCH /api/v1/sessions/11/ixnetwork/statistics/csvSnapshot
PATCH /api/v1/sessions/11/ixnetwork/statistics/csvSnapshot
Connection: keep-alive
Content-Type: application/json
Accept: */*
Cookie: spyder-ixSessionId=e32ba117-6a51-4259-a850-18c043798116,$Version=1;IXUSER=matsuda
Host: 127.0.0.1:9101
User-Agent: ixnetwork-restpy
Content-Length: 281
X-HTTP-Method-Override: PATCH
X-Api-Key: bad6768e164e4b92b35b99a42f7a6ce5

{
  "views": [
    "/api/v1/sessions/11/ixnetwork/statistics/view/13"
  ],
  "snapshotViewCsvGenerationMode": "overwriteCSVFile",
  "snapshotViewContents": "allPages",
  "csvName": "Flow Statistics Snapshot",
  "csvLocation": "/root/.local/share/Ixia/IxNetwork/data/logs/Test1-20200907-224306099821"
}

200 OK
Content-Type: text/plain; charset=utf-8
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *

[*2] However, csvsnapshot (local) is not updated

CsvSnapshot[0]: /api/v1/sessions/11/ixnetwork/statistics/csvSnapshot
        CsvDecimalPrecision: 3
        CsvDumpTxPortLabelMap: False
        CsvFormatTimestamp: True
        CsvLocation: /root/.local/share/Ixia/sdmStreamManager/common
        CsvName: ixnetwork.restpy.1599543795.0188916.Port-Statistics
        CsvStringQuotes: False
        CsvSupportsCSVSorting: False
        NextGenRefreshBeforeSnapshot: True
        OpenViewer: False
        SnapshotSettingsName: DefaultSnapshotSettings
        SnapshotViewContents: allPages
        SnapshotViewCsvGenerationMode: overwriteCSVFile
        Views: ['/api/v1/sessions/11/ixnetwork/statistics/view/1']

[*3] As a result, download fails due to NotFoundError

Traceback (most recent call last):
  File "/home/mtdtks/work/IxNetwork/RestPy/DemoScripts/demo3a.py", line 126, in <module>
    session.Session.DownloadFile(remoteFile, localFile)
  File "/usr/local/lib/python3.6/dist-packages/ixnetwork_restpy/testplatform/sessions/sessions.py", line 343, in DownloadFile
    remote_filename=remote_filename, local_filename=local_filename)
  File "/usr/local/lib/python3.6/dist-packages/ixnetwork_restpy/connection.py", line 284, in _get_file
    self._process_response_status_code(url, headers, response)
  File "/usr/local/lib/python3.6/dist-packages/ixnetwork_restpy/connection.py", line 353, in _process_response_status_code
    raise NotFoundError(message, response.status_code)
ixnetwork_restpy.errors.NotFoundError: File /root/.local/share/Ixia/sdmStreamManager/common/ixnetwork.restpy.1599543795.0188916.Port-Statistics.csv does not exist on the system

If I modify the following line, I can download the correct file (Flow Statistics Snapshot.csv). remoteFile = os.path.normpath(os.path.join(statistics.CsvFilePath, 'Flow Statistics Snapshot.csv'))

Thanks, Matsuda

therkong commented 4 years ago

Hi Matsuda,

You need to add csvsnapshot.refresh() after calling csvsnapshot.update(CsvName='Flow Statistics Snapshot',...) csvsnapshot.update() only updates the ixNet API Server side, not the script side. You need to call refresh() in order to update csvsnapshot.CsvName var on the script side. Please try it out and let me know how it goes.

matsuda73 commented 4 years ago

Hi,

It goes well now.

By the way, my script worked without csvsnapshot.refresh() with the earlier version of ixnetwork-restpy (probably 1.0.55). Is it changed recently? And csvsnapshot.refresh() is missing in the following sample script. ($LIBRARY PATH)/ixnetwork_restpy/samples/statistics/csv_snapshot.py

Thanks, Matsuda

therkong commented 4 years ago

Hi Matsuda,

I tried with ixNetwork 9.0. I need the refresh() line. I also tried with older ixnetwork_restpy version 1.0.53. I also need the refresh() line. I'm not sure how your script worked before, but as far as I know, you need to call refresh after the update. We will update the sample script in ixnetwork_restpy samples.