def setUp(self): super(SQLAlchemyEngineSubBase, self).setUp() self.conf = cfg.CONF self.conf.database_connection = 'sqlite://' # Use a real MySQL server if we can connect, but fall back # to a Sqlite in-memory connection if we cannot. if CEILOMETER_TEST_LIVE: # should pull from conf file but for now manually specified # just make sure ceilometer_test db exists in mysql self.conf.database_connection = MYSQL_URL engine = sqlalchemy.create_engine(MYSQL_BASE_URL) engine_conn = engine.connect() try: engine_conn.execute('drop database %s' % MYSQL_DBNAME) except sqlalchemy.exc.OperationalError: pass engine_conn.execute('create database %s' % MYSQL_DBNAME) self.conn = Connection(self.conf) self.session = self.conn.session migration.db_sync()
def setUp(self): super(SQLAlchemyEngineTestBase, self).setUp() self.conf = cfg.CONF self.conf.database_connection = 'sqlite://' # Use a real MySQL server if we can connect, but fall back # to a Sqlite in-memory connection if we cannot. if CEILOMETER_TEST_LIVE: # should pull from conf file but for now manually specified # just make sure ceilometer_test db exists in mysql self.conf.database_connection = MYSQL_URL self.conn = Connection(self.conf) self.session = self.conn.session migration.db_sync() self.counter = counter.Counter( 'instance', counter.TYPE_CUMULATIVE, volume=1, user_id='user-id', project_id='project-id', resource_id='resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } ) self.msg1 = meter.meter_message_from_counter(self.counter, cfg.CONF.metering_secret, 'test-1', ) self.conn.record_metering_data(self.msg1) self.counter2 = counter.Counter( 'instance', counter.TYPE_CUMULATIVE, volume=1, user_id='user-id', project_id='project-id', resource_id='resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } ) self.msg2 = meter.meter_message_from_counter(self.counter2, cfg.CONF.metering_secret, 'test-2', ) self.conn.record_metering_data(self.msg2) self.counter3 = counter.Counter( 'instance', counter.TYPE_CUMULATIVE, volume=1, user_id='user-id-alternate', project_id='project-id', resource_id='resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter3', } ) self.msg3 = meter.meter_message_from_counter(self.counter3, cfg.CONF.metering_secret, 'test-3', ) self.conn.record_metering_data(self.msg3) for i in range(2, 4): c = counter.Counter( 'instance', counter.TYPE_CUMULATIVE, 1, 'user-id-%s' % i, 'project-id-%s' % i, 'resource-id-%s' % i, timestamp=datetime.datetime(2012, 7, 2, 10, 40 + i), resource_metadata={'display_name': 'test-server', 'tag': 'counter-%s' % i, } ) msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret, 'test') self.conn.record_metering_data(msg)