diff --git a/tacker/conductor/conductor_server.py b/tacker/conductor/conductor_server.py index d5b76301e..3c3747c4a 100644 --- a/tacker/conductor/conductor_server.py +++ b/tacker/conductor/conductor_server.py @@ -16,7 +16,6 @@ import datetime import functools import inspect -import io import os import shutil import sys @@ -338,7 +337,8 @@ class Conductor(manager.Manager): for file in imported_yamls: file_path = os.path.join( csar_path, dir_of_parent_definition_file, file) - file_data = yaml.safe_load(io.open(file_path)) + with open(file_path) as f: + file_data = yaml.safe_load(f) dest_file_path = os.path.abspath(file_path).split( csar_path + '/')[-1] file_path_and_data[dest_file_path] = yaml.dump(file_data) @@ -356,8 +356,9 @@ class Conductor(manager.Manager): # This is CSAR containing a TOSCA-Metadata directory, which # includes the TOSCA.meta metadata file providing an entry # information for processing a CSAR file. - tosca_meta_data = yaml.safe_load(io.open(os.path.join( - csar_path, 'TOSCA-Metadata', 'TOSCA.meta'))) + with open(os.path.join( + csar_path, 'TOSCA-Metadata', 'TOSCA.meta')) as f: + tosca_meta_data = yaml.safe_load(f) file_path_and_data['TOSCA-Metadata/TOSCA.meta'] = yaml.dump( tosca_meta_data) entry_defination_file = tosca_meta_data['Entry-Definitions'] @@ -371,7 +372,8 @@ class Conductor(manager.Manager): os.listdir(csar_path), key=lambda item: item.endswith(('yaml', '.yml')))[-1] src_path = os.path.join(csar_path, root_yaml_file) - file_data = yaml.safe_load(io.open(src_path)) + with open(src_path) as f: + file_data = yaml.safe_load(f) file_path_and_data[root_yaml_file] = yaml.dump(file_data) return file_path_and_data diff --git a/tacker/tests/unit/conductor/fakes.py b/tacker/tests/unit/conductor/fakes.py index 885314eea..be9e152d0 100644 --- a/tacker/tests/unit/conductor/fakes.py +++ b/tacker/tests/unit/conductor/fakes.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import io import os from oslo_config import cfg import shutil @@ -105,9 +104,9 @@ def get_expected_vnfd_data(zip_file=None): 'Definitions/etsi_nfv_sol001_common_types.yaml'] file_path_and_data = {} for file_name in file_names: - with io.open(os.path.join(csar_temp_dir, file_name)) as f: - file_path_and_data.update({file_name: yaml.dump(yaml.safe_load( - f))}) + with open(os.path.join(csar_temp_dir, file_name)) as f: + file_path_and_data.update({file_name: yaml.dump( + yaml.safe_load(f))}) shutil.rmtree(csar_temp_dir) return file_path_and_data diff --git a/tacker/tests/unit/nfvo/test_nfvo_plugin.py b/tacker/tests/unit/nfvo/test_nfvo_plugin.py index 634d0dfa9..8a56b0b4a 100644 --- a/tacker/tests/unit/nfvo/test_nfvo_plugin.py +++ b/tacker/tests/unit/nfvo/test_nfvo_plugin.py @@ -51,8 +51,8 @@ def dummy_get_vim(*args, **kwargs): def _get_template(name): filename = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../etc/samples/' + str(name))) - f = codecs.open(filename, encoding='utf-8', errors='strict') - return f.read() + with codecs.open(filename, encoding='utf-8', errors='strict') as f: + return f.read() class FakeDriverManager(mock.Mock): diff --git a/tacker/tests/unit/vnfm/tosca/test_utils.py b/tacker/tests/unit/vnfm/tosca/test_utils.py index 3cfb49131..2cc5fdc5a 100644 --- a/tacker/tests/unit/vnfm/tosca/test_utils.py +++ b/tacker/tests/unit/vnfm/tosca/test_utils.py @@ -27,8 +27,8 @@ def _get_template(name): filename = os.path.join( os.path.dirname(os.path.abspath(__file__)), "../infra_drivers/openstack/data/", name) - f = codecs.open(filename, encoding='utf-8', errors='strict') - return f.read() + with codecs.open(filename, encoding='utf-8', errors='strict') as f: + return f.read() class TestToscaUtils(testtools.TestCase): diff --git a/tacker/tests/unit/vnfpkgm/fakes.py b/tacker/tests/unit/vnfpkgm/fakes.py index 032075698..fd9e9e72b 100644 --- a/tacker/tests/unit/vnfpkgm/fakes.py +++ b/tacker/tests/unit/vnfpkgm/fakes.py @@ -16,7 +16,6 @@ from copy import deepcopy import datetime -import io import iso8601 import os import shutil @@ -249,9 +248,9 @@ def return_vnfd_data(csar_without_tosca_meta=False): 'Definitions/etsi_nfv_sol001_vnfd_types.yaml'] file_path_and_data = {} for file_name in file_names: - with io.open(os.path.join(csar_temp_dir, file_name)) as f: - file_path_and_data.update({file_name: yaml.dump(yaml.safe_load( - f))}) + with open(os.path.join(csar_temp_dir, file_name)) as f: + file_path_and_data.update({file_name: yaml.dump( + yaml.safe_load(f))}) shutil.rmtree(csar_temp_dir) return file_path_and_data