Replace file with open, which is Python 3 compatible
Change-Id: I471ae9b372f88a508d4654b1a18c6da90397a828
This commit is contained in:
@@ -431,7 +431,7 @@ class OpenStackImagesShell(object):
|
|||||||
force_auth=True)
|
force_auth=True)
|
||||||
schema = client.schemas.get("image")
|
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()))
|
f.write(json.dumps(schema.raw()))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#NOTE(esheffield) do nothing here, we'll get a message later
|
#NOTE(esheffield) do nothing here, we'll get a message later
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def get_image_schema():
|
|||||||
if IMAGE_SCHEMA is None:
|
if IMAGE_SCHEMA is None:
|
||||||
schema_path = expanduser("~/.glanceclient/image_schema.json")
|
schema_path = expanduser("~/.glanceclient/image_schema.json")
|
||||||
if os.path.exists(schema_path) and os.path.isfile(schema_path):
|
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()
|
schema_raw = f.read()
|
||||||
IMAGE_SCHEMA = json.loads(schema_raw)
|
IMAGE_SCHEMA = json.loads(schema_raw)
|
||||||
return IMAGE_SCHEMA
|
return IMAGE_SCHEMA
|
||||||
|
|||||||
+10
-10
@@ -137,7 +137,7 @@ class ShellCacheSchemaTest(utils.TestCase):
|
|||||||
|
|
||||||
return Args(args)
|
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):
|
def test_cache_schema_gets_when_not_exists(self):
|
||||||
mocked_path_exists_result_lst = [True, False]
|
mocked_path_exists_result_lst = [True, False]
|
||||||
os.path.exists.side_effect = \
|
os.path.exists.side_effect = \
|
||||||
@@ -150,12 +150,12 @@ class ShellCacheSchemaTest(utils.TestCase):
|
|||||||
self.shell._cache_schema(self._make_args(options),
|
self.shell._cache_schema(self._make_args(options),
|
||||||
home_dir=self.cache_dir)
|
home_dir=self.cache_dir)
|
||||||
|
|
||||||
self.assertEqual(4, file.mock_calls.__len__())
|
self.assertEqual(4, open.mock_calls.__len__())
|
||||||
self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0])
|
self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0])
|
||||||
self.assertEqual(mock.call().write(json.dumps(self.schema_dict)),
|
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):
|
def test_cache_schema_gets_when_forced(self):
|
||||||
os.path.exists.return_value = True
|
os.path.exists.return_value = True
|
||||||
|
|
||||||
@@ -166,12 +166,12 @@ class ShellCacheSchemaTest(utils.TestCase):
|
|||||||
self.shell._cache_schema(self._make_args(options),
|
self.shell._cache_schema(self._make_args(options),
|
||||||
home_dir=self.cache_dir)
|
home_dir=self.cache_dir)
|
||||||
|
|
||||||
self.assertEqual(4, file.mock_calls.__len__())
|
self.assertEqual(4, open.mock_calls.__len__())
|
||||||
self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0])
|
self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0])
|
||||||
self.assertEqual(mock.call().write(json.dumps(self.schema_dict)),
|
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):
|
def test_cache_schema_leaves_when_present_not_forced(self):
|
||||||
os.path.exists.return_value = True
|
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_dir)
|
||||||
os.path.exists.assert_any_call(self.cache_file)
|
os.path.exists.assert_any_call(self.cache_file)
|
||||||
self.assertEqual(2, os.path.exists.call_count)
|
self.assertEqual(2, os.path.exists.call_count)
|
||||||
self.assertEqual(0, file.mock_calls.__len__())
|
self.assertEqual(0, open.mock_calls.__len__())
|
||||||
|
|||||||
+6
-6
@@ -120,7 +120,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
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
|
# The expected cert should have CN=0.0.0.0
|
||||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||||
try:
|
try:
|
||||||
@@ -135,7 +135,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||||
file(cert_file).read())
|
open(cert_file).read())
|
||||||
# The expected cert should have CN=*.pong.example.com
|
# The expected cert should have CN=*.pong.example.com
|
||||||
self.assertEqual(cert.get_subject().commonName, '*.pong.example.com')
|
self.assertEqual(cert.get_subject().commonName, '*.pong.example.com')
|
||||||
try:
|
try:
|
||||||
@@ -150,7 +150,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
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
|
# The expected cert should have CN=0.0.0.0
|
||||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||||
try:
|
try:
|
||||||
@@ -171,7 +171,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
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
|
# The expected cert should have CN=0.0.0.0
|
||||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||||
try:
|
try:
|
||||||
@@ -199,7 +199,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
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
|
# The expected cert should have CN=0.0.0.0
|
||||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||||
try:
|
try:
|
||||||
@@ -216,7 +216,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
|||||||
"""
|
"""
|
||||||
cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt')
|
cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt')
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||||
file(cert_file).read())
|
open(cert_file).read())
|
||||||
# The expected expired cert has CN=openstack.example.com
|
# The expected expired cert has CN=openstack.example.com
|
||||||
self.assertEqual(cert.get_subject().commonName,
|
self.assertEqual(cert.get_subject().commonName,
|
||||||
'openstack.example.com')
|
'openstack.example.com')
|
||||||
|
|||||||
Reference in New Issue
Block a user