Skip to content

Commit

Permalink
#49 partially fix acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrytar committed Jun 7, 2019
1 parent 71deb41 commit 04b52a1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ exclude =
.venv,
cloudkeeper_os.egg-info,
cloudkeeper_os/grpc/cloudkeeper_grpc_python/cloudkeeper_pb2.py,
cloudkeeper_os/grpc/cloudkeeper-grpc-python/cloudkeeper_pb2_grpc.py
cloudkeeper_os/grpc/cloudkeeper_grpc_python/cloudkeeper_pb2_grpc.py
max-line-length = 120
ignore = I100
18 changes: 2 additions & 16 deletions cloudkeeper_os/grpc/core_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,37 @@ class CoreConnector(cloudkeeper_pb2_grpc.CommunicatorServicer):

def __init__(self):
super().__init__()
self.LOG = log.getLogger(__name__)
self.log = log.getLogger(__name__)
self.h = handler.Handler()

def PreAction(self, request, context): # noqa: N802
pass

return cloudkeeper_pb2.Empty()

def PostAction(self, request, context): # noqa: N802
pass

return cloudkeeper_pb2.Empty()

def AddAppliance(self, request, context): # noqa: N802
self.h.register_appliance(request)

return cloudkeeper_pb2.Empty()

def UpdateAppliance(self, request, context): # noqa: N802
self.UpdateApplianceMetadata(request, context)
self.h.update_image(request.image, request.identifier)

return cloudkeeper_pb2.Empty()

def UpdateApplianceMetadata(self, request, context): # noqa: N802
params = self.h.appliance_metadata_to_dict(request)
params = handler.appliance_metadata_to_dict(request)
image = self.h.update_tags(request.identifier, **params)

return cloudkeeper_pb2.Empty()

def RemoveAppliance(self, request, context): # noqa: N802
self.h.remove_appliance(request.identifier)

return cloudkeeper_pb2.Empty()

def RemoveImageList(self, request, context): # noqa: N802
pass

return cloudkeeper_pb2.Empty()

def ImageLists(self, request, context): # noqa: N802
pass

yield cloudkeeper_pb2.Empty()

def Appliances(self, request, context): # noqa: N802
Expand All @@ -67,10 +55,8 @@ def Appliances(self, request, context): # noqa: N802
appliance_image_list = self.h.image_dict_to_appliance_message(i)
appliance_dict = appliance_image_list[0]
appliance_dict['image'] = cloudkeeper_pb2.Image(**appliance_image_list[1])

yield cloudkeeper_pb2.Appliance(**appliance_dict)

def RemoveExpiredAppliances(self, request, context): # noqa: N802
self.h.remove_expired_appliances()

return cloudkeeper_pb2.Empty()
107 changes: 55 additions & 52 deletions cloudkeeper_os/openstack/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,70 @@
from cloudkeeper_os.openstack import glance


APPLIANCE_TAGS_PREFIX = 'CLOUDKEEPER_'

def appliance_metadata_to_dict(request):
"""
Parsing Appliance metadata to dictionary
"""

params = {}

if request.title:
params[APPLIANCE_TAGS_PREFIX + 'title'] = request.title
params['name'] = request.title
if request.description:
params[APPLIANCE_TAGS_PREFIX + 'description'] = request.description
params['description'] = request.description
if request.mpuri:
params[APPLIANCE_TAGS_PREFIX + 'mpuri'] = request.mpuri
if request.group:
params[APPLIANCE_TAGS_PREFIX + 'group'] = request.group
if request.ram:
params[APPLIANCE_TAGS_PREFIX + 'ram'] = str(request.ram)
params['min_ram'] = request.ram
if request.core:
params[APPLIANCE_TAGS_PREFIX + 'core'] = str(request.core)
params['min_disk'] = request.core
if request.version:
params[APPLIANCE_TAGS_PREFIX + 'version'] = request.version
if request.architecture:
params[APPLIANCE_TAGS_PREFIX + 'architecture'] = request.architecture
if request.operating_system:
params[APPLIANCE_TAGS_PREFIX + 'operating_system'] = request.operating_system
if request.vo:
params[APPLIANCE_TAGS_PREFIX + 'vo'] = request.vo
if request.expiration_date:
params[APPLIANCE_TAGS_PREFIX + 'expiration_date'] = str(request.expiration_date)
if request.image_list_identifier:
params[APPLIANCE_TAGS_PREFIX + 'image_list_identifier'] = request.image_list_identifier
if request.base_mpuri:
params[APPLIANCE_TAGS_PREFIX + 'base_mpuri'] = request.base_mpuri
if request.appid:
params[APPLIANCE_TAGS_PREFIX + 'appid'] = request.appid
if request.digest:
params[APPLIANCE_TAGS_PREFIX + 'digest'] = request.digest

return params

class Handler:
"""
Handler for communication with OpenStack
"""
def __init__(self):
self.client = glance.client()
self.APPLIANCE_TAGS_PREFIX = 'CLOUDKEEPER_'

def appliance_metadata_to_dict(self, request):
"""
Parsing Appliance metadata to dictionary
"""

params = {}

if request.title:
params[self.APPLIANCE_TAGS_PREFIX + 'title'] = request.title
params['name'] = request.title
if request.description:
params[self.APPLIANCE_TAGS_PREFIX + 'description'] = request.description
params['description'] = request.description
if request.mpuri:
params[self.APPLIANCE_TAGS_PREFIX + 'mpuri'] = request.mpuri
if request.group:
params[self.APPLIANCE_TAGS_PREFIX + 'group'] = request.group
if request.ram:
params[self.APPLIANCE_TAGS_PREFIX + 'ram'] = str(request.ram)
params['min_ram'] = request.ram
if request.core:
params[self.APPLIANCE_TAGS_PREFIX + 'core'] = str(request.core)
params['min_disk'] = request.core
if request.version:
params[self.APPLIANCE_TAGS_PREFIX + 'version'] = request.version
if request.architecture:
params[self.APPLIANCE_TAGS_PREFIX + 'architecture'] = request.architecture
if request.operating_system:
params[self.APPLIANCE_TAGS_PREFIX + 'operating_system'] = request.operating_system
if request.vo:
params[self.APPLIANCE_TAGS_PREFIX + 'vo'] = request.vo
if request.expiration_date:
params[self.APPLIANCE_TAGS_PREFIX + 'expiration_date'] = str(request.expiration_date)
if request.image_list_identifier:
params[self.APPLIANCE_TAGS_PREFIX + 'image_list_identifier'] = request.image_list_identifier
if request.base_mpuri:
params[self.APPLIANCE_TAGS_PREFIX + 'base_mpuri'] = request.base_mpuri
if request.appid:
params[self.APPLIANCE_TAGS_PREFIX + 'appid'] = request.appid
if request.digest:
params[self.APPLIANCE_TAGS_PREFIX + 'digest'] = request.digest

return params

def image_dict_to_appliance_message(self, request):
appliance_dict = {}

for k, v in request.items():
if self.APPLIANCE_TAGS_PREFIX in k:
if k.replace(self.APPLIANCE_TAGS_PREFIX, '') == 'expiration_date':
appliance_dict[k.replace(self.APPLIANCE_TAGS_PREFIX, '')] = int(v)
if APPLIANCE_TAGS_PREFIX in k:
if k.replace(APPLIANCE_TAGS_PREFIX, '') == 'expiration_date':
appliance_dict[k.replace(APPLIANCE_TAGS_PREFIX, '')] = int(v)
else:
appliance_dict[k.replace(self.APPLIANCE_TAGS_PREFIX, '')] = v
appliance_dict[k.replace(APPLIANCE_TAGS_PREFIX, '')] = v
else:
print(str(k) + " - " + str(v))

if 'id' in request:
appliance_dict['identifier'] = request['id']
Expand Down Expand Up @@ -118,7 +121,7 @@ def register_appliance(self, request):

self.register_image(request.image, appliance.id)

params = self.appliance_metadata_to_dict(request)
params = appliance_metadata_to_dict(request)

self.update_tags(appliance.id, **params)

Expand All @@ -134,7 +137,7 @@ def register_image(self, request, image_id):
image = self.client.images.update(image_id, container_format=container_format)

if (request.mode == cloudkeeper_pb2.Image.LOCAL):
image = self.client.images.upload(image_id, open(request.location, 'rb'))
self.client.images.upload(image_id, open(request.location, 'rb'))
elif (request.mode == cloudkeeper_pb2.Image.REMOTE):
self.client.images.image_import(image_id, method='web-download', uri=request.uri)

Expand Down

0 comments on commit 04b52a1

Please sign in to comment.