sara-nl / irods-msi-persistent-id

iRODS microservices for managing EPIC PIDs
Other
0 stars 0 forks source link

msiPidLookupKey adds extra empty line to output of search #7

Closed cookie33 closed 5 years ago

cookie33 commented 5 years ago

The test shows following:

[irodstest2.storage.surfsara.nl]:~/git/B2SAFE-core/scripts/tests
robertv$ ./testB2SafeCmd.py -test msipid
Test msiPid Script
test_search_handle_by_key_value (testB2SafeCmd.msipidintgtest.MsiPidIntegrationTests)
Test that search by key-value returns matching handle. ... FAIL
['21.T12996/0166E994-3EC9-45BF-8BA6-E719DE4A89C3', '21.T12996/258856EE-7D3B-4EAE-B686-29F9991CD62A', '21.T12996/4C336C14-6B9F-4C12-B2E1-19D7A90164E3', '21.T12996/C88B06B1-610E-4C01-ABB2-A66F21156A2E', '21.T12996/EA4DCF65-D45F-493B-B83D-B6A68AB240BA', '']
test_search_handle_by_non_existing_key_value (testB2SafeCmd.msipidintgtest.MsiPidIntegrationTests)
Test that search handle by non existing key-value returns 'empty'. ... ['21.T12996/0166E994-3EC9-45BF-8BA6-E719DE4A89C3', '21.T12996/258856EE-7D3B-4EAE-B686-29F9991CD62A', '21.T12996/4C336C14-6B9F-4C12-B2E1-19D7A90164E3', '21.T12996/C88B06B1-610E-4C01-ABB2-A66F21156A2E', '21.T12996/EA4DCF65-D45F-493B-B83D-B6A68AB240BA', '']
ok

======================================================================
FAIL: test_search_handle_by_key_value (testB2SafeCmd.msipidintgtest.MsiPidIntegrationTests)
Test that search by key-value returns matching handle.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/robertv/git/B2SAFE-core/scripts/tests/testB2SafeCmd/msipidintgtest.py", line 184, in test_search_handle_by_key_value
    'search existing handle by key returns unexpected response')
AssertionError: search existing handle by key returns unexpected response

----------------------------------------------------------------------
Ran 2 tests in 2.617s

FAILED (failures=1)

It shows an extra empty line when shows matching handles:

[irodstest2.storage.surfsara.nl]:~/git/B2SAFE-core/scripts/tests
robertv$ irule -F /tmp/msiPidLookupKey.r "*key='URL'" "*value='*/igor/testB2SafeCmd/1'"
21.T12996/0166E994-3EC9-45BF-8BA6-E719DE4A89C3
21.T12996/258856EE-7D3B-4EAE-B686-29F9991CD62A
21.T12996/4C336C14-6B9F-4C12-B2E1-19D7A90164E3
21.T12996/C88B06B1-610E-4C01-ABB2-A66F21156A2E
21.T12996/EA4DCF65-D45F-493B-B83D-B6A68AB240BA

Can the extra line be removed?

cookie33 commented 5 years ago

create 2 handles:

[irodstest2.storage.surfsara.nl]:/tmp
robertv$  irule -F /tmp/msiPidCreate.r  "*path='/igor/testB2SafeCmd/1'" "*key_values_inp='CHECKSUM,12345,AAP,noot'"
0
21.T12996/250369cf-ce3d-4da0-a1bf-e0980096f7d3

[irodstest2.storage.surfsara.nl]:/tmp
robertv$  irule -F /tmp/msiPidCreate.r  "*path='/igor/testB2SafeCmd/1'" "*key_values_inp='CHECKSUM,12345,AAP,noot'"
0
21.T12996/e43554ae-b075-4090-806f-721159978996

The script to do this is:

myRule {
   if(strlen(*key_values_inp) > 0)
   {
      *key_values = split(*key_values_inp, ",");
   }
   else
   {
       *key_values = "";
   }

   *err = errorcode(msiPidCreate(*path,*key_values,*handle));
   writeLine("stdout", *err);
   writeLine("stdout", *handle);
}

INPUT *path="", *key_values_inp=""
OUTPUT ruleExecOut

Searching shows:

[irodstest2.storage.surfsara.nl]:/tmp
robertv$ irule -F /tmp/msiPidLookupKey.r "*key='URL'" "*value='*/igor/testB2SafeCmd/1'"
0
21.T12996/250369CF-CE3D-4DA0-A1BF-E0980096F7D3
21.T12996/E43554AE-B075-4090-806F-721159978996

[irodstest2.storage.surfsara.nl]:/tmp
robertv$

So there is an empty extra line in the output. The script to do this is:

myRule {
   *err = errorcode(msiPidLookupKey(*key, "*value", *handles));
   writeLine("stdout", *err);
   foreach(*handles) {
      writeLine("stdout", *handles);
   }
}

INPUT *key="", *value=""
OUTPUT ruleExecOut

The curl search returns:

[irodstest2.storage.surfsara.nl]:/tmp
rods$ curl -u "username:<password>" "https://<fqdn>:<port>/hrls/handles/21.T12996?URL=*/igor/testB2SafeCmd/1"
["21.T12996/250369CF-CE3D-4DA0-A1BF-E0980096F7D3","21.T12996/E43554AE-B075-4090-806F-721159978996"]
cookie33 commented 5 years ago

It seems it is an artefact of my iRODS installation:

Use following script:

[irodstest2.storage.surfsara.nl]:/tmp
robertv$ cat /tmp/test.r
myRule {
       *l=list("a", "b");
       foreach(*l) {
            writeLine("stdout", *l)
       }
}

OUTPUT ruleExecOut

produces next output:

[irodstest2.storage.surfsara.nl]:/tmp
robertv$ irule -F /tmp/test.r
a
b

[irodstest2.storage.surfsara.nl]:/tmp
robertv$

So with an extra line.

[irodstest2.storage.surfsara.nl]:/tmp
robertv$ irule -F /tmp/test.r | wc -l
2

[irodstest2.storage.surfsara.nl]:/tmp
robertv$

Need to test some more...

cookie33 commented 5 years ago

It seems a setting of the session. The PS1 parameter might cause it.

cookie33 commented 5 years ago

Or it might be the test. It does in python:

def subprocess_popen(cmd, input_string=None):
    '''run shell command, get output back in an array'''

    process = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
    (data_stdout, data_stderr) = process.communicate(input_string)
    process.wait()

    if data_stderr != None:
        # relay errors to stderr
        sys.stderr.write(data_stderr)

    arr = string.split(data_stdout, '\n')
    arr = map(string.strip, arr)
    return arr

What if it adds here standard a \n? Even if not needed

cookie33 commented 5 years ago

Fixed testcode:

def subprocess_popen(cmd, input_string=None):
    '''run shell command, get output back in an array'''

    process = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
    (data_stdout, data_stderr) = process.communicate(input_string)
    process.wait()

    if data_stderr != None:
        # relay errors to stderr
        sys.stderr.write(data_stderr)

    arr = string.split(data_stdout, '\n')
    arr = map(string.strip, arr)
    if arr and arr[-1] == '':
        arr.pop()
    return arr