pep8 compliance cleanup.

This commit is contained in:
tmetsch
2013-05-03 14:00:57 +02:00
parent eaa0bb5e70
commit 1fe13f62bc
13 changed files with 226 additions and 198 deletions

View File

@@ -81,14 +81,16 @@ class NetworkInterfaceBackend(backend.KindBackend):
if link.target.identifier == '/network/public':
# public means floating IP in OS!
# if the os_net_link mixin is avail. a pool must be provided:
if not 'org.openstack.network.floating.pool' in link.attributes and os_addon.OS_NET_LINK in link.mixins:
raise AttributeError('Please specify the pool name when using this mixin!')
if not 'org.openstack.network.floating.pool' in link.attributes\
and os_addon.OS_NET_LINK in link.mixins:
raise AttributeError('Please specify the pool name when using'
' this mixin!')
elif os_addon.OS_NET_LINK in link.mixins:
pool = link.attributes['org.openstack.network.floating.pool']
else:
pool = None
address = net.add_floating_ip(link.source.attributes[
'occi.core.id'],
address = net.add_floating_ip(link.source.attributes['occi.'
'core.id'],
pool,
extras['nova_ctx'])
link.attributes['occi.networkinterface.interface'] = 'eth0'
@@ -113,5 +115,6 @@ class NetworkInterfaceBackend(backend.KindBackend):
if link.target.identifier == '/network/public':
# public means floating IP in OS!
net.remove_floating_ip(link.source.attributes['occi.core.id'],
link.attributes['occi.networkinterface.address'],
link.attributes['occi.networkinterface.'
'address'],
extras['nova_ctx'])

View File

@@ -93,7 +93,6 @@ class OsNetLinkBackend(backend.MixinBackend, backend.ActionBackend):
pass
class SecurityGroupBackend(backend.UserDefinedMixinBackend):
"""
Security Group backend.
@@ -104,8 +103,8 @@ class SecurityGroupBackend(backend.UserDefinedMixinBackend):
Creates the security group as specified in the request.
"""
#do not recreate default openstack security groups
if (category.scheme ==
'http://schemas.openstack.org/infrastructure/security/group#'):
if category.scheme == \
'http://schemas.openstack.org/infrastructure/security/group#':
return
context = extras['nova_ctx']

View File

@@ -49,8 +49,9 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
if 'occi.storage.size' not in entity.attributes:
raise AttributeError('size attribute not found!')
new_volume = storage.create_storage(entity.attributes['occi.storage' \
'.size'], context)
new_volume = storage.create_storage(entity.attributes['occi.storage'
'.size'],
context)
vol_id = new_volume['id']
# Work around problem that instance is lazy-loaded...

View File

@@ -260,8 +260,8 @@ def start_vm(uid, context):
try:
COMPUTE_API.resume(context, instance)
except Exception as error:
raise exceptions.HTTPError(500, 'Error while starting VM: ' + str
(error))
raise exceptions.HTTPError(500, 'Error while starting VM: ' +
str(error))
def stop_vm(uid, context):
@@ -281,8 +281,8 @@ def stop_vm(uid, context):
# self.compute_api.stop(context, instance)
COMPUTE_API.suspend(context, instance)
except Exception as error:
raise exceptions.HTTPError(500, 'Error while stopping VM: ' + str
(error))
raise exceptions.HTTPError(500, 'Error while stopping VM: ' +
str(error))
def restart_vm(uid, method, context):

View File

@@ -39,6 +39,7 @@ from occi_os_api.nova_glue import net
from nova.flags import FLAGS
class OCCIRegistry(occi_registry.NonePersistentRegistry):
"""
Registry for OpenStack.
@@ -51,9 +52,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
super(OCCIRegistry, self).__init__()
self.cache = {}
self.adm_net = core_model.Resource('/network/admin',
infrastructure.NETWORK, [infrastructure.IPNETWORK])
infrastructure.NETWORK,
[infrastructure.IPNETWORK])
self.pub_net = core_model.Resource('/network/public',
infrastructure.NETWORK, [infrastructure.IPNETWORK])
infrastructure.NETWORK,
[infrastructure.IPNETWORK])
self._setup_network()
@@ -215,8 +218,8 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
stor_res_ids = [item['id'] for item in stors]
for item in self.cache.values():
if item.extras is not None and item.extras['user_id'] != context\
.user_id:
if item.extras is not None and item.extras['user_id'] != \
context.user_id:
# filter out items not belonging to this user!
continue
item_id = item.identifier[item.identifier.rfind('/') + 1:]
@@ -355,7 +358,8 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
str(stor['instance_uuid']), extras)
link = core_model.Link(infrastructure.STORAGELINK.location +
str(uuid.uuid4()),
infrastructure.STORAGELINK, [], source, entity)
infrastructure.STORAGELINK, [], source,
entity)
link.extras = self.get_extras(extras)
source.links.append(link)
result.append(link)
@@ -402,7 +406,8 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
link = core_model.Link(infrastructure.NETWORKINTERFACE.location +
str(uuid.uuid4()),
infrastructure.NETWORKINTERFACE,
[infrastructure.IPNETWORKINTERFACE], source, target)
[infrastructure.IPNETWORKINTERFACE], source,
target)
link.attributes = {
'occi.networkinterface.interface': net_desc['interface'],
'occi.networkinterface.mac': net_desc['mac'],

View File

@@ -177,14 +177,14 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
LOG.debug(msg)
continue
ctg_term = occify_terms(img['name'])
os_template = os_mixins.OsTemplate(
term=ctg_term,
os_template = os_mixins.OsTemplate(term=ctg_term,
scheme=template_schema,
os_id=img['id'],
related=[infrastructure.OS_TEMPLATE],
related=[infrastructure.
OS_TEMPLATE],
attributes=None,
title='This is an OS ' + img['name'] + \
' VM image',
title='This is an OS ' +
img['name'] + ' VM image',
location='/' + ctg_term + '/')
try:
@@ -234,23 +234,25 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
excld_grps.append(cat.term)
groups = db.security_group_get_by_project(extras['nova_ctx'],
extras['nova_ctx'].project_id)
extras['nova_'
'ctx'].project_id)
sec_grp = 'http://schemas.openstack.org/infrastructure/security/group#'
for group in groups:
if group['name'] not in excld_grps:
sec_mix = os_mixins.UserSecurityGroupMixin(
term=str(group["id"]), # NOTE(aloga): group.id is a long
term=str(group["id"]),
scheme=sec_grp,
related=[os_addon.SEC_GROUP],
attributes=None,
title=group['name'],
location='/security/' + quote(str(group['id'])) + '/')
location='/security/' + quote(str(group['name'])) + '/')
try:
self.registry.get_backend(sec_mix, extras)
except AttributeError:
self.register_backend(sec_mix, MIXIN_BACKEND)
def occify_terms(term_name):
'''
Occifies a term_name so that it is compliant with GFD 185.

View File

@@ -30,8 +30,7 @@ import random
HEADS = {'Content-Type': 'text/occi',
'Accept': 'text/occi'
}
'Accept': 'text/occi'}
KEYSTONE_HOST = '127.0.0.1:5000'
OCCI_HOST = '127.0.0.1:8787'
@@ -196,43 +195,43 @@ class SystemTest(unittest.TestCase):
'.org/occi/infrastructure#"']
vm_location = create_node(self.token, cats)
# list computes
if 'http://' + OCCI_HOST + vm_location not in list_nodes(self.token,
'/compute/'):
if 'http://' + OCCI_HOST + vm_location not \
in list_nodes(self.token, '/compute/'):
LOG.error('VM should be listed!')
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
# trigger stop
trigger_action(self.token, vm_location + '?action=stop',
'stop; scheme="http://schemas.ogf'
'.org/occi/infrastructure/compute/action#"')
'stop; scheme="http://schemas.ogf.org/occi/'
'infrastructure/compute/action#"')
# wait
cont = False
while not cont:
if 'occi.compute.state="inactive"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="inactive"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
# trigger start
trigger_action(self.token, vm_location + '?action=start',
'start; scheme="http://schemas.ogf'
'.org/occi/infrastructure/compute/action#"')
'start; scheme="http://schemas.ogf.org/occi/'
'infrastructure/compute/action#"')
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
@@ -249,7 +248,8 @@ class SystemTest(unittest.TestCase):
heads['X-Auth-Token'] = self.token
name = 'my_grp' + str(random.randint(1, 999999))
heads['Category'] = name + '; scheme="http://www.mystuff.org/sec#"; ' \
' rel="http://schemas.ogf.org/occi/infrastructure/security#group"; ' \
'rel="http://schemas.ogf.org/occi/' \
'infrastructure/security#group"; ' \
'location="/mygroups/"'
do_request('POST', '/-/', heads)
@@ -284,8 +284,8 @@ class SystemTest(unittest.TestCase):
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
@@ -307,8 +307,10 @@ class SystemTest(unittest.TestCase):
# change pw
LOG.debug(trigger_action(self.token, vm_location + '?action=chg_pwd',
'chg_pwd; scheme="http://schemas.openstack.org/instance/action#"',
'org.openstack.credentials.admin_pwd="new_pass"'))
'chg_pwd; scheme="http://schemas.'
'openstack.org/instance/action#"',
'org.openstack.credentials.admin_pwd'
'="new_pass"'))
# clean VM
destroy_node(self.token, vm_location)
@@ -322,7 +324,7 @@ class SystemTest(unittest.TestCase):
heads = HEADS.copy()
heads['X-Auth-Token'] = self.token
heads['Category'] = name + '; scheme="http://www.mystuff.org/sec#"'
do_request('DELETE', '/-/', heads)
#do_request('DELETE', '/-/', heads)
def test_storage_stuff(self):
"""
@@ -334,7 +336,8 @@ class SystemTest(unittest.TestCase):
'.org/template/resource#"',
'cirros-0-3-0-x86_64-uec; scheme="http://schemas.openstack'
'.org/template/os#"',
'compute; scheme="http://schemas.ogf.org/occi/infrastructure#"']
'compute; scheme="http://schemas.ogf.org/occi/'
'infrastructure#"']
vm_location = create_node(self.token, cats)
# create volume
@@ -378,18 +381,19 @@ class SystemTest(unittest.TestCase):
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
# Create a Image from an Active VM
LOG.debug(trigger_action(self.token, vm_location +
'?action=create_image',
'create_image; scheme="http://schemas.openstack'
'.org/instance/action#"',
'org.openstack.snapshot.image_name="awesome_ware"'))
LOG.debug(trigger_action(self.token, vm_location + '?action='
'create_image',
'create_image; scheme="http://schemas.'
'openstack.org/instance/action#"',
'org.openstack.snapshot.image_name='
'"awesome_ware"'))
destroy_node(self.token, vm_location)
@@ -402,14 +406,15 @@ class SystemTest(unittest.TestCase):
'.org/template/resource#"',
'cirros-0-3-0-x86_64-uec; scheme="http://schemas.openstack'
'.org/template/os#"',
'compute; scheme="http://schemas.ogf.org/occi/infrastructure#"']
'compute; scheme="http://schemas.ogf.org/occi/'
'infrastructure#"']
vm_location = create_node(self.token, cats)
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)
@@ -424,8 +429,8 @@ class SystemTest(unittest.TestCase):
# wait
cont = False
while not cont:
if 'occi.compute.state="active"' in get_node(self.token,
vm_location)['x-occi-attribute']:
if 'occi.compute.state="active"' in \
get_node(self.token, vm_location)['x-occi-attribute']:
cont = True
else:
time.sleep(5)

View File

@@ -91,7 +91,8 @@ class TestComputeBackend(unittest.TestCase):
self.sec_obj)
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[core_model.Category('http://foo.com', 'bar', '', '', '')])
[core_model.Category('http://foo.com',
'bar', '', '', '')])
self.assertRaises(AttributeError, self.backend.update, res1, res2,
self.sec_obj)
@@ -144,8 +145,8 @@ class TestComputeBackend(unittest.TestCase):
})
self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture')
nova_glue.storage.get_image_architecture(mox.IsA(object),
mox.IsA(object)).AndReturn(
'foo')
mox.IsA(object)).\
AndReturn('foo')
self.mox.ReplayAll()
@@ -176,7 +177,8 @@ class TestComputeBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.vm, 'get_occi_state')
nova_glue.vm.get_occi_state(mox.IsA(object),
mox.IsA(object)).AndReturn(('active', [infrastructure.STOP,
mox.IsA(object)).\
AndReturn(('active', [infrastructure.STOP,
infrastructure.SUSPEND,
infrastructure.RESTART]))
self.mox.StubOutWithMock(nova_glue.vm, 'get_vm')
@@ -188,8 +190,8 @@ class TestComputeBackend(unittest.TestCase):
})
self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture')
nova_glue.storage.get_image_architecture(mox.IsA(object),
mox.IsA(object)).AndReturn(
'foo')
mox.IsA(object)).\
AndReturn('foo')
self.mox.ReplayAll()
self.backend.retrieve(res, self.sec_obj)
@@ -312,8 +314,7 @@ class TestComputeBackend(unittest.TestCase):
})
self.mox.ReplayAll()
self.backend.action(res1, infrastructure.RESTART,
{'method': 'graceful'},
self.sec_obj)
{'method': 'graceful'}, self.sec_obj)
self.mox.VerifyAll()
# suspend

View File

@@ -72,7 +72,8 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
# should have pool name in attribute...
target.identifier = '/network/public'
link = core_model.Link('foo', None, [os_addon.OS_NET_LINK], source, target)
link = core_model.Link('foo', None, [os_addon.OS_NET_LINK], source,
target)
self.mox.ReplayAll()
self.assertRaises(AttributeError, self.backend.create, link,
@@ -103,7 +104,7 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
link.attributes = {'org.openstack.network.floating.pool': 'nova'}
self.mox.StubOutWithMock(nova_glue.net, 'add_floating_ip')
nova_glue.net.add_floating_ip(mox.IsA(object), mox.IsA(str),
nova_glue.net.add_floating_ip(mox.IsA(str), mox.IsA(str),
mox.IsA(object)).AndReturn('10.0.0.1')
self.mox.ReplayAll()
@@ -120,16 +121,18 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
# self.assertIn(infrastructure.IPNETWORKINTERFACE, link.mixins)
# self.assertIn(infrastructure.NETWORKINTERFACE, link.mixins)
self.mox.VerifyAll()
# test without pool name...
self.mox.UnsetStubs()
self.mox.StubOutWithMock(nova_glue.net, 'add_floating_ip')
link = core_model.Link('foo', None, [], source, target)
nova_glue.net.add_floating_ip(mox.IsA(object), mox.IsA(str),
mox.IsA(object)).AndReturn('10.0.0.1')
self.mox.StubOutWithMock(nova_glue.net, 'add_floating_ip')
nova_glue.net.add_floating_ip(mox.IsA(str), mox.IsA(None),
mox.IsA(object)).AndReturn('10.0.0.2')
self.mox.ReplayAll()
self.backend.create(link, self.sec_obj)
self.mox.VerifyAll()
def test_delete_for_sanity(self):
"""

View File

@@ -69,10 +69,12 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'create_storage')
nova_glue.storage.create_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'id': '1'})
mox.IsA(object)).\
AndReturn({'id': '1'})
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'error'})
mox.IsA(object)).\
AndReturn({'status': 'error'})
self.mox.ReplayAll()
@@ -103,10 +105,12 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'create_storage')
nova_glue.storage.create_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'id': '1'})
mox.IsA(object)).\
AndReturn({'id': '1'})
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'available'})
mox.IsA(object)).\
AndReturn({'status': 'available'})
self.mox.ReplayAll()
@@ -129,7 +133,8 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'available', 'size': '1'})
mox.IsA(object)).\
AndReturn({'status': 'available', 'size': '1'})
self.mox.ReplayAll()
@@ -146,7 +151,8 @@ class TestStorageBackend(unittest.TestCase):
self.mox.UnsetStubs()
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'bla', 'size': '1'})
mox.IsA(object)).\
AndReturn({'status': 'bla', 'size': '1'})
self.mox.ReplayAll()
@@ -164,8 +170,8 @@ class TestStorageBackend(unittest.TestCase):
res1 = mox.MockObject(core_model.Resource)
res1.attributes = {}
res2 = mox.MockObject(core_model.Resource)
res2.attributes = {'occi.core.title': 'foo', 'occi.core.summary':
'bar'}
res2.attributes = {'occi.core.title': 'foo',
'occi.core.summary': 'bar'}
self.mox.ReplayAll()
@@ -207,7 +213,9 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage,
'snapshot_storage_instance')
nova_glue.storage.snapshot_storage_instance(mox.IsA(object),
mox.IsA(object), mox.IsA(object), mox.IsA(object))
mox.IsA(object),
mox.IsA(object),
mox.IsA(object))
self.mox.ReplayAll()
self.backend.action(res, infrastructure.SNAPSHOT, {}, self.sec_obj)
self.mox.VerifyAll()
@@ -253,7 +261,8 @@ class TestStorageLinkBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.vm, 'attach_volume')
nova_glue.vm.attach_volume(mox.IsA(object), mox.IsA(object),
mox.IsA(object), mox.IsA(object)).AndReturn({})
mox.IsA(object), mox.IsA(object)).\
AndReturn({})
self.mox.ReplayAll()