* Replace __builtin__ with six.moves.builtins.
* Replace tempfile.mkstemp() with tempfile.NamedTemporaryFile() to get a
text file instead of a binary file.
* tox.ini: add the following tests to Python 3.4
- cinder.tests.unit.test_hitachi_hnas_backend
- cinder.tests.unit.test_hitachi_hnas_iscsi
- cinder.tests.unit.test_hitachi_hnas_nfs
Blueprint cinder-python3
Change-Id: I9a26b4e67033a443271e8f13bcaea5e122ec865a
super(HDSHNASBendTest, self).setUp()
self.hnas_bend = hnas_backend.HnasBackend(DRV_CONF)
- @mock.patch('__builtin__.open')
+ @mock.patch('six.moves.builtins.open')
@mock.patch('os.path.isfile', return_value=True)
@mock.patch('paramiko.RSAKey.from_private_key_file')
@mock.patch('paramiko.SSHClient')
self.backend = SimulatedHnasBackend()
_factory_bend.return_value = self.backend
- (handle, self.config_file) = tempfile.mkstemp('.xml')
- os.write(handle, HNASCONF)
- os.close(handle)
+ self.config_file = tempfile.NamedTemporaryFile("w+", suffix='.xml')
+ self.addCleanup(self.config_file.close)
+ self.config_file.write(HNASCONF)
+ self.config_file.flush()
self.configuration = mock.Mock(spec=conf.Configuration)
- self.configuration.hds_hnas_iscsi_config_file = self.config_file
+ self.configuration.hds_hnas_iscsi_config_file = self.config_file.name
self.configuration.hds_svc_iscsi_chap_enabled = True
self.driver = iscsi.HDSISCSIDriver(configuration=self.configuration)
self.driver.do_setup("")
- self.addCleanup(self._clean)
-
- def _clean(self):
- os.remove(self.config_file)
def _create_volume(self):
loc = self.driver.create_volume(_VOLUME)
vol['provider_location'] = loc['provider_location']
return vol
- @mock.patch('__builtin__.open')
+ @mock.patch('six.moves.builtins.open')
@mock.patch.object(os, 'access')
def test_read_config(self, m_access, m_open):
# Test exception when file is not found
self.backend = SimulatedHnasBackend()
m_factory_bend.return_value = self.backend
- (handle, self.config_file) = tempfile.mkstemp('.xml')
- os.write(handle, HNASCONF)
- os.close(handle)
- (handle, self.shares_file) = tempfile.mkstemp('')
- os.write(handle, SHARESCONF)
- os.close(handle)
+ self.config_file = tempfile.NamedTemporaryFile("w+", suffix='.xml')
+ self.addCleanup(self.config_file.close)
+ self.config_file.write(HNASCONF)
+ self.config_file.flush()
+
+ self.shares_file = tempfile.NamedTemporaryFile("w+", suffix='.xml')
+ self.addCleanup(self.shares_file.close)
+ self.shares_file.write(SHARESCONF)
+ self.shares_file.flush()
self.configuration = mock.Mock(spec=conf.Configuration)
- self.configuration.hds_hnas_nfs_config_file = self.config_file
- self.configuration.nfs_shares_config = self.shares_file
+ self.configuration.hds_hnas_nfs_config_file = self.config_file.name
+ self.configuration.nfs_shares_config = self.shares_file.name
self.configuration.nfs_mount_point_base = '/opt/stack/cinder/mnt'
self.configuration.nfs_mount_options = None
self.configuration.nas_ip = None
self.driver = nfs.HDSNFSDriver(configuration=self.configuration)
self.driver.do_setup("")
- self.addCleanup(self._clean)
-
- def _clean(self):
- os.remove(self.config_file)
- os.remove(self.shares_file)
- @mock.patch('__builtin__.open')
+ @mock.patch('six.moves.builtins.open')
@mock.patch.object(os, 'access')
def test_read_config(self, m_access, m_open):
# Test exception when file is not found
cinder.tests.unit.test_hitachi_hbsd_horcm_fc \
cinder.tests.unit.test_hitachi_hbsd_snm2_fc \
cinder.tests.unit.test_hitachi_hbsd_snm2_iscsi \
+ cinder.tests.unit.test_hitachi_hnas_backend \
+ cinder.tests.unit.test_hitachi_hnas_iscsi \
+ cinder.tests.unit.test_hitachi_hnas_nfs \
cinder.tests.unit.test_hp_xp_fc \
cinder.tests.unit.test_hplefthand \
cinder.tests.unit.test_huawei_drivers \