def test_create_dir(self): p = os.path.join(self.BASEDIRNAME, base.random_num_string(15)) base.create_dir(p) self.assertTrue(os.path.exists(p)) self.assertTrue(os.path.isdir(p))
def create_samba_share(host, share): upper_share = share.upper() uid = pwd.getpwnam('cluster_user').pw_uid gid = grp.getgrnam('cluster_user').gr_gid create_dir('/home/data/smbshares/%s/%s' % (host, upper_share)) os.chmod('/home/data/smbshares/%s/%s' % (host, upper_share), 0o777) os.chown('/home/data/smbshares/%s/%s' % (host, upper_share), uid, gid)
def upload(): ret = {} expected_length = int(request.headers.get('X-Seekscale-Payload-Length')) expected_shasum = request.headers.get('X-Seekscale-Payload-Shasum') uploaded_body_path = request.headers.get('X-FILE') if uploaded_body_path is not None: uploaded_file_length = os.path.getsize(uploaded_body_path) uploaded_file_shasum = sha256sum(uploaded_body_path) if uploaded_file_length != expected_length: logger.info('Size mismatch (expected %d got %d)' % (expected_length, uploaded_file_length)) ret['Size mismatch'] = True if uploaded_file_shasum != expected_shasum: logger.info('Shasum mismatch (expected %s got %s)' % (expected_shasum, uploaded_file_shasum)) ret['Shasum mismatch'] = True if uploaded_file_length == expected_length and uploaded_file_shasum == expected_shasum: ret['Size+shasum match'] = True directory = os.path.join(FILE_CACHE_DIRECTORY, expected_shasum[0], expected_shasum[1], expected_shasum[2]) create_dir(directory) new_path = os.path.join(directory, expected_shasum) shutil.move(uploaded_body_path, new_path) os.chmod(new_path, 0644) ret['path'] = new_path return ret
def mount(self): if self.is_mounted(): logging.info('Drive %s already mounted. Nothing to do.' % self.normalized_unc_path) return # Create the mountpoint create_dir(self.mountpoint) # Do the mount cmd = [ 'mount.cifs', self.linux_formatted_unc, self.mountpoint, '-o', 'credentials=%s' % (settings.SMB_CREDENTIALS_FILE,) ] retcode, out, err = exec_command(cmd) if retcode == 0: logging.info('Successfully mounted %s as %s' % ( self.normalized_unc_path, self.mountpoint )) return True else: logging.error('Could not mount %s: %d [%s][%s]' % ( self.normalized_unc_path, retcode, out, err )) return False
def mount(self): if self.is_mounted(): logging.info('Drive %s already mounted. Nothing to do.' % self.normalized_unc_path) return # Create the mountpoint create_dir(self.mountpoint) # Do the mount cmd = [ 'mount.cifs', self.linux_formatted_unc, self.mountpoint, '-o', 'credentials=%s' % (settings.SMB_CREDENTIALS_FILE, ) ] retcode, out, err = exec_command(cmd) if retcode == 0: logging.info('Successfully mounted %s as %s' % (self.normalized_unc_path, self.mountpoint)) return True else: logging.error('Could not mount %s: %d [%s][%s]' % (self.normalized_unc_path, retcode, out, err)) return False
def create_samba_share(host, share): upper_share = share.upper() uid = pwd.getpwnam('cluster_user').pw_uid gid = grp.getgrnam('cluster_user').gr_gid create_dir('/home/data/smbshares/%s/%s' % (host, upper_share)) os.chmod('/home/data/smbshares/%s/%s' % (host, upper_share), 0o777) os.chown('/home/data/smbshares/%s/%s' % (host, upper_share), uid, gid)
def test_create_dir_root(self): """Tests that create_dir works on paths like "C:\\" when the drive exists""" if platform.system() == 'Windows': p = "C:\\" base.create_dir(p) self.assertTrue(os.path.exists(p))
def setUp(self): base.create_dir(self.BASEDIRNAME) self.p1 = os.path.join(self.BASEDIRNAME, base.random_num_string()) self.p2 = os.path.join(self.BASEDIRNAME, base.random_num_string()) self.p3 = os.path.join(self.BASEDIRNAME, base.random_num_string()) self.p11 = os.path.join(self.p1, base.random_num_string()) self.p21 = os.path.join(self.p2, base.random_num_string()) self.p22 = os.path.join(self.p2, base.random_num_string()) base.create_dir(self.p1) base.create_dir(self.p2) base.create_dir(self.p3) with open(self.p11, 'wb') as _: pass with open(self.p21, 'wb') as _: pass with open(self.p22, 'wb') as _: pass
def create_samba_host(host, shares): create_dir('/usr/local/samba/alt/%s' % host) create_dir('/usr/local/samba/alt/%s/private' % host) create_dir('/usr/local/samba/alt/%s/pid' % host) create_dir('/usr/local/samba/alt/%s/lock' % host) create_dir('/home/data/smbshares/%s' % host) os.chmod('/home/data/smbshares/%s' % host, 0o777) uid = pwd.getpwnam('cluster_user').pw_uid gid = grp.getgrnam('cluster_user').gr_gid os.chown('/home/data/smbshares/%s' % host, uid, gid) create_dir('/home/data/smbshares/%s/.seekscale_tmp' % host) create_samba_config(host, shares) subprocess.check_call( '/bin/echo -e \"cluster_user_password\\ncluster_user_password\\n\" | /usr/local/samba/bin/smbpasswd -c /usr/local/samba/etc/smb-%s.conf -s -a cluster_user' % host, shell=True) for share in shares: create_samba_share(host, share)
def create_samba_host(host, shares): create_dir('/usr/local/samba/alt/%s' % host) create_dir('/usr/local/samba/alt/%s/private' % host) create_dir('/usr/local/samba/alt/%s/pid' % host) create_dir('/usr/local/samba/alt/%s/lock' % host) create_dir('/home/data/smbshares/%s' % host) os.chmod('/home/data/smbshares/%s' % host, 0o777) uid = pwd.getpwnam('cluster_user').pw_uid gid = grp.getgrnam('cluster_user').gr_gid os.chown('/home/data/smbshares/%s' % host, uid, gid) create_dir('/home/data/smbshares/%s/.seekscale_tmp' % host) create_samba_config(host, shares) subprocess.check_call('/bin/echo -e \"cluster_user_password\\ncluster_user_password\\n\" | /usr/local/samba/bin/smbpasswd -c /usr/local/samba/etc/smb-%s.conf -s -a cluster_user' % host, shell=True) for share in shares: create_samba_share(host, share)