From 168502384f3965ee42a22d956a672c448de65e7f Mon Sep 17 00:00:00 2001 From: Brett Johnson Date: Tue, 8 May 2018 12:35:00 +1000 Subject: [PATCH 1/4] Update dependency versions --- requirements_dev.txt | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index acd4ddc..a323cef 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -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 From 11a2cd589ec415cdc955d69f8e3825809a186307 Mon Sep 17 00:00:00 2001 From: Brett Johnson Date: Tue, 8 May 2018 12:35:38 +1000 Subject: [PATCH 2/4] Correct linting errors due to whitespace --- tests/unit_tests/test_server.py | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/unit_tests/test_server.py b/tests/unit_tests/test_server.py index a0a9053..6c7d694 100644 --- a/tests/unit_tests/test_server.py +++ b/tests/unit_tests/test_server.py @@ -71,7 +71,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 @@ -88,28 +87,29 @@ 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 @@ -117,12 +117,12 @@ def test_valid_disk_state(add_mo_mock, commit_mock): # 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 @@ -198,12 +198,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 From 29141a426fe29faddd5bd4b43098d04fb208a624 Mon Sep 17 00:00:00 2001 From: Brett Johnson Date: Tue, 8 May 2018 16:19:09 +1000 Subject: [PATCH 3/4] Add uuid pools module and test for uuid_pool creation --- tests/unit_tests/test_server.py | 39 ++++++++++++- ucsmsdk_samples/server/uuid_pools.py | 86 ++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 ucsmsdk_samples/server/uuid_pools.py diff --git a/tests/unit_tests/test_server.py b/tests/unit_tests/test_server.py index 6c7d694..9ceb120 100644 --- a/tests/unit_tests/test_server.py +++ b/tests/unit_tests/test_server.py @@ -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 @@ -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') @@ -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) diff --git a/ucsmsdk_samples/server/uuid_pools.py b/ucsmsdk_samples/server/uuid_pools.py new file mode 100644 index 0000000..0e82e5c --- /dev/null +++ b/ucsmsdk_samples/server/uuid_pools.py @@ -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 From 81ec39d3c103f1b27bb6f55080853fe44bd96ae0 Mon Sep 17 00:00:00 2001 From: Brett Johnson Date: Fri, 11 May 2018 11:32:40 +1000 Subject: [PATCH 4/4] Adding function to test if server pool exists --- ucsmsdk_samples/server/server_pool.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ucsmsdk_samples/server/server_pool.py b/ucsmsdk_samples/server/server_pool.py index cf176a3..cac28db 100644 --- a/ucsmsdk_samples/server/server_pool.py +++ b/ucsmsdk_samples/server/server_pool.py @@ -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