def test_oswl_get_last_by_cluster_id_resource_type(self): cluster_id = 1 dt = datetime.datetime.utcnow() obj_data = { 'cluster_id': cluster_id, 'resource_type': consts.OSWL_RESOURCE_TYPES.vm, 'created_date': dt.date(), 'updated_time': dt.time(), 'resource_checksum': "" } obj = OpenStackWorkloadStats.create(obj_data) self.assertEqual( OpenStackWorkloadStats.get_last_by(cluster_id, consts.OSWL_RESOURCE_TYPES.vm), obj) self.assertIsNone( OpenStackWorkloadStats.get_last_by(0, consts.OSWL_RESOURCE_TYPES.vm)) self.assertIsNone( OpenStackWorkloadStats.get_last_by( cluster_id, consts.OSWL_RESOURCE_TYPES.tenant)) OpenStackWorkloadStats.delete(obj) self.assertIsNone( OpenStackWorkloadStats.get_last_by(cluster_id, consts.OSWL_RESOURCE_TYPES.vm))
def test_oswl_get_last_by_cluster_id_resource_type(self): cluster_id = 1 dt = datetime.datetime.utcnow() obj_data = { 'cluster_id': cluster_id, 'resource_type': consts.OSWL_RESOURCE_TYPES.vm, 'created_date': dt.date(), 'updated_time': dt.time(), 'resource_checksum': "" } obj = OpenStackWorkloadStats.create(obj_data) self.assertEqual( OpenStackWorkloadStats.get_last_by( cluster_id, consts.OSWL_RESOURCE_TYPES.vm), obj ) self.assertIsNone( OpenStackWorkloadStats.get_last_by( 0, consts.OSWL_RESOURCE_TYPES.vm) ) self.assertIsNone( OpenStackWorkloadStats.get_last_by( cluster_id, consts.OSWL_RESOURCE_TYPES.tenant) ) OpenStackWorkloadStats.delete(obj) self.assertIsNone( OpenStackWorkloadStats.get_last_by( cluster_id, consts.OSWL_RESOURCE_TYPES.vm) )
def test_oswl_get_last_by_cluster_id_resource_type(self): cluster = self.env.create(nodes_kwargs=[{ 'roles': ['compute'] }, { 'roles': ['compute'] }, { 'roles': ['controller'] }]) dt = datetime.datetime.utcnow() obj_data = { 'cluster_id': cluster['id'], 'resource_type': consts.OSWL_RESOURCE_TYPES.vm, 'created_date': dt.date(), 'updated_time': dt.time(), 'resource_checksum': "" } obj = OpenStackWorkloadStats.create(obj_data) self.assertEqual( OpenStackWorkloadStats.get_last_by(cluster['id'], consts.OSWL_RESOURCE_TYPES.vm), obj) self.assertIsNone( OpenStackWorkloadStats.get_last_by(0, consts.OSWL_RESOURCE_TYPES.vm)) self.assertIsNone( OpenStackWorkloadStats.get_last_by( cluster['id'], consts.OSWL_RESOURCE_TYPES.tenant)) OpenStackWorkloadStats.delete(obj) self.assertIsNone( OpenStackWorkloadStats.get_last_by(cluster['id'], consts.OSWL_RESOURCE_TYPES.vm))
def check_oswl_data_send_result(self, send_data_to_url, status, is_sent): # make yesterdays record (today's will not be sent) dt = datetime.datetime.utcnow() - datetime.timedelta(days=1) obj_data = { 'cluster_id': 1, 'resource_type': consts.OSWL_RESOURCE_TYPES.vm, 'created_date': dt.date(), 'updated_time': dt.time(), 'resource_checksum': "" } obj = OpenStackWorkloadStats.create(obj_data) self.assertEqual( OpenStackWorkloadStats.get_last_by( 1, consts.OSWL_RESOURCE_TYPES.vm), obj ) rec_id = obj.id self.assertEqual(obj.is_sent, False) # emulate the answer from requests.post() class response(object): status_code = 200 data = { "status": "ok", "text": "ok", "oswl_stats": [{ "master_node_uid": "", "id": rec_id, "status": status }] } def __getitem__(self, key): return self.data[key] @classmethod def json(cls): return cls.data send_data_to_url.return_value = response sender = StatsSender() sender.send_oswl_info() obj_data_sent = {'oswl_stats': [{ 'id': rec_id, 'cluster_id': 1, 'created_date': dt.date().isoformat(), 'updated_time': dt.time().isoformat(), 'resource_type': 'vm', 'resource_checksum': '', 'master_node_uid': None, 'resource_data': None, }]} send_data_to_url.assert_called_once_with( url=sender.build_collector_url("COLLECTOR_OSWL_INFO_URL"), data=obj_data_sent) obj = OpenStackWorkloadStats.get_last_by( 1, consts.OSWL_RESOURCE_TYPES.vm) self.assertEqual(obj.is_sent, is_sent) OpenStackWorkloadStats.delete(obj) send_data_to_url.reset_mock()
def check_oswl_data_send_result(self, send_data_to_url, status, is_sent): # make yesterdays record (today's will not be sent) dt = datetime.datetime.utcnow() - datetime.timedelta(days=1) obj_data = { 'cluster_id': 1, 'resource_type': consts.OSWL_RESOURCE_TYPES.vm, 'created_date': dt.date(), 'updated_time': dt.time(), 'resource_checksum': "" } obj = OpenStackWorkloadStats.create(obj_data) self.assertEqual( OpenStackWorkloadStats.get_last_by(1, consts.OSWL_RESOURCE_TYPES.vm), obj) rec_id = obj.id self.assertEqual(obj.is_sent, False) # emulate the answer from requests.post() class response(object): status_code = 200 data = { "status": "ok", "text": "ok", "oswl_stats": [{ "master_node_uid": "", "id": rec_id, "status": status }] } def __getitem__(self, key): return self.data[key] @classmethod def json(cls): return cls.data send_data_to_url.return_value = response sender = StatsSender() sender.send_oswl_info() obj_data_sent = { 'oswl_stats': [{ 'id': rec_id, 'cluster_id': 1, 'created_date': dt.date().isoformat(), 'updated_time': dt.time().isoformat(), 'resource_type': 'vm', 'resource_checksum': '', 'master_node_uid': None, 'resource_data': None, }] } send_data_to_url.assert_called_once_with( url=sender.build_collector_url("COLLECTOR_OSWL_INFO_URL"), data=obj_data_sent) obj = OpenStackWorkloadStats.get_last_by(1, consts.OSWL_RESOURCE_TYPES.vm) self.assertEqual(obj.is_sent, is_sent) OpenStackWorkloadStats.delete(obj) send_data_to_url.reset_mock()