def _do_test_execute_mistral(self, trigger_alarm): executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') num_executions = len(executions) alarms = utils.wait_for_answer(2, 0.5, self._check_alarms) self.assertIsNotNone(alarms, 'Failed to get the list of alarms') num_alarms = len(alarms) try: # Trigger an alarm. According to v1_execute_mistral.yaml template, # the alarm should cause execution of the workflow self._trigger_do_action(trigger_alarm) # Wait for the alarm to be raised self.assertTrue(wait_for_status( 10, self._check_num_vitrage_alarms, num_alarms=num_alarms + 1), 'Trigger alarm was not raised') # Wait for the Mistral workflow execution self.assertTrue(wait_for_status( 20, self._check_mistral_workflow_execution, num_executions=num_executions + 1), 'Mistral workflow was not executed') finally: self._rollback_to_default(trigger_alarm, num_alarms)
def delete_all_stacks(): stacks = TempestClients.heat().stacks.list() for stack in stacks: try: TempestClients.heat().stacks.delete(stack.to_dict()['id']) except Exception: pass wait_for_status(30, _check_num_stacks, num_stacks=0) time.sleep(4)
def create_volume_and_attach(name, size, instance_id, mount_point): volume = TempestClients.cinder().volumes.create(name=name, size=size) time.sleep(2) TempestClients.cinder().volumes.attach(volume=volume, instance_uuid=instance_id, mountpoint=mount_point) wait_for_status(30, _check_num_volumes, num_volumes=1, state='in-use') time.sleep(2) return volume
def delete_all_instances(**kwargs): instances = TempestClients.nova().servers.list() instances_to_delete = g_utils.all_matches(instances, **kwargs) for item in instances_to_delete: try: TempestClients.nova().servers.force_delete(item) except Exception: LOG.exception('Failed to force delete instance %s', item.id) wait_for_status(30, check_deleted_instances, ids=[instance.id for instance in instances_to_delete]) time.sleep(2)
def delete_template(uuid=None, **kwargs): if not uuid: template = get_first_template(**kwargs) if template: uuid = template['uuid'] else: return TempestClients.vitrage().template.delete(uuid) wait_for_status( 100, lambda _id: True if not get_first_template(uuid=_id) else False, _id=uuid)
def add_template(filename='', folder='templates/api', template_type=TemplateTypes.STANDARD, status=TemplateStatus.ACTIVE): full_path = g_utils.tempest_resources_dir() + '/' + folder + '/' + filename t = TempestClients.vitrage().template.add(full_path, template_type) if t and t[0]: wait_for_status( 100, get_first_template, uuid=t[0]['uuid'], status=status) return t[0] return None
def delete_all_volumes(): cinder = TempestClients.cinder() volumes = cinder.volumes.list() for volume in volumes: try: cinder.volumes.detach(volume) cinder.volumes.force_delete(volume) except Exception: cinder.volumes.reset_state(volume, state='available', attach_status='detached') cinder.volumes.force_delete(volume) wait_for_status(30, _check_num_volumes, num_volumes=0) time.sleep(2)
def _do_test_execute_mistral(self, trigger_alarm): workflows = self.mistral_client.workflows.list() self.assertIsNotNone(workflows, 'Failed to get the list of workflows') num_workflows = len(workflows) executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') num_executions = len(executions) alarms = utils.wait_for_answer(2, 0.5, self._check_alarms) self.assertIsNotNone(alarms, 'Failed to get the list of alarms') num_alarms = len(alarms) try: # Create a Mistral workflow self.mistral_client.workflows.create(WF_DEFINITION) # Validate the workflow creation workflows = self.mistral_client.workflows.list() self.assertIsNotNone(workflows, 'Failed to get the list of workflows') self.assertThat(workflows, HasLength(num_workflows + 1), 'Mistral workflow was not created') # Trigger an alarm. According to v1_execute_mistral.yaml template, # the alarm should cause execution of the workflow self._trigger_do_action(trigger_alarm) # Wait for the alarm to be raised self.assertTrue( wait_for_status(10, self._check_num_vitrage_alarms, num_alarms=num_alarms + 1), 'Trigger alarm was not raised') # Wait for the Mistral workflow execution self.assertTrue( wait_for_status(20, self._check_mistral_workflow_execution, num_executions=num_executions + 1), 'Mistral workflow was not executed') except Exception as e: self._handle_exception(e) raise finally: self._rollback_to_default(WF_NAME, num_workflows, trigger_alarm, num_alarms) pass
def create_stacks(num_stacks, nested, template_file, image): tpl_files, template = template_utils.process_template_path( template_file, object_request=http.authenticated_fetcher(TempestClients.heat())) for i in range(num_stacks): stack_name = 'stack_%s' % i + ('_nested' if nested else '') TempestClients.heat().stacks.create(stack_name=stack_name, template=template, files=tpl_files, parameters={'image': image}) wait_for_status(45, _check_num_stacks, num_stacks=num_stacks, state='CREATE_COMPLETE') time.sleep(2)
def _rollback_to_default(self, trigger_alarm, num_alarms): # Clear the trigger alarm and wait it to be deleted self._trigger_undo_action(trigger_alarm) self.assertTrue(wait_for_status( 10, self._check_num_vitrage_alarms, num_alarms=num_alarms), 'Vitrage trigger alarm was not deleted')
def _create_instances(flavor, image, name, nics, num_instances): resources = [ TempestClients.nova().servers.create(name='%s-%s' % (name, index), flavor=flavor, image=image, nics=nics) for index in range(num_instances) ] success = wait_for_status(30, check_new_instances, ids=[instance.id for instance in resources]) return success, resources
def _rollback_to_default(self, workflow_name, num_workflows, trigger_alarm, num_alarms): # Delete the workflow self.mistral_client.workflows.delete(workflow_name) workflows = self.mistral_client.workflows.list() self.assertIsNotNone(workflows, 'Failed to get the list of workflows') self.assertThat(workflows, HasLength(num_workflows), 'Failed to remove the test workflow') # Clear the trigger alarm and wait it to be deleted self._trigger_undo_action(trigger_alarm) self.assertTrue( wait_for_status(10, self._check_num_vitrage_alarms, num_alarms=num_alarms), 'Vitrage trigger alarm was not deleted')
def delete_template_with_name(name): TempestClients.vitrage().template.delete(name) wait_for_status( 100, lambda name: True if not get_first_template(name=name) else False, name=name)