Tempest plugin for the murano project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

159 lines
6.0 KiB

  1. # Copyright (c) 2016 Mirantis, Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. import os
  16. from oslo_serialization import jsonutils as json
  17. from tempest import config
  18. from tempest.lib.common import rest_client
  19. from murano_tempest_tests import utils
  20. CONF = config.CONF
  21. class ArtifactsClient(rest_client.RestClient):
  22. """Tempest REST client for Glance Artifacts"""
  23. def __init__(self, auth_provider):
  24. super(ArtifactsClient, self).__init__(
  25. auth_provider,
  26. CONF.artifacts.catalog_type,
  27. CONF.identity.region,
  28. endpoint_type=CONF.artifacts.endpoint_type)
  29. self.build_interval = CONF.artifacts.build_interval
  30. self.build_timeout = CONF.artifacts.build_timeout
  31. # -----------------------------Artifacts methods-------------------------------
  32. def list_artifacts(self):
  33. uri = 'v0.1/artifacts/murano/v1'
  34. resp, body = self.get(uri)
  35. self.expected_success(200, resp.status)
  36. parsed = self._parse_resp(body)
  37. return parsed['artifacts']
  38. def list_drafts(self):
  39. uri = 'v0.1/artifacts/murano/v1/creating'
  40. resp, body = self.get(uri)
  41. self.expected_success(200, resp.status)
  42. return self._parse_resp(body)
  43. def list_deactivated_drafts(self):
  44. uri = 'v0.1/artifacts/murano/v1/deactivated'
  45. resp, body = self.get(uri)
  46. self.expected_success(200, resp.status)
  47. return self._parse_resp(body)
  48. def create_artifact_draft(self, name, version, **kwargs):
  49. uri = 'v0.1/artifacts/murano/v1/drafts'
  50. kwargs.update({'name': name, 'version': version})
  51. resp, body = self.post(uri, body=json.dumps(kwargs))
  52. self.expected_success(201, resp.status)
  53. return self._parse_resp(body)
  54. def publish_artifact(self, artifact_id):
  55. uri = 'v0.1/artifacts/murano/v1/{0}/publish'.format(artifact_id)
  56. resp, body = self.post(uri, body='')
  57. self.expected_success(200, resp.status)
  58. return self._parse_resp(body)
  59. def get_artifact(self, artifact_id):
  60. uri = 'v0.1/artifacts/murano/v1/{0}'.format(artifact_id)
  61. resp, body = self.get(uri)
  62. self.expected_success(200, resp.status)
  63. return self._parse_resp(body)
  64. def update_artifact(self, artifact_id, body):
  65. headers = {
  66. 'Content-Type': 'application/openstack-images-v2.1-json-patch'}
  67. uri = 'v0.1/artifacts/murano/v1/{0}'.format(artifact_id)
  68. resp, body = self.patch(uri, json.dumps(body), headers=headers)
  69. self.expected_success(200, resp.status)
  70. return self._parse_resp(body)
  71. def delete_artifact(self, artifact_id):
  72. uri = 'v0.1/artifacts/murano/v1/{0}'.format(artifact_id)
  73. resp, body = self.delete(uri)
  74. self.expected_success(204, resp.status)
  75. return self._parse_resp(body)
  76. def upload_blob(self, artifact_id, blob_type, data):
  77. headers = {'Content-Type': 'application/octet-stream'}
  78. uri = 'v0.1/artifacts/murano/v1/{0}/{1}'.format(
  79. artifact_id, blob_type)
  80. resp, body = self.put(uri, data, headers=headers)
  81. self.expected_success(200, resp.status)
  82. return self._parse_resp(body)
  83. def download_blob(self, artifact_id, blob_type):
  84. uri = 'v0.1/artifacts/murano/v1/{0}/{1}/download'.format(
  85. artifact_id, blob_type)
  86. resp, body = self.get(uri)
  87. self.expected_success(200, resp.status)
  88. return self._parse_resp(body)
  89. # -----------------------------Packages methods-------------------------------
  90. def get_list_packages(self):
  91. return self.list_artifacts()
  92. def delete_package(self, package_id):
  93. return self.delete_artifact(package_id)
  94. def upload_package(self, package_name, package_path, top_dir, body):
  95. files = {package_name: open(os.path.join(top_dir, package_path), 'rb')}
  96. is_public = body.pop('is_public', None)
  97. if is_public is not None:
  98. body['visibility'] = 'public' if is_public else 'private'
  99. fqn = list(files.keys())[0]
  100. package = utils.Package.from_file(files[fqn])
  101. manifest = package.manifest
  102. package_draft = {
  103. 'name': manifest.get('FullName', fqn),
  104. 'version': manifest.get('Version', '0.0.0'),
  105. 'description': manifest.get('Description'),
  106. 'display_name': manifest.get('Name', fqn),
  107. 'type': manifest.get('Type', 'Application'),
  108. 'author': manifest.get('Author'),
  109. 'tags': manifest.get('Tags', []),
  110. 'class_definitions': package.classes.keys()
  111. }
  112. for k, v in body.items():
  113. package_draft[k] = v
  114. inherits = utils.get_local_inheritance(package.classes)
  115. # TODO(kzaitsev): add local and global inheritance information tests
  116. package_draft['inherits'] = inherits
  117. keywords = package_draft['tags']
  118. package_draft['keywords'] = keywords
  119. draft = self.create_artifact_draft(**package_draft)
  120. self.upload_blob(draft['id'], 'archive', package.file())
  121. # TODO(kzaitsev): add logo upload code, currently it's failing for me
  122. # with io.UnsupportedOperation: fileno
  123. # if package.logo is not None:
  124. # self.upload_blob(draft['id'], 'logo', package.logo)
  125. # if package.ui is not None:
  126. # self.client.artifacts.upload_blob(draft['id'], 'ui_definition',
  127. # package.ui)
  128. self.publish_artifact(draft['id'])
  129. return draft