<commit_before>import difflib
import os
import random
import time
import json

from locust import HttpLocust, TaskSet, task

import keystone_v2_base as keystone_base
import heat_v1_base as heat_base

""" These are more complex 'tasks' built, upon the base api tasks.
    They are intended to be a write-once, re-use-many resource and
    to provide the building blocks for task-sets / test runs.

"""

def abandon_and_adopt_stack(self):
    """ Designed to randomly select a stack,
        abandon it, save the data from the call,
        then re-adopt it.

        Intended to allow for collisions and messiness.
        This is for bug-hunting. 

    """
 
    stack_name, stack_id = heat_base.get_stack_name_and_id(self)
    response = heat_base.abandon_stack(self,
                                       stack_name=stack_name,
                                       stack_id=stack_id)
    response = json.loads(response.content)
    self.output("abandon_adopt_RESPONSE:")
    self.output(response)
    template = response['template']
    resources = response['resources']


def create_stack(self):
    """ We use this method to help handle the particulars
        of our basic test scenarios.  Tailored to basic
        test stack creation for templates in etc dir.

    """
    
    params = {}
    disable_rollback=True

    # stack name
    stack_name = "stack-%s-%s" % (self.id, self.stack_count)
    self.stack_count += 1

    # generate timeout
    timeout_mins = 30 # general default / maybe leave None(?)
    if self.one_in_ten():
        timeout_mins = random.choice([0,0,0,1,1,5,5,10,10,10,15,20,100,-1,'zebra golfcart tango',10000000000000000, .5])
    # pick a template file
    template_file = random.choice(self.heat_templates)
    template_data = self.get_file_contents(template_file)

    # params:
    if '1vm' in template_file:
        params['instance1_name'] = '%s-server-1' % (stack_name)
    elif '2vm' in template_file:
        params['instance1_name'] = '%s-server-1' % (stack_name)
        params['instance2_name'] = '%s-server-2' % (stack_name)

    # disable rollback
    if self.one_in_ten():
        disable_rollback=False

    # create the stack
    response = heat_base.create_stack(self,
                                      stack_name=stack_name,
                                      template=template_data,
                                      params=params,
                                      disable_rollback=disable_rollback,
                                      timeout_mins=timeout_mins)
    return response, stack_name


def update_stack(self):
    params = {}
    disable_rollback=True

    # get stack_name, stack_id
    stack_name, stack_id = heat_base.get_stack_name_and_id(self)

    # generate timeout
    timeout_mins = 30 # general default / maybe leave None(?)
    if self.one_in_ten():
        timeout_mins = random.choice([0,0,0,1,1,5,5,10,10,10,15,20,100,-1,'zebra golfcart tango',10000000000000000, .5])

    # pick a template file
    template_file = random.choice(self.heat_templates)
    template_data = self.get_file_contents(template_file)

    # params:
    if self.one_in_ten():
        if '1vm' in template_file:
            params['instance1_name'] = '%s-newname-1' % (stack_name)
        elif '2vm' in template_file:
            params['instance1_name'] = '%s-newname-1' % (stack_name)
            params['instance2_name'] = '%s-newname-2' % (stack_name)
    else:
        if '1vm' in template_file:
            params['instance1_name'] = '%s-server-1' % (stack_name)
        elif '2vm' in template_file:
            params['instance1_name'] = '%s-server-1' % (stack_name)
            params['instance2_name'] = '%s-server-2' % (stack_name)

    if self.one_in_five():
        params['flavor'] = random.choice(self.flavor_list)
    
    # disable rollback<commit_msg>Clean up of code<commit_after>import difflib
import os
import random
import time
import json

from locust import HttpLocust, TaskSet, task

import keystone_v2_base as keystone_base
import heat_v1_base as heat_base

""" These are more complex 'tasks' built, upon the base api tasks.
    They are intended to be a write-once, re-use-many resource and
    to provide the building blocks for task-sets / test runs.

"""

def abandon_and_adopt_stack(self):
    """ Designed to randomly select a stack,
        abandon it, save the data from the call,
        then re-adopt it.

        Intended to allow for collisions and messiness.
        This is for bug-hunting. 

    """
 
    stack_name, stack_id = heat_base.get_stack_name_and_id(self)
    response = heat_base.abandon_stack(self,
                                       stack_name=stack_name,
                                       stack_id=stack_id)
    response = json.loads(response.content)
    self.output("abandon_adopt_RESPONSE:")
    self.output(response)
    template = response['template']
    resources = response['resources']


def create_stack(self):
    """ We use this method to help handle the particulars
        of our basic test scenarios.  Tailored to basic
        test stack creation for templates in etc dir.

    """
    
    params = {}
    disable_rollback=True

    # stack name
    stack_name = "stack-%s-%s" % (self.id, self.stack_count)
    self.stack_count += 1

    # generate timeout
    timeout_mins = 30 # general default / maybe leave None(?)
    if self.one_in_ten():
        timeout_mins = random.choice([0,0,0,1,1,5,5,10,10,10,15,20,100,-1,'zebra golfcart tango',10000000000000000, .5])
    # pick a template file
    template_file = random.choice(self.heat_templates)
    template_data = self.get_file_contents(template_file)

    # params:
    if '1vm' in template_file:
        params['instance1_name'] = '%s-server-1' % (stack_name)
    elif '2vm' in template_file:
        params['instance1_name'] = '%s-server-1' % (stack_name)
        params['instance2_name'] = '%s-server-2' % (stack_name)

    # disable rollback
    if self.one_in_ten():
        disable_rollback=False

    # create the stack
    response = heat_base.create_stack(self,
                                      stack_name=stack_name,
                                      template=template_data,
                                      params=params,
                                      disable_rollback=disable_rollback,
                                      timeout_mins=timeout_mins)
    return response, stack_name


def update_stack(self):
    params = {}
    disable_rollback=True

    # get stack_name, stack_id
    stack_name, stack_id = heat_base.get_stack_name_and_id(self)

    # generate timeout
    timeout_mins = 30 # general default / maybe leave None(?)
    if self.one_in_ten():
        timeout_mins = random.choice([0,0,0,1,1,5,5,10,10,10,15,20,100,-1,'zebra golfcart tango',10000000000000000, .5])

    # pick a template file
    template_file = random.choice(self.heat_templates)
    template_data = self.get_file_contents(template_file)

    # params:
    server_string='server'
    if self.one_in_ten():
        server_string='newname'

    if '1vm' in template_file:
        params['instance1_name'] = '%s-%s-1' % (stack_name, server_string)
    elif '2vm' in template_file:
        params['instance1_name'] = '%s-%s-1' % (stack_name, server_string)
        params['instance2_name'] = '%s-%s-2' % (stack_name, server_string)

    if self.one_in_five():
        params['flavor'] = random.choice(self.flavor_list)
    
    # disable rollback
{'fraction_non_alphanumeric': 0.10148614272325612, 'fraction_numerical': 0.028116213683223992, 'mean_word_length': 2.5235849056603774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4886861', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2286, 'n_words': 537}