def test_different_time_formats_should_not_raise_exception(self): payload_json = { 'tenant_id': '2882', 'access_ip_v4': '5.79.20.138', 'access_ip_v6': '2a00:1a48:7804:0110:a8a0:fa07:ff08:157a', 'audit_period_beginning': '2012-09-15T10:51:11Z', 'audit_period_ending': '2012-09-16 10:51:11', 'audit_period_ending': '2012-09-16T10:51:11.799674', 'bandwidth': { 'private': { 'bw_in': 0, 'bw_out': 264902 }, 'public': { 'bw_in': 1001, 'bw_out': 19992 } }, 'image_meta': { 'com.rackspace__1__options': '1' }, 'instance_id': '56', 'dummy_flavor_field_name': '10', 'launched_at': '2012-09-15 11:51:11', 'deleted_at': '', 'instance_type': 'm1.nano', 'state': 'active', 'state_description': '' } payload = NotificationPayload(payload_json) self.assertEquals(payload.end_time, datetime.datetime(2012, 9, 16, 10, 51, 11, 799674))
def test_end_time_should_be_audit_period_ending_when_deleted_at_is_empty( self): payload_json = { 'tenant_id': '2882', 'access_ip_v4': '5.79.20.138', 'access_ip_v6': '2a00:1a48:7804:0110:a8a0:fa07:ff08:157a', 'audit_period_beginning': '2012-09-15 10:51:11', 'audit_period_ending': '2012-09-16 10:51:11', 'bandwidth': { 'private': { 'bw_in': 0, 'bw_out': 264902 }, 'public': { 'bw_in': 1001, 'bw_out': 19992 } }, 'image_meta': { 'com.rackspace__1__options': '1' }, 'instance_id': '56', 'instance_type_id': '10', 'launched_at': '2012-09-15 11:51:11', 'deleted_at': '' } payload = NotificationPayload(payload_json) self.assertEquals(payload.end_time, '2012-09-16 10:51:11')
def test_end_time_should_get_min_of_deleted_at_and_audit_period_ending( self): payload_json = { 'tenant_id': '2882', 'access_ip_v4': '5.79.20.138', 'access_ip_v6': '2a00:1a48:7804:0110:a8a0:fa07:ff08:157a', 'audit_period_beginning': '2012-09-15 10:51:11', 'audit_period_ending': '2012-09-16 10:51:11', 'bandwidth': { 'private': { 'bw_in': 0, 'bw_out': 264902 }, 'public': { 'bw_in': 1001, 'bw_out': 19992 } }, 'image_meta': { 'com.rackspace__1__options': '1' }, 'instance_id': '56', 'dummy_flavor_field_name': '10', 'launched_at': '2012-09-15 11:51:11', 'deleted_at': '2012-09-15 09:51:11', 'instance_type': 'm1.nano', 'state': 'active', 'state_description': '' } payload = NotificationPayload(payload_json) self.assertEquals(str(payload.end_time), '2012-09-15 09:51:11')
def _create_cuf_xml(self, deployment_info, json_body): payload = NotificationPayload(json_body['payload']) notification_options = {'com.rackspace__1__options': payload.options} cuf_xml_values = NotificationOptions( notification_options).to_cuf_options() cuf_xml_values['bandwidth_in'] = payload.bandwidth_in cuf_xml_values['bandwidth_out'] = payload.bandwidth_out cuf_xml_values['start_time'] = payload.start_time cuf_xml_values['end_time'] = payload.end_time cuf_xml_values['tenant_id'] = payload.tenant_id cuf_xml_values['instance_id'] = payload.instance_id cuf_xml_values['id'] = json_body['_unique_id'] cuf_xml_values['flavor'] = payload.flavor cuf_xml_values['data_center'] = deployment_info['data_center'] cuf_xml_values['region'] = deployment_info['region'] cuf_xml = nova_cuf_template % cuf_xml_values return cuf_xml
def _create_cuf_xml(self, json_body): payload = NotificationPayload(json_body['payload']) notification_options = {'com.rackspace__1__options': payload.options} cuf_xml_values = {} cuf_xml_values['options_string'] = NotificationOptions( notification_options).to_cuf_options() cuf_xml_values['bandwidth_in'] = payload.bandwidth_in cuf_xml_values['bandwidth_out'] = payload.bandwidth_out cuf_xml_values['start_time'] = datetime.datetime.strftime( payload.start_time, atom_hopper_time_format) cuf_xml_values['end_time'] = datetime.datetime.strftime( payload.end_time, atom_hopper_time_format) cuf_xml_values['tenant_id'] = payload.tenant_id cuf_xml_values['instance_id'] = payload.instance_id cuf_xml_values['instance_name'] = payload.instance_name cuf_xml_values['id'] = self.generate_new_id() cuf_xml_values['flavor_id'] = payload.flavor_id cuf_xml_values['flavor_name'] = payload.flavor_name cuf_xml_values['status'] = payload.status cuf_xml_values['data_center'] = self.data_center cuf_xml_values['region'] = self.region cuf_xml = nova_cuf_template % cuf_xml_values return cuf_xml