示例#1
0
def osd_in_out(action):
    """Pause/Resume the ceph OSDs unit ont the local machine only.

    :param action: Either IN or OUT (see global constants)
    :type action: string
    :raises RuntimeError: if a supported action is not used
    :raises subprocess.CalledProcessError: if the ceph commands fails
    :raises OSError: if the unit can't get the local osd ids
    """
    if action not in (IN, OUT):
        raise RuntimeError("Unknown action \"{}\"".format(action))

    osds = parse_osds_arguments()
    osds, failed_osds = check_osd_id(osds)

    if failed_osds:
        function_fail("invalid ceph OSD device id: "
                      "{}".format(",".join(failed_osds)))
        return

    outputs = []
    for osd_id in osds:
        output = ceph_osd_upgrade(action, str(osd_id))
        outputs.append(output)

    function_set({
        "message":
        "osd-{action} action was successfully executed for ceph "
        "OSD devices [{osds}]".format(action=action, osds=",".join(osds)),
        "outputs":
        os.linesep.join(outputs)
    })

    assess_status()
示例#2
0
def execute_action(action):
    """Core implementation of the 'start'/'stop' actions

    :param action: Either START or STOP (see global constants)
    :return: None
    """
    if action not in (START, STOP):
        raise RuntimeError('Unknown action "{}"'.format(action))

    osds = parse_osds_arguments()
    services = osd_ids_to_service_names(osds)

    check_service_is_present(services)

    systemctl_execute(action, services)

    assess_status()
示例#3
0
    def test_parse_service_ids_with_all(self, mock_function_get):
        mock_function_get.return_value = "1,2,all"
        expected_id = {utils.ALL}

        parsed = utils.parse_osds_arguments()
        self.assertEqual(parsed, expected_id)
示例#4
0
    def test_parse_service_ids(self, mock_function_get):
        mock_function_get.return_value = "1,2,3"
        expected_ids = {"1", "2", "3"}

        parsed = utils.parse_osds_arguments()
        self.assertEqual(parsed, expected_ids)
示例#5
0
 def test_raise_on_missing_arguments(self, mock_function_get):
     mock_function_get.return_value = None
     err_msg = "Action argument \"osds\" is missing"
     with self.assertRaises(RuntimeError, msg=err_msg):
         utils.parse_osds_arguments()