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

@@ -72,8 +72,8 @@ class ComputeBackend(KindBackend, ActionBackend):
# set valid actions # set valid actions
entity.actions = [infrastructure.STOP, entity.actions = [infrastructure.STOP,
infrastructure.SUSPEND, infrastructure.SUSPEND,
infrastructure.RESTART] infrastructure.RESTART]
# Tell the world that is is an VM in OpenStack... # Tell the world that is is an VM in OpenStack...
entity.mixins.append(os_addon.OS_VM) entity.mixins.append(os_addon.OS_VM)
@@ -96,7 +96,7 @@ class ComputeBackend(KindBackend, ActionBackend):
# set up to date attributes # set up to date attributes
entity.attributes['occi.compute.hostname'] = instance['hostname'] entity.attributes['occi.compute.hostname'] = instance['hostname']
entity.attributes['occi.compute.architecture'] =\ entity.attributes['occi.compute.architecture'] =\
storage.get_image_architecture(uid, extras['nova_ctx']) storage.get_image_architecture(uid, extras['nova_ctx'])
entity.attributes['occi.compute.cores'] = str(instance['vcpus']) entity.attributes['occi.compute.cores'] = str(instance['vcpus'])
entity.attributes['occi.compute.speed'] = str(0.0) # N/A in instance entity.attributes['occi.compute.speed'] = str(0.0) # N/A in instance
value = str(float(instance['memory_mb']) / 1024) value = str(float(instance['memory_mb']) / 1024)

View File

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

View File

@@ -44,7 +44,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
# set additional actions # set additional actions
if 'occi.compute.state' in entity.attributes and entity.attributes[ if 'occi.compute.state' in entity.attributes and entity.attributes[
'occi.compute.state'] == 'active': 'occi.compute.state'] == 'active':
entity.actions.append(os_addon.OS_CREATE_IMAGE) entity.actions.append(os_addon.OS_CREATE_IMAGE)
entity.actions.append(os_addon.OS_CHG_PWD) entity.actions.append(os_addon.OS_CHG_PWD)
@@ -52,7 +52,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
console = vm.get_vnc(uid, context) console = vm.get_vnc(uid, context)
if console: if console:
entity.attributes['org.openstack.compute.console.vnc'] =\ entity.attributes['org.openstack.compute.console.vnc'] =\
console['url'] console['url']
else: else:
entity.attributes['org.openstack.compute.console.vnc'] = 'N/A' entity.attributes['org.openstack.compute.console.vnc'] = 'N/A'
@@ -93,7 +93,6 @@ class OsNetLinkBackend(backend.MixinBackend, backend.ActionBackend):
pass pass
class SecurityGroupBackend(backend.UserDefinedMixinBackend): class SecurityGroupBackend(backend.UserDefinedMixinBackend):
""" """
Security Group backend. Security Group backend.
@@ -104,8 +103,8 @@ class SecurityGroupBackend(backend.UserDefinedMixinBackend):
Creates the security group as specified in the request. Creates the security group as specified in the request.
""" """
#do not recreate default openstack security groups #do not recreate default openstack security groups
if (category.scheme == if category.scheme == \
'http://schemas.openstack.org/infrastructure/security/group#'): 'http://schemas.openstack.org/infrastructure/security/group#':
return return
context = extras['nova_ctx'] context = extras['nova_ctx']
@@ -158,7 +157,7 @@ class SecurityRuleBackend(backend.KindBackend):
try: try:
context = extras['nova_ctx'] context = extras['nova_ctx']
rule = security.retrieve_rule(entity.attributes['occi.core.id'], rule = security.retrieve_rule(entity.attributes['occi.core.id'],
context) context)
security.remove_rule(rule, context) security.remove_rule(rule, context)
except Exception as error: except Exception as error:
@@ -174,7 +173,7 @@ def make_sec_rule(entity, sec_grp_id):
'parent_group_id': sec_grp_id} 'parent_group_id': sec_grp_id}
entity.attributes['occi.core.id'] = str(sg_rule['id']) entity.attributes['occi.core.id'] = str(sg_rule['id'])
prot = \ prot = \
entity.attributes['occi.network.security.protocol'].lower().strip() entity.attributes['occi.network.security.protocol'].lower().strip()
if prot in ('tcp', 'udp', 'icmp'): if prot in ('tcp', 'udp', 'icmp'):
sg_rule['protocol'] = prot sg_rule['protocol'] = prot
else: else:

View File

@@ -49,8 +49,9 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
if 'occi.storage.size' not in entity.attributes: if 'occi.storage.size' not in entity.attributes:
raise AttributeError('size attribute not found!') raise AttributeError('size attribute not found!')
new_volume = storage.create_storage(entity.attributes['occi.storage' \ new_volume = storage.create_storage(entity.attributes['occi.storage'
'.size'], context) '.size'],
context)
vol_id = new_volume['id'] vol_id = new_volume['id']
# Work around problem that instance is lazy-loaded... # Work around problem that instance is lazy-loaded...
@@ -66,7 +67,7 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
entity.attributes['occi.storage.state'] = 'active' entity.attributes['occi.storage.state'] = 'active'
entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP, entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
infrastructure.SNAPSHOT, infrastructure.RESIZE] infrastructure.SNAPSHOT, infrastructure.RESIZE]
def retrieve(self, entity, extras): def retrieve(self, entity, extras):
""" """
@@ -98,13 +99,13 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
if len(new.attributes) > 0: if len(new.attributes) > 0:
# support only title and summary changes now. # support only title and summary changes now.
if 'occi.core.title' in new.attributes and \ if 'occi.core.title' in new.attributes and \
len(new.attributes['occi.core.title']) > 0: len(new.attributes['occi.core.title']) > 0:
old.attributes['occi.core.title'] = \ old.attributes['occi.core.title'] = \
new.attributes['occi.core.title'] new.attributes['occi.core.title']
if 'occi.core.title' in new.attributes and\ if 'occi.core.title' in new.attributes and \
len(new.attributes['occi.core.summary']) > 0: len(new.attributes['occi.core.summary']) > 0:
old.attributes['occi.core.summary'] = \ old.attributes['occi.core.summary'] = \
new.attributes['occi.core.summary'] new.attributes['occi.core.summary']
def delete(self, entity, extras): def delete(self, entity, extras):
""" """
@@ -122,7 +123,7 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
if action not in entity.actions: if action not in entity.actions:
raise AttributeError("This action is currently no applicable.") raise AttributeError("This action is currently no applicable.")
elif action in [infrastructure.ONLINE, infrastructure.OFFLINE, elif action in [infrastructure.ONLINE, infrastructure.OFFLINE,
infrastructure.BACKUP, infrastructure.RESIZE]: infrastructure.BACKUP, infrastructure.RESIZE]:
LOG.warn('The operations online, offline, backup and resize are ' LOG.warn('The operations online, offline, backup and resize are '
'currently not supported!') 'currently not supported!')
elif action == infrastructure.SNAPSHOT: elif action == infrastructure.SNAPSHOT:
@@ -155,7 +156,7 @@ class StorageLinkBackend(backend.KindBackend):
link.attributes['occi.core.id'] = str(uuid.uuid4()) link.attributes['occi.core.id'] = str(uuid.uuid4())
link.attributes['occi.storagelink.deviceid'] = \ link.attributes['occi.storagelink.deviceid'] = \
link.attributes['occi.storagelink.deviceid'] link.attributes['occi.storagelink.deviceid']
link.attributes['occi.storagelink.mountpoint'] = '' link.attributes['occi.storagelink.mountpoint'] = ''
link.attributes['occi.storagelink.state'] = 'active' link.attributes['occi.storagelink.state'] = 'active'

View File

@@ -30,7 +30,7 @@ _SEC_RULE_ATTRIBUTES = {
'occi.network.security.to': '', 'occi.network.security.to': '',
'occi.network.security.from': '', 'occi.network.security.from': '',
'occi.network.security.range': '', 'occi.network.security.range': '',
} }
SEC_RULE = core_model.Kind( SEC_RULE = core_model.Kind(
'http://schemas.openstack.org/occi/infrastructure/network/security#', 'http://schemas.openstack.org/occi/infrastructure/network/security#',
'rule', 'rule',
@@ -48,16 +48,16 @@ SEC_GROUP = core_model.Mixin(
# OS change adminstrative password action # OS change adminstrative password action
_OS_CHG_PWD_ATTRIBUTES = {'org.openstack.credentials.admin_pwd': '', } _OS_CHG_PWD_ATTRIBUTES = {'org.openstack.credentials.admin_pwd': '', }
OS_CHG_PWD = core_model.Action( OS_CHG_PWD = core_model.Action(
'http://schemas.openstack.org/instance/action#', 'http://schemas.openstack.org/instance/action#',
'chg_pwd', 'Changes Admin password.', 'chg_pwd', 'Changes Admin password.',
_OS_CHG_PWD_ATTRIBUTES) _OS_CHG_PWD_ATTRIBUTES)
# OS create image from VM action # OS create image from VM action
_OS_CREATE_IMAGE_ATTRIBUTES = {'org.openstack.snapshot.image_name': '', } _OS_CREATE_IMAGE_ATTRIBUTES = {'org.openstack.snapshot.image_name': '', }
OS_CREATE_IMAGE = core_model.Action( OS_CREATE_IMAGE = core_model.Action(
'http://schemas.openstack.org/instance/action#', 'http://schemas.openstack.org/instance/action#',
'create_image', 'Creates a new image for the given server.', 'create_image', 'Creates a new image for the given server.',
_OS_CREATE_IMAGE_ATTRIBUTES) _OS_CREATE_IMAGE_ATTRIBUTES)
# A Mixin for OpenStack VMs # A Mixin for OpenStack VMs
_OS_VM_ATTRIBUTES = {'org.openstack.compute.console.vnc': 'immutable', _OS_VM_ATTRIBUTES = {'org.openstack.compute.console.vnc': 'immutable',
@@ -69,7 +69,7 @@ OS_VM = core_model.Mixin(
# OS Key pair extension # OS Key pair extension
_OS_KEY_PAIR_ATTRIBUTES = {'org.openstack.credentials.publickey.name': '', _OS_KEY_PAIR_ATTRIBUTES = {'org.openstack.credentials.publickey.name': '',
'org.openstack.credentials.publickey.data': '', } 'org.openstack.credentials.publickey.data': '', }
OS_KEY_PAIR_EXT = core_model.Mixin( OS_KEY_PAIR_EXT = core_model.Mixin(
'http://schemas.openstack.org/instance/credentials#', 'http://schemas.openstack.org/instance/credentials#',
'public_key', attributes=_OS_KEY_PAIR_ATTRIBUTES) 'public_key', attributes=_OS_KEY_PAIR_ATTRIBUTES)

View File

@@ -115,7 +115,7 @@ def remove_rule(rule, context):
try: try:
db.security_group_rule_destroy(context, rule['id']) db.security_group_rule_destroy(context, rule['id'])
SEC_HANDLER.trigger_security_group_rule_destroy_refresh(context, SEC_HANDLER.trigger_security_group_rule_destroy_refresh(context,
[rule['id']]) [rule['id']])
except Exception as err: except Exception as err:
raise AttributeError('Unable to remove rule: ' + str(err)) raise AttributeError('Unable to remove rule: ' + str(err))

View File

@@ -260,8 +260,8 @@ def start_vm(uid, context):
try: try:
COMPUTE_API.resume(context, instance) COMPUTE_API.resume(context, instance)
except Exception as error: except Exception as error:
raise exceptions.HTTPError(500, 'Error while starting VM: ' + str raise exceptions.HTTPError(500, 'Error while starting VM: ' +
(error)) str(error))
def stop_vm(uid, context): def stop_vm(uid, context):
@@ -281,8 +281,8 @@ def stop_vm(uid, context):
# self.compute_api.stop(context, instance) # self.compute_api.stop(context, instance)
COMPUTE_API.suspend(context, instance) COMPUTE_API.suspend(context, instance)
except Exception as error: except Exception as error:
raise exceptions.HTTPError(500, 'Error while stopping VM: ' + str raise exceptions.HTTPError(500, 'Error while stopping VM: ' +
(error)) str(error))
def restart_vm(uid, method, context): 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 from nova.flags import FLAGS
class OCCIRegistry(occi_registry.NonePersistentRegistry): class OCCIRegistry(occi_registry.NonePersistentRegistry):
""" """
Registry for OpenStack. Registry for OpenStack.
@@ -51,9 +52,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
super(OCCIRegistry, self).__init__() super(OCCIRegistry, self).__init__()
self.cache = {} self.cache = {}
self.adm_net = core_model.Resource('/network/admin', self.adm_net = core_model.Resource('/network/admin',
infrastructure.NETWORK, [infrastructure.IPNETWORK]) infrastructure.NETWORK,
[infrastructure.IPNETWORK])
self.pub_net = core_model.Resource('/network/public', self.pub_net = core_model.Resource('/network/public',
infrastructure.NETWORK, [infrastructure.IPNETWORK]) infrastructure.NETWORK,
[infrastructure.IPNETWORK])
self._setup_network() self._setup_network()
@@ -81,7 +84,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
backend is called. backend is called.
""" """
if (hasattr(mixin, 'related') and if (hasattr(mixin, 'related') and
os_addon.SEC_GROUP in mixin.related): os_addon.SEC_GROUP in mixin.related):
backend = self.get_backend(mixin, extras) backend = self.get_backend(mixin, extras)
backend.destroy(mixin, extras) backend.destroy(mixin, extras)
@@ -92,7 +95,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
Assigns user id and tenant id to user defined mixins Assigns user id and tenant id to user defined mixins
""" """
if (hasattr(category, 'related') and if (hasattr(category, 'related') and
os_addon.SEC_GROUP in category.related): os_addon.SEC_GROUP in category.related):
backend = openstack.SecurityGroupBackend() backend = openstack.SecurityGroupBackend()
backend.init_sec_group(category, extras) backend.init_sec_group(category, extras)
@@ -105,11 +108,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
Just here to prevent the super class from filling up an unused dict. Just here to prevent the super class from filling up an unused dict.
""" """
if (key, extras['nova_ctx'].user_id) not in self.cache and \ if (key, extras['nova_ctx'].user_id) not in self.cache and \
core_model.Link.kind in resource.kind.related: core_model.Link.kind in resource.kind.related:
# don't need to cache twice, only adding links :-) # don't need to cache twice, only adding links :-)
self.cache[(key, extras['nova_ctx'].user_id)] = resource self.cache[(key, extras['nova_ctx'].user_id)] = resource
elif (key, extras['nova_ctx'].user_id) not in self.cache and \ elif (key, extras['nova_ctx'].user_id) not in self.cache and \
resource.kind == os_addon.SEC_RULE: resource.kind == os_addon.SEC_RULE:
# don't need to cache twice, only adding links :-) # don't need to cache twice, only adding links :-)
self.cache[(key, extras['nova_ctx'].user_id)] = resource self.cache[(key, extras['nova_ctx'].user_id)] = resource
@@ -141,7 +144,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
# I have already seen it # I have already seen it
cached_item = self.cache[(key, context.user_id)] cached_item = self.cache[(key, context.user_id)]
if not iden in vm_res_ids and cached_item.kind == \ if not iden in vm_res_ids and cached_item.kind == \
infrastructure.COMPUTE: infrastructure.COMPUTE:
# it was delete in OS -> remove links, cache + KeyError! # it was delete in OS -> remove links, cache + KeyError!
# can delete it because it was my item! # can delete it because it was my item!
for link in cached_item.links: for link in cached_item.links:
@@ -149,7 +152,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
self.cache.pop((key, repr(extras))) self.cache.pop((key, repr(extras)))
raise KeyError raise KeyError
if not iden in stor_res_ids and cached_item.kind == \ if not iden in stor_res_ids and cached_item.kind == \
infrastructure.STORAGE: infrastructure.STORAGE:
# it was delete in OS -> remove from cache + KeyError! # it was delete in OS -> remove from cache + KeyError!
# can delete it because it was my item! # can delete it because it was my item!
self.cache.pop((key, repr(extras))) self.cache.pop((key, repr(extras)))
@@ -215,8 +218,8 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
stor_res_ids = [item['id'] for item in stors] stor_res_ids = [item['id'] for item in stors]
for item in self.cache.values(): for item in self.cache.values():
if item.extras is not None and item.extras['user_id'] != context\ if item.extras is not None and item.extras['user_id'] != \
.user_id: context.user_id:
# filter out items not belonging to this user! # filter out items not belonging to this user!
continue continue
item_id = item.identifier[item.identifier.rfind('/') + 1:] item_id = item.identifier[item.identifier.rfind('/') + 1:]
@@ -224,31 +227,31 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
# add to result set # add to result set
result.append(item) result.append(item)
elif item_id in vm_res_ids and item.kind == \ elif item_id in vm_res_ids and item.kind == \
infrastructure.COMPUTE: infrastructure.COMPUTE:
# check & update (take links, mixins from cache) # check & update (take links, mixins from cache)
# add compute and it's links to result # add compute and it's links to result
self._update_occi_compute(item, extras) self._update_occi_compute(item, extras)
result.append(item) result.append(item)
result.extend(item.links) result.extend(item.links)
elif item_id in stor_res_ids and item.kind == \ elif item_id in stor_res_ids and item.kind == \
infrastructure.STORAGE: infrastructure.STORAGE:
# check & update (take links, mixins from cache) # check & update (take links, mixins from cache)
# add compute and it's links to result # add compute and it's links to result
self._update_occi_storage(item, extras) self._update_occi_storage(item, extras)
result.append(item) result.append(item)
elif item_id not in vm_res_ids and item.kind == \ elif item_id not in vm_res_ids and item.kind == \
infrastructure.COMPUTE: infrastructure.COMPUTE:
# remove item and it's links from cache! # remove item and it's links from cache!
for link in item.links: for link in item.links:
self.cache.pop((link.identifier, item.extras['user_id'])) self.cache.pop((link.identifier, item.extras['user_id']))
self.cache.pop((item.identifier, item.extras['user_id'])) self.cache.pop((item.identifier, item.extras['user_id']))
elif item_id not in stor_res_ids and item.kind == \ elif item_id not in stor_res_ids and item.kind == \
infrastructure.STORAGE: infrastructure.STORAGE:
# remove item # remove item
self.cache.pop((item.identifier, item.extras['user_id'])) self.cache.pop((item.identifier, item.extras['user_id']))
for item in vms: for item in vms:
if (infrastructure.COMPUTE.location + item['uuid'], if (infrastructure.COMPUTE.location + item['uuid'],
context.user_id) in self.cache: context.user_id) in self.cache:
continue continue
else: else:
# construct (with links and mixins and add to cache! # construct (with links and mixins and add to cache!
@@ -257,7 +260,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
result.extend(ent_list) result.extend(ent_list)
for item in stors: for item in stors:
if (infrastructure.STORAGE.location + item['id'], if (infrastructure.STORAGE.location + item['id'],
context.user_id) in self.cache: context.user_id) in self.cache:
continue continue
else: else:
# construct (with links and mixins and add to cache! # construct (with links and mixins and add to cache!
@@ -293,7 +296,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
# 1. get identifier # 1. get identifier
iden = infrastructure.COMPUTE.location + identifier iden = infrastructure.COMPUTE.location + identifier
entity = core_model.Resource(iden, infrastructure.COMPUTE, entity = core_model.Resource(iden, infrastructure.COMPUTE,
[os_addon.OS_VM]) [os_addon.OS_VM])
result.append(entity) result.append(entity)
# 2. os and res templates # 2. os and res templates
@@ -312,11 +315,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
net_links = net.get_network_details(identifier, context) net_links = net.get_network_details(identifier, context)
for item in net_links['public']: for item in net_links['public']:
link = self._construct_network_link(item, entity, self.pub_net, link = self._construct_network_link(item, entity, self.pub_net,
extras) extras)
result.append(link) result.append(link)
for item in net_links['admin']: for item in net_links['admin']:
link = self._construct_network_link(item, entity, self.adm_net, link = self._construct_network_link(item, entity, self.adm_net,
extras) extras)
result.append(link) result.append(link)
# core.id and cache it! # core.id and cache it!
@@ -355,7 +358,8 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
str(stor['instance_uuid']), extras) str(stor['instance_uuid']), extras)
link = core_model.Link(infrastructure.STORAGELINK.location + link = core_model.Link(infrastructure.STORAGELINK.location +
str(uuid.uuid4()), str(uuid.uuid4()),
infrastructure.STORAGELINK, [], source, entity) infrastructure.STORAGELINK, [], source,
entity)
link.extras = self.get_extras(extras) link.extras = self.get_extras(extras)
source.links.append(link) source.links.append(link)
result.append(link) result.append(link)
@@ -382,7 +386,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
'occi.networkinterface.gateway': '192.168' 'occi.networkinterface.gateway': '192.168'
'.0.1', '.0.1',
'occi.networkinterface.allocation': 'occi.networkinterface.allocation':
'static'} 'static'}
self.adm_net.attributes = {'occi.network.vlan': 'admin', self.adm_net.attributes = {'occi.network.vlan': 'admin',
'occi.network.label': 'default', 'occi.network.label': 'default',
'occi.network.state': 'active', 'occi.network.state': 'active',
@@ -391,7 +395,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
'occi.networkinterface.gateway': '10.0.0' 'occi.networkinterface.gateway': '10.0.0'
'.1', '.1',
'occi.networkinterface.allocation': 'occi.networkinterface.allocation':
'static'} 'static'}
self.cache[(self.adm_net.identifier, None)] = self.adm_net self.cache[(self.adm_net.identifier, None)] = self.adm_net
self.cache[(self.pub_net.identifier, None)] = self.pub_net self.cache[(self.pub_net.identifier, None)] = self.pub_net
@@ -401,8 +405,9 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
""" """
link = core_model.Link(infrastructure.NETWORKINTERFACE.location + link = core_model.Link(infrastructure.NETWORKINTERFACE.location +
str(uuid.uuid4()), str(uuid.uuid4()),
infrastructure.NETWORKINTERFACE, infrastructure.NETWORKINTERFACE,
[infrastructure.IPNETWORKINTERFACE], source, target) [infrastructure.IPNETWORKINTERFACE], source,
target)
link.attributes = { link.attributes = {
'occi.networkinterface.interface': net_desc['interface'], 'occi.networkinterface.interface': net_desc['interface'],
'occi.networkinterface.mac': net_desc['mac'], 'occi.networkinterface.mac': net_desc['mac'],

View File

@@ -51,13 +51,13 @@ LOG = logging.getLogger(__name__)
#Setup options #Setup options
OCCI_OPTS = [ OCCI_OPTS = [
cfg.IntOpt("occiapi_listen_port", cfg.IntOpt("occiapi_listen_port",
default=8787, default=8787,
help="Port OCCI interface will listen on."), help="Port OCCI interface will listen on."),
cfg.StrOpt("occi_custom_location_hostname", cfg.StrOpt("occi_custom_location_hostname",
default=None, default=None,
help="Override OCCI location hostname with custom value") help="Override OCCI location hostname with custom value")
] ]
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
FLAGS.register_opts(OCCI_OPTS) FLAGS.register_opts(OCCI_OPTS)
@@ -105,10 +105,10 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
self.register_backend(infrastructure.UP, network_backend) self.register_backend(infrastructure.UP, network_backend)
self.register_backend(infrastructure.DOWN, network_backend) self.register_backend(infrastructure.DOWN, network_backend)
self.register_backend(infrastructure.NETWORKINTERFACE, self.register_backend(infrastructure.NETWORKINTERFACE,
networkinterface_backend) networkinterface_backend)
self.register_backend(infrastructure.IPNETWORK, ipnetwork_backend) self.register_backend(infrastructure.IPNETWORK, ipnetwork_backend)
self.register_backend(infrastructure.IPNETWORKINTERFACE, self.register_backend(infrastructure.IPNETWORKINTERFACE,
ipnetworking_backend) ipnetworking_backend)
self.register_backend(infrastructure.STORAGE, storage_backend) self.register_backend(infrastructure.STORAGE, storage_backend)
self.register_backend(infrastructure.ONLINE, storage_backend) self.register_backend(infrastructure.ONLINE, storage_backend)
@@ -120,19 +120,19 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
# add extensions for occi. # add extensions for occi.
self.register_backend(os_addon.SEC_GROUP, self.register_backend(os_addon.SEC_GROUP,
openstack.SecurityGroupBackend()) openstack.SecurityGroupBackend())
self.register_backend(os_addon.SEC_RULE, self.register_backend(os_addon.SEC_RULE,
openstack.SecurityRuleBackend()) openstack.SecurityRuleBackend())
self.register_backend(os_addon.OS_VM, self.register_backend(os_addon.OS_VM,
openstack.OsComputeBackend()) openstack.OsComputeBackend())
self.register_backend(os_addon.OS_CREATE_IMAGE, self.register_backend(os_addon.OS_CREATE_IMAGE,
openstack.OsComputeBackend()) openstack.OsComputeBackend())
self.register_backend(os_addon.OS_KEY_PAIR_EXT, self.register_backend(os_addon.OS_KEY_PAIR_EXT,
openstack.OsComputeBackend()) openstack.OsComputeBackend())
self.register_backend(os_addon.OS_CHG_PWD, self.register_backend(os_addon.OS_CHG_PWD,
openstack.OsComputeBackend()) openstack.OsComputeBackend())
self.register_backend(os_addon.OS_NET_LINK, self.register_backend(os_addon.OS_NET_LINK,
openstack.OsNetLinkBackend()) openstack.OsNetLinkBackend())
def __call__(self, environ, response): def __call__(self, environ, response):
""" """
@@ -156,7 +156,7 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
self._refresh_security_mixins(extras) self._refresh_security_mixins(extras)
return self._call_occi(environ, response, nova_ctx=extras['nova_ctx'], return self._call_occi(environ, response, nova_ctx=extras['nova_ctx'],
registry=self.registry) registry=self.registry)
def _refresh_os_mixins(self, extras): def _refresh_os_mixins(self, extras):
""" """
@@ -177,15 +177,15 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
LOG.debug(msg) LOG.debug(msg)
continue continue
ctg_term = occify_terms(img['name']) ctg_term = occify_terms(img['name'])
os_template = os_mixins.OsTemplate( os_template = os_mixins.OsTemplate(term=ctg_term,
term=ctg_term, scheme=template_schema,
scheme=template_schema, os_id=img['id'],
os_id=img['id'], related=[infrastructure.
related=[infrastructure.OS_TEMPLATE], OS_TEMPLATE],
attributes=None, attributes=None,
title='This is an OS ' + img['name'] + \ title='This is an OS ' +
' VM image', img['name'] + ' VM image',
location='/' + ctg_term + '/') location='/' + ctg_term + '/')
try: try:
self.registry.get_backend(os_template, extras) self.registry.get_backend(os_template, extras)
@@ -230,30 +230,32 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
excld_grps = [] excld_grps = []
for cat in self.registry.get_categories(extras): for cat in self.registry.get_categories(extras):
if (isinstance(cat, core_model.Mixin) and if (isinstance(cat, core_model.Mixin) and
os_addon.SEC_GROUP in cat.related): os_addon.SEC_GROUP in cat.related):
excld_grps.append(cat.term) excld_grps.append(cat.term)
groups = db.security_group_get_by_project(extras['nova_ctx'], 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#' sec_grp = 'http://schemas.openstack.org/infrastructure/security/group#'
for group in groups: for group in groups:
if group['name'] not in excld_grps: if group['name'] not in excld_grps:
sec_mix = os_mixins.UserSecurityGroupMixin( sec_mix = os_mixins.UserSecurityGroupMixin(
term=str(group["id"]), # NOTE(aloga): group.id is a long term=str(group["id"]),
scheme=sec_grp, scheme=sec_grp,
related=[os_addon.SEC_GROUP], related=[os_addon.SEC_GROUP],
attributes=None, attributes=None,
title=group['name'], title=group['name'],
location='/security/' + quote(str(group['id'])) + '/') location='/security/' + quote(str(group['name'])) + '/')
try: try:
self.registry.get_backend(sec_mix, extras) self.registry.get_backend(sec_mix, extras)
except AttributeError: except AttributeError:
self.register_backend(sec_mix, MIXIN_BACKEND) self.register_backend(sec_mix, MIXIN_BACKEND)
def occify_terms(term_name): def occify_terms(term_name):
''' '''
Occifies a term_name so that it is compliant with GFD 185. Occifies a term_name so that it is compliant with GFD 185.
''' '''
term = term_name.strip().replace(' ', '_').replace('.','-').lower() term = term_name.strip().replace(' ', '_').replace('.', '-').lower()
return term return term

View File

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

View File

@@ -68,15 +68,15 @@ class TestComputeBackend(unittest.TestCase):
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, []) res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, [])
self.assertRaises(AttributeError, self.backend.create, res, self.assertRaises(AttributeError, self.backend.create, res,
self.sec_obj) self.sec_obj)
# provide immutable attr # provide immutable attr
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template]) [self.os_template])
res.attributes = {'occi.compute.cores': 2} res.attributes = {'occi.compute.cores': 2}
self.assertRaises(AttributeError, self.backend.create, res, self.assertRaises(AttributeError, self.backend.create, res,
self.sec_obj) self.sec_obj)
def test_update_for_failure(self): def test_update_for_failure(self):
""" """
@@ -88,13 +88,14 @@ class TestComputeBackend(unittest.TestCase):
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, []) res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, [])
self.assertRaises(AttributeError, self.backend.update, res1, res2, self.assertRaises(AttributeError, self.backend.update, res1, res2,
self.sec_obj) self.sec_obj)
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, 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.assertRaises(AttributeError, self.backend.update, res1, res2,
self.sec_obj) self.sec_obj)
def test_action_for_failure(self): def test_action_for_failure(self):
""" """
@@ -110,7 +111,7 @@ class TestComputeBackend(unittest.TestCase):
}) })
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertRaises(AttributeError, self.backend.action, res1, self.assertRaises(AttributeError, self.backend.action, res1,
infrastructure.STOP, {}, self.sec_obj) infrastructure.STOP, {}, self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
# missing method! # missing method!
@@ -122,7 +123,7 @@ class TestComputeBackend(unittest.TestCase):
}) })
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertRaises(AttributeError, self.backend.action, res1, self.assertRaises(AttributeError, self.backend.action, res1,
infrastructure.RESTART, {}, self.sec_obj) infrastructure.RESTART, {}, self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
# Test for Sanity # Test for Sanity
@@ -132,7 +133,7 @@ class TestComputeBackend(unittest.TestCase):
Simulate a create call! Simulate a create call!
""" """
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template]) [self.os_template])
self.mox.StubOutWithMock(nova_glue.vm, 'create_vm') self.mox.StubOutWithMock(nova_glue.vm, 'create_vm')
nova_glue.vm.create_vm(mox.IsA(object), mox.IsA(object)).AndReturn( nova_glue.vm.create_vm(mox.IsA(object), mox.IsA(object)).AndReturn(
@@ -144,8 +145,8 @@ class TestComputeBackend(unittest.TestCase):
}) })
self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture') self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture')
nova_glue.storage.get_image_architecture(mox.IsA(object), nova_glue.storage.get_image_architecture(mox.IsA(object),
mox.IsA(object)).AndReturn( mox.IsA(object)).\
'foo') AndReturn('foo')
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -171,14 +172,15 @@ class TestComputeBackend(unittest.TestCase):
Simulate a retrieve call! Simulate a retrieve call!
""" """
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template]) [self.os_template])
res.attributes = {'occi.core.id': 'bar'} res.attributes = {'occi.core.id': 'bar'}
self.mox.StubOutWithMock(nova_glue.vm, 'get_occi_state') self.mox.StubOutWithMock(nova_glue.vm, 'get_occi_state')
nova_glue.vm.get_occi_state(mox.IsA(object), nova_glue.vm.get_occi_state(mox.IsA(object),
mox.IsA(object)).AndReturn(('active', [infrastructure.STOP, mox.IsA(object)).\
infrastructure.SUSPEND, AndReturn(('active', [infrastructure.STOP,
infrastructure.RESTART])) infrastructure.SUSPEND,
infrastructure.RESTART]))
self.mox.StubOutWithMock(nova_glue.vm, 'get_vm') self.mox.StubOutWithMock(nova_glue.vm, 'get_vm')
nova_glue.vm.get_vm(mox.IsA(object), mox.IsA(object)).AndReturn( nova_glue.vm.get_vm(mox.IsA(object), mox.IsA(object)).AndReturn(
{ {
@@ -188,8 +190,8 @@ class TestComputeBackend(unittest.TestCase):
}) })
self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture') self.mox.StubOutWithMock(nova_glue.storage, 'get_image_architecture')
nova_glue.storage.get_image_architecture(mox.IsA(object), nova_glue.storage.get_image_architecture(mox.IsA(object),
mox.IsA(object)).AndReturn( mox.IsA(object)).\
'foo') AndReturn('foo')
self.mox.ReplayAll() self.mox.ReplayAll()
self.backend.retrieve(res, self.sec_obj) self.backend.retrieve(res, self.sec_obj)
@@ -216,16 +218,16 @@ class TestComputeBackend(unittest.TestCase):
Simulate a update call! Simulate a update call!
""" """
res1 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res1 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template]) [self.os_template])
res1.attributes = {'occi.core.id': 'bar'} res1.attributes = {'occi.core.id': 'bar'}
# case 1 - rebuild VM with different OS # case 1 - rebuild VM with different OS
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template2]) [self.os_template2])
self.mox.StubOutWithMock(nova_glue.vm, 'rebuild_vm') self.mox.StubOutWithMock(nova_glue.vm, 'rebuild_vm')
nova_glue.vm.rebuild_vm(mox.IsA(object), mox.IsA(object), nova_glue.vm.rebuild_vm(mox.IsA(object), mox.IsA(object),
mox.IsA(object)) mox.IsA(object))
self.mox.ReplayAll() self.mox.ReplayAll()
self.backend.update(res1, res2, self.sec_obj) self.backend.update(res1, res2, self.sec_obj)
@@ -235,11 +237,11 @@ class TestComputeBackend(unittest.TestCase):
# case 2 - resize the VM # case 2 - resize the VM
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.res_template2]) [self.res_template2])
self.mox.StubOutWithMock(nova_glue.vm, 'resize_vm') self.mox.StubOutWithMock(nova_glue.vm, 'resize_vm')
nova_glue.vm.resize_vm(mox.IsA(object), mox.IsA(object), nova_glue.vm.resize_vm(mox.IsA(object), mox.IsA(object),
mox.IsA(object)) mox.IsA(object))
self.mox.ReplayAll() self.mox.ReplayAll()
self.backend.update(res1, res2, self.sec_obj) self.backend.update(res1, res2, self.sec_obj)
@@ -258,7 +260,7 @@ class TestComputeBackend(unittest.TestCase):
Simulate a delete call. Simulate a delete call.
""" """
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
[self.os_template]) [self.os_template])
res.attributes = {'occi.core.id': 'bar'} res.attributes = {'occi.core.id': 'bar'}
self.mox.StubOutWithMock(nova_glue.vm, 'delete_vm') self.mox.StubOutWithMock(nova_glue.vm, 'delete_vm')
@@ -304,7 +306,7 @@ class TestComputeBackend(unittest.TestCase):
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.StubOutWithMock(nova_glue.vm, 'restart_vm') self.mox.StubOutWithMock(nova_glue.vm, 'restart_vm')
nova_glue.vm.restart_vm(mox.IsA(object), mox.IsA(str), nova_glue.vm.restart_vm(mox.IsA(object), mox.IsA(str),
mox.IsA(object)) mox.IsA(object))
self.mox.StubOutWithMock(nova_glue.vm, 'get_vm') self.mox.StubOutWithMock(nova_glue.vm, 'get_vm')
nova_glue.vm.get_vm(mox.IsA(object), mox.IsA(object)).AndReturn( nova_glue.vm.get_vm(mox.IsA(object), mox.IsA(object)).AndReturn(
{ {
@@ -312,8 +314,7 @@ class TestComputeBackend(unittest.TestCase):
}) })
self.mox.ReplayAll() self.mox.ReplayAll()
self.backend.action(res1, infrastructure.RESTART, self.backend.action(res1, infrastructure.RESTART,
{'method': 'graceful'}, {'method': 'graceful'}, self.sec_obj)
self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
# suspend # suspend

View File

@@ -66,17 +66,18 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertRaises(AttributeError, self.backend.create, link, self.assertRaises(AttributeError, self.backend.create, link,
self.sec_obj) self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
# should have pool name in attribute... # should have pool name in attribute...
target.identifier = '/network/public' 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.mox.ReplayAll()
self.assertRaises(AttributeError, self.backend.create, link, self.assertRaises(AttributeError, self.backend.create, link,
self.sec_obj) self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
@@ -85,7 +86,7 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
No updates allowed! No updates allowed!
""" """
self.assertRaises(AttributeError, self.backend.update, None, None, self.assertRaises(AttributeError, self.backend.update, None, None,
None) None)
# Test for sanity! # Test for sanity!
@@ -100,10 +101,10 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
link = core_model.Link('foo', None, [os_addon.OS_NET_LINK], source, link = core_model.Link('foo', None, [os_addon.OS_NET_LINK], source,
target) target)
link.attributes = {'org.openstack.network.floating.pool':'nova'} link.attributes = {'org.openstack.network.floating.pool': 'nova'}
self.mox.StubOutWithMock(nova_glue.net, 'add_floating_ip') 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') mox.IsA(object)).AndReturn('10.0.0.1')
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -120,16 +121,18 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
# self.assertIn(infrastructure.IPNETWORKINTERFACE, link.mixins) # self.assertIn(infrastructure.IPNETWORKINTERFACE, link.mixins)
# self.assertIn(infrastructure.NETWORKINTERFACE, link.mixins) # self.assertIn(infrastructure.NETWORKINTERFACE, link.mixins)
self.mox.VerifyAll()
# test without pool name... # test without pool name...
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.StubOutWithMock(nova_glue.net, 'add_floating_ip')
link = core_model.Link('foo', None, [], source, target) 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.backend.create(link, self.sec_obj)
self.mox.VerifyAll()
def test_delete_for_sanity(self): def test_delete_for_sanity(self):
""" """
@@ -145,7 +148,7 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.net, 'remove_floating_ip') self.mox.StubOutWithMock(nova_glue.net, 'remove_floating_ip')
nova_glue.net.remove_floating_ip(mox.IsA(object), mox.IsA(object), nova_glue.net.remove_floating_ip(mox.IsA(object), mox.IsA(object),
mox.IsA(object)) mox.IsA(object))
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -176,7 +179,7 @@ class TestNetworkBackend(unittest.TestCase):
Expecting an error! Expecting an error!
""" """
self.assertRaises(AttributeError, self.backend.action, None, self.assertRaises(AttributeError, self.backend.action, None,
None, None, None) None, None, None)
class TestIpNetworkBackend(unittest.TestCase): class TestIpNetworkBackend(unittest.TestCase):

View File

@@ -62,22 +62,24 @@ class TestStorageBackend(unittest.TestCase):
res = mox.MockObject(core_model.Resource) res = mox.MockObject(core_model.Resource)
res.attributes = {} res.attributes = {}
self.assertRaises(AttributeError, self.backend.create, res, self.assertRaises(AttributeError, self.backend.create, res,
self.sec_obj) self.sec_obj)
# error in volume creation # error in volume creation
res.attributes = {'occi.storage.size': '1'} res.attributes = {'occi.storage.size': '1'}
self.mox.StubOutWithMock(nova_glue.storage, 'create_storage') self.mox.StubOutWithMock(nova_glue.storage, 'create_storage')
nova_glue.storage.create_storage(mox.IsA(object), 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') self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object), nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'error'}) mox.IsA(object)).\
AndReturn({'status': 'error'})
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertRaises(exceptions.HTTPError, self.backend.create, res, self.assertRaises(exceptions.HTTPError, self.backend.create, res,
self.sec_obj) self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
@@ -90,7 +92,7 @@ class TestStorageBackend(unittest.TestCase):
# snapshot # snapshot
self.assertRaises(AttributeError, self.backend.action, res, self.assertRaises(AttributeError, self.backend.action, res,
infrastructure.SNAPSHOT, {}, self.sec_obj) infrastructure.SNAPSHOT, {}, self.sec_obj)
# Test for sanity # Test for sanity
@@ -103,10 +105,12 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'create_storage') self.mox.StubOutWithMock(nova_glue.storage, 'create_storage')
nova_glue.storage.create_storage(mox.IsA(object), 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') self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object), nova_glue.storage.get_storage(mox.IsA(object),
mox.IsA(object)).AndReturn({'status': 'available'}) mox.IsA(object)).\
AndReturn({'status': 'available'})
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -129,7 +133,8 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage') self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object), 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() self.mox.ReplayAll()
@@ -139,14 +144,15 @@ class TestStorageBackend(unittest.TestCase):
self.assertEqual(res.attributes['occi.storage.state'], 'online') self.assertEqual(res.attributes['occi.storage.state'], 'online')
self.assertListEqual([infrastructure.OFFLINE, infrastructure.BACKUP, self.assertListEqual([infrastructure.OFFLINE, infrastructure.BACKUP,
infrastructure.SNAPSHOT, infrastructure.RESIZE], infrastructure.SNAPSHOT, infrastructure.RESIZE],
res.actions) res.actions)
self.mox.VerifyAll() self.mox.VerifyAll()
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.StubOutWithMock(nova_glue.storage, 'get_storage') self.mox.StubOutWithMock(nova_glue.storage, 'get_storage')
nova_glue.storage.get_storage(mox.IsA(object), 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() self.mox.ReplayAll()
@@ -164,8 +170,8 @@ class TestStorageBackend(unittest.TestCase):
res1 = mox.MockObject(core_model.Resource) res1 = mox.MockObject(core_model.Resource)
res1.attributes = {} res1.attributes = {}
res2 = mox.MockObject(core_model.Resource) res2 = mox.MockObject(core_model.Resource)
res2.attributes = {'occi.core.title': 'foo', 'occi.core.summary': res2.attributes = {'occi.core.title': 'foo',
'bar'} 'occi.core.summary': 'bar'}
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -186,7 +192,7 @@ class TestStorageBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.storage, 'delete_storage_instance') self.mox.StubOutWithMock(nova_glue.storage, 'delete_storage_instance')
nova_glue.storage.delete_storage_instance(mox.IsA(object), nova_glue.storage.delete_storage_instance(mox.IsA(object),
mox.IsA(object)) mox.IsA(object))
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -205,9 +211,11 @@ class TestStorageBackend(unittest.TestCase):
# snapshot # snapshot
self.mox.StubOutWithMock(nova_glue.storage, self.mox.StubOutWithMock(nova_glue.storage,
'snapshot_storage_instance') 'snapshot_storage_instance')
nova_glue.storage.snapshot_storage_instance(mox.IsA(object), 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.mox.ReplayAll()
self.backend.action(res, infrastructure.SNAPSHOT, {}, self.sec_obj) self.backend.action(res, infrastructure.SNAPSHOT, {}, self.sec_obj)
self.mox.VerifyAll() self.mox.VerifyAll()
@@ -253,7 +261,8 @@ class TestStorageLinkBackend(unittest.TestCase):
self.mox.StubOutWithMock(nova_glue.vm, 'attach_volume') self.mox.StubOutWithMock(nova_glue.vm, 'attach_volume')
nova_glue.vm.attach_volume(mox.IsA(object), mox.IsA(object), 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() self.mox.ReplayAll()
@@ -261,7 +270,7 @@ class TestStorageLinkBackend(unittest.TestCase):
# verify all attrs. # verify all attrs.
self.assertEqual(link.attributes['occi.storagelink.deviceid'], self.assertEqual(link.attributes['occi.storagelink.deviceid'],
'/dev/sda') '/dev/sda')
self.assertIn('occi.storagelink.mountpoint', link.attributes) self.assertIn('occi.storagelink.mountpoint', link.attributes)
self.assertEqual(link.attributes['occi.storagelink.state'], 'active') self.assertEqual(link.attributes['occi.storagelink.state'], 'active')