예제 #1
0
def test_vmedia_get_existing_uri(login_mock, query_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle w/o real CIMC
    # Patch ImcHandle.query_children to simulate CIMC interaction
    login_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: No pre-existing mappings
    query_mock.return_value = []
    assert vmedia_get_existing_uri(test_cimc) == []
    #  Assert query_children called with correct in_dn
    assert query_mock.mock_calls[0] == \
        call(in_dn='sys/svc-ext/vmedia-svc')

    # Scenario: Three pre-existing mappings
    vmedia1 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="One.iso")
    vmedia1.remote_share = "http://169.254.1.2/"
    vmedia1.remote_file = "One.iso"
    vmedia2 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Two")
    vmedia2.remote_share = "http://169.254.1.2/"
    vmedia2.remote_file = "Two.iso"
    vmedia3 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Three")
    vmedia3.remote_share = "http://169.254.1.2/"
    vmedia3.remote_file = "Three.iso"
    query_mock.return_value = [vmedia1, vmedia2, vmedia3]
    assert vmedia_get_existing_uri(test_cimc) == \
        ["http://169.254.1.2/One.iso",
         "http://169.254.1.2/Two.iso",
         "http://169.254.1.2/Three.iso"]
예제 #2
0
def test_invalid_remove_vmedia_all(login_mock, query_mock, remove_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.query_children to simulate CIMC interaction w/o real CIMC
    # Patch ImcHandle.remove_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: Three pre-exising mounts, only two unsuccessfully
    vmedia1 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="One.iso")
    vmedia1.remote_share = "http://169.254.1.2/"
    vmedia1.remote_file = "One.iso"
    vmedia2 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Two")
    vmedia2.remote_share = "http://169.254.1.2/"
    vmedia2.remote_file = "Two.iso"
    vmedia3 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Three")
    vmedia3.remote_share = "http://169.254.1.2/"
    vmedia3.remote_file = "Three.iso"
    query_mock.side_effect = [[vmedia1, vmedia2, vmedia3], [vmedia1]]
    assert_raises(ImcOperationError, vmedia_mount_remove_all, test_cimc)
예제 #3
0
def test_valid_remove_vmedia_all(login_mock, query_mock, remove_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.query_children to simulate CIMC interaction w/o real CIMC
    # Patch ImcHandle.remove_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: server has no vmedia mounts
    query_mock.return_value = []
    assert vmedia_mount_remove_all(test_cimc) is True
    assert remove_mock.mock_calls == []

    # Scenario: Three pre-exising mounts, removed successfully
    vmedia1 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="One.iso")
    vmedia1.remote_share = "http://169.254.1.2/"
    vmedia1.remote_file = "One.iso"
    vmedia2 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Two")
    vmedia2.remote_share = "http://169.254.1.2/"
    vmedia2.remote_file = "Two.iso"
    vmedia3 = CommVMediaMap(parent_mo_or_dn="sys/svc-ext/vmedia-svc",
                            volume_name="Three")
    vmedia3.remote_share = "http://169.254.1.2/"
    vmedia3.remote_file = "Three.iso"
    # query_mocked call first time in remove_existing_virtual_media
    # query_mock called a second time in get_existing_virtual_media_uri
    query_mock.side_effect = [[vmedia1, vmedia2, vmedia3], []]
    assert vmedia_mount_remove_all(test_cimc) is True
    assert remove_mock.mock_calls == [call(vmedia1),
                                      call(vmedia2),
                                      call(vmedia3)]
예제 #4
0
def vmedia_mount_create(handle, volume_name, remote_share, remote_file,
                        map="www", mount_options="noauto", username="",
                        password="", server_id=1, timeout=60):
    """
    This method will setup the vmedia mapping
    Args:
        handle (ImcHandle)
        volume_name (string): Name of the volume or identity of the image
        map (string): "cifs", "nfs", "www"
        mount_options (string): Options to be passed while mounting the image
        remote_share (string): URI of the image
        remote_file (string): name of the image
        username (string): username
        password (string): password
        server_id (int): Server Id to be specified for C3260 platforms
    Returns:
        CommVMediaMap object
    Examples:
        vmedia_mount_add(
            handle,
            volume_name="c",
            map="www",
            mount_options="noauto", "nolock" etc.
            remote_share="http://1.1.1.1/files",
            remote_file="ubuntu-14.04.2-server-amd64.iso",
            username="******",
            password="******")
    """
    image_type = remote_file.split('.')[-1]
    vmedia_mount_remove_image(handle, image_type)

    mo = CommVMediaMap(parent_mo_or_dn=_get_vmedia_mo_dn(handle, server_id),
                       volume_name=volume_name)
    mo.map = map
    if mount_options:
        mo.mount_options = mount_options
    mo.remote_share = remote_share
    mo.remote_file = remote_file
    mo.username = username
    mo.password = password

    handle.add_mo(mo, modify_present="True")

    wait_time = 0
    interval = 10
    while wait_time < timeout:
        time.sleep(interval)
        mo = handle.query_dn(mo.dn)
        existing_mapping_status = mo.mapping_status
        if existing_mapping_status == "OK":
            return mo
        elif re.match(r"ERROR", existing_mapping_status):
            raise ImcOperationError("vmedia_mount_create",
                                    mo.mapping_status)
        wait_time += interval

    raise ImcOperationError("vmedia_mount_create",
                            "ERROR - Mapped image status stuck at %s" %
                            existing_mapping_status)
예제 #5
0
def vmedia_mount_add(handle,
                     volume_name,
                     mount_protocol,
                     mount_options=None,
                     remote_share=None,
                     remote_file=None,
                     user_id="",
                     password="",
                     server_id=1):
    """
    This method will setup the vmedia mapping
    Args:
        handle (ImcHandle)
        volume_name (string): Name of the volume or identity of the image
        mount_protocol (string): "cifs", "nfs", "www"
        mount_options (string): Options to be passed while mounting the image
        remote_share (string): URI of the image
        remote_file (string): name of the image
        user_id (string): username
        password (string): password
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommVMediaMap object

    Examples:
        vmedia_mount_add(
            handle,
            volume_name="c",
            mount_protocol="www",
            mount_options="noauto", "nolock" etc.
            remote_share="http://1.1.1.1/files",
            remote_file="ubuntu-14.04.2-server-amd64.iso",
            user_id="abcd",
            password="******")
    """

    vmediamap_mo = CommVMediaMap(parent_mo_or_dn=_get_vmedia_mo_dn(
        handle, server_id),
                                 volume_name=volume_name)
    vmediamap_mo.map = mount_protocol
    if mount_options:
        vmediamap_mo.mount_options = mount_options
    vmediamap_mo.remote_share = remote_share
    vmediamap_mo.remote_file = remote_file
    vmediamap_mo.username = user_id
    vmediamap_mo.password = password

    handle.add_mo(vmediamap_mo, modify_present="True")
    return vmediamap_mo
예제 #6
0
def vmedia_mount_add(handle, volume_name, mount_protocol,
                     mount_options=None, remote_share=None,
                     remote_file=None, user_id="", password="", server_id=1):
    """
    This method will setup the vmedia mapping
    Args:
        handle (ImcHandle)
        volume_name (string): Name of the volume or identity of the image
        mount_protocol (string): "cifs", "nfs", "www"
        mount_options (string): Options to be passed while mounting the image
        remote_share (string): URI of the image
        remote_file (string): name of the image
        user_id (string): username
        password (string): password
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommVMediaMap object

    Examples:
        vmedia_mount_add(
            handle,
            volume_name="c",
            mount_protocol="www",
            mount_options="noauto", "nolock" etc.
            remote_share="http://1.1.1.1/files",
            remote_file="ubuntu-14.04.2-server-amd64.iso",
            user_id="abcd",
            password="******")
    """

    vmediamap_mo = CommVMediaMap(
        parent_mo_or_dn=_get_vmedia_mo_dn(handle, server_id),
        volume_name=volume_name)
    vmediamap_mo.map = mount_protocol
    if mount_options:
        vmediamap_mo.mount_options = mount_options
    vmediamap_mo.remote_share = remote_share
    vmediamap_mo.remote_file = remote_file
    vmediamap_mo.username = user_id
    vmediamap_mo.password = password

    handle.add_mo(vmediamap_mo, modify_present="True")
    return vmediamap_mo
예제 #7
0
파일: vmedia.py 프로젝트: CiscoUcs/imcsdk
def vmedia_mount_create(handle, volume_name, remote_share, remote_file,
                        map="www", mount_options="noauto", username="",
                        password="", server_id=1, timeout=60):
    """
    This method will setup the vmedia mapping
    Args:
        handle (ImcHandle)
        volume_name (string): Name of the volume or identity of the image
        map (string): "cifs", "nfs", "www"
        mount_options (string): Options to be passed while mounting the image
        remote_share (string): URI of the image
        remote_file (string): name of the image
        username (string): username
        password (string): password
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommVMediaMap object

    Examples:
        vmedia_mount_add(
            handle,
            volume_name="c",
            map="www",
            mount_options="noauto", "nolock" etc.
            remote_share="http://1.1.1.1/files",
            remote_file="ubuntu-14.04.2-server-amd64.iso",
            username="******",
            password="******")
    """
    image_type = remote_file.split('.')[-1]
    vmedia_mount_remove_image(handle, image_type)

    mo = CommVMediaMap(parent_mo_or_dn=_get_vmedia_mo_dn(handle, server_id),
                       volume_name=volume_name)
    mo.map = map
    if mount_options:
        mo.mount_options = mount_options
    mo.remote_share = remote_share
    mo.remote_file = remote_file
    mo.username = username
    mo.password = password

    handle.add_mo(mo, modify_present="True")

    wait_time = 0
    interval = 10
    while wait_time < timeout:
        time.sleep(interval)
        mo = handle.query_dn(mo.dn)
        existing_mapping_status = mo.mapping_status
        if existing_mapping_status == "OK":
            return mo
        elif re.match(r"ERROR", existing_mapping_status):
            raise ImcOperationError("vmedia_mount_create",
                                    mo.mapping_status)
        wait_time += interval

    raise ImcOperationError("vmedia_mount_create",
                            "ERROR - Mapped ISO status stuck at %s" %
                            existing_mapping_status)