pep8 compliance cleanup.
This commit is contained in:
parent
eaa0bb5e70
commit
1fe13f62bc
@ -72,8 +72,8 @@ class ComputeBackend(KindBackend, ActionBackend):
|
||||
|
||||
# set valid actions
|
||||
entity.actions = [infrastructure.STOP,
|
||||
infrastructure.SUSPEND,
|
||||
infrastructure.RESTART]
|
||||
infrastructure.SUSPEND,
|
||||
infrastructure.RESTART]
|
||||
|
||||
# Tell the world that is is an VM in OpenStack...
|
||||
entity.mixins.append(os_addon.OS_VM)
|
||||
@ -96,7 +96,7 @@ class ComputeBackend(KindBackend, ActionBackend):
|
||||
# set up to date attributes
|
||||
entity.attributes['occi.compute.hostname'] = instance['hostname']
|
||||
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.speed'] = str(0.0) # N/A in instance
|
||||
value = str(float(instance['memory_mb']) / 1024)
|
||||
|
@ -81,16 +81,18 @@ 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'],
|
||||
pool,
|
||||
extras['nova_ctx'])
|
||||
address = net.add_floating_ip(link.source.attributes['occi.'
|
||||
'core.id'],
|
||||
pool,
|
||||
extras['nova_ctx'])
|
||||
link.attributes['occi.networkinterface.interface'] = 'eth0'
|
||||
link.attributes['occi.networkinterface.mac'] = 'aa:bb:cc:dd:ee:ff'
|
||||
link.attributes['occi.networkinterface.state'] = 'active'
|
||||
@ -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'],
|
||||
extras['nova_ctx'])
|
||||
link.attributes['occi.networkinterface.'
|
||||
'address'],
|
||||
extras['nova_ctx'])
|
||||
|
@ -44,7 +44,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
|
||||
|
||||
# set additional actions
|
||||
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_CHG_PWD)
|
||||
|
||||
@ -52,7 +52,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
|
||||
console = vm.get_vnc(uid, context)
|
||||
if console:
|
||||
entity.attributes['org.openstack.compute.console.vnc'] =\
|
||||
console['url']
|
||||
console['url']
|
||||
else:
|
||||
entity.attributes['org.openstack.compute.console.vnc'] = 'N/A'
|
||||
|
||||
@ -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']
|
||||
@ -158,7 +157,7 @@ class SecurityRuleBackend(backend.KindBackend):
|
||||
try:
|
||||
context = extras['nova_ctx']
|
||||
rule = security.retrieve_rule(entity.attributes['occi.core.id'],
|
||||
context)
|
||||
context)
|
||||
|
||||
security.remove_rule(rule, context)
|
||||
except Exception as error:
|
||||
@ -174,7 +173,7 @@ def make_sec_rule(entity, sec_grp_id):
|
||||
'parent_group_id': sec_grp_id}
|
||||
entity.attributes['occi.core.id'] = str(sg_rule['id'])
|
||||
prot = \
|
||||
entity.attributes['occi.network.security.protocol'].lower().strip()
|
||||
entity.attributes['occi.network.security.protocol'].lower().strip()
|
||||
if prot in ('tcp', 'udp', 'icmp'):
|
||||
sg_rule['protocol'] = prot
|
||||
else:
|
||||
|
@ -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...
|
||||
@ -66,7 +67,7 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
|
||||
entity.attributes['occi.storage.state'] = 'active'
|
||||
|
||||
entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
|
||||
infrastructure.SNAPSHOT, infrastructure.RESIZE]
|
||||
infrastructure.SNAPSHOT, infrastructure.RESIZE]
|
||||
|
||||
def retrieve(self, entity, extras):
|
||||
"""
|
||||
@ -98,13 +99,13 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
|
||||
if len(new.attributes) > 0:
|
||||
# support only title and summary changes now.
|
||||
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'] = \
|
||||
new.attributes['occi.core.title']
|
||||
if 'occi.core.title' in new.attributes and\
|
||||
new.attributes['occi.core.title']
|
||||
if 'occi.core.title' in new.attributes and \
|
||||
len(new.attributes['occi.core.summary']) > 0:
|
||||
old.attributes['occi.core.summary'] = \
|
||||
new.attributes['occi.core.summary']
|
||||
new.attributes['occi.core.summary']
|
||||
|
||||
def delete(self, entity, extras):
|
||||
"""
|
||||
@ -122,7 +123,7 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
|
||||
if action not in entity.actions:
|
||||
raise AttributeError("This action is currently no applicable.")
|
||||
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 '
|
||||
'currently not supported!')
|
||||
elif action == infrastructure.SNAPSHOT:
|
||||
@ -155,7 +156,7 @@ class StorageLinkBackend(backend.KindBackend):
|
||||
|
||||
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.mountpoint'] = ''
|
||||
link.attributes['occi.storagelink.state'] = 'active'
|
||||
|
||||
|
@ -30,7 +30,7 @@ _SEC_RULE_ATTRIBUTES = {
|
||||
'occi.network.security.to': '',
|
||||
'occi.network.security.from': '',
|
||||
'occi.network.security.range': '',
|
||||
}
|
||||
}
|
||||
SEC_RULE = core_model.Kind(
|
||||
'http://schemas.openstack.org/occi/infrastructure/network/security#',
|
||||
'rule',
|
||||
@ -48,16 +48,16 @@ SEC_GROUP = core_model.Mixin(
|
||||
# OS change adminstrative password action
|
||||
_OS_CHG_PWD_ATTRIBUTES = {'org.openstack.credentials.admin_pwd': '', }
|
||||
OS_CHG_PWD = core_model.Action(
|
||||
'http://schemas.openstack.org/instance/action#',
|
||||
'chg_pwd', 'Changes Admin password.',
|
||||
_OS_CHG_PWD_ATTRIBUTES)
|
||||
'http://schemas.openstack.org/instance/action#',
|
||||
'chg_pwd', 'Changes Admin password.',
|
||||
_OS_CHG_PWD_ATTRIBUTES)
|
||||
|
||||
# OS create image from VM action
|
||||
_OS_CREATE_IMAGE_ATTRIBUTES = {'org.openstack.snapshot.image_name': '', }
|
||||
OS_CREATE_IMAGE = core_model.Action(
|
||||
'http://schemas.openstack.org/instance/action#',
|
||||
'create_image', 'Creates a new image for the given server.',
|
||||
_OS_CREATE_IMAGE_ATTRIBUTES)
|
||||
'http://schemas.openstack.org/instance/action#',
|
||||
'create_image', 'Creates a new image for the given server.',
|
||||
_OS_CREATE_IMAGE_ATTRIBUTES)
|
||||
|
||||
# A Mixin for OpenStack VMs
|
||||
_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_ATTRIBUTES = {'org.openstack.credentials.publickey.name': '',
|
||||
'org.openstack.credentials.publickey.data': '', }
|
||||
'org.openstack.credentials.publickey.data': '', }
|
||||
OS_KEY_PAIR_EXT = core_model.Mixin(
|
||||
'http://schemas.openstack.org/instance/credentials#',
|
||||
'public_key', attributes=_OS_KEY_PAIR_ATTRIBUTES)
|
||||
@ -79,4 +79,4 @@ _OS_NET_LINK_ATTRIBUTES = {'org.openstack.network.floating.pool': 'required'}
|
||||
OS_NET_LINK = core_model.Mixin(
|
||||
'http://schemas.openstack.org/network/instance#',
|
||||
'os_net_link', actions=[],
|
||||
attributes=_OS_NET_LINK_ATTRIBUTES)
|
||||
attributes=_OS_NET_LINK_ATTRIBUTES)
|
||||
|
@ -115,7 +115,7 @@ def remove_rule(rule, context):
|
||||
try:
|
||||
db.security_group_rule_destroy(context, rule['id'])
|
||||
SEC_HANDLER.trigger_security_group_rule_destroy_refresh(context,
|
||||
[rule['id']])
|
||||
[rule['id']])
|
||||
except Exception as err:
|
||||
raise AttributeError('Unable to remove rule: ' + str(err))
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
||||
@ -81,7 +84,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
backend is called.
|
||||
"""
|
||||
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.destroy(mixin, extras)
|
||||
|
||||
@ -92,7 +95,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
Assigns user id and tenant id to user defined mixins
|
||||
"""
|
||||
if (hasattr(category, 'related') and
|
||||
os_addon.SEC_GROUP in category.related):
|
||||
os_addon.SEC_GROUP in category.related):
|
||||
backend = openstack.SecurityGroupBackend()
|
||||
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.
|
||||
"""
|
||||
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 :-)
|
||||
self.cache[(key, extras['nova_ctx'].user_id)] = resource
|
||||
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 :-)
|
||||
self.cache[(key, extras['nova_ctx'].user_id)] = resource
|
||||
|
||||
@ -141,7 +144,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
# I have already seen it
|
||||
cached_item = self.cache[(key, context.user_id)]
|
||||
if not iden in vm_res_ids and cached_item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
infrastructure.COMPUTE:
|
||||
# it was delete in OS -> remove links, cache + KeyError!
|
||||
# can delete it because it was my item!
|
||||
for link in cached_item.links:
|
||||
@ -149,7 +152,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
self.cache.pop((key, repr(extras)))
|
||||
raise KeyError
|
||||
if not iden in stor_res_ids and cached_item.kind == \
|
||||
infrastructure.STORAGE:
|
||||
infrastructure.STORAGE:
|
||||
# it was delete in OS -> remove from cache + KeyError!
|
||||
# can delete it because it was my item!
|
||||
self.cache.pop((key, repr(extras)))
|
||||
@ -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:]
|
||||
@ -224,31 +227,31 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
# add to result set
|
||||
result.append(item)
|
||||
elif item_id in vm_res_ids and item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
infrastructure.COMPUTE:
|
||||
# check & update (take links, mixins from cache)
|
||||
# add compute and it's links to result
|
||||
self._update_occi_compute(item, extras)
|
||||
result.append(item)
|
||||
result.extend(item.links)
|
||||
elif item_id in stor_res_ids and item.kind == \
|
||||
infrastructure.STORAGE:
|
||||
infrastructure.STORAGE:
|
||||
# check & update (take links, mixins from cache)
|
||||
# add compute and it's links to result
|
||||
self._update_occi_storage(item, extras)
|
||||
result.append(item)
|
||||
elif item_id not in vm_res_ids and item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
infrastructure.COMPUTE:
|
||||
# remove item and it's links from cache!
|
||||
for link in item.links:
|
||||
self.cache.pop((link.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 == \
|
||||
infrastructure.STORAGE:
|
||||
infrastructure.STORAGE:
|
||||
# remove item
|
||||
self.cache.pop((item.identifier, item.extras['user_id']))
|
||||
for item in vms:
|
||||
if (infrastructure.COMPUTE.location + item['uuid'],
|
||||
context.user_id) in self.cache:
|
||||
context.user_id) in self.cache:
|
||||
continue
|
||||
else:
|
||||
# construct (with links and mixins and add to cache!
|
||||
@ -257,7 +260,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
result.extend(ent_list)
|
||||
for item in stors:
|
||||
if (infrastructure.STORAGE.location + item['id'],
|
||||
context.user_id) in self.cache:
|
||||
context.user_id) in self.cache:
|
||||
continue
|
||||
else:
|
||||
# construct (with links and mixins and add to cache!
|
||||
@ -293,7 +296,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
# 1. get identifier
|
||||
iden = infrastructure.COMPUTE.location + identifier
|
||||
entity = core_model.Resource(iden, infrastructure.COMPUTE,
|
||||
[os_addon.OS_VM])
|
||||
[os_addon.OS_VM])
|
||||
result.append(entity)
|
||||
|
||||
# 2. os and res templates
|
||||
@ -312,11 +315,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
net_links = net.get_network_details(identifier, context)
|
||||
for item in net_links['public']:
|
||||
link = self._construct_network_link(item, entity, self.pub_net,
|
||||
extras)
|
||||
extras)
|
||||
result.append(link)
|
||||
for item in net_links['admin']:
|
||||
link = self._construct_network_link(item, entity, self.adm_net,
|
||||
extras)
|
||||
extras)
|
||||
result.append(link)
|
||||
|
||||
# core.id and cache it!
|
||||
@ -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)
|
||||
@ -382,7 +386,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
'occi.networkinterface.gateway': '192.168'
|
||||
'.0.1',
|
||||
'occi.networkinterface.allocation':
|
||||
'static'}
|
||||
'static'}
|
||||
self.adm_net.attributes = {'occi.network.vlan': 'admin',
|
||||
'occi.network.label': 'default',
|
||||
'occi.network.state': 'active',
|
||||
@ -391,7 +395,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
||||
'occi.networkinterface.gateway': '10.0.0'
|
||||
'.1',
|
||||
'occi.networkinterface.allocation':
|
||||
'static'}
|
||||
'static'}
|
||||
self.cache[(self.adm_net.identifier, None)] = self.adm_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 +
|
||||
str(uuid.uuid4()),
|
||||
infrastructure.NETWORKINTERFACE,
|
||||
[infrastructure.IPNETWORKINTERFACE], source, target)
|
||||
infrastructure.NETWORKINTERFACE,
|
||||
[infrastructure.IPNETWORKINTERFACE], source,
|
||||
target)
|
||||
link.attributes = {
|
||||
'occi.networkinterface.interface': net_desc['interface'],
|
||||
'occi.networkinterface.mac': net_desc['mac'],
|
||||
|
@ -51,13 +51,13 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
#Setup options
|
||||
OCCI_OPTS = [
|
||||
cfg.IntOpt("occiapi_listen_port",
|
||||
default=8787,
|
||||
help="Port OCCI interface will listen on."),
|
||||
cfg.StrOpt("occi_custom_location_hostname",
|
||||
default=None,
|
||||
help="Override OCCI location hostname with custom value")
|
||||
]
|
||||
cfg.IntOpt("occiapi_listen_port",
|
||||
default=8787,
|
||||
help="Port OCCI interface will listen on."),
|
||||
cfg.StrOpt("occi_custom_location_hostname",
|
||||
default=None,
|
||||
help="Override OCCI location hostname with custom value")
|
||||
]
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
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.DOWN, network_backend)
|
||||
self.register_backend(infrastructure.NETWORKINTERFACE,
|
||||
networkinterface_backend)
|
||||
networkinterface_backend)
|
||||
self.register_backend(infrastructure.IPNETWORK, ipnetwork_backend)
|
||||
self.register_backend(infrastructure.IPNETWORKINTERFACE,
|
||||
ipnetworking_backend)
|
||||
ipnetworking_backend)
|
||||
|
||||
self.register_backend(infrastructure.STORAGE, storage_backend)
|
||||
self.register_backend(infrastructure.ONLINE, storage_backend)
|
||||
@ -120,19 +120,19 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
||||
|
||||
# add extensions for occi.
|
||||
self.register_backend(os_addon.SEC_GROUP,
|
||||
openstack.SecurityGroupBackend())
|
||||
openstack.SecurityGroupBackend())
|
||||
self.register_backend(os_addon.SEC_RULE,
|
||||
openstack.SecurityRuleBackend())
|
||||
openstack.SecurityRuleBackend())
|
||||
self.register_backend(os_addon.OS_VM,
|
||||
openstack.OsComputeBackend())
|
||||
openstack.OsComputeBackend())
|
||||
self.register_backend(os_addon.OS_CREATE_IMAGE,
|
||||
openstack.OsComputeBackend())
|
||||
openstack.OsComputeBackend())
|
||||
self.register_backend(os_addon.OS_KEY_PAIR_EXT,
|
||||
openstack.OsComputeBackend())
|
||||
openstack.OsComputeBackend())
|
||||
self.register_backend(os_addon.OS_CHG_PWD,
|
||||
openstack.OsComputeBackend())
|
||||
openstack.OsComputeBackend())
|
||||
self.register_backend(os_addon.OS_NET_LINK,
|
||||
openstack.OsNetLinkBackend())
|
||||
openstack.OsNetLinkBackend())
|
||||
|
||||
def __call__(self, environ, response):
|
||||
"""
|
||||
@ -156,7 +156,7 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
||||
self._refresh_security_mixins(extras)
|
||||
|
||||
return self._call_occi(environ, response, nova_ctx=extras['nova_ctx'],
|
||||
registry=self.registry)
|
||||
registry=self.registry)
|
||||
|
||||
def _refresh_os_mixins(self, extras):
|
||||
"""
|
||||
@ -177,15 +177,15 @@ 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,
|
||||
scheme=template_schema,
|
||||
os_id=img['id'],
|
||||
related=[infrastructure.OS_TEMPLATE],
|
||||
attributes=None,
|
||||
title='This is an OS ' + img['name'] + \
|
||||
' VM image',
|
||||
location='/' + ctg_term + '/')
|
||||
os_template = os_mixins.OsTemplate(term=ctg_term,
|
||||
scheme=template_schema,
|
||||
os_id=img['id'],
|
||||
related=[infrastructure.
|
||||
OS_TEMPLATE],
|
||||
attributes=None,
|
||||
title='This is an OS ' +
|
||||
img['name'] + ' VM image',
|
||||
location='/' + ctg_term + '/')
|
||||
|
||||
try:
|
||||
self.registry.get_backend(os_template, extras)
|
||||
@ -230,30 +230,32 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
||||
excld_grps = []
|
||||
for cat in self.registry.get_categories(extras):
|
||||
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)
|
||||
|
||||
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
|
||||
scheme=sec_grp,
|
||||
related=[os_addon.SEC_GROUP],
|
||||
attributes=None,
|
||||
title=group['name'],
|
||||
location='/security/' + quote(str(group['id'])) + '/')
|
||||
term=str(group["id"]),
|
||||
scheme=sec_grp,
|
||||
related=[os_addon.SEC_GROUP],
|
||||
attributes=None,
|
||||
title=group['name'],
|
||||
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.
|
||||
'''
|
||||
term = term_name.strip().replace(' ', '_').replace('.','-').lower()
|
||||
return term
|
||||
term = term_name.strip().replace(' ', '_').replace('.', '-').lower()
|
||||
return term
|
||||
|
@ -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)
|
||||
@ -248,9 +247,10 @@ class SystemTest(unittest.TestCase):
|
||||
heads = HEADS.copy()
|
||||
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"; ' \
|
||||
'location="/mygroups/"'
|
||||
heads['Category'] = name + '; scheme="http://www.mystuff.org/sec#"; ' \
|
||||
'rel="http://schemas.ogf.org/occi/' \
|
||||
'infrastructure/security#group"; ' \
|
||||
'location="/mygroups/"'
|
||||
do_request('POST', '/-/', heads)
|
||||
|
||||
# create sec rule
|
||||
@ -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):
|
||||
"""
|
||||
@ -331,10 +333,11 @@ class SystemTest(unittest.TestCase):
|
||||
|
||||
# create new VM
|
||||
cats = ['m1-tiny; scheme="http://schemas.openstack'
|
||||
'.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#"']
|
||||
'.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#"']
|
||||
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)
|
||||
|
||||
@ -399,17 +403,18 @@ class SystemTest(unittest.TestCase):
|
||||
"""
|
||||
# create new VM
|
||||
cats = ['itsy; scheme="http://schemas.openstack'
|
||||
'.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#"']
|
||||
'.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#"']
|
||||
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)
|
||||
|
@ -68,15 +68,15 @@ class TestComputeBackend(unittest.TestCase):
|
||||
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE, [])
|
||||
|
||||
self.assertRaises(AttributeError, self.backend.create, res,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
# provide immutable attr
|
||||
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template])
|
||||
[self.os_template])
|
||||
res.attributes = {'occi.compute.cores': 2}
|
||||
|
||||
self.assertRaises(AttributeError, self.backend.create, res,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
def test_update_for_failure(self):
|
||||
"""
|
||||
@ -88,13 +88,14 @@ class TestComputeBackend(unittest.TestCase):
|
||||
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE, [])
|
||||
|
||||
self.assertRaises(AttributeError, self.backend.update, res1, res2,
|
||||
self.sec_obj)
|
||||
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)
|
||||
self.sec_obj)
|
||||
|
||||
def test_action_for_failure(self):
|
||||
"""
|
||||
@ -110,7 +111,7 @@ class TestComputeBackend(unittest.TestCase):
|
||||
})
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(AttributeError, self.backend.action, res1,
|
||||
infrastructure.STOP, {}, self.sec_obj)
|
||||
infrastructure.STOP, {}, self.sec_obj)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
# missing method!
|
||||
@ -122,7 +123,7 @@ class TestComputeBackend(unittest.TestCase):
|
||||
})
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(AttributeError, self.backend.action, res1,
|
||||
infrastructure.RESTART, {}, self.sec_obj)
|
||||
infrastructure.RESTART, {}, self.sec_obj)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
# Test for Sanity
|
||||
@ -132,7 +133,7 @@ class TestComputeBackend(unittest.TestCase):
|
||||
Simulate a create call!
|
||||
"""
|
||||
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template])
|
||||
[self.os_template])
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'create_vm')
|
||||
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')
|
||||
nova_glue.storage.get_image_architecture(mox.IsA(object),
|
||||
mox.IsA(object)).AndReturn(
|
||||
'foo')
|
||||
mox.IsA(object)).\
|
||||
AndReturn('foo')
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -171,14 +172,15 @@ class TestComputeBackend(unittest.TestCase):
|
||||
Simulate a retrieve call!
|
||||
"""
|
||||
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template])
|
||||
[self.os_template])
|
||||
res.attributes = {'occi.core.id': 'bar'}
|
||||
|
||||
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,
|
||||
infrastructure.SUSPEND,
|
||||
infrastructure.RESTART]))
|
||||
mox.IsA(object)).\
|
||||
AndReturn(('active', [infrastructure.STOP,
|
||||
infrastructure.SUSPEND,
|
||||
infrastructure.RESTART]))
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'get_vm')
|
||||
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')
|
||||
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)
|
||||
@ -216,16 +218,16 @@ class TestComputeBackend(unittest.TestCase):
|
||||
Simulate a update call!
|
||||
"""
|
||||
res1 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template])
|
||||
[self.os_template])
|
||||
res1.attributes = {'occi.core.id': 'bar'}
|
||||
|
||||
# case 1 - rebuild VM with different OS
|
||||
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template2])
|
||||
[self.os_template2])
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'rebuild_vm')
|
||||
nova_glue.vm.rebuild_vm(mox.IsA(object), mox.IsA(object),
|
||||
mox.IsA(object))
|
||||
mox.IsA(object))
|
||||
self.mox.ReplayAll()
|
||||
self.backend.update(res1, res2, self.sec_obj)
|
||||
|
||||
@ -235,11 +237,11 @@ class TestComputeBackend(unittest.TestCase):
|
||||
|
||||
# case 2 - resize the VM
|
||||
res2 = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.res_template2])
|
||||
[self.res_template2])
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'resize_vm')
|
||||
nova_glue.vm.resize_vm(mox.IsA(object), mox.IsA(object),
|
||||
mox.IsA(object))
|
||||
mox.IsA(object))
|
||||
self.mox.ReplayAll()
|
||||
self.backend.update(res1, res2, self.sec_obj)
|
||||
|
||||
@ -258,7 +260,7 @@ class TestComputeBackend(unittest.TestCase):
|
||||
Simulate a delete call.
|
||||
"""
|
||||
res = core_model.Resource('/foo/bar', infrastructure.COMPUTE,
|
||||
[self.os_template])
|
||||
[self.os_template])
|
||||
res.attributes = {'occi.core.id': 'bar'}
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'delete_vm')
|
||||
@ -304,7 +306,7 @@ class TestComputeBackend(unittest.TestCase):
|
||||
self.mox.UnsetStubs()
|
||||
self.mox.StubOutWithMock(nova_glue.vm, 'restart_vm')
|
||||
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')
|
||||
nova_glue.vm.get_vm(mox.IsA(object), mox.IsA(object)).AndReturn(
|
||||
{
|
||||
@ -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
|
||||
|
@ -66,17 +66,18 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.assertRaises(AttributeError, self.backend.create, link,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
# 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,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -85,7 +86,7 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
|
||||
No updates allowed!
|
||||
"""
|
||||
self.assertRaises(AttributeError, self.backend.update, None, None,
|
||||
None)
|
||||
None)
|
||||
|
||||
# Test for sanity!
|
||||
|
||||
@ -100,10 +101,10 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
|
||||
|
||||
link = core_model.Link('foo', None, [os_addon.OS_NET_LINK], source,
|
||||
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')
|
||||
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):
|
||||
"""
|
||||
@ -145,7 +148,7 @@ class TestNetworkInterfaceBackend(unittest.TestCase):
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.net, 'remove_floating_ip')
|
||||
nova_glue.net.remove_floating_ip(mox.IsA(object), mox.IsA(object),
|
||||
mox.IsA(object))
|
||||
mox.IsA(object))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -176,7 +179,7 @@ class TestNetworkBackend(unittest.TestCase):
|
||||
Expecting an error!
|
||||
"""
|
||||
self.assertRaises(AttributeError, self.backend.action, None,
|
||||
None, None, None)
|
||||
None, None, None)
|
||||
|
||||
|
||||
class TestIpNetworkBackend(unittest.TestCase):
|
||||
|
@ -62,22 +62,24 @@ class TestStorageBackend(unittest.TestCase):
|
||||
res = mox.MockObject(core_model.Resource)
|
||||
res.attributes = {}
|
||||
self.assertRaises(AttributeError, self.backend.create, res,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
# error in volume creation
|
||||
res.attributes = {'occi.storage.size': '1'}
|
||||
|
||||
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()
|
||||
|
||||
self.assertRaises(exceptions.HTTPError, self.backend.create, res,
|
||||
self.sec_obj)
|
||||
self.sec_obj)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -90,7 +92,7 @@ class TestStorageBackend(unittest.TestCase):
|
||||
|
||||
# snapshot
|
||||
self.assertRaises(AttributeError, self.backend.action, res,
|
||||
infrastructure.SNAPSHOT, {}, self.sec_obj)
|
||||
infrastructure.SNAPSHOT, {}, self.sec_obj)
|
||||
|
||||
# Test for sanity
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -139,14 +144,15 @@ class TestStorageBackend(unittest.TestCase):
|
||||
self.assertEqual(res.attributes['occi.storage.state'], 'online')
|
||||
self.assertListEqual([infrastructure.OFFLINE, infrastructure.BACKUP,
|
||||
infrastructure.SNAPSHOT, infrastructure.RESIZE],
|
||||
res.actions)
|
||||
res.actions)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
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()
|
||||
|
||||
@ -186,7 +192,7 @@ class TestStorageBackend(unittest.TestCase):
|
||||
|
||||
self.mox.StubOutWithMock(nova_glue.storage, 'delete_storage_instance')
|
||||
nova_glue.storage.delete_storage_instance(mox.IsA(object),
|
||||
mox.IsA(object))
|
||||
mox.IsA(object))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -205,9 +211,11 @@ class TestStorageBackend(unittest.TestCase):
|
||||
|
||||
# snapshot
|
||||
self.mox.StubOutWithMock(nova_glue.storage,
|
||||
'snapshot_storage_instance')
|
||||
'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()
|
||||
|
||||
@ -261,7 +270,7 @@ class TestStorageLinkBackend(unittest.TestCase):
|
||||
|
||||
# verify all attrs.
|
||||
self.assertEqual(link.attributes['occi.storagelink.deviceid'],
|
||||
'/dev/sda')
|
||||
'/dev/sda')
|
||||
self.assertIn('occi.storagelink.mountpoint', link.attributes)
|
||||
self.assertEqual(link.attributes['occi.storagelink.state'], 'active')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user