def test_create_host_pipe_prefix_with_real_dir(self, temp_dir): runtime_paths = RunTimePaths('account', {'host_root': temp_dir}) runtime_paths.create_host_pipe_prefix() path = runtime_paths.host_pipe_prefix() self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isdir(path)) permission = oct(os.stat(path)[ST_MODE])[-3:] # TODO(kota_): make sure if this is really acceptable self.assertEqual('777', permission)
class TestRuntimePaths(unittest.TestCase): def setUp(self): self.scope = '0123456789abc' self._initialize() def _initialize(self): # TODO(takashi): take these values from config file base_dir = '/home/docker_device' self.script_dir = os.path.join(base_dir, 'scripts') self.pipes_dir = os.path.join(base_dir, 'pipes', 'scopes') self.storlets_dir = os.path.join(base_dir, 'storlets', 'scopes') self.log_dir = os.path.join(base_dir, 'logs', 'scopes') self.cache_dir = os.path.join(base_dir, 'cache', 'scopes') self.conf = {} self.storlet_id = 'org.openstack.storlet.mystorlet' self.paths = RunTimePaths(self.scope, self.conf) def tearDown(self): pass def test_host_pipe_prefix(self): self.assertEqual(self.paths.host_pipe_prefix(), os.path.join(self.pipes_dir, self.scope)) def test_create_host_pipe_prefix(self): pipedir = self.paths.host_pipe_prefix() # When the directory exists with mock.patch('os.path.exists', return_value=True), \ mock.patch('os.makedirs') as m, \ mock.patch('os.chmod') as c: self.paths.create_host_pipe_prefix() self.assertEqual(0, m.call_count) cargs, ckwargs = c.call_args # Make sure about the target directory self.assertEqual(cargs[0], pipedir) # When the directory does not exist with mock.patch('os.path.exists', return_value=False), \ mock.patch('os.makedirs') as m, \ mock.patch('os.chmod') as c: self.paths.create_host_pipe_prefix(), self.assertEqual(1, m.call_count) # Make sure about the target directory margs, mkwargs = m.call_args self.assertEqual(margs[0], pipedir) cargs, ckwargs = c.call_args self.assertEqual(cargs[0], pipedir) def test_host_factory_pipe(self): self.assertEqual( self.paths.host_factory_pipe(), os.path.join(self.pipes_dir, self.scope, 'factory_pipe')) def test_host_storlet_pipe(self): self.assertEqual( self.paths.host_storlet_pipe(self.storlet_id), os.path.join(self.pipes_dir, self.scope, self.storlet_id)) def test_sbox_storlet_pipe(self): self.assertEqual(self.paths.sbox_storlet_pipe(self.storlet_id), os.path.join('/mnt/channels', self.storlet_id)) def test_sbox_storlet_exec(self): self.assertEqual(self.paths.sbox_storlet_exec(self.storlet_id), os.path.join('/home/swift', self.storlet_id)) def test_host_storlet_prefix(self): self.assertEqual(self.paths.host_storlet_prefix(), os.path.join(self.storlets_dir, self.scope)) def test_host_storlet(self): self.assertEqual( self.paths.host_storlet(self.storlet_id), os.path.join(self.storlets_dir, self.scope, self.storlet_id)) def test_slog_path(self): with mock.patch('os.path.exists', return_value=True), \ mock.patch('os.makedirs') as m: self.assertEqual( self.paths.slog_path(self.storlet_id), os.path.join(self.log_dir, self.scope, self.storlet_id)) self.assertEqual(0, m.call_count) with mock.patch('os.path.exists', return_value=False), \ mock.patch('os.makedirs') as m: self.assertEqual( self.paths.slog_path(self.storlet_id), os.path.join(self.log_dir, self.scope, self.storlet_id)) self.assertEqual(1, m.call_count) def test_get_host_storlet_cache_dir(self): self.assertEqual(self.paths.get_host_storlet_cache_dir(), os.path.join(self.cache_dir, self.scope, 'storlet')) def test_get_host_dependency_cache_dir(self): self.assertEqual( self.paths.get_host_dependency_cache_dir(), os.path.join(self.cache_dir, self.scope, 'dependency')) def test_runtime_paths_default(self): # CHECK: docs says we need 4 dirs for communicate # ==================================================================== # |1| host_factory_pipe_path | <pipes_dir>/<scope>/factory_pipe | # ==================================================================== # |2| host_storlet_pipe_path | <pipes_dir>/<scope>/<storlet_id> | # ==================================================================== # |3| sandbox_factory_pipe_path | /mnt/channels/factory_pipe | # ==================================================================== # |4| sandbox_storlet_pipe_path | /mnt/channels/<storlet_id> | # ==================================================================== # # With this test, the scope value is "account" and the storlet_id is # "Storlet-1.0.jar" (app name?) # ok, let's check for these values runtime_paths = RunTimePaths('account', {}) storlet_id = 'Storlet-1.0.jar' # For pipe self.assertEqual('/home/docker_device/pipes/scopes/account', runtime_paths.host_pipe_prefix()) # 1. host_factory_pipe_path <pipes_dir>/<scope>/factory_pipe self.assertEqual( '/home/docker_device/pipes/scopes/account/factory_pipe', runtime_paths.host_factory_pipe()) # 2. host_storlet_pipe_path <pipes_dir>/<scope>/<storlet_id> self.assertEqual( '/home/docker_device/pipes/scopes/account/Storlet-1.0.jar', runtime_paths.host_storlet_pipe(storlet_id)) # 3. Yes, right now, we don't have the path for #3 in Python # 4. sandbox_storlet_pipe_path | /mnt/channels/<storlet_id> self.assertEqual('/mnt/channels/Storlet-1.0.jar', runtime_paths.sbox_storlet_pipe(storlet_id)) # This looks like for jar load? self.assertEqual('/home/docker_device/storlets/scopes/account', runtime_paths.host_storlet_prefix()) self.assertEqual( '/home/docker_device/storlets/scopes/account/Storlet-1.0.jar', runtime_paths.host_storlet(storlet_id)) # And this one is a mount poit in sand box? self.assertEqual('/home/swift/Storlet-1.0.jar', runtime_paths.sbox_storlet_exec(storlet_id)) @with_tempdir def test_create_host_pipe_prefix_with_real_dir(self, temp_dir): runtime_paths = RunTimePaths('account', {'host_root': temp_dir}) runtime_paths.create_host_pipe_prefix() path = runtime_paths.host_pipe_prefix() self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isdir(path)) permission = oct(os.stat(path)[ST_MODE])[-3:] # TODO(kota_): make sure if this is really acceptable self.assertEqual('777', permission)
class TestRuntimePaths(unittest.TestCase): def setUp(self): self.scope = '0123456789abc' self._initialize() def _initialize(self): # TODO(takashi): take these values from config file base_dir = '/home/docker_device' self.script_dir = os.path.join(base_dir, 'scripts') self.pipes_dir = os.path.join(base_dir, 'pipes', 'scopes') self.storlets_dir = os.path.join(base_dir, 'storlets', 'scopes') self.log_dir = os.path.join(base_dir, 'logs', 'scopes') self.cache_dir = os.path.join(base_dir, 'cache', 'scopes') self.conf = {} self.storlet_id = 'org.openstack.storlet.mystorlet' self.paths = RunTimePaths(self.scope, self.conf) def tearDown(self): pass def test_host_pipe_prefix(self): self.assertEqual( self.paths.host_pipe_prefix(), os.path.join(self.pipes_dir, self.scope)) def test_create_host_pipe_prefix(self): pipedir = self.paths.host_pipe_prefix() # When the directory exists with mock.patch('os.path.exists', return_value=True), \ mock.patch('os.makedirs') as m, \ mock.patch('os.chmod') as c: self.paths.create_host_pipe_prefix() self.assertEqual(m.call_count, 0) cargs, ckwargs = c.call_args # Make sure about the target directory self.assertEqual(cargs[0], pipedir) # When the directory does not exist with mock.patch('os.path.exists', return_value=False), \ mock.patch('os.makedirs') as m, \ mock.patch('os.chmod') as c: self.paths.create_host_pipe_prefix(), self.assertEqual(m.call_count, 1) # Make sure about the target directory margs, mkwargs = m.call_args self.assertEqual(margs[0], pipedir) cargs, ckwargs = c.call_args self.assertEqual(cargs[0], pipedir) def test_host_factory_pipe(self): self.assertEqual( self.paths.host_factory_pipe(), os.path.join(self.pipes_dir, self.scope, 'factory_pipe')) def test_host_storlet_pipe(self): self.assertEqual( self.paths.host_storlet_pipe(self.storlet_id), os.path.join(self.pipes_dir, self.scope, self.storlet_id)) def test_sbox_storlet_pipe(self): self.assertEqual( self.paths.sbox_storlet_pipe(self.storlet_id), os.path.join('/mnt/channels', self.storlet_id)) def test_sbox_storlet_exec(self): self.assertEqual( self.paths.sbox_storlet_exec(self.storlet_id), os.path.join('/home/swift', self.storlet_id)) def test_host_storlet_prefix(self): self.assertEqual( self.paths.host_storlet_prefix(), os.path.join(self.storlets_dir, self.scope)) def test_host_storlet(self): self.assertEqual( self.paths.host_storlet(self.storlet_id), os.path.join(self.storlets_dir, self.scope, self.storlet_id)) def test_slog_path(self): with mock.patch('os.path.exists', return_value=True), \ mock.patch('os.makedirs') as m: self.assertEqual( self.paths.slog_path(self.storlet_id), os.path.join(self.log_dir, self.scope, self.storlet_id)) self.assertEqual(m.call_count, 0) with mock.patch('os.path.exists', return_value=False), \ mock.patch('os.makedirs') as m: self.assertEqual( self.paths.slog_path(self.storlet_id), os.path.join(self.log_dir, self.scope, self.storlet_id)) self.assertEqual(m.call_count, 1) def test_get_host_storlet_cache_dir(self): self.assertEqual( self.paths.get_host_storlet_cache_dir(), os.path.join(self.cache_dir, self.scope, 'storlet')) def test_get_host_dependency_cache_dir(self): self.assertEqual( self.paths.get_host_dependency_cache_dir(), os.path.join(self.cache_dir, self.scope, 'dependency')) def test_runtime_paths_default(self): # CHECK: docs says we need 4 dirs for communicate # ==================================================================== # |1| host_factory_pipe_path | <pipes_dir>/<scope>/factory_pipe | # ==================================================================== # |2| host_storlet_pipe_path | <pipes_dir>/<scope>/<storlet_id> | # ==================================================================== # |3| sandbox_factory_pipe_path | /mnt/channels/factory_pipe | # ==================================================================== # |4| sandbox_storlet_pipe_path | /mnt/channels/<storlet_id> | # ==================================================================== # # With this test, the scope value is "account" and the storlet_id is # "Storlet-1.0.jar" (app name?) # ok, let's check for these values runtime_paths = RunTimePaths('account', {}) storlet_id = 'Storlet-1.0.jar' # For pipe self.assertEqual('/home/docker_device/pipes/scopes/account', runtime_paths.host_pipe_prefix()) # 1. host_factory_pipe_path <pipes_dir>/<scope>/factory_pipe self.assertEqual( '/home/docker_device/pipes/scopes/account/factory_pipe', runtime_paths.host_factory_pipe()) # 2. host_storlet_pipe_path <pipes_dir>/<scope>/<storlet_id> self.assertEqual( '/home/docker_device/pipes/scopes/account/Storlet-1.0.jar', runtime_paths.host_storlet_pipe(storlet_id)) # 3. Yes, right now, we don't have the path for #3 in Python # 4. sandbox_storlet_pipe_path | /mnt/channels/<storlet_id> self.assertEqual('/mnt/channels/Storlet-1.0.jar', runtime_paths.sbox_storlet_pipe(storlet_id)) # This looks like for jar load? self.assertEqual('/home/docker_device/storlets/scopes/account', runtime_paths.host_storlet_prefix()) self.assertEqual( '/home/docker_device/storlets/scopes/account/Storlet-1.0.jar', runtime_paths.host_storlet(storlet_id)) # And this one is a mount poit in sand box? self.assertEqual('/home/swift/Storlet-1.0.jar', runtime_paths.sbox_storlet_exec(storlet_id)) @with_tempdir def test_create_host_pipe_prefix_with_real_dir(self, temp_dir): runtime_paths = RunTimePaths('account', {'host_root': temp_dir}) runtime_paths.create_host_pipe_prefix() path = runtime_paths.host_pipe_prefix() self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isdir(path)) permission = oct(os.stat(path)[ST_MODE])[-3:] # TODO(kota_): make sure if this is really acceptable self.assertEqual('777', permission)