Comment 4 for bug 1806089

Revision history for this message
Martin Kopec (mkopec) wrote :

Let's say, I have the following script and I made the changes in Tempest showed below:

```
$ cat script.py

import json
import sys

def func(f):
    with open(f) as json_file:
        json_data = json.load(json_file)
        print(json_data)

if __name__ == '__main__':
    func(sys.argv[1])

$ git diff
diff --git a/tempest/cmd/cleanup.py b/tempest/cmd/cleanup.py
index 2f54f9a..f71b2b0 100644
--- a/tempest/cmd/cleanup.py
+++ b/tempest/cmd/cleanup.py
@@ -311,7 +311,11 @@ class TempestCleanup(command.Command):

     def _load_json(self):
         try:
             with open(SAVED_STATE_JSON) as json_file:
+ import pdb; pdb.set_trace()
+ import script
+ script.func(SAVED_STATE_JSON)
                 self.json_data = json.load(json_file)

         except IOError as ex:

$ tempest cleanup
> /home/centos/tempest/tempest/cmd/cleanup.py(317)_load_json()
-> import script
(Pdb) n
> /home/centos/tempest/tempest/cmd/cleanup.py(318)_load_json()
-> script.func(SAVED_STATE_JSON)
(Pdb) n
{'domains': {'default': 'Default'}, 'flavors': {'1': 'm1.tiny', '161c6e9a-a5a0-4bd2-abb2-eb4a19a29afc': 'm1.micro', '2': 'm1.small', '3': 'm1.medium', '4': 'm1.large', '5': 'm1.xlarge', '79388ef4-b963-4057-8d11-a0ce4b156e1f': 'm1.nano'}, 'images': {}, 'projects': {'268bcb63488b4aa2942ecaac0f85ed62': 'demo', 'c40e248acd22492abf4ca0cfad13aca3': 'admin', 'f2f2bb73de1e4edf9c465249cb000e2e': 'services', 'f81c157b99184c53a08c42edcf25664e': 'alt_demo'}, 'roles': {}, 'users': {'023e65a5922a454585a91c6af8310968': 'demo', '26b295116d354bd7b6d6534a874788b7': 'nova', '2bca7128607946c38b61e1555dc0632a': 'placement', '405bb53f68c84841b454cf31ecd6fc62': 'ceilometer', '4d7d436275204d119bdb5b1053add033': 'glance', '7ec1aac2c02e4653a920b4e28c64c166': 'swift', '9092e14ceb0e432a9ef48723e4a980ec': 'neutron', 'ae1e668149c4445ab837a23fefe1ec30': 'admin', 'bd2782e336b44e019a62cb8f56a19adb': 'gnocchi', 'f334a6c7949b4ceaaf5d78e2e7240950': 'aodh', 'f3e9262159d247d5956b9f82d29d6543': 'cinder', 'f4952230adb949d5a4140e87b51764d5': 'alt_demo'}}
> /home/centos/tempest/tempest/cmd/cleanup.py(319)_load_json()
-> self.json_data = json.load(json_file)
(Pdb) n
TypeError: can't concat str to bytes

```

I can't explain why `json.load(json_file)` in the script works, but the one other one no. Hmmmmm