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)
120 changes: 120 additions & 0 deletions tests/unit_tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# 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


# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
@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.object(UcsHandle, 'commit')
@patch.object(UcsHandle, 'add_mo')
@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')

# 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 CIMC interaction w/o real CIMC
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
@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 CIMC interaction w/o real CIMC
@patch.object(UcsHandle, 'commit')
# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC
@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")
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
12 changes: 8 additions & 4 deletions ucsmsdk_samples/admin/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ def key_ring_exists(handle, name, descr="", policy_owner="local", tp="",
dn = "sys/pki-ext/keyring-" + name
mo = handle.query_dn(dn)
if mo:
if ((descr and mo.descr != descr) and
if (
(descr and mo.descr != descr) and
(policy_owner and mo.policy_owner != policy_owner) and
(tp and mo.tp != tp) and
(cert and mo.cert != cert) and
(regen and mo.regen != regen) and
(modulus and mo.modulus != modulus)):
(modulus and mo.modulus != modulus)
):
return False
return True
return False
Expand Down Expand Up @@ -273,7 +275,8 @@ def certificate_request_exists(handle, name, dns="", locality="", state="",
dn = "sys/pki-ext/keyring-" + name + "certreq"
mo = handle.query_dn(dn)
if mo:
if ((dns and mo.dns != dns) and
if (
(dns and mo.dns != dns) and
(locality and mo.locality != locality) and
(state and mo.state != state) and
(country and mo.country != country) and
Expand All @@ -287,7 +290,8 @@ def certificate_request_exists(handle, name, dns="", locality="", state="",
(ip_b and mo.ip_b != ip_b) and
(ipv6 and mo.ipv6 != ipv6) and
(ipv6_a and mo.ipv6_a != ipv6_a) and
(ipv6_b and mo.ipv6_b != ipv6_b)):
(ipv6_b and mo.ipv6_b != ipv6_b)
):
return False
return True
return False
Expand Down
9 changes: 5 additions & 4 deletions ucsmsdk_samples/admin/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def ldap_provider_exists(handle, name, order="lowest-available", rootdn="",
dn = "sys/ldap-ext/provider-" + name
mo = handle.query_dn(dn)
if mo:
if ((order and mo.order != order) and
if (
(order and mo.order != order) and
(rootdn and mo.rootdn != rootdn) and
(basedn and mo.basedn != basedn) and
(port and mo.port != port) and
Expand All @@ -111,7 +112,8 @@ def ldap_provider_exists(handle, name, order="lowest-available", rootdn="",
(timeout and mo.timeout != timeout) and
(vendor and mo.vendor != vendor) and
(retries and mo.retries != retries) and
(descr and mo.descr != descr)):
(descr and mo.descr != descr)
):
return False
return True
return False
Expand Down Expand Up @@ -581,8 +583,7 @@ def ldap_provider_group_provider_exists(handle, group_name, name, order,
provider_dn = group_dn + "/provider-ref-" + name
mo = handle.query_dn(provider_dn)
if mo:
if ((descr and mo.descr != descr) and
(order and mo.order != order)):
if ((descr and mo.descr != descr) and (order and mo.order != order)):
return False
return True
return False
Expand Down
6 changes: 4 additions & 2 deletions ucsmsdk_samples/admin/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def locale_exists(handle, name, descr="", policy_owner="local"):
dn = "sys/user-ext/locale-" + name
mo = handle.query_dn(dn)
if mo:
if ((descr and mo.descr != descr) and
(policy_owner and mo.policy_owner != policy_owner)):
if (
(descr and mo.descr != descr) and
(policy_owner and mo.policy_owner != policy_owner)
):
return False
return True
return False
Expand Down
Loading