def test_metadata_image_through_conductor(self): # There should be no links here, should default to None self.INSTANCE_PROPERTIES['image'] = {'id': 1} self.instance = FauxInstance(**self.INSTANCE_PROPERTIES) md = util._get_metadata_from_object(self.CONF, self.instance) self.assertEqual(1, md['image_ref']) self.assertIsNone(md['image_ref_url'])
def test_metadata_empty_image(self): self.INSTANCE_PROPERTIES['image'] = None self.instance = FauxInstance(**self.INSTANCE_PROPERTIES) md = util._get_metadata_from_object(self.instance) self.assertIsNone(md['image']) self.assertIsNone(md['image_ref']) self.assertIsNone(md['image_ref_url'])
def test_metadata_image_through_conductor(self): # There should be no links here, should default to None self.INSTANCE_PROPERTIES['image'] = {'id': 1} self.instance = FauxInstance(**self.INSTANCE_PROPERTIES) md = util._get_metadata_from_object(self.instance) self.assertEqual(1, md['image_ref']) self.assertIsNone(md['image_ref_url'])
def test_metadata_empty_image(self): self.INSTANCE_PROPERTIES['image'] = None self.instance = FauxInstance(**self.INSTANCE_PROPERTIES) md = util._get_metadata_from_object(self.CONF, self.instance) self.assertIsNone(md['image']) self.assertIsNone(md['image_ref']) self.assertIsNone(md['image_ref_url'])
def test_metadata(self): md = util._get_metadata_from_object(self.instance) for prop, value in six.iteritems(self.INSTANCE_PROPERTIES): if prop not in ("metadata"): # Special cases if prop == 'name': prop = 'display_name' elif prop == 'hostId': prop = "host" elif prop == 'OS-EXT-SRV-ATTR:instance_name': prop = 'name' self.assertEqual(value, md[prop]) user_metadata = md['user_metadata'] expected = self.INSTANCE_PROPERTIES[ 'metadata']['metering.autoscale.group'][:256] self.assertEqual(expected, user_metadata['autoscale_group']) self.assertEqual(1, len(user_metadata))
def test_metadata(self): md = util._get_metadata_from_object(self.instance) for prop, value in self.INSTANCE_PROPERTIES.iteritems(): if prop not in ("metadata"): # Special cases if prop == 'name': prop = 'display_name' elif prop == 'hostId': prop = "host" elif prop == 'OS-EXT-SRV-ATTR:instance_name': prop = 'name' self.assertEqual(value, md[prop]) user_metadata = md['user_metadata'] expected = self.INSTANCE_PROPERTIES[ 'metadata']['metering.autoscale.group'][:256] self.assertEqual(expected, user_metadata['autoscale_group']) self.assertEqual(1, len(user_metadata))
def test_metadata(self): md = util._get_metadata_from_object(self.instance) for prop, value in six.iteritems(self.INSTANCE_PROPERTIES): if prop not in ("metadata"): # Special cases if prop == "name": prop = "display_name" elif prop == "hostId": prop = "host" elif prop == "OS-EXT-SRV-ATTR:host": prop = "instance_host" elif prop == "OS-EXT-SRV-ATTR:instance_name": prop = "name" elif prop == "id": prop = "instance_id" self.assertEqual(value, md[prop]) user_metadata = md["user_metadata"] expected = self.INSTANCE_PROPERTIES["metadata"]["metering.autoscale.group"][:256] self.assertEqual(expected, user_metadata["autoscale_group"]) self.assertEqual(1, len(user_metadata))
def handle_delivery(channel, method, header, body): """Called when we receive a message from RabbitMQ""" print body LOG.info('CW -> Meter dequeued:\n%s', body) try: # JSON MESSAGE PARSING j = json.loads(body) METER_name = j['name'] METER_volume = j['volume'] METER_metadata = j[ 'additional_metadata'] #e.g.: {'geo_meter':'coord' } METER_unit = j['unit'] METER_type = j['type'] METER_timestamp = j['timestamp'] #METER_timestamp_format = datetime.datetime.fromtimestamp(METER_timestamp/1000.0).strftime('%Y-%m-%dT%H:%M:%SZ') # Y2 - NO UTC format #METER_timestamp_utc = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(METER_timestamp/1000.0)) # Y2 - UTC format #Y3 UTC TIMESTAMP CONVERSION METER_timestamp_utc = ( datetime.datetime.fromtimestamp(METER_timestamp / 1000.0) - UTC_OFFSET_TIMEDELTA).strftime('%Y-%m-%dT%H:%M:%S.%f') LOG.info("CW -> TIMESTAMP: %s -> %s", str(METER_timestamp), str(METER_timestamp_utc)) instance_uuid = j['probe_inst'] if j['probe_inst']: LOG.info("CW -> Getting instance information...") #Y2 #inst=getInstance(j['probe_inst']) #LOG.info("GET FROM getInstance: %s", inst); #Y3 inst = filter(lambda x: x.id == j['probe_inst'], instances)[0] LOG.info("CW ----> INSTANCE got from list: %s", inst) METER_resource_metadata = util._get_metadata_from_object(inst) METER_resource_metadata.update(METER_metadata) #LOG.info("CW -> INSTANCE SELECTED: %s with UUID %s", inst, instance_uuid) LOG.info('CW -> METER FROM %s : %s %s %s', instance_uuid, METER_name, METER_volume, METER_unit) # CEILOMETER SAMPLE CREATION new_sample = sample.Sample( name=METER_name, type=METER_type, unit=METER_unit, volume=METER_volume, user_id=inst.user_id, project_id=inst.tenant_id, resource_id=inst.id, timestamp=METER_timestamp_utc, resource_metadata=METER_resource_metadata, ) meter_pipe.publish_data(metering_context, [new_sample]) LOG.info("CW -> SAMPLE PUBLISHED!\n") else: LOG.info( "CW -> SAMPLE NO PUBLISHED: Nova client ERROR communication!\n" ) except Exception as ex: LOG.info( "CW -> WARNING IN SAMPLE PUBLISHING: NO INSTANCE FOR THE SAMPLE!!!!!!!!!!!!" ) LOG.info("\t\tWARNING: %s", ex)
def handle_delivery(channel, method, header, body): """Called when we receive a message from RabbitMQ""" print body LOG.info('CW -> Meter dequeued:\n%s', body) try: # JSON MESSAGE PARSING j = json.loads(body) METER_name = j['name'] METER_volume = j['volume'] METER_metadata = j['additional_metadata'] #e.g.: {'geo_meter':'coord' } METER_unit = j['unit'] METER_type = j['type'] METER_timestamp = j['timestamp'] #METER_timestamp_format = datetime.datetime.fromtimestamp(METER_timestamp/1000.0).strftime('%Y-%m-%dT%H:%M:%SZ') # Y2 - NO UTC format #METER_timestamp_utc = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(METER_timestamp/1000.0)) # Y2 - UTC format #Y3 UTC TIMESTAMP CONVERSION METER_timestamp_utc = (datetime.datetime.fromtimestamp(METER_timestamp/1000.0) - UTC_OFFSET_TIMEDELTA).strftime('%Y-%m-%dT%H:%M:%S.%f') LOG.info("CW -> TIMESTAMP: %s -> %s", str(METER_timestamp), str(METER_timestamp_utc)) instance_uuid = j['probe_inst'] if j['probe_inst']: LOG.info("CW -> Getting instance information...") #Y2 #inst=getInstance(j['probe_inst']) #LOG.info("GET FROM getInstance: %s", inst); #Y3 inst = filter(lambda x: x.id == j['probe_inst'], instances)[0] LOG.info("CW ----> INSTANCE got from list: %s", inst); METER_resource_metadata = util._get_metadata_from_object(inst) METER_resource_metadata.update(METER_metadata) #LOG.info("CW -> INSTANCE SELECTED: %s with UUID %s", inst, instance_uuid) LOG.info('CW -> METER FROM %s : %s %s %s', instance_uuid, METER_name, METER_volume, METER_unit) # CEILOMETER SAMPLE CREATION new_sample = sample.Sample( name=METER_name, type=METER_type, unit=METER_unit, volume=METER_volume, user_id=inst.user_id, project_id=inst.tenant_id, resource_id=inst.id, timestamp=METER_timestamp_utc, resource_metadata=METER_resource_metadata, ) meter_pipe.publish_data(metering_context,[new_sample]) LOG.info("CW -> SAMPLE PUBLISHED!\n") else: LOG.info("CW -> SAMPLE NO PUBLISHED: Nova client ERROR communication!\n") except Exception as ex: LOG.info("CW -> WARNING IN SAMPLE PUBLISHING: NO INSTANCE FOR THE SAMPLE!!!!!!!!!!!!") LOG.info("\t\tWARNING: %s", ex)