from __future__ import print_function
import argparse
import base64
+import glob
import json
import logging
import os
nargs='?',
help='The FSID of the OSD, similar to a SHA1'
)
+ parser.add_argument(
+ '--all',
+ help='Activate all OSDs with a OSD JSON config',
+ action='store_true',
+ default=False,
+ )
parser.add_argument(
'--file',
help='The path to a JSON file, from a scanned OSD'
print(sub_command_help)
return
args = parser.parse_args(self.argv)
- if not args.file:
+ if not args.file and not args.all:
if not args.osd_id and not args.osd_fsid:
terminal.error('ID and FSID are required to find the right OSD to activate')
terminal.error('from a scanned OSD location in /etc/ceph/osd/')
# implicitly indicate that it would be possible to activate a json file
# at a non-default location which would not work at boot time if the
# custom location is not exposed through an ENV var
+ self.skip_systemd = args.skip_systemd
json_dir = os.environ.get('CEPH_VOLUME_SIMPLE_JSON_DIR', '/etc/ceph/osd/')
- if args.file:
- json_config = args.file
+ if args.all:
+ if args.file or args.osd_id:
+ mlogger.warn('--all was passed, ignoring --file and ID/FSID arguments')
+ json_configs = glob.glob('{}/*.json'.format(json_dir))
+ for json_config in json_configs:
+ mlogger.info('activating OSD specified in {}'.format(json_config))
+ args.json_config = json_config
+ self.activate(args)
else:
- json_config = os.path.join(json_dir, '%s-%s.json' % (args.osd_id, args.osd_fsid))
- if not os.path.exists(json_config):
- raise RuntimeError('Expected JSON config path not found: %s' % json_config)
- args.json_config = json_config
- self.skip_systemd = args.skip_systemd
- self.activate(args)
+ if args.file:
+ json_config = args.file
+ else:
+ json_config = os.path.join(json_dir, '%s-%s.json' % (args.osd_id, args.osd_fsid))
+ if not os.path.exists(json_config):
+ raise RuntimeError('Expected JSON config path not found: %s' % json_config)
+ args.json_config = json_config
+ self.activate(args)
stdout, stderr = capsys.readouterr()
assert 'Activate OSDs by mounting devices previously configured' in stdout
+ def test_activate_all(self, is_root, monkeypatch):
+ '''
+ make sure Activate calls activate for each file returned by glob
+ '''
+ mocked_glob = []
+ def mock_glob(glob):
+ path = os.path.dirname(glob)
+ mocked_glob.extend(['{}/{}.json'.format(path, file_) for file_ in
+ ['1', '2', '3']])
+ return mocked_glob
+ activate_files = []
+ def mock_activate(self, args):
+ activate_files.append(args.json_config)
+ monkeypatch.setattr('glob.glob', mock_glob)
+ monkeypatch.setattr(activate.Activate, 'activate', mock_activate)
+ activate.Activate(['--all']).main()
+ assert activate_files == mocked_glob
+
+
+
class TestEnableSystemdUnits(object):