def _create_osd(self, svc_arg=None, inbuf=None): # type: (Optional[str], Optional[str]) -> HandleCommandResult """Create one or more OSDs""" usage = """ Usage: ceph orch osd create -i <json_file/yaml_file> ceph orch osd create host:device1,device2,... """ if inbuf: try: dgs = DriveGroupSpecs(yaml.load(inbuf)) drive_groups = dgs.drive_groups except ValueError as e: msg = 'Failed to read JSON input: {}'.format(str(e)) + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) elif svc_arg: try: host_name, block_device = svc_arg.split(":") block_devices = block_device.split(',') except (TypeError, KeyError, ValueError): msg = "Invalid host:device spec: '{}'".format(svc_arg) + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) devs = DeviceSelection(paths=block_devices) drive_groups = [DriveGroupSpec(host_name, data_devices=devs)] else: return HandleCommandResult(-errno.EINVAL, stderr=usage) completion = self.create_osds(drive_groups) self._orchestrator_wait([completion]) raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str())
def test_DriveGroup(test_input): dgs = DriveGroupSpecs(test_input) for dg in dgs.drive_groups: assert dg.placement.pattern_matches_hosts(['hostname']) == ['hostname'] assert dg.service_id == 'testing_drivegroup' assert all([isinstance(x, Device) for x in dg.data_devices.paths]) assert dg.data_devices.paths[0].path == '/dev/sda'
def _create_with_drive_groups(self, drive_groups): """Create OSDs with DriveGroups.""" orch = OrchClient.instance() try: orch.osds.create(DriveGroupSpecs(drive_groups).drive_groups) except (ValueError, TypeError, DriveGroupValidationError) as e: raise DashboardException(e, component='osd')
def test_DriveGroup(): dg_json = {'testing_drivegroup': {'host_pattern': 'hostname', 'data_devices': {'paths': ['/dev/sda']} } } dgs = DriveGroupSpecs(dg_json) for dg in dgs.drive_groups: assert dg.hosts(['hostname']) == ['hostname'] assert dg.name == 'testing_drivegroup' assert all([isinstance(x, Device) for x in dg.data_devices.paths]) assert dg.data_devices.paths[0].path == '/dev/sda'