Skip to content
Open
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
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Complexity
output/*.html
output/*/index.html

# Sphinx
docs/_build

# Idea IDE
.idea/*

.DS_Store
tags
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ flake8==2.4.1
tox==2.1.1
coverage==4.0
Sphinx==1.3.1

nose==1.3.7
mock==2.0.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
]

test_requirements = [
# TODO: put package test requirements here
'nose'
]

setup(
Expand Down Expand Up @@ -49,7 +49,7 @@
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
],
test_suite='tests',
test_suite='nose.collector',
tests_require=test_requirements,
extras_require={
'docs': ['sphinx<1.3', 'sphinxcontrib-napoleon',
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ucsmsdk_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import unittest

from ucsmsdk_samples import ucsmsdk_samples


class TestUcsmsdk_samples(unittest.TestCase):

Expand Down
93 changes: 93 additions & 0 deletions tests/unit_tests/test_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2016 Cisco Systems, Inc.
#
# 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.

from mock import patch
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk_samples.network.uplink_port import uplink_port_create
from ucsmsdk_samples.network.server_port import server_port_create


@patch.object(UcsHandle, 'commit')
@patch.object(UcsHandle, 'add_mo')
def test_valid_uplink_port_create(add_mo_mock, commit_mock):
# 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')

# Scenario: Set Fabric-A port Eth1/10 to uplink port
fabric_dn = 'fabric/lan/A'
port_id = '10'
slot_id = '1'
uplink_port_create(handle, fabric_dn, port_id, slot_id)

# Assert values of the object passed to add_mo()
test_uplink_mo = add_mo_mock.call_args[0][0]
assert test_uplink_mo.port_id == "10"
assert test_uplink_mo.slot_id == "1"
assert test_uplink_mo.dn == '{0}/phys-slot-{1}-port-{2}'.format(fabric_dn,
slot_id,
port_id)

# Scenario: Set Fabric-B port Eth2/6 to uplink port
fabric_dn = 'fabric/lan/B'
port_id = '6'
slot_id = '2'
uplink_port_create(handle, fabric_dn, port_id, slot_id)

# Assert values of the object passed to add_mo()
test_uplink_mo = add_mo_mock.call_args[0][0]
assert test_uplink_mo.port_id == "6"
assert test_uplink_mo.slot_id == "2"
assert test_uplink_mo.dn == '{0}/phys-slot-{1}-port-{2}'.format(fabric_dn,
slot_id,
port_id)


@patch.object(UcsHandle, 'commit')
@patch.object(UcsHandle, 'add_mo')
def test_valid_server_port_create(add_mo_mock, commit_mock):
# 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')

# Scenario: Set Fabric-A port Eth1/10 to server port
fabric_dn = 'fabric/lan/A'
port_id = '10'
slot_id = '1'
server_port_create(handle, fabric_dn, port_id, slot_id)

# Assert values of the object passed to add_mo()
test_server_mo = add_mo_mock.call_args[0][0]
assert test_server_mo.port_id == "10"
assert test_server_mo.slot_id == "1"
assert test_server_mo.dn == '{0}/slot-{1}-port-{2}'.format(fabric_dn,
slot_id,
port_id)

# Scenario: Set Fabric-B port Eth2/6 to server port
fabric_dn = 'fabric/lan/B'
port_id = '6'
slot_id = '2'
server_port_create(handle, fabric_dn, port_id, slot_id)

# Assert values of the object passed to add_mo()
test_server_mo = add_mo_mock.call_args[0][0]
assert test_server_mo.port_id == "6"
assert test_server_mo.slot_id == "2"
assert test_server_mo.dn == '{0}/slot-{1}-port-{2}'.format(fabric_dn,
slot_id,
port_id)
205 changes: 205 additions & 0 deletions tests/unit_tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Copyright 2016 Cisco Systems, Inc.
#
# 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.


from mock import patch
from nose.tools import assert_raises
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.org.OrgOrg import OrgOrg
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 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 orgs
@patch.object(UcsHandle, 'query_dn')
def test_valid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock):
# Create a root org as a return value to query_dn
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
ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy")
# Verify we were passed back the correct object type
assert isinstance(ipmi_retval, AaaEpAuthProfile)
# Verify the name we gave it was assigned correctly
assert ipmi_retval.name == "test_ipmi_policy"
# Verify the retruned object has no users (children)
assert len(ipmi_retval.child) == 0

# Scenario: default user, custom password
ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy",
password="password")
user_retval = ipmi_retval.child[0]
# Verify the returned policy has a user (child)
assert user_retval is not None
# Verify the username is the default 'admin'
assert user_retval.name is 'admin'
# Verify the password was assigned correctly
assert user_retval.pwd is 'password'

# Scenario: custom user, custom password
ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy",
username="myuser", password="password")
user_retval = ipmi_retval.child[0]
# Verify the returned policy has a user (child)
assert user_retval is not None
# Verify the username was assigned correctly
assert user_retval.name is 'myuser'
# Verify the password was assigned correctly
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):
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, 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')

# 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: 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')

# 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,)
10 changes: 5 additions & 5 deletions ucsmsdk_samples/admin/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def domain_exists(handle, name, refresh_period="600", session_timeout="7200",
dn = "sys/svc-ext/dns-svc/dns-" + name
mo = handle.query_dn(dn)
if mo:
if ((descr and (mo.descr != descr))
and
(refresh_period and (mo.refresh_period != refresh_period))
and
(session_timeout and (mo.session_timeout != session_timeout))):
if (
(descr and (mo.descr != descr)) and
(refresh_period and (mo.refresh_period != refresh_period)) and
(session_timeout and (mo.session_timeout != session_timeout))
):
return False
return True
return False
Expand Down
Loading