コード例 #1
0
    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", str(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", str(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", str(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", str(nova_service.state))
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._trigger_undo_action(TRIGGER_ALARM_3)
            self._trigger_undo_action(TRIGGER_ALARM_4)
            # nova.host datasource may take up to snapshot_intreval to update
            time.sleep(130)
コード例 #2
0
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)
コード例 #3
0
    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_3)
            nova_instance = TempestClients.nova().servers.get(vm_id)
            self.assertEqual("ERROR", str(nova_instance.status))

            # Undo
            self._trigger_undo_action(TRIGGER_ALARM_3)
            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_3)
            nova_utils.delete_all_instances(id=vm_id)
コード例 #4
0
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
コード例 #5
0
def _check_num_instances(num_instances=0, state=''):
    if len(TempestClients.nova().servers.list()) != num_instances:
        return False

    return all(instance.__dict__['status'].upper() == state.upper()
               for instance in TempestClients.nova().servers.list())
コード例 #6
0
def get_first_flavor():
    return TempestClients.nova().flavors.list()[0]
コード例 #7
0
ファイル: test_aodh.py プロジェクト: pczerkas/vitrage
 def _find_instance_resource_id(self):
     servers = TempestClients.nova().servers.list()
     return servers[0].id