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

Dev #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Dev #35

Show file tree
Hide file tree
Changes from all commits
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
42 changes: 36 additions & 6 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
alabaster==0.7.10
argh==0.26.2
Babel==2.5.3
bumpversion==0.5.3
wheel==0.23.0
watchdog==0.8.3
flake8==2.4.1
tox==2.1.1
certifi==2018.4.16
chardet==3.0.4
coverage==4.0
Sphinx==1.3.1
nose==1.3.7
docutils==0.14
flake8==2.4.1
idna==2.6
imagesize==1.0.0
Jinja2==2.10
MarkupSafe==1.0
mccabe==0.3.1
mock==2.0.0
nose==1.3.7
packaging==17.1
pathtools==0.1.2
pbr==4.0.2
pep8==1.7.1
pluggy==0.3.1
py==1.5.3
pycodestyle==2.3.1
pyflakes==0.8.1
Pygments==2.2.0
pyparsing==2.2.0
pytz==2018.4
PyYAML==3.12
requests==2.18.4
six==1.11.0
snowballstemmer==1.2.1
Sphinx==1.3.1
sphinx-rtd-theme==0.1.9
sphinxcontrib-websupport==1.0.1
tox==2.1.1
ucsmsdk==0.9.3.2
urllib3==1.22
virtualenv==15.2.0
watchdog==0.8.3
83 changes: 60 additions & 23 deletions tests/unit_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from mock import patch
from nose.tools import assert_raises
from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.org.OrgOrg import OrgOrg
from ucsmsdk_samples.server.ipmi_policy import ipmi_policy_create
Expand All @@ -25,8 +26,10 @@
from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit
from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
from ucsmsdk_samples.server.uuid_pools import uuid_pool_create


@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate ucsm interaction w/o real ucsm
@patch.object(UcsHandle, 'add_mo')
Expand Down Expand Up @@ -71,7 +74,6 @@ 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
Expand All @@ -88,41 +90,42 @@ def test_invalid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock):
# Verify exception was raised for invalid org
assert_raises(ValueError, ipmi_policy_create, handle, 'invalid')


# 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')
def test_valid_disk_state(add_mo_mock, commit_mock):
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

# Scenario: jbod mode
test_retval = disk_state_set(handle, 1, 4, "jbod")
assert test_retval.admin_action == "jbod"
assert test_retval.dn == "sys/rack-unit-1/board/storage-SAS-1/disk-4"
# Scenario: jbod mode
test_retval = disk_state_set(handle, 1, 4, "jbod")
assert test_retval.admin_action == "jbod"
assert test_retval.dn == "sys/rack-unit-1/board/storage-SAS-1/disk-4"

# Scenario: unconfigured-good mode
test_retval = disk_state_set(handle, 2, 5, "unconfigured-good")
assert test_retval.admin_action == "unconfigured-good"
assert test_retval.dn == "sys/rack-unit-2/board/storage-SAS-1/disk-5"
# Scenario: unconfigured-good mode
test_retval = disk_state_set(handle, 2, 5, "unconfigured-good")
assert test_retval.admin_action == "unconfigured-good"
assert test_retval.dn == "sys/rack-unit-2/board/storage-SAS-1/disk-5"

# Scenario: custom controller
test_retval = disk_state_set(handle, 3, 6, "jbod", "storage-SAS-4")
assert test_retval.dn == "sys/rack-unit-3/board/storage-SAS-4/disk-6"
# Scenario: custom controller
test_retval = disk_state_set(handle, 3, 6, "jbod", "storage-SAS-4")
assert test_retval.dn == "sys/rack-unit-3/board/storage-SAS-4/disk-6"


# 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')
def test_invalid_disk_state(add_mo_mock, commit_mock):
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')
add_mo_mock.return_value = True
commit_mock.return_value = True
handle = UcsHandle('169.254.1.1', 'admin', 'password')

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


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
Expand Down Expand Up @@ -198,12 +201,12 @@ def test_invalid_server_pool_add_rack_unit(query_mock, add_mo_mock,
# 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,)
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,)
assert_raises(TypeError, server_pool_add_rack_unit, handle, 16, )


# Patch UcsHandle.commit to simulate ucsm interaction w/o real ucsm
Expand Down Expand Up @@ -249,3 +252,37 @@ def test_invalid_server_pool_add_slot(query_mock, add_mo_mock,
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_slot, handle, 1, 8)


# 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_uuid_pool_create(query_mock, add_mo_mock, commit_mock):
query_mock.return_value = UuidpoolPool(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')

uuid_pool = uuid_pool_create(handle=handle, name="test-pool")

assert uuid_pool.name == "test-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_missing_name_uuid_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: Name missing
query_mock.return_value = None

assert_raises(TypeError, uuid_pool_create, handle)
26 changes: 26 additions & 0 deletions ucsmsdk_samples/server/server_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,29 @@ def server_pool_add_slot(handle, chassis_id, slot_id, parent_dn="org-root"):
handle.add_mo(mo)
handle.commit()
return mo


def server_pool_exists(handle, parent_dn="org-root"):
"""
This method adds a validates if a server pool exists.

Args:
handle (UcsHandle)
parent_dn (string): Parent of Org.

Returns:
ComputePooledSlot: Managed Object

Example:
server_pool_add_slot(handle,
parent_dn="org-root/org-sub/compute-pool-sample_compute_pool")

"""

obj = handle.query_dn(parent_dn)
if not obj:
return False
if not isinstance(obj, ComputePool):
raise TypeError("Object {0} is not a ComputePool".format(obj.dn))
else:
return True
86 changes: 86 additions & 0 deletions ucsmsdk_samples/server/uuid_pools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This module contains methods required for creating UUID Pools.
"""


def uuid_pool_create(handle, name, descr="", prefix="derived", assignment_order="default", parent_dn="org-root"):
"""
This method creates Maintenance policy.

Args:
handle (UcsHandle)
name (string): Name of the maintenance policy.
prefix (string) : "derived" or UUID prefix value
assignment_order (string): "default" or "sequential"
descr (string): Basic description.
parent_dn (string): Parent of Org.

Returns:
UuidpoolPool: Managed Object

Raises:
TypeError: If Name is not present

Example:
maintenance_policy_create(handle, name="sample_uuid_pool",
prefix="derived",
assignment_order="sequential",
parent_dn="org-root")

"""

from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool

mo = UuidpoolPool(parent_mo_or_dn=parent_dn,
prefix=prefix,
descr=descr,
assignment_order=assignment_order,
name=name)

handle.add_mo(mo, True)
handle.commit()
return mo


def uuid_block_create(handle, parent_mo, r_from, to):
"""
This method creates a UUID block.

Args:
handle (UcsHandle)
parent_mo (ManagedObject): UUID pool block is added to
r_from (string) : Starting range of UUID Block
to (string): End of block range

Returns:
UuidpoolPool: Managed Object

Raises:
TypeError: If any input is not present

Example:
maintenance_policy_create(handle, parent_mo=mo,
r_from="0000-010101000000",
to="0000-010101000100")
"""

from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

UuidpoolBlock(parent_mo_or_dn=parent_mo,
to=to,
r_from=r_from)

handle.add_mo(parent_mo, True)
handle.commit()
return parent_mo