Example #1
0
def get_hyperscale_version():

    version = None
    cmd_err = None
    try:
        cmd_arg = {'operation': 'version'}
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for version
        (cmd_out, cmd_err) = hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            version = processed_output.get('payload')
        else:
            LOG.error("Error %s in getting hyperscale version", cmd_err)
            raise exception.ErrorInHyperScaleVersion(cmd_err=cmd_err)
    except (exception.UnableToExecuteHyperScaleCmd,
            exception.UnableToProcessHyperScaleCmdOutput):
        LOG.error("Exception in running the command for version",
                  exc_info=True)
        raise exception.UnableToExecuteHyperScaleCmd(message="version")

    return version
Example #2
0
def get_datanode_id():

    dnid = None
    cmd_out = None
    cmd_err = None
    try:
        cmd_arg = {'operation': 'get_datanode_id'}
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for get_datanode_id
        (cmd_out, cmd_err) = hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            dnid = processed_output.get('payload')
        else:
            LOG.error("Error %s in getting datanode hypervisor id", cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute get_datanode_id", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process get_datanode_id output",
                      exc_info=True)
    return dnid
Example #3
0
def get_image_path(image_id, op_type='image'):

    cmd_out = None
    cmd_err = None
    image_path = None
    try:
        cmd_arg = {}
        if op_type == 'image':
            cmd_arg['operation'] = 'get_image_path'
        elif op_type == 'volume':
            cmd_arg['operation'] = 'get_volume_path'
        cmd_arg['image_id'] = image_id
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for get_image_path
        (cmd_out, cmd_err) = hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            image_path = processed_output.get('payload')
        else:
            LOG.error("Error %s in processing get_image_path", cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute get_image_path", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process get_image_path output", exc_info=True)
    return image_path
Example #4
0
def update_image(image_path, volume_id, hs_img_id):
    cmd_out = None
    cmd_err = None
    output = None
    try:
        cmd_arg = {}
        cmd_arg['operation'] = 'update_image'
        cmd_arg['image_path'] = image_path
        cmd_arg['volume_id'] = volume_id
        cmd_arg['hs_image_id'] = hs_img_id
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        (cmd_out, cmd_err) = hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            output = process_cmd_out(cmd_out)
        else:
            LOG.error("Error %s in execution of update_image", cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute update_image", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process update_image output", exc_info=True)
    return output
Example #5
0
def episodic_snap(meta):

    cmd_out = None
    cmd_err = None
    out_meta = None
    try:
        cmd_arg = {}
        cmd_arg['operation'] = 'episodic_snap'
        cmd_arg['metadata'] = meta
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for episodic_snap
        (cmd_out, cmd_err) = hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            out_meta = processed_output.get('payload')
        else:
            LOG.error("Error %s in processing episodic_snap", cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute episodic_snap", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process episodic_snap output", exc_info=True)
    return out_meta
Example #6
0
 def test_create_volume_from_snapshot_with_exception(self, mock_mdp):
     """Test case create volume from snapshot thorws exception."""
     fake_volume, fake_snapshot = _stub_volume(), _stub_snapshot()
     mock_mdp.side_effect = exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_volume_from_snapshot, fake_volume,
                       fake_snapshot)
Example #7
0
 def test_create_cloned_volume_with_exception(self, mock_mdp):
     """Test case throws exception when command failed to execute."""
     vol_a = _stub_volume()
     vol_b = _stub_volume()
     mock_mdp.side_effect = exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_cloned_volume, vol_b, vol_a)
Example #8
0
 def test_create_snapshot_with_exception(self, mock_gvmv, mock_es,
                                         mock_mcp):
     """Test case create snapshot throws exception."""
     mock_gvmv.side_effect = VRTSHyperScaleDriverTestCase.gvmv_side_effect
     mock_es_obj = {'payload': {'update': False}}
     mock_es.return_value = mock_es_obj
     mock_mcp.side_effect = exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     fake_snapshot = _stub_snapshot()
     self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_snapshot, fake_snapshot)
Example #9
0
def hsexecute(cmdarg_json):

    cmd_out = None
    cmd_err = None
    try:
        # call hyperscale cli
        (cmd_out, cmd_err) = utils.execute("hscli",
                                           cmdarg_json,
                                           run_as_root=True)
    except (putils.UnknownArgumentError, putils.ProcessExecutionError,
            OSError):
        LOG.error("Exception in running the command for %s",
                  cmdarg_json,
                  exc_info=True)
        raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)

    except Exception:
        LOG.error("Internal exception in cmd for %s", cmdarg_json,
                  exc_info=True)
        raise exception.UnableToExecuteHyperScaleCmd(message=cmdarg_json)

    return (cmd_out, cmd_err)
Example #10
0
def hsexecute(cmdarg_json):

    cmd_out = None
    cmd_err = None
    try:
        # call hyperscale cli
        (cmd_out, cmd_err) = putils.execute("hscli", cmdarg_json)
    except (putils.UnknownArgumentError, putils.ProcessExecutionError,
            OSError):
        LOG.exception("Exception in running the command for %s",
                      cmdarg_json)
        raise exception.UnableToExecuteHyperScaleCmd(command=cmdarg_json)

    return (cmd_out, cmd_err)