<commit_before># Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function

import pprint
import uuid

from tripleo_common import update as update_common

from tripleoclient.workflows import base


def update(clients, **workflow_input):
    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.update.v1.update_plan',
        workflow_input=workflow_input
    )

    with tripleoclients.messaging_websocket(queue_name) as ws:
        message = ws.wait_for_message(execution.id)
        assert message['status'] == "SUCCESS", pprint.pformat(message)


def update_and_wait(log, clients, stack, plan_name, verbose_level,
                    timeout=None):
    """Start the update and wait for it to give breakpoints or finish"""

    log.info("Performing Heat stack update")
    queue_name = str(uuid.uuid4())

    workflow_input = {
        "container": plan_name,
        "queue_name": queue_name,
    }

    if timeout is not None:
        workflow_input['timeout'] = timeout

    update(clients, **workflow_input)

    update_manager = update_common.PackageUpdateManager(
        heatclient=clients.orchestration,
        novaclient=clients.compute,
        stack_id=stack)

    update_manager.do_interactive_update()


def abort_update(clients, **workflow_input):

    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    workflow_input['queue_name'] = str(uuid.uuid4())
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.update.v1.cancel_stack_update',
        workflow_input=workflow_input
    )

    with tripleoclients.messaging_websocket(queue_name) as ws:
        message = ws.wait_for_message(execution.id)
        assert message['status'] == "SUCCESS", pprint.pformat(message)


def clear_breakpoints(clients, **workflow_input):
    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    workflow_input['queue_name'] = str(uuid.uuid4())
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.update.v1.clear_breakpoints',
        workflow_input=workflow_input<commit_msg>Fixed overcloud stack update workflow name error<commit_after># Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function

import pprint
import uuid

from tripleo_common import update as update_common

from tripleoclient.workflows import base


def update(clients, **workflow_input):
    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.package_update.v1.package_update_plan',
        workflow_input=workflow_input
    )

    with tripleoclients.messaging_websocket(queue_name) as ws:
        message = ws.wait_for_message(execution.id)
        assert message['status'] == "SUCCESS", pprint.pformat(message)


def update_and_wait(log, clients, stack, plan_name, verbose_level,
                    timeout=None):
    """Start the update and wait for it to give breakpoints or finish"""

    log.info("Performing Heat stack update")
    queue_name = str(uuid.uuid4())

    workflow_input = {
        "container": plan_name,
        "queue_name": queue_name,
    }

    if timeout is not None:
        workflow_input['timeout'] = timeout

    update(clients, **workflow_input)

    update_manager = update_common.PackageUpdateManager(
        heatclient=clients.orchestration,
        novaclient=clients.compute,
        stack_id=stack)

    update_manager.do_interactive_update()


def abort_update(clients, **workflow_input):

    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    workflow_input['queue_name'] = str(uuid.uuid4())
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.package_update.v1.cancel_stack_update',
        workflow_input=workflow_input
    )

    with tripleoclients.messaging_websocket(queue_name) as ws:
        message = ws.wait_for_message(execution.id)
        assert message['status'] == "SUCCESS", pprint.pformat(message)


def clear_breakpoints(clients, **workflow_input):
    workflow_client = clients.workflow_engine
    tripleoclients = clients.tripleoclient
    workflow_input['queue_name'] = str(uuid.uuid4())
    queue_name = workflow_input['queue_name']

    execution = base.start_workflow(
        workflow_client,
        'tripleo.package_update.v1.clear_breakpoints',
        workflow_input=workflow_input
{'fraction_non_alphanumeric': 0.08346213292117466, 'fraction_numerical': 0.003434655675768504, 'mean_word_length': 3.8412302576891104, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4927344', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1687, 'n_words': 421}