From: Andrew Schoen Date: Wed, 6 Dec 2017 16:40:55 +0000 (-0600) Subject: ceph-volume: removed the explicit use of sudo X-Git-Tag: v13.0.1~25^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=aee71a3f5169043f750fd768e7fea9c74309e12d;p=ceph.git ceph-volume: removed the explicit use of sudo This will allow users to run ceph-volume on systems that do not have sudo installed. Fixes: http://tracker.ceph.com/issues/22282 Signed-off-by: Andrew Schoen --- diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index d82aee685f7b2..60f977dd86fc9 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -76,7 +76,7 @@ def get_api_vgs(): Command and sample delimeted output, should look like:: - $ sudo vgs --noheadings --separator=';' \ + $ vgs --noheadings --separator=';' \ -o vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free ubuntubox-vg;1;2;0;wz--n-;299.52g;12.00m osd_vg;3;1;0;wz--n-;29.21g;9.21g @@ -84,7 +84,7 @@ def get_api_vgs(): """ fields = 'vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free' stdout, stderr, returncode = process.call( - ['sudo', 'vgs', '--noheadings', '--separator=";"', '-o', fields] + ['vgs', '--noheadings', '--separator=";"', '-o', fields] ) return _output_parser(stdout, fields) @@ -96,14 +96,14 @@ def get_api_lvs(): Command and delimeted output, should look like:: - $ sudo lvs --noheadings --separator=';' -o lv_tags,lv_path,lv_name,vg_name + $ lvs --noheadings --separator=';' -o lv_tags,lv_path,lv_name,vg_name ;/dev/ubuntubox-vg/root;root;ubuntubox-vg ;/dev/ubuntubox-vg/swap_1;swap_1;ubuntubox-vg """ fields = 'lv_tags,lv_path,lv_name,vg_name,lv_uuid' stdout, stderr, returncode = process.call( - ['sudo', 'lvs', '--noheadings', '--separator=";"', '-o', fields] + ['lvs', '--noheadings', '--separator=";"', '-o', fields] ) return _output_parser(stdout, fields) @@ -115,7 +115,7 @@ def get_api_pvs(): Command and delimeted output, should look like:: - $ sudo pvs --noheadings --separator=';' -o pv_name,pv_tags,pv_uuid + $ pvs --noheadings --separator=';' -o pv_name,pv_tags,pv_uuid /dev/sda1;; /dev/sdv;;07A4F654-4162-4600-8EB3-88D1E42F368D @@ -125,7 +125,7 @@ def get_api_pvs(): # note the use of `pvs -a` which will return every physical volume including # ones that have not been initialized as "pv" by LVM stdout, stderr, returncode = process.call( - ['sudo', 'pvs', '-a', '--no-heading', '--separator=";"', '-o', fields] + ['pvs', '-a', '--no-heading', '--separator=";"', '-o', fields] ) return _output_parser(stdout, fields) @@ -184,7 +184,6 @@ def create_pv(device): to journals. """ process.run([ - 'sudo', 'pvcreate', '-v', # verbose '-f', # force it @@ -202,7 +201,6 @@ def create_vg(name, *devices): Once created the volume group is returned as a ``VolumeGroup`` object """ process.run([ - 'sudo', 'vgcreate', '--force', '--yes', @@ -222,7 +220,6 @@ def remove_lv(path): """ stdout, stderr, returncode = process.call( [ - 'sudo', 'lvremove', '-v', # verbose '-f', # force it @@ -259,7 +256,6 @@ def create_lv(name, group, size=None, tags=None): } if size: process.run([ - 'sudo', 'lvcreate', '--yes', '-L', @@ -270,7 +266,6 @@ def create_lv(name, group, size=None, tags=None): # system call is different for LVM else: process.run([ - 'sudo', 'lvcreate', '--yes', '-l', @@ -658,7 +653,7 @@ class Volume(object): """ for k, v in self.tags.items(): tag = "%s=%s" % (k, v) - process.run(['sudo', 'lvchange', '--deltag', tag, self.lv_path]) + process.run(['lvchange', '--deltag', tag, self.lv_path]) def set_tags(self, tags): """ @@ -689,11 +684,11 @@ class Volume(object): if self.tags.get(key): current_value = self.tags[key] tag = "%s=%s" % (key, current_value) - process.call(['sudo', 'lvchange', '--deltag', tag, self.lv_api['lv_path']]) + process.call(['lvchange', '--deltag', tag, self.lv_api['lv_path']]) process.call( [ - 'sudo', 'lvchange', + 'lvchange', '--addtag', '%s=%s' % (key, value), self.lv_path ] ) @@ -752,11 +747,11 @@ class PVolume(object): if self.tags.get(key): current_value = self.tags[key] tag = "%s=%s" % (key, current_value) - process.call(['sudo', 'pvchange', '--deltag', tag, self.pv_name]) + process.call(['pvchange', '--deltag', tag, self.pv_name]) process.call( [ - 'sudo', 'pvchange', + 'pvchange', '--addtag', '%s=%s' % (key, value), self.pv_name ] ) diff --git a/src/ceph-volume/ceph_volume/devices/lvm/activate.py b/src/ceph-volume/ceph_volume/devices/lvm/activate.py index 0a50e7a33cd8c..f0392fed67432 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/activate.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/activate.py @@ -39,12 +39,12 @@ def activate_filestore(lvs): source = osd_lv.lv_path destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id) if not system.device_is_mounted(source, destination=destination): - process.run(['sudo', 'mount', '-v', source, destination]) + process.run(['mount', '-v', source, destination]) # always re-do the symlink regardless if it exists, so that the journal # device path that may have changed can be mapped correctly every time destination = '/var/lib/ceph/osd/%s-%s/journal' % (conf.cluster, osd_id) - process.run(['sudo', 'ln', '-snf', osd_journal, destination]) + process.run(['ln', '-snf', osd_journal, destination]) # make sure that the journal has proper permissions system.chown(osd_journal) @@ -103,22 +103,22 @@ def activate_bluestore(lvs): os.unlink(os.path.join(osd_path, link_name)) # Once symlinks are removed, the osd dir can be 'primed again. process.run([ - 'sudo', 'ceph-bluestore-tool', '--cluster=%s' % conf.cluster, + 'ceph-bluestore-tool', '--cluster=%s' % conf.cluster, 'prime-osd-dir', '--dev', osd_lv.lv_path, '--path', osd_path]) # always re-do the symlink regardless if it exists, so that the block, # block.wal, and block.db devices that may have changed can be mapped # correctly every time - process.run(['sudo', 'ln', '-snf', osd_lv.lv_path, os.path.join(osd_path, 'block')]) + process.run(['ln', '-snf', osd_lv.lv_path, os.path.join(osd_path, 'block')]) system.chown(os.path.join(osd_path, 'block')) system.chown(osd_path) if db_device_path: destination = os.path.join(osd_path, 'block.db') - process.run(['sudo', 'ln', '-snf', db_device_path, destination]) + process.run(['ln', '-snf', db_device_path, destination]) system.chown(db_device_path) if wal_device_path: destination = os.path.join(osd_path, 'block.wal') - process.run(['sudo', 'ln', '-snf', wal_device_path, destination]) + process.run(['ln', '-snf', wal_device_path, destination]) system.chown(wal_device_path) # enable the ceph-volume unit for this OSD diff --git a/src/ceph-volume/ceph_volume/devices/lvm/zap.py b/src/ceph-volume/ceph_volume/devices/lvm/zap.py index df19686ff996e..4b19efebab46c 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/zap.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/zap.py @@ -14,7 +14,6 @@ def wipefs(path): Removes the filesystem from an lv or partition. """ process.run([ - 'sudo', 'wipefs', '--all', path diff --git a/src/ceph-volume/ceph_volume/devices/simple/activate.py b/src/ceph-volume/ceph_volume/devices/simple/activate.py index fdc50f0fa5149..ac1bfff74057d 100644 --- a/src/ceph-volume/ceph_volume/devices/simple/activate.py +++ b/src/ceph-volume/ceph_volume/devices/simple/activate.py @@ -44,7 +44,7 @@ class Activate(object): ) if not system.device_is_mounted(data_device, destination=osd_dir): - process.run(['sudo', 'mount', '-v', data_device, osd_dir]) + process.run(['mount', '-v', data_device, osd_dir]) device_map = { 'journal': journal_device, @@ -59,7 +59,7 @@ class Activate(object): # always re-do the symlink regardless if it exists, so that the journal # device path that may have changed can be mapped correctly every time destination = os.path.join(osd_dir, name) - process.run(['sudo', 'ln', '-snf', device, destination]) + process.run(['ln', '-snf', device, destination]) # make sure that the journal has proper permissions system.chown(device) diff --git a/src/ceph-volume/ceph_volume/systemd/systemctl.py b/src/ceph-volume/ceph_volume/systemd/systemctl.py index ab8f3e70ae31d..d5fd0dd8083ef 100644 --- a/src/ceph-volume/ceph_volume/systemd/systemctl.py +++ b/src/ceph-volume/ceph_volume/systemd/systemctl.py @@ -5,23 +5,23 @@ from ceph_volume import process def start(unit): - process.run(['sudo', 'systemctl', 'start', unit]) + process.run(['systemctl', 'start', unit]) def stop(unit): - process.run(['sudo', 'systemctl', 'stop', unit]) + process.run(['systemctl', 'stop', unit]) def enable(unit): - process.run(['sudo', 'systemctl', 'enable', unit]) + process.run(['systemctl', 'enable', unit]) def disable(unit): - process.run(['sudo', 'systemctl', 'disable', unit]) + process.run(['systemctl', 'disable', unit]) def mask(unit): - process.run(['sudo', 'systemctl', 'mask', unit]) + process.run(['systemctl', 'mask', unit]) def start_osd(id_): @@ -50,7 +50,7 @@ def mask_ceph_disk(): # masking ceph-disk@* will not work, so we must link the service directly. # /etc/systemd takes precendence regardless of the location of the unit process.run( - ['sudo', 'ln', '-sf', '/dev/null', '/etc/systemd/system/ceph-disk@.service'] + ['ln', '-sf', '/dev/null', '/etc/systemd/system/ceph-disk@.service'] ) diff --git a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py index 3639f01e5de59..b1068e98c36f5 100644 --- a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py +++ b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py @@ -379,7 +379,7 @@ class TestCreateLV(object): monkeypatch.setattr(process, 'call', capture) monkeypatch.setattr(api, 'get_lv', lambda *a, **kw: self.foo_volume) api.create_lv('foo', 'foo_group', size='5G', tags={'ceph.type': 'data'}) - expected = ['sudo', 'lvcreate', '--yes', '-L', '5G', '-n', 'foo', 'foo_group'] + expected = ['lvcreate', '--yes', '-L', '5G', '-n', 'foo', 'foo_group'] assert capture.calls[0]['args'][0] == expected def test_calls_to_set_type_tag(self, monkeypatch, capture): @@ -387,7 +387,7 @@ class TestCreateLV(object): monkeypatch.setattr(process, 'call', capture) monkeypatch.setattr(api, 'get_lv', lambda *a, **kw: self.foo_volume) api.create_lv('foo', 'foo_group', size='5G', tags={'ceph.type': 'data'}) - ceph_tag = ['sudo', 'lvchange', '--addtag', 'ceph.type=data', '/path'] + ceph_tag = ['lvchange', '--addtag', 'ceph.type=data', '/path'] assert capture.calls[1]['args'][0] == ceph_tag def test_calls_to_set_data_tag(self, monkeypatch, capture): @@ -395,5 +395,5 @@ class TestCreateLV(object): monkeypatch.setattr(process, 'call', capture) monkeypatch.setattr(api, 'get_lv', lambda *a, **kw: self.foo_volume) api.create_lv('foo', 'foo_group', size='5G', tags={'ceph.type': 'data'}) - data_tag = ['sudo', 'lvchange', '--addtag', 'ceph.data_device=/path', '/path'] + data_tag = ['lvchange', '--addtag', 'ceph.data_device=/path', '/path'] assert capture.calls[2]['args'][0] == data_tag diff --git a/src/ceph-volume/ceph_volume/util/disk.py b/src/ceph-volume/ceph_volume/util/disk.py index da3dc93413ced..79d8e3a265138 100644 --- a/src/ceph-volume/ceph_volume/util/disk.py +++ b/src/ceph-volume/ceph_volume/util/disk.py @@ -10,7 +10,7 @@ def get_partuuid(device): device """ out, err, rc = process.call( - ['sudo', 'blkid', '-s', 'PARTUUID', '-o', 'value', device] + ['blkid', '-s', 'PARTUUID', '-o', 'value', device] ) return ' '.join(out).strip() @@ -21,7 +21,7 @@ def get_device_from_partuuid(partuuid): device is """ out, err, rc = process.call( - ['sudo', 'blkid', '-t', 'PARTUUID="%s"' % partuuid, '-o', 'device'] + ['blkid', '-t', 'PARTUUID="%s"' % partuuid, '-o', 'device'] ) return ' '.join(out).strip() @@ -90,7 +90,7 @@ def lsblk(device, columns=None): Normal CLI output, as filtered by the flags in this function will look like :: - $ sudo lsblk --nodeps -P -o NAME,KNAME,MAJ:MIN,FSTYPE,MOUNTPOINT + $ lsblk --nodeps -P -o NAME,KNAME,MAJ:MIN,FSTYPE,MOUNTPOINT NAME="sda1" KNAME="sda1" MAJ:MIN="8:1" FSTYPE="ext4" MOUNTPOINT="/" :param columns: A list of columns to report as keys in its original form. @@ -107,7 +107,7 @@ def lsblk(device, columns=None): # on the actual device we are querying for # -P -> Produce pairs of COLUMN="value" # -o -> Use the columns specified or default ones provided by this function - command = ['sudo', 'lsblk', '--nodeps', '-P', '-o'] + command = ['lsblk', '--nodeps', '-P', '-o'] command.append(','.join(columns)) command.append(device) out, err, rc = process.call(command) @@ -134,7 +134,7 @@ def _lsblk_type(device): It does not process the output to return a boolean, but it does process it to return the """ out, err, rc = process.call( - ['sudo', 'blkid', '-s', 'PARTUUID', '-o', 'value', device] + ['blkid', '-s', 'PARTUUID', '-o', 'value', device] ) return ' '.join(out).strip() diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index 6b38fe0978d53..026ccafae56b6 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -59,7 +59,6 @@ def create_id(fsid, json_secrets): def mount_tmpfs(path): process.run([ - 'sudo', 'mount', '-t', 'tmpfs', 'tmpfs', @@ -76,7 +75,7 @@ def create_osd_path(osd_id, tmpfs=False): def format_device(device): # only supports xfs - command = ['sudo', 'mkfs', '-t', 'xfs'] + command = ['mkfs', '-t', 'xfs'] # get the mkfs options if any for xfs, # fallback to the default options defined in constants.mkfs @@ -98,7 +97,7 @@ def format_device(device): def mount_osd(device, osd_id): destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id) - command = ['sudo', 'mount', '-t', 'xfs', '-o'] + command = ['mount', '-t', 'xfs', '-o'] flags = conf.ceph.get_list( 'osd', 'osd_mount_options_xfs', @@ -122,7 +121,7 @@ def _link_device(device, device_type, osd_id): osd_id, device_type ) - command = ['sudo', 'ln', '-s', device, device_path] + command = ['ln', '-s', device, device_path] system.chown(device) process.run(command) @@ -158,7 +157,6 @@ def get_monmap(osd_id): monmap_destination = os.path.join(path, 'activate.monmap') process.run([ - 'sudo', 'ceph', '--cluster', conf.cluster, '--name', 'client.bootstrap-osd', @@ -187,7 +185,6 @@ def osd_mkfs_bluestore(osd_id, fsid, keyring=None, wal=False, db=False): system.chown(path) base_command = [ - 'sudo', 'ceph-osd', '--cluster', conf.cluster, # undocumented flag, sets the `type` file to contain 'bluestore' @@ -245,7 +242,6 @@ def osd_mkfs_filestore(osd_id, fsid): system.chown(path) process.run([ - 'sudo', 'ceph-osd', '--cluster', conf.cluster, # undocumented flag, sets the `type` file to contain 'filestore' diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index d580a4c28f08f..dc265e80aac19 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -94,7 +94,6 @@ class tmp_mount(object): def __enter__(self): self.path = tempfile.mkdtemp() process.run([ - 'sudo', 'mount', '-v', self.device, @@ -104,7 +103,6 @@ class tmp_mount(object): def __exit__(self, exc_type, exc_val, exc_tb): process.run([ - 'sudo', 'umount', '-v', self.path