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_volumes(): volumes = TempestClients.cinder().volumes.list() for volume in volumes: try: TempestClients.cinder().volumes.detach(volume) TempestClients.cinder().volumes.force_delete(volume) except Exception: TempestClients.cinder().volumes.force_delete(volume) wait_for_status(30, _check_num_volumes, num_volumes=0) time.sleep(2)
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 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: pass wait_for_status(30, _check_num_instances, num_instances=len(instances) - len(instances_to_delete)) time.sleep(2)
def test_execute_mistral(self): hostname = vitrage_utils.get_first_host()['name'] workflows = self.mistral_client.workflows.list() self.assertIsNotNone(workflows) num_workflows = len(workflows) executions = self.mistral_client.executions.list() self.assertIsNotNone(executions) num_executions = len(executions) alarms = utils.wait_for_answer(2, 0.5, self._check_alarms) self.assertIsNotNone(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) self.assertThat(workflows, HasLength(num_workflows + 1)) # Send a Doctor event that should generate an alarm. According to # execute_mistral.yaml template, the alarm should cause execution # of the workflow details = self._create_doctor_event_details(hostname, DOWN) self._post_event(details) # Wait for the alarm to be raised self.assertTrue( wait_for_status(10, self._check_num_vitrage_alarms, num_alarms=num_alarms + 1)) # Wait for the Mistral workflow execution self.assertTrue( wait_for_status(20, self._check_mistral_workflow_execution, num_executions=num_executions + 1)) except Exception as e: self._handle_exception(e) raise finally: self._rollback_to_default(WF_NAME, num_workflows, hostname, num_alarms) pass
def create_stacks(num_stacks, nested, template_file): 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={}) wait_for_status(45, _check_num_stacks, num_stacks=num_stacks, state='CREATE_COMPLETE') time.sleep(2)
def create_instances(num_instances=1, set_public_network=False, name='vm'): nics = [] flavor = get_first_flavor() image = glance_utils.get_first_image() if set_public_network: public_net = neutron_utils.get_public_network() if public_net: nics = [{'net-id': public_net['id']}] resources = [ TempestClients.nova().servers.create(name='%s-%s' % (name, index), flavor=flavor, image=image, nics=nics) for index in range(num_instances) ] wait_for_status(30, _check_num_instances, num_instances=num_instances, state='active') time.sleep(2) return resources
def _rollback_to_default(self, workflow_name, num_workflows, hostname, num_alarms): # Delete the workflow self.mistral_client.workflows.delete(workflow_name) workflows = self.mistral_client.workflows.list() self.assertIsNotNone(workflows) self.assertThat(workflows, HasLength(num_workflows)) # Clear the host down event and wait for the alarm to be deleted details = self._create_doctor_event_details(hostname, UP) self._post_event(details) self.assertTrue( wait_for_status(10, self._check_num_vitrage_alarms, num_alarms=num_alarms))