Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server pools #30

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit tests for server_pool
Signed-off-by: Britt Houser <[email protected]>
  • Loading branch information
britthouser committed Dec 3, 2016
commit 440be34c43fed4565164d3edf65cca58e2a17cee
103 changes: 94 additions & 9 deletions tests/unit_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 19,15 @@
from ucsmsdk_samples.server.ipmi_policy import ipmi_policy_create
from ucsmsdk.mometa.aaa.AaaEpAuthProfile import AaaEpAuthProfile
from ucsmsdk_samples.server.local_drive import disk_state_set
from ucsmsdk_samples.server.server_pool import server_pool_create, \
server_pool_add_rack_unit
from ucsmsdk.mometa.compute.ComputePool import ComputePool
from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit


# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate orgs
@patch.object(UcsHandle, 'query_dn')
Expand Down Expand Up @@ -66,13 70,13 @@ def test_valid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock):
assert user_retval.pwd is 'password'


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
@patch.object(UcsHandle, 'query_dn')
def test_invalid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock):
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')
Expand All @@ -83,9 87,9 @@ def test_invalid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock):
assert_raises(ValueError, ipmi_policy_create, handle, 'invalid')


# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
def test_valid_disk_state(add_mo_mock, commit_mock):
add_mo_mock.return_value = True
Expand All @@ -107,9 111,9 @@ def test_valid_disk_state(add_mo_mock, commit_mock):
assert test_retval.dn == "sys/rack-unit-3/board/storage-SAS-4/disk-6"


# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
def test_invalid_disk_state(add_mo_mock, commit_mock):
add_mo_mock.return_value = True
Expand All @@ -118,3 122,84 @@ def test_invalid_disk_state(add_mo_mock, commit_mock):

# Scenario invalid state
assert_raises(ValueError, disk_state_set, handle, 16, 1, "blah")


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
@patch.object(UcsHandle, 'query_dn')
def test_valid_server_pool_create(query_mock, add_mo_mock, commit_mock):
query_mock.return_value = OrgOrg(parent_mo_or_dn="org-root", name="root")
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

# Scenario: Default parameters
pool_retval = server_pool_create(handle, 'valid-pool')
# Verify we were passed back the correct object type
assert isinstance(pool_retval, ComputePool)
# Verify the name we gave it was assigned correctly
assert pool_retval.name == "valid-pool"


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
@patch.object(UcsHandle, 'query_dn')
def test_invalid_server_pool_create(query_mock, add_mo_mock, commit_mock):
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

# Scenario: Invalid Org
query_mock.return_value = None
# Verify exception was raised for invalid org
assert_raises(ValueError, server_pool_create, handle, 'invalid-pool')


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
@patch.object(UcsHandle, 'query_dn')
def test_valid_server_pool_add_rack_unit(query_mock, add_mo_mock, commit_mock):
query_mock.return_value = ComputePool(parent_mo_or_dn="org-root",
name="test-pool")
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

# Scenario: Default parameters
pool_retval = server_pool_add_rack_unit(handle, 16)
# Verify we were passed back the correct object type
assert isinstance(pool_retval, ComputePooledRackUnit)
# Verify the ID we gave it was assigned correctly
assert pool_retval.id == str(16)


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
# Patch UcsHandle.query_dn to simulate valid/invalid orgs
@patch.object(UcsHandle, 'query_dn')
def test_invalid_server_pool_add_rack_unit(query_mock, add_mo_mock,
commit_mock):
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

# Scenario: Invalid Org
query_mock.return_value = None
# Verify exception was raised for invalid org
assert_raises(ValueError, server_pool_add_rack_unit, handle, 16,)

# Scenario: Org is not a ComputePool
query_mock.return_value = OrgOrg(parent_mo_or_dn="org-root", name="root")
# Verify exception was raised for invalid type
assert_raises(TypeError, server_pool_add_rack_unit, handle, 16,)