| 1 |
# Copyright 2020 - Nokia Software. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
|
| 16 |
import json |
| 17 |
from pathlib import Path |
| 18 |
|
| 19 |
from rally.common import cfg |
| 20 |
from rally.task import validation |
| 21 |
from rally_openstack import consts |
| 22 |
from rally_openstack import scenario |
| 23 |
from rally_openstack.scenarios.mistral import utils |
| 24 |
|
| 25 |
CONF = cfg.CONF |
| 26 |
|
| 27 |
SCENARIO_TIMEOUT_SEC = 16000 |
| 28 |
|
| 29 |
home_dir = str(Path.home()) |
| 30 |
wf_dir = '%s/.rally/extra/scenarios/big_wf/' % home_dir |
| 31 |
|
| 32 |
action_files = ['dummy_actions.yaml', 'dummy_actions_nuage.yaml'] |
| 33 |
common_workflow_files = ['sub_wfs.yaml'] |
| 34 |
|
| 35 |
|
| 36 |
class MistralHugeWorkflowScenario(utils.MistralScenario): |
| 37 |
main_wf_file_name = '' |
| 38 |
params_filename = '' |
| 39 |
wf_name = '' |
| 40 |
created_wfs = [] |
| 41 |
created_wbs = [] |
| 42 |
|
| 43 |
def run(self): |
| 44 |
namespace = '' |
| 45 |
CONF.openstack.mistral_execution_timeout = SCENARIO_TIMEOUT_SEC |
| 46 |
|
| 47 |
self.create_common_workflows() |
| 48 |
self.create_actions() |
| 49 |
self.create_main_workflow(namespace=namespace) |
| 50 |
params = self._read_params_from_file() |
| 51 |
|
| 52 |
self.run_workflow(params, namespace=namespace) |
| 53 |
self.clean_after_scenario(namespace=namespace) |
| 54 |
|
| 55 |
def clean_after_scenario(self, namespace=''): |
| 56 |
for wf in self.created_wfs: |
| 57 |
self._delete_workflow(wf, namespace=namespace) |
| 58 |
|
| 59 |
for wb in self.created_wbs: |
| 60 |
self._delete_workbook(wb, namespace=namespace) |
| 61 |
|
| 62 |
def create_common_workflows(self): |
| 63 |
for file in common_workflow_files: |
| 64 |
with open(wf_dir + file, 'r+') as f: |
| 65 |
definition = f.read() |
| 66 |
wfs = self._create_workflow(definition) |
| 67 |
|
| 68 |
for wf in wfs: |
| 69 |
self.created_wfs.append(wf.name) |
| 70 |
|
| 71 |
def create_actions(self): |
| 72 |
for file in action_files: |
| 73 |
with open(wf_dir + file, 'r+') as f: |
| 74 |
definition = f.read() |
| 75 |
wb = self._create_workbook(definition) |
| 76 |
|
| 77 |
self.created_wbs.append(wb.name) |
| 78 |
|
| 79 |
def _create_workbook(self, definition, namespace=''): |
| 80 |
return self.clients("mistral").workbooks.create( |
| 81 |
definition, |
| 82 |
namespace=namespace |
| 83 |
) |
| 84 |
|
| 85 |
def _read_params_from_file(self): |
| 86 |
with open(wf_dir + self.params_filename, 'r+') as f: |
| 87 |
params_string = f.read() |
| 88 |
params = json.loads(params_string) |
| 89 |
|
| 90 |
return params |
| 91 |
|
| 92 |
def run_workflow(self, params, namespace=''): |
| 93 |
input = {} |
| 94 |
|
| 95 |
self._create_execution( |
| 96 |
self.wf_name, |
| 97 |
wf_input=input, |
| 98 |
namespace=namespace, |
| 99 |
**params |
| 100 |
) |
| 101 |
|
| 102 |
def create_main_workflow(self, namespace=''): |
| 103 |
with open(wf_dir + self.main_wf_file_name, 'r+') as f: |
| 104 |
definition = f.read() |
| 105 |
wfs = self._create_workflow(definition, namespace=namespace) |
| 106 |
|
| 107 |
for wf in wfs: |
| 108 |
self.created_wfs.append(wf.name) |
| 109 |
|
| 110 |
|
| 111 |
@validation.add("required_platform", platform="openstack", users=True) |
| 112 |
@validation.add("required_services", services=[consts.Service.MISTRAL]) |
| 113 |
@scenario.configure(name="MistralExecutions.TerminateScenario", |
| 114 |
platform="openstack") |
| 115 |
class TerminateScenario(MistralHugeWorkflowScenario): |
| 116 |
main_wf_file_name = 'terminate_wf.yaml' |
| 117 |
params_filename = 'terminate_params.json' |
| 118 |
wf_name = 'mistral_cmg_terminate' |
| 119 |
|
| 120 |
|
| 121 |
@validation.add("required_platform", platform="openstack", users=True) |
| 122 |
@validation.add("required_services", services=[consts.Service.MISTRAL]) |
| 123 |
@scenario.configure(name="MistralExecutions.DeployScenario", |
| 124 |
platform="openstack") |
| 125 |
class DeployScenario(MistralHugeWorkflowScenario): |
| 126 |
main_wf_file_name = 'deploy_wf.yaml' |
| 127 |
params_filename = 'deploy_params.json' |
| 128 |
wf_name = 'mistral_cmg_deploy' |