diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 321b7e9..3a8607d 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -431,7 +431,7 @@ class OpenStackImagesShell(object): force_auth=True) schema = client.schemas.get("image") - with file(schema_file_path, 'w') as f: + with open(schema_file_path, 'w') as f: f.write(json.dumps(schema.raw())) except Exception as e: #NOTE(esheffield) do nothing here, we'll get a message later diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index b21429b..d7c62b3 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -29,7 +29,7 @@ def get_image_schema(): if IMAGE_SCHEMA is None: schema_path = expanduser("~/.glanceclient/image_schema.json") if os.path.exists(schema_path) and os.path.isfile(schema_path): - with file(schema_path, "r") as f: + with open(schema_path, "r") as f: schema_raw = f.read() IMAGE_SCHEMA = json.loads(schema_raw) return IMAGE_SCHEMA diff --git a/tests/test_shell.py b/tests/test_shell.py index 47b5b30..28b8f6d 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -137,7 +137,7 @@ class ShellCacheSchemaTest(utils.TestCase): return Args(args) - @mock.patch('__builtin__.file', new=mock.mock_open(), create=True) + @mock.patch('__builtin__.open', new=mock.mock_open(), create=True) def test_cache_schema_gets_when_not_exists(self): mocked_path_exists_result_lst = [True, False] os.path.exists.side_effect = \ @@ -150,12 +150,12 @@ class ShellCacheSchemaTest(utils.TestCase): self.shell._cache_schema(self._make_args(options), home_dir=self.cache_dir) - self.assertEqual(4, file.mock_calls.__len__()) - self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0]) + self.assertEqual(4, open.mock_calls.__len__()) + self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0]) self.assertEqual(mock.call().write(json.dumps(self.schema_dict)), - file.mock_calls[2]) + open.mock_calls[2]) - @mock.patch('__builtin__.file', new=mock.mock_open(), create=True) + @mock.patch('__builtin__.open', new=mock.mock_open(), create=True) def test_cache_schema_gets_when_forced(self): os.path.exists.return_value = True @@ -166,12 +166,12 @@ class ShellCacheSchemaTest(utils.TestCase): self.shell._cache_schema(self._make_args(options), home_dir=self.cache_dir) - self.assertEqual(4, file.mock_calls.__len__()) - self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0]) + self.assertEqual(4, open.mock_calls.__len__()) + self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0]) self.assertEqual(mock.call().write(json.dumps(self.schema_dict)), - file.mock_calls[2]) + open.mock_calls[2]) - @mock.patch('__builtin__.file', new=mock.mock_open(), create=True) + @mock.patch('__builtin__.open', new=mock.mock_open(), create=True) def test_cache_schema_leaves_when_present_not_forced(self): os.path.exists.return_value = True @@ -185,4 +185,4 @@ class ShellCacheSchemaTest(utils.TestCase): os.path.exists.assert_any_call(self.cache_dir) os.path.exists.assert_any_call(self.cache_file) self.assertEqual(2, os.path.exists.call_count) - self.assertEqual(0, file.mock_calls.__len__()) + self.assertEqual(0, open.mock_calls.__len__()) diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 569fabb..5403f0f 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -120,7 +120,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected cert should have CN=0.0.0.0 self.assertEqual(cert.get_subject().commonName, '0.0.0.0') try: @@ -135,7 +135,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected cert should have CN=*.pong.example.com self.assertEqual(cert.get_subject().commonName, '*.pong.example.com') try: @@ -150,7 +150,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected cert should have CN=0.0.0.0 self.assertEqual(cert.get_subject().commonName, '0.0.0.0') try: @@ -171,7 +171,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected cert should have CN=0.0.0.0 self.assertEqual(cert.get_subject().commonName, '0.0.0.0') try: @@ -199,7 +199,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected cert should have CN=0.0.0.0 self.assertEqual(cert.get_subject().commonName, '0.0.0.0') try: @@ -216,7 +216,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): """ cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, - file(cert_file).read()) + open(cert_file).read()) # The expected expired cert has CN=openstack.example.com self.assertEqual(cert.get_subject().commonName, 'openstack.example.com')