Exemplo n.º 1
0
 def tearDown(cls):
     """Remove test resources."""
     logging.info('Running teardown')
     cache_wait = False
     for alarm in cls.aodh_client.alarm.list():
         if alarm['name'].startswith(cls.RESOURCE_PREFIX):
             cache_wait = True
             logging.info('Removing Alarm {}'.format(alarm['name']))
             telemetry_utils.delete_alarm(cls.aodh_client,
                                          alarm['name'],
                                          cache_wait=False)
     if cache_wait:
         logging.info('Waiting for alarm cache to clear')
         telemetry_utils.alarm_cache_wait()
Exemplo n.º 2
0
 def resource_cleanup(cls):
     """Remove test resources."""
     logging.info('Running teardown')
     for alarm in cls.aodh_client.alarm.list():
         if alarm['name'].startswith(cls.RESOURCE_PREFIX):
             logging.info('Removing Alarm {}'.format(alarm['name']))
             telemetry_utils.delete_alarm(
                 cls.aodh_client,
                 alarm['name'],
                 cache_wait=False)
     for server in cls.nova_client.servers.list():
         if server.name.startswith(cls.RESOURCE_PREFIX):
             logging.info('Removing server {}'.format(server.name))
             openstack_utils.delete_resource(
                 cls.nova_client.servers,
                 server.id,
                 msg="server")
Exemplo n.º 3
0
    def test_alarm_on_power_off(self):
        """Test server alarm is triggered when server is powered off."""
        server_name = '{}-server'.format(self.RESOURCE_PREFIX)
        alarm_name = '{}_instance_off'.format(self.RESOURCE_PREFIX)
        try:
            server = self.nova_client.servers.find(name=server_name)
            logging.info("Found existing server {}".format(server_name))
        except novaclient.exceptions.NotFound:
            logging.info("Launching new server {}".format(server_name))
            server = zaza.openstack.configure.guest.launch_instance(
                glance_setup.LTS_IMAGE_NAME,
                vm_name=server_name)
        assert server.status == 'ACTIVE', "Server {} not active".format(
            server.name)

        logging.info('Deleting alarm {} if it exists'.format(alarm_name))
        telemetry_utils.delete_alarm(
            self.aodh_client,
            alarm_name,
            cache_wait=True)
        logging.info('Creating alarm {}'.format(alarm_name))
        alarm_info = telemetry_utils.create_server_power_off_alarm(
            self.aodh_client,
            alarm_name,
            server.id)
        alarm_state = telemetry_utils.get_alarm_state(
            self.aodh_client,
            alarm_info['alarm_id'])
        logging.info('Alarm in state {}'.format(alarm_state))
        # Until data is collected alarm come up in an 'insufficient data'
        # state.
        self.assertEqual(alarm_state, 'insufficient data')
        logging.info('Stopping server {}'.format(server.name))
        server.stop()
        telemetry_utils.block_until_alarm_state(
            self.aodh_client,
            alarm_info['alarm_id'])