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 _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'] script_dir = os.path.dirname(__file__) rel_path = "../templates/nova_cuf.xml" abs_file_path = os.path.join(script_dir, rel_path) f = open(abs_file_path) cuf_xml = f.read().format(**cuf_xml_values) return cuf_xml