def attach(self, context, volmap): mountpoint = mount.get_mountpoint(volmap.volume.uuid) fileutils.ensure_tree(mountpoint) filename = '/'.join([mountpoint, volmap.volume.uuid]) with open(filename, 'wb') as fd: content = utils.decode_file_data(volmap.contents) fd.write(content)
def test_attach(self, mock_get_mountpoint, mock_ensure_tree): mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Local() with mock.patch('zun.volume.driver.open', mock.mock_open() ) as mock_open: volume_driver.attach(self.context, self.volmap) expected_file_path = self.fake_mountpoint + '/' + self.fake_uuid mock_open.assert_called_once_with(expected_file_path, 'wb') mock_open().write.assert_called_once_with( utils.decode_file_data(self.fake_contents)) mock_get_mountpoint.assert_called_once_with(self.fake_uuid)