def test_overlapping_action_mark_down(self): try: host_name = self.orig_host.get(VProps.NAME) # Do - first self._trigger_do_action(TRIGGER_ALARM_3) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("down", nova_service.state) # Do - second self._trigger_do_action(TRIGGER_ALARM_4) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("down", nova_service.state) # Undo - first self._trigger_undo_action(TRIGGER_ALARM_3) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("down", nova_service.state) # Undo - second self._trigger_undo_action(TRIGGER_ALARM_4) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("up", nova_service.state) finally: self._trigger_undo_action(TRIGGER_ALARM_3) self._trigger_undo_action(TRIGGER_ALARM_4) # nova.host datasource may take up to snapshot_interval to update time.sleep(130)
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 _do_test_action_mark_down_instance(self, trigger_name): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do self._trigger_do_action(trigger_name) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ERROR", nova_instance.status) # Undo self._trigger_undo_action(trigger_name) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ACTIVE", nova_instance.status) finally: self._trigger_undo_action(trigger_name) nova_utils.delete_all_instances(id=vm_id)
def _do_test_action_mark_down_host(self, trigger_name): try: host_name = self.orig_host.get(VProps.NAME) # Do self._trigger_do_action(trigger_name) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("down", nova_service.state) # Undo self._trigger_undo_action(trigger_name) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("up", nova_service.state) finally: self._trigger_undo_action(trigger_name) # nova.host datasource may take up to snapshot_intreval to update time.sleep(130)
def check_new_instances(ids): servers = TempestClients.nova().servers.list() for _id in ids: ok = False for s in servers: if _id == s.id and s.status.lower() == 'active': ok = True break if not ok: return False return True
def test_action_mark_down_instance(self): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do self._trigger_do_action(TRIGGER_ALARM_5) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ERROR", str(nova_instance.status)) # Undo self._trigger_undo_action(TRIGGER_ALARM_5) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ACTIVE", str(nova_instance.status)) except Exception as e: self._handle_exception(e) raise finally: pass self._trigger_undo_action(TRIGGER_ALARM_5) nova_utils.delete_all_instances(id=vm_id)
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 test_action_mark_down_host(self): try: host_name = self.orig_host.get(VProps.NAME) # Do self._trigger_do_action(TRIGGER_ALARM_4) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("down", str(nova_service.state)) # Undo self._trigger_undo_action(TRIGGER_ALARM_4) nova_service = TempestClients.nova().services.list( host=host_name, binary='nova-compute')[0] self.assertEqual("up", str(nova_service.state)) except Exception as e: self._handle_exception(e) raise finally: self._trigger_undo_action(TRIGGER_ALARM_4) # nova.host datasource may take up to snapshot_intreval to update time.sleep(130)
def test_execute_mistral_more_than_once(self): executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') num_executions = len(executions) # Make sure there are at least two instances in the environment nova_utils.create_instances(num_instances=2, set_public_network=True) num_instances = len(TempestClients.nova().servers.list()) # Add a template that executes the same Mistral workflow for every # instance. This should immediately trigger execute_mistral actions. template = None try: template = v_utils.add_template('v3_execute_mistral_twice.yaml') finally: if template: v_utils.delete_template(template['uuid']) # no longer needed time.sleep(2) # wait for the evaluator to process the new template # Verify that there is an execution for every instance executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') msg = "There are %d executions. Expected number of executions: %d " \ "(old number of executions) + %d (number of instances)" % \ (len(executions), num_executions, num_instances) self.assertThat(executions, HasLength(num_executions + num_instances), msg) executed_on_instances = set() for i in range(num_instances): # There may be many old executions in the list. The relevant ones # are at the end. Check the last `num_instances` executions. execution = \ self.mistral_client.executions.get(executions[-i].id) execution_input = jsonutils.loads(execution.input) executed_on_instances.add(execution_input['farewell']) msg = "There are %d instances in the graph but only %d distinct " \ "executions" % (num_instances, len(executed_on_instances)) self.assertThat(executed_on_instances, HasLength(num_instances), msg)
def check_deleted_instances(ids): servers = TempestClients.nova().servers.list() for s in servers: if s.id in ids: return False return True
def get_first_flavor(): return TempestClients.nova().flavors.list(sort_key='memory_mb')[0]
def _find_instance_resource_id(self): servers = TempestClients.nova().servers.list() return servers[0].id