Add ability to specify directory with murano package files

Currently we are able to specify murano package in the Murano context
by specifying murano package address. Now we add ability to specify
non-zipped murano package to Murano context.

Add function that helps to pack a directory with murano package files
into zipfile correctly.

Change-Id: Iba95025c10181109f402824e781afedcdd549b5e
This commit is contained in:
Roman Vasilets 2015-06-25 19:47:10 +03:00
parent 104d7433f7
commit 4a22346fdc
7 changed files with 114 additions and 9 deletions

View File

@ -0,0 +1,25 @@
Namespaces:
=: io.murano.apps
std: io.murano
sys: io.murano.system
Name: HelloReporter
Extends: std:Application
Properties:
name:
Contract: $.string().notNull()
Workflow:
initialize:
Body:
- $.environment: $.find(std:Environment).require()
deploy:
Body:
- If: not $.getAttr(deployed, false)
Then:
- $.environment.reporter.report($this, 'Starting deployment! Hello!')
- $.setAttr(deployed, True)

View File

@ -0,0 +1,23 @@
Version: 2
Application:
?:
type: io.murano.apps.HelloReporter
name: $.appConfiguration.name
Forms:
- appConfiguration:
fields:
- name: name
type: string
label: Application Name
description: >-
Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and
underline are allowed
- name: unitNamingPattern
type: string
required: false
hidden: true
widgetMedia:
js: ['muranodashboard/js/support_placeholder.js']
css: {all: ['muranodashboard/css/support_placeholder.css']}

View File

@ -0,0 +1,10 @@
Format: 1.0
Type: Application
FullName: io.murano.apps.HelloReporter
Name: HelloReporter
Description: |
HelloReporter test app.
Author: 'Mirantis, Inc'
Tags: [App, Test, HelloWorld]
Classes:
io.murano.apps.HelloReporter: HelloReporter.yaml

View File

@ -46,3 +46,21 @@
sla:
failure_rate:
max: 0
-
args:
packages_per_env: 2
runner:
type: "constant"
times: 8
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
murano_packages:
app_package: "/home/jenkins/.rally/extra/murano/applications/HelloReporter/io.murano.apps.HelloReporter/"
roles:
- "admin"
sla:
failure_rate:
max: 0

View File

@ -13,13 +13,16 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import zipfile
from rally.common import fileutils
from rally.common.i18n import _
from rally.common.i18n import _LE
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import exceptions
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.task import context
@ -46,18 +49,27 @@ class PackageGenerator(context.Context):
@utils.log_task_wrapper(LOG.info, _("Enter context: `Murano packages`"))
def setup(self):
if not zipfile.is_zipfile(self.config["app_package"]):
msg = (_LE("There is no zip archive by this path: %s")
% self.config["app_package"])
raise OSError(msg)
is_config_app_dir = False
if zipfile.is_zipfile(self.config["app_package"]):
zip_name = self.config["app_package"]
elif os.path.isdir(self.config["app_package"]):
is_config_app_dir = True
zip_name = fileutils.pack_dir(self.config["app_package"])
else:
msg = (_LE("There is no zip archive or directory by this path:"
" %s") % self.config["app_package"])
raise exceptions.ContextSetupFailure(msg=msg,
ctx="murano_packages")
for user, tenant_id in utils.iterate_per_tenants(
self.context["users"]):
clients = osclients.Clients(user["endpoint"])
self.context["tenants"][tenant_id]["packages"] = []
if is_config_app_dir:
self.context["tenants"][tenant_id]["murano_ctx"] = zip_name
package = clients.murano().packages.create(
{"categories": ["Web"], "tags": ["tag"]},
{"file": open(self.config["app_package"])})
{"file": open(zip_name)})
self.context["tenants"][tenant_id]["packages"].append(package)

View File

@ -16,14 +16,13 @@
from rally.common import log as logging
from rally import consts
from rally.plugins.openstack.scenarios.murano import utils
from rally.plugins.openstack.scenarios.vm import utils as vm_utils
from rally.task.scenarios import base
from rally.task import validation
LOG = logging.getLogger(__name__)
class MuranoEnvironments(utils.MuranoScenario, vm_utils.VMScenario):
class MuranoEnvironments(utils.MuranoScenario):
"""Benchmark scenarios for Murano environments."""
@validation.required_clients("murano")
@validation.required_services(consts.Service.MURANO)

View File

@ -80,14 +80,32 @@ class MuranoGeneratorTestCase(test.TestCase):
@mock.patch("%s.osclients" % CTX)
@mock.patch("%s.resource_manager.cleanup" % CTX)
def test_cleanup(self, mock_cleanup, mock_osclients):
def test_cleanup_with_zip(self, mock_cleanup, mock_osclients):
mock_app = mock.Mock(id="fake_app_id")
(mock_osclients.Clients().murano().
packages.create.return_value) = mock_app
murano_ctx = murano_packages.PackageGenerator(self._get_context())
murano_ctx.setup()
murano_ctx.cleanup()
mock_cleanup.assert_called_once_with(names=["murano.packages"],
users=murano_ctx.context["users"])
@mock.patch("%s.osclients" % CTX)
@mock.patch("%s.resource_manager.cleanup" % CTX)
def test_cleanup_with_dir(self, mock_cleanup, mock_osclients):
mock_app = mock.Mock(id="fake_app_id")
(mock_osclients.Clients().murano().
packages.create.return_value) = mock_app
ctx_dict = self._get_context()
app_dir = ("rally-jobs/extra/murano/applications/"
"HelloReporter/io.murano.apps.HelloReporter/")
ctx_dict["config"]["murano_packages"]["app_package"] = app_dir
murano_ctx = murano_packages.PackageGenerator(ctx_dict)
murano_ctx.setup()
murano_ctx.cleanup()
mock_cleanup.assert_called_once_with(names=["murano.packages"],
users=murano_ctx.context["users"])