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
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): json_file)
print( json_data)
with open(f) as json_file:
json_data = json.load(
if __name__ == '__main__': sys.argv[ 1])
func(
$ git diff cmd/cleanup. py b/tempest/ cmd/cleanup. py cmd/cleanup. py cmd/cleanup. py command. Command) :
diff --git a/tempest/
index 2f54f9a..f71b2b0 100644
--- a/tempest/
+++ b/tempest/
@@ -311,7 +311,11 @@ class TempestCleanup(
def _load_json(self): STATE_JSON) as json_file: func(SAVED_ STATE_JSON)
self. json_data = json.load( json_file)
try:
with open(SAVED_
+ import pdb; pdb.set_trace()
+ import script
+ script.
except IOError as ex:
$ tempest cleanup tempest/ tempest/ cmd/cleanup. py(317) _load_json( ) tempest/ tempest/ cmd/cleanup. py(318) _load_json( ) func(SAVED_ STATE_JSON) a5a0-4bd2- abb2-eb4a19a29a fc': 'm1.micro', '2': 'm1.small', '3': 'm1.medium', '4': 'm1.large', '5': 'm1.xlarge', '79388ef4- b963-4057- 8d11-a0ce4b156e 1f': 'm1.nano'}, 'images': {}, 'projects': {'268bcb63488b4 aa2942ecaac0f85 ed62': 'demo', 'c40e248acd2249 2abf4ca0cfad13a ca3': 'admin', 'f2f2bb73de1e4e df9c465249cb000 e2e': 'services', 'f81c157b99184c 53a08c42edcf256 64e': 'alt_demo'}, 'roles': {}, 'users': {'023e65a5922a4 54585a91c6af831 0968': 'demo', '26b295116d354b d7b6d6534a87478 8b7': 'nova', '2bca7128607946 c38b61e1555dc06 32a': 'placement', '405bb53f68c848 41b454cf31ecd6f c62': 'ceilometer', '4d7d436275204d 119bdb5b1053add 033': 'glance', '7ec1aac2c02e46 53a920b4e28c64c 166': 'swift', '9092e14ceb0e43 2a9ef48723e4a98 0ec': 'neutron', 'ae1e668149c444 5ab837a23fefe1e c30': 'admin', 'bd2782e336b44e 019a62cb8f56a19 adb': 'gnocchi', 'f334a6c7949b4c eaaf5d78e2e7240 950': 'aodh', 'f3e9262159d247 d5956b9f82d29d6 543': 'cinder', 'f4952230adb949 d5a4140e87b5176 4d5': 'alt_demo'}} tempest/ tempest/ cmd/cleanup. py(319) _load_json( ) json_file)
> /home/centos/
-> import script
(Pdb) n
> /home/centos/
-> script.
(Pdb) n
{'domains': {'default': 'Default'}, 'flavors': {'1': 'm1.tiny', '161c6e9a-
> /home/centos/
-> self.json_data = json.load(
(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