Example #1
0
def test_valid_enable_ipmi(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    ipmi_enabled_mock = MagicMock()
    ipmi_enabled_mock.admin_state = "enabled"
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)
    query_dn_mock.return_value = ipmi_enabled_mock

    # Scenario: Enable IPMI default values
    assert ipmi_enable(test_cimc) is ipmi_enabled_mock
    # Assert values of the object passed to add_mo()
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "enabled"
    assert test_ipmi_mo.priv == CommIpmiLanConsts.PRIV_ADMIN
    assert test_ipmi_mo.key == '0'*40

    # Scenario: Enable IPMI custom priv and key
    assert ipmi_enable(test_cimc, priv="user", key='1'*40) is ipmi_enabled_mock
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "enabled"
    assert test_ipmi_mo.priv == "user"
    assert test_ipmi_mo.key == '1'*40
Example #2
0
def test_vmedia_get_existing_status(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_status(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
    # mapping_status is not a read-write property, so mock it.
    vmedia1 = MagicMock()
    vmedia1.mapping_status = "In-Progress"
    vmedia2 = MagicMock()
    vmedia2.mapping_status = "OK"
    vmedia3 = MagicMock()
    vmedia3.mapping_status = "Error"
    query_mock.return_value = [vmedia1, vmedia2, vmedia3]
    assert vmedia_get_existing_status(test_cimc) == \
        ["In-Progress", "OK", "Error"]
Example #3
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"]
Example #4
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)
Example #5
0
def test_valid_enable_ipmi(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    ipmi_enabled_mock = MagicMock()
    ipmi_enabled_mock.admin_state = "enabled"
    test_cimc = ImcHandle(ip='169.254.1.1', username='******', password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)
    query_dn_mock.return_value = ipmi_enabled_mock

    # Scenario: Enable IPMI default values
    assert ipmi_enable(test_cimc) is ipmi_enabled_mock
    # Assert values of the object passed to add_mo()
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "enabled"
    assert test_ipmi_mo.priv == CommIpmiLanConsts.PRIV_ADMIN
    assert test_ipmi_mo.key == '0' * 40

    # Scenario: Enable IPMI custom priv and key
    assert ipmi_enable(test_cimc, priv="user",
                       key='1' * 40) is ipmi_enabled_mock
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "enabled"
    assert test_ipmi_mo.priv == "user"
    assert test_ipmi_mo.key == '1' * 40
Example #6
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)]
Example #7
0
def test_invalid_vmedia_mount_iso_uri(login_mock, add_mount_mock, exist_mock,
                                      state_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch vmedia_mount_add to simulate CIMC interaction w/o real CIMC
    # Patch vmedia_get_existing_uri to simulate existing ISOs
    # Patch vmedia_get_existing_status to simulate ISO status
    login_mock.return_value = True
    add_mount_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1', username='******', password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: Zero value passed in as check interval
    assert_raises(ValueError,
                  vmedia_mount_iso_uri,
                  test_cimc,
                  'http://1.1.1.1/test.iso',
                  interval=0)

    # Scenario: Invalid protocol
    exist_mock.side_effect = [[], ["britt://1.1.1.1/test.iso"]]
    assert_raises(ValueError,
                  vmedia_mount_iso_uri,
                  test_cimc,
                  'britt://1.1.1.1/test.iso',
                  interval=1)

    # Scenario: Mapping failed
    exist_mock.side_effect = [[], []]
    assert_raises(ImcOperationError,
                  vmedia_mount_iso_uri,
                  test_cimc,
                  'http://169.254.1.2/test.iso',
                  interval=1)

    # Scenario: Timeout on state change
    exist_mock.side_effect = [[], ["http://169.254.1.2/test.iso"]]
    state_mock.side_effect = [['In Progress'], ['In Progress']]
    assert_raises(ImcOperationError,
                  vmedia_mount_iso_uri,
                  test_cimc,
                  'http://169.254.1.2/test.iso',
                  interval=1,
                  timeout=0)

    # State returns Error
    exist_mock.side_effect = [[], ["http://169.254.1.2/test.iso"]]
    state_mock.side_effect = [['In Progress'],
                              ['ERROR: [404] File not found. ']]
    assert_raises(ImcOperationError,
                  vmedia_mount_iso_uri,
                  test_cimc,
                  'http://169.254.1.2/test.iso',
                  interval=1)
Example #8
0
def test_invalid_enable_ipmi(login_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1', username='******', password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: Invalid priv value
    assert_raises(ValueError, ipmi_enable, test_cimc, priv="Wrong")

    # Scenario: Invalid key
    assert_raises(ValueError, ipmi_enable, test_cimc, key='bacon')
Example #9
0
def test_invalid_enable_ipmi(login_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: Invalid priv value
    assert_raises(ValueError, ipmi_enable, test_cimc, priv="Wrong")

    # Scenario: Invalid key
    assert_raises(ValueError, ipmi_enable, test_cimc, key='bacon')
Example #10
0
def test_valid_disable_ipmi(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    ipmi_disabled_mock = MagicMock()
    ipmi_disabled_mock.admin_state = "disabled"
    test_cimc = ImcHandle(ip='169.254.1.1', username='******', password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)
    query_dn_mock.return_value = ipmi_disabled_mock

    # Scenario: Enable IPMI default values
    assert ipmi_disable(test_cimc) is ipmi_disabled_mock
    # Assert values of the object passed to add_mo()
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "disabled"
Example #11
0
def test_valid_disable_ipmi(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    ipmi_disabled_mock = MagicMock()
    ipmi_disabled_mock.admin_state = "disabled"
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')

    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)
    query_dn_mock.return_value = ipmi_disabled_mock

    # Scenario: Enable IPMI default values
    assert ipmi_disable(test_cimc) is ipmi_disabled_mock
    # Assert values of the object passed to add_mo()
    test_ipmi_mo = set_mo_mock.call_args[0][0]
    assert test_ipmi_mo.admin_state == "disabled"
Example #12
0
def test_invalid_power_up_server(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.query_dn to simulate CIMC interaction w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    pwrd_off_mock = MagicMock()
    pwrd_off_mock.oper_power = "off"
    pwrd_on_mock = MagicMock()
    pwrd_on_mock.oper_power = "on"
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: Zero value passed in as check interval
    assert_raises(ValueError, server_power_up, test_cimc, 0, 0)

    # Scenario: server starts power off, and doesn't power on
    query_dn_mock.return_value = pwrd_off_mock
    assert_raises(ImcOperationError, server_power_up, test_cimc, 0, 1)
Example #13
0
def test_valid_power_up_server(login_mock, query_dn_mock, set_mo_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch ImcHandle.query_dn to simulate CIMC interaction w/o real CIMC
    # Patch ImcHandle.set_mo to simulate CIMC interaction w/o real CIMC
    login_mock.return_value = True
    set_mo_mock.return_value = True
    pwrd_off_mock = MagicMock()
    pwrd_off_mock.oper_power = "off"
    pwrd_on_mock = MagicMock()
    pwrd_on_mock.oper_power = "on"
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # Scenario: server starts powered on
    query_dn_mock.return_value = pwrd_on_mock
    assert server_power_up(test_cimc, 0, 1) is pwrd_on_mock

    # Scenario: server starts powered off, and powers on successfully
    query_dn_mock.side_effect = [pwrd_off_mock, pwrd_on_mock, pwrd_on_mock, pwrd_on_mock]
    assert server_power_up(test_cimc, 0, 1) is pwrd_on_mock
Example #14
0
def test_valid_vmedia_mount_iso_uri(login_mock, add_mount_mock,
                                    exist_mock, state_mock):
    # Patch ImcHandle.login to create a Faux ImcHandle object w/o real CIMC
    # Patch vmedia_mount_create to simulate CIMC interaction w/o real CIMC
    # Patch vmedia_get_existing_uri to simulate existing ISOs
    # Patch vmedia_get_existing_status to simulate ISO status
    login_mock.return_value = True
    add_mount_mock.return_value = True
    test_cimc = ImcHandle(ip='169.254.1.1',
                          username='******',
                          password='******')
    test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

    # http mapping succeeded
    exist_mock.return_value = ["http://169.254.1.2/test.iso"]
    state_mock.side_effect = [['In Progress'], ['OK']]
    assert vmedia_mount_iso_uri(
        test_cimc,
        'http://169.254.1.2/test.iso',
        interval=1
    ) is True
    # Assert values of the mount options
    assert add_mount_mock.call_args[1] == {
        'volume_name': 'test.iso',
        'map': 'www',
        'mount_options': 'noauto',
        'remote_share': "http://169.254.1.2/",
        'remote_file': 'test.iso',
        'username': '',
        'password': '',
        'server_id': 1
    }

    # https mapping succeeded
    exist_mock.return_value = ["https://169.254.1.2/test.iso"]
    state_mock.side_effect = [['In Progress'], ['OK']]
    assert vmedia_mount_iso_uri(
        test_cimc,
        'https://169.254.1.2/test.iso',
        interval=1
    ) is True
    # Assert values of the mount options
    assert add_mount_mock.call_args[1] == {
        'volume_name': 'test.iso',
        'mount_options': 'noauto',
        'map': 'www',
        'remote_share': "https://169.254.1.2/",
        'remote_file': 'test.iso',
        'username': '',
        'password': '',
        'server_id': 1
    }

    # CIFS mapping succeeded
    exist_mock.return_value = ["//169.254.1.2/test.iso"]
    state_mock.side_effect = [['In Progress'], ['OK']]
    assert vmedia_mount_iso_uri(
        test_cimc,
        '//169.254.1.2/test.iso',
        interval=1
    ) is True
    # Assert values of the object passed to add_mo()
    assert add_mount_mock.call_args[1] == {
        'volume_name': 'test.iso',
        'mount_options': 'noauto',
        'map': 'cifs',
        'remote_share': "//169.254.1.2/",
        'remote_file': 'test.iso',
        'username': '',
        'password': '',
        'server_id': 1
    }

    # NFS mapping succeeded
    exist_mock.return_value = ["169.254.1.2:/test.iso"]
    state_mock.side_effect = [['In Progress'], ['OK']]
    assert vmedia_mount_iso_uri(
        test_cimc,
        '169.254.1.2:/test.iso',
        interval=1
    ) is True
    # Assert values of the object passed to add_mo()
    assert add_mount_mock.call_args[1] == {
        'volume_name': 'test.iso',
        'mount_options': 'noauto',
        'map': 'nfs',
        'remote_share': "169.254.1.2:/",
        'remote_file': 'test.iso',
        'username': '',
        'password': '',
        'server_id': 1
    }