Add functional tests for server, pool, volumes
This commit is contained in:
@@ -71,6 +71,8 @@ class Manager(utils.HookableMixin):
|
||||
def _create(self, url, body, return_raw=False, **kwargs):
|
||||
self.run_hooks('modify_body_for_create', body, **kwargs)
|
||||
_resp, body = self.api.client.post(url, body=body)
|
||||
if isinstance(body, basestring):
|
||||
return self.get(body.partition('/')[-1])
|
||||
if return_raw:
|
||||
return body
|
||||
for k, v in body.iteritems():
|
||||
@@ -84,6 +86,9 @@ class Manager(utils.HookableMixin):
|
||||
self.run_hooks('modify_body_for_update', body, **kwargs)
|
||||
_resp, body = self.api.client.put(url, body=body)
|
||||
if body:
|
||||
if isinstance(body, basestring):
|
||||
return self.get(body.partition('/')[-1])
|
||||
|
||||
if body == kwargs.get('action'):
|
||||
return
|
||||
for k, v in body.iteritems():
|
||||
|
44
seamicroclient/tests/functional/v2/test_pools.py
Normal file
44
seamicroclient/tests/functional/v2/test_pools.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# -*- 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.
|
||||
import uuid
|
||||
|
||||
from seamicroclient.tests import utils
|
||||
from seamicroclient.v2 import Client
|
||||
|
||||
|
||||
cs = Client("admin", "seamicro", "http://chassis/v2.0")
|
||||
|
||||
|
||||
class PoolsTest(utils.TestCase):
|
||||
|
||||
def test_list_pool(self):
|
||||
pool_list = cs.pools.list()
|
||||
self.assertTrue(len(pool_list) > 0)
|
||||
|
||||
def test_list_pool_with_filter(self):
|
||||
filters = {'id': 'p6-'}
|
||||
for pool in cs.pools.list(filters):
|
||||
for k, v in filters.iteritems():
|
||||
self.assertIn(v, getattr(pool, k))
|
||||
|
||||
def test_list_pool_with_filter_no_match(self):
|
||||
filters = {'id': str(uuid.uuid4())}
|
||||
for pool in cs.pools.list(filters):
|
||||
for k, v in filters.iteritems():
|
||||
self.assertNotIn(getattr(pool, k), v)
|
||||
|
||||
def test_get_pool(self):
|
||||
pool_id = cs.pools.list()[0].id
|
||||
pool = cs.pools.get(pool_id)
|
||||
self.assertEqual(pool.id, pool_id)
|
@@ -11,15 +11,66 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import time
|
||||
|
||||
from seamicroclient.tests import utils
|
||||
from seamicroclient.v2 import Client
|
||||
|
||||
|
||||
STATUS_WAIT_TIMEOUT = 30
|
||||
BUILD_INTERVAL = 10
|
||||
|
||||
SERVER_ID = '0/0'
|
||||
VLAN_ID = '7'
|
||||
cs = Client("admin", "seamicro", "http://chassis/v2.0")
|
||||
|
||||
|
||||
class FunctionalException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ServersTest(utils.TestCase):
|
||||
|
||||
@staticmethod
|
||||
def wait_for_server_status(s, active):
|
||||
start_time = int(time.time())
|
||||
while True:
|
||||
timed_out = int(time.time()) - start_time > STATUS_WAIT_TIMEOUT
|
||||
if timed_out:
|
||||
raise FunctionalException()
|
||||
time.sleep(BUILD_INTERVAL)
|
||||
s = cs.servers.get(s.id)
|
||||
if s.active == active:
|
||||
return
|
||||
|
||||
def test_list_servers(self):
|
||||
sl = cs.servers.list()
|
||||
self.assertTrue(len(sl) > 0)
|
||||
|
||||
def test_get_server(self):
|
||||
s = cs.servers.get(SERVER_ID)
|
||||
self.assertEqual(s.id, SERVER_ID)
|
||||
|
||||
def test_power_on_power_off(self):
|
||||
s = cs.servers.get(SERVER_ID)
|
||||
self.assertEqual(s.id, SERVER_ID)
|
||||
if s.active:
|
||||
s.power_off()
|
||||
self.wait_for_server_status(s, active=False)
|
||||
s = cs.servers.get(s.id)
|
||||
self.assertEqual(s.active, False)
|
||||
s.power_on()
|
||||
else:
|
||||
s.power_on()
|
||||
self.wait_for_server_status(s, active=True)
|
||||
s = cs.servers.get(s.id)
|
||||
self.assertEqual(s.active, True)
|
||||
s.power_off()
|
||||
|
||||
def test_reset(self):
|
||||
s = cs.servers.get(SERVER_ID)
|
||||
self.assertEqual(s.id, SERVER_ID)
|
||||
s.reset()
|
||||
self.wait_for_server_status(s, active=True)
|
||||
s = cs.servers.get(SERVER_ID)
|
||||
self.assertEqual(s.active, True)
|
||||
|
50
seamicroclient/tests/functional/v2/test_volumes.py
Normal file
50
seamicroclient/tests/functional/v2/test_volumes.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- 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 import exceptions
|
||||
from seamicroclient.tests import utils
|
||||
from seamicroclient.v2 import Client
|
||||
|
||||
|
||||
cs = Client("admin", "seamicro", "http://chassis/v2.0")
|
||||
|
||||
|
||||
class VolumesTest(utils.TestCase):
|
||||
|
||||
@staticmethod
|
||||
def create_volume(volume_size=2, pool=None):
|
||||
return cs.volumes.create(volume_size, pool)
|
||||
|
||||
def test_list_volume(self):
|
||||
volume_list = cs.volumes.list()
|
||||
self.assertTrue(len(volume_list) > 0)
|
||||
|
||||
def test_get_volume(self):
|
||||
volume_id = cs.volumes.list()[0].id
|
||||
volume = cs.volumes.get(volume_id)
|
||||
self.assertEqual(volume.id, volume_id)
|
||||
|
||||
def test_create_volume(self):
|
||||
pool = cs.pools.list()[0]
|
||||
volume_size = 2
|
||||
volume = self.create_volume(volume_size, pool)
|
||||
self.assertIn(pool, volume.id)
|
||||
self.assertEqual(volume.size, volume_size)
|
||||
volume.delete()
|
||||
|
||||
def test_delete_volume(self):
|
||||
volume = self.create_volume()
|
||||
volume.delete()
|
||||
self.assertRaises(exceptions.NotFound, cs.volumes.get,
|
||||
volume.id)
|
@@ -50,20 +50,21 @@ class PoolManager(base.ManagerWithFind):
|
||||
for k, v in filters.iteritems():
|
||||
for pool in pools:
|
||||
if isinstance(v, basestring):
|
||||
if v in pool[k]:
|
||||
if v in getattr(pool, k):
|
||||
output.add(pool)
|
||||
else:
|
||||
if pool in output:
|
||||
output.remove(pool)
|
||||
elif isinstance(v, int):
|
||||
if v == pool[k]:
|
||||
if v == getattr(pool, k):
|
||||
output.add(pool)
|
||||
else:
|
||||
if pool in output:
|
||||
output.remove(pool)
|
||||
else:
|
||||
continue
|
||||
return output
|
||||
return output
|
||||
return pools
|
||||
|
||||
def _action(self, action, pool, info=None, **kwargs):
|
||||
"""
|
||||
|
@@ -14,7 +14,9 @@
|
||||
Volume interface.
|
||||
"""
|
||||
|
||||
from seamicroclient.openstack.common import uuidutils
|
||||
import binascii
|
||||
import os
|
||||
|
||||
from seamicroclient import base
|
||||
|
||||
|
||||
@@ -60,7 +62,7 @@ class VolumeManager(base.ManagerWithFind):
|
||||
"""
|
||||
create_params = {}
|
||||
if volume_id is None:
|
||||
volume_id = uuidutils.generate_uuid()
|
||||
volume_id = str(binascii.b2a_hex(os.urandom(6)))
|
||||
if pool and volume_id and size:
|
||||
create_params = {'volume-size': str(size)}
|
||||
resource_url = "%s/%s" % (base.getid(pool), volume_id)
|
||||
|
Reference in New Issue
Block a user