Add unit tests

For smcards, chassis, system, fantrays, pools, interfaces,
powersupplies, scards.
This commit is contained in:
Rohan Kanade 2014-02-24 14:45:33 +01:00
parent 69e20cbdcd
commit 626460aa55
16 changed files with 448 additions and 11 deletions

View File

@ -151,12 +151,12 @@ class ManagerWithFind(Manager):
To find volume with size less than equal to 500 GB and id contains
'ironic'
kwargs = {'freeSize_le': 500, 'id_has': 'ironic'}
kwargs = {'freeSize_le': 500, 'id_has': 'ironic', "UsedSize": 300}
Operator:
no operator required for "equal to" checks
_le: less than equal to
_ge: greater than equal to
_eq: equal to
_has: contains string
This isn't very efficient: it loads the entire list then filters on
@ -182,6 +182,10 @@ class ManagerWithFind(Manager):
elif attr.endswith('_has'):
if value in getattr(obj, attr):
found.append(obj)
else:
if getattr(obj, attr) == value:
found.append(obj)
except AttributeError:
continue

View File

@ -111,3 +111,78 @@ class FakeHTTPClient(base_client.HTTPClient):
def delete_servers_1_vdisk_0(self, **kwargs):
return (200, {}, {})
def get_storage_disks(self, **kwargs):
return (200, {}, {})
def get_storage_disks_1(self, **kwargs):
return (200, {}, {'1': {}})
def put_storage_disks_1(self, **kwargs):
return (200, {}, {'1': {}})
def get_chassis(self, **kwargs):
return (200, {}, {})
def put_chassis_system_writeMem(self, **kwargs):
return (200, {}, {})
def get_chassis_fanTray(self, **kwargs):
return (200, {}, {})
def get_chassis_fanTray_1(self, **kwargs):
return (200, {}, {})
def get_interfaces(self, **kwargs):
return (200, {}, {})
def get_interfaces_1(self, **kwargs):
return (200, {}, {})
def put_interfaces_1_shutdown(self, **kwargs):
return (200, {}, {})
def put_interfaces_1_vlans_taggedVlans(self, **kwargs):
return (200, {}, {})
def put_interfaces_1_vlans_untaggedVlans(self, **kwargs):
return (200, {}, {})
def put_storage_pools_1_pool_name(self, **kwargs):
return (200, {}, {})
def delete_storage_pools_1_pool_name(self, **kwargs):
return (200, {}, {})
def put_storage_pools_1(self, **kwargs):
return (200, {}, {})
def get_chassis_powersupply(self, **kwargs):
return (200, {}, {})
def get_chassis_powersupply_1(self, **kwargs):
return (200, {}, {})
def get_chassis_scard(self, **kwargs):
return (200, {}, {})
def get_chassis_scard_1(self, **kwargs):
return (200, {}, {})
def put_chassis_scard_1_mgmtMode(self, **kwargs):
return (200, {}, {})
def get_chassis_smcard(self, **kwargs):
return (200, {}, {})
def get_chassis_smcard_1(self, **kwargs):
return (200, {}, {})
def get_chassis_systems(self, **kwargs):
return (200, {}, {})
def put_chassis_system_switchover(self, **kwargs):
return (200, {}, {})
def put_chassis_system_reload(self, **kwargs):
return (200, {}, {})

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import smcards
cs = fakes.FakeClient()
class SMCardstest(utils.TestCase):
def test_list_smcards(self):
pl = cs.smcards.list()
cs.assert_called('GET', '/chassis/smcard')
[self.assertTrue(isinstance(s, smcards.SMCard)) for s in pl]
def test_get_smcards(self):
p = cs.smcards.get(1)
cs.assert_called('GET', '/chassis/smcard/1')
self.assertTrue(isinstance(p, smcards.SMCard))

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import chassis
cs = fakes.FakeClient()
class ChassisTest(utils.TestCase):
def test_list_chassiss(self):
sl = cs.chassis.list()
cs.assert_called('GET', '/chassis')
[self.assertTrue(isinstance(s, chassis.Chassis)) for s in sl]
def test_chassis_write_mem(self):
cs.chassis.writemem(1)
cs.assert_called('PUT', '/chassis/system/writeMem')

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import disks
cs = fakes.FakeClient()
class DisksTest(utils.TestCase):
def test_list_disks(self):
sl = cs.disks.list()
cs.assert_called('GET', '/storage/disks')
[self.assertTrue(isinstance(s, disks.Disk)) for s in sl]
def test_get_disk(self):
s = cs.disks.get(1)
cs.assert_called('GET', '/storage/disks/1')
self.assertTrue(isinstance(s, disks.Disk))
def test_disk_power_on(self):
cs.disks.power_on(1)
cs.assert_called('PUT', '/storage/disks/1')
def test_disk_power_off(self):
cs.disks.power_off(1)
cs.assert_called('PUT', '/storage/disks/1')
def test_disk_activate_led(self):
cs.disks.activate_led(1)
cs.assert_called('PUT', '/storage/disks/1')
def test_disk_deactivate_lef(self):
cs.disks.deactivate_led(1)
cs.assert_called('PUT', '/storage/disks/1')

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import fantrays
cs = fakes.FakeClient()
class FanTraysTest(utils.TestCase):
def test_list_fantrays(self):
sl = cs.fantrays.list()
cs.assert_called('GET', '/chassis/fanTray')
[self.assertTrue(isinstance(s, fantrays.FanTray)) for s in sl]
def test_fantray_get(self):
cs.fantrays.get(1)
cs.assert_called('GET', '/chassis/fanTray/1')

View File

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import interfaces
cs = fakes.FakeClient()
class InterfacesTest(utils.TestCase):
def test_list_interfaces(self):
sl = cs.interfaces.list()
cs.assert_called('GET', '/interfaces')
[self.assertTrue(isinstance(s, interfaces.Interface)) for s in sl]
def test_interface_get(self):
cs.interfaces.get(1)
cs.assert_called('GET', '/interfaces/1')
def test_interface_shutdown(self):
cs.interfaces.shutdown(1)
cs.assert_called('PUT', '/interfaces/1/shutdown')
def test_interface_no_shutdown(self):
cs.interfaces.no_shutdown(1)
cs.assert_called('PUT', '/interfaces/1/shutdown')
def test_interface_add_taggedvlan_list(self):
cs.interfaces.add_tagged_vlan(1, [1, 2, 3])
cs.assert_called('PUT', '/interfaces/1/vlans/taggedVlans')
def test_interface_add_taggedvlan_single(self):
cs.interfaces.add_tagged_vlan(1, '23-25')
cs.assert_called('PUT', '/interfaces/1/vlans/taggedVlans')
def test_interface_remove_taggedvlan(self):
cs.interfaces.remove_tagged_vlan(1, '23-25')
cs.assert_called('PUT', '/interfaces/1/vlans/taggedVlans')
def test_interface_add_untaggedvlan(self):
cs.interfaces.add_untagged_vlan(1, '23')
cs.assert_called('PUT', '/interfaces/1/vlans/untaggedVlans')
def test_interface_remove_untaggedvlan(self):
cs.interfaces.remove_untagged_vlan(1, '23')
cs.assert_called('PUT', '/interfaces/1/vlans/untaggedVlans')

View File

@ -31,3 +31,19 @@ class PoolsTest(utils.TestCase):
p = cs.pools.get(1)
cs.assert_called('GET', '/storage/pools/1')
self.assertTrue(isinstance(p, pools.Pool))
def test_create_pool(self):
cs.pools.create(1, "pool-name", [1, 5, 6])
cs.assert_called('PUT', '/storage/pools/1/pool-name')
def test_delete_pool(self):
cs.pools.delete('1/pool-name')
cs.assert_called('DELETE', '/storage/pools/1/pool-name')
def test_mount_pool(self):
cs.pools.mount(1)
cs.assert_called('PUT', '/storage/pools/1')
def test_unmount_pool(self):
cs.pools.unmount(1)
cs.assert_called('PUT', '/storage/pools/1')

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import powersupplies
cs = fakes.FakeClient()
class PowerSuppliesTest(utils.TestCase):
def test_list_powersupplies(self):
pl = cs.powersupplies.list()
cs.assert_called('GET', '/chassis/powersupply')
[self.assertTrue(isinstance(s, powersupplies.PowerSupply)) for s in pl]
def test_get_powersupplie(self):
p = cs.powersupplies.get(1)
cs.assert_called('GET', '/chassis/powersupply/1')
self.assertTrue(isinstance(p, powersupplies.PowerSupply))

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import scards
cs = fakes.FakeClient()
class ScardsTest(utils.TestCase):
def test_list_scards(self):
pl = cs.scards.list()
cs.assert_called('GET', '/chassis/scard')
[self.assertTrue(isinstance(s, scards.Scard)) for s in pl]
def test_get_scard(self):
p = cs.scards.get(1)
cs.assert_called('GET', '/chassis/scard/1')
self.assertTrue(isinstance(p, scards.Scard))
def test_scard_management_mode(self):
cs.scards.set_management_mode(1, 'disk')
self.assertTrue('PUT', '/chassis/scard/1/mgmtMode')

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# 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 seamicroclient.tests import utils
from seamicroclient.tests.v2 import fakes
from seamicroclient.v2 import system
cs = fakes.FakeClient()
class Systemstest(utils.TestCase):
def test_list_system(self):
pl = cs.system.list()
cs.assert_called('GET', '/chassis/systems')
[self.assertTrue(isinstance(s, system.System)) for s in pl]
def test_switchover_system(self):
cs.system.switchover(1)
cs.assert_called('PUT', '/chassis/system/switchover')
def test_writemem_system(self):
cs.system.writemem(1)
cs.assert_called('PUT', '/chassis/system/writeMem')
def test_reload_system(self):
cs.system.reload(1)
cs.assert_called('PUT', '/chassis/system/reload')

View File

@ -15,6 +15,14 @@ from seamicroclient import client
from seamicroclient.v2 import servers
from seamicroclient.v2 import pools
from seamicroclient.v2 import volumes
from seamicroclient.v2 import disks
from seamicroclient.v2 import chassis
from seamicroclient.v2 import fantrays
from seamicroclient.v2 import interfaces
from seamicroclient.v2 import powersupplies
from seamicroclient.v2 import scards
from seamicroclient.v2 import smcards
from seamicroclient.v2 import system
class Client(object):
@ -40,6 +48,14 @@ class Client(object):
self.servers = servers.ServerManager(self)
self.pools = pools.PoolManager(self)
self.volumes = volumes.VolumeManager(self)
self.disks = disks.DiskManager(self)
self.chassis = chassis.ChassisManager(self)
self.fantrays = fantrays.FanTrayManager(self)
self.interfaces = interfaces.InterfaceManager(self)
self.powersupplies = powersupplies.PowerSupplyManager(self)
self.scards = scards.ScardManager(self)
self.smcards = smcards.SMCardManager(self)
self.system = system.SystemManager(self)
self.client = client.HTTPClient(username,
password,

View File

@ -58,7 +58,7 @@ class DiskManager(base.ManagerWithFind):
"""
Power off the specified Disk
"""
url = "/storage/disks/%s/" % base.getid(disk)
url = "/storage/disks/%s" % base.getid(disk)
body = {'action': 'power-off'}
return self.api.client.put(url, body=body)
@ -66,7 +66,7 @@ class DiskManager(base.ManagerWithFind):
"""
Power on the specified Disk
"""
url = "/storage/disks/%s/" % base.getid(disk)
url = "/storage/disks/%s" % base.getid(disk)
body = {'action': 'power-on'}
return self.api.client.put(url, body=body)
@ -74,7 +74,7 @@ class DiskManager(base.ManagerWithFind):
"""
Activate LED of the specified Disk
"""
url = "/storage/disks/%s/" % base.getid(disk)
url = "/storage/disks/%s" % base.getid(disk)
body = {'action': 'activate-led'}
return self.api.client.put(url, body=body)
@ -82,6 +82,6 @@ class DiskManager(base.ManagerWithFind):
"""
De-activate LED of the specified Disk
"""
url = "/storage/disks/%s/" % base.getid(disk)
url = "/storage/disks/%s" % base.getid(disk)
body = {'action': 'deactivate-led'}
return self.api.client.put(url, body=body)

View File

@ -82,10 +82,11 @@ class InterfaceManager(base.ManagerWithFind):
"""
url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface)
if isinstance(vlan_id, list):
vlan_id = map(lambda x: str(x), vlan_id)
body = {'add': ','.join(vlan_id)}
else:
body = {'add': str(vlan_id)}
return self.api.client.put(url, body)
return self.api.client.put(url, body=body)
def remove_tagged_vlan(self, interface, vlan_id, **kwargs):
"""
@ -93,7 +94,7 @@ class InterfaceManager(base.ManagerWithFind):
"""
url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface)
body = {'remove': str(vlan_id)}
return self.api.client.put(url, body)
return self.api.client.put(url, body=body)
def add_untagged_vlan(self, interface, vlan_id, **kwargs):
"""
@ -101,7 +102,7 @@ class InterfaceManager(base.ManagerWithFind):
"""
url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
body = {'add': str(vlan_id)}
return self.api.client.put(url, body)
return self.api.client.put(url, body=body)
def remove_untagged_vlan(self, interface, vlan_id, **kwargs):
"""
@ -109,4 +110,4 @@ class InterfaceManager(base.ManagerWithFind):
"""
url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
body = {'remove': str(vlan_id)}
return self.api.client.put(url, body)
return self.api.client.put(url, body=body)

View File

@ -55,6 +55,7 @@ class PoolManager(base.ManagerWithFind):
:rtype: Instance of :class:`Pool`
"""
disks = map(lambda x: str(x), disks)
body = {'disks': ','.join(disks), 'raidLevel': raid_level}
url = '/storage/pools/%s/%s' % (base.getid(slot), pool_name)
return self.api.client.put(url, body=body)
@ -83,7 +84,6 @@ class PoolManager(base.ManagerWithFind):
Perform a pool "action" -- .
"""
body = {"action": action}
body.update(info)
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/storage/pools/%s' % base.getid(pool)
return self.api.client.put(url, body=body)

View File

@ -41,6 +41,15 @@ class ScardManager(base.ManagerWithFind):
"""
return self._list("/chassis/scard", filters=filters)
def get(self, scard, **kwargs):
"""
Get a specific scard.
:rtype: Instance of :class:`Scard`
"""
return self._get(base.getid(scard),
'/chassis/scard/%s' % base.getid(scard))
def set_management_mode(self, scard, mode, force=False, **kwargs):
"""
Set management mode of the specified scard