def test_process_delete(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test deleting a system.""" msg_dict = {'id': A_SYSTEM_DELETE['id'] + '1'} with DatabasePool(1): # make sure system is in DB system_copy = deepcopy(A_SYSTEM) system_copy['host']['id'] += '1' db_import_system(system_copy, system_copy['vmaas-json'], []) # delete the system with caplog.at_level(logging.INFO): process_delete(msg_dict) assert caplog.records[0].msg.startswith( "Deleted system with inventory_id:") caplog.clear() # try to delete the system again with caplog.at_level(logging.INFO): process_delete(msg_dict) assert caplog.records[0].msg.startswith( "Unable to delete system, inventory_id not found:") caplog.clear() with caplog.at_level(logging.WARNING): db_import_system(system_copy, system_copy['vmaas-json'], []) assert caplog.records[0].msg.startswith( 'Received recently deleted inventory id:') caplog.clear()
def test_process_update(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test updating a system.""" with DatabasePool(1): # make sure system is in DB db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) # update the system with caplog.at_level(logging.INFO): process_update(A_SYSTEM_UPDATE) assert caplog.records[0].msg.startswith( "Updated system with inventory_id:") caplog.clear() # try to update system with non-existing id with caplog.at_level(logging.INFO): process_update({ 'host': { 'id': '1-XXX', 'display_name': 'new.example.com' } }) assert caplog.records[0].msg.startswith( 'Unable to update system, inventory_id not found: ') caplog.clear()
def test_process_delete(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test deleting a system.""" msg_dict = { 'id': '0c32021e-8af8-4186-afb4-0255a71ece96', 'account': A_SYSTEM_DELETE['account'] } with DatabasePool(1): # make sure system is in DB system_copy = deepcopy(A_SYSTEM) system_copy['host']['id'] = msg_dict['id'] db_import_system(system_copy, system_copy['vmaas-json'], []) # delete the system with caplog.at_level(logging.INFO): process_delete(msg_dict) assert caplog.records[0].msg.startswith( "Deleted system with inventory_id:") caplog.clear() with caplog.at_level(logging.WARNING): db_import_system(system_copy, system_copy['vmaas-json'], []) assert caplog.records[0].msg.startswith( 'Received recently deleted inventory id:') caplog.clear()
def test_delete_system(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test deleting a system.""" with DatabasePool(1): # make sure system is in DB db_import_system(A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) # now delete the system rtrn = db_delete_system(A_SYSTEM['inv-id']) assert rtrn['deleted'] assert not rtrn['failed'] # try to delete it again rtrn = db_delete_system(A_SYSTEM['inv-id']) assert not rtrn['deleted'] assert not rtrn['failed'] # try to delete system with invalid id with caplog.at_level(logging.ERROR): rtrn = db_delete_system(0) assert not rtrn['deleted'] assert rtrn['failed'] assert caplog.records[0].msg.startswith("Error deleting system:") caplog.clear()
def test_import_system(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test importing a system not-in-the-db, followed by same so it's-already-there""" # new system with DatabasePool(1): rtrn = db_import_system(A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert rtrn['inserted'] assert rtrn['changed'] assert not rtrn['updated'] # And now it's an rtrn['updated'], but same json rtrn = db_import_system(A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert not rtrn['inserted'] assert rtrn['updated'] assert not rtrn['changed'] # And now it's another rtrn['updated'], same json rtrn = db_import_system(A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert not rtrn['inserted'] assert rtrn['updated'] assert not rtrn['changed'] # And now it's an rtrn['updated'], with diff json rtrn = db_import_system(A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'] + '-1', A_SYSTEM['managed']) assert not rtrn['inserted'] assert rtrn['updated'] assert rtrn['changed'] # And try to import system with invalid inventory id with caplog.at_level(logging.ERROR): rtrn = db_import_system(None, A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert caplog.records[0].msg.startswith("Error importing system:") caplog.clear()
def test_import_system(self, pg_db_conn): """Test importing a system not-in-the-db, followed by same so it's-already-there""" # new system (inserted, updated) = db_import_system(pg_db_conn, A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert inserted assert not updated # And now it's an update (inserted, updated) = db_import_system(pg_db_conn, A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) assert not inserted assert updated
def test_process_delete(self, pg_db_conn, caplog): """Test deleting a system.""" msg_dict = {'id': A_SYSTEM['inv-id']} # make sure system is in DB db_import_system(pg_db_conn, A_SYSTEM['inv-id'], A_SYSTEM['rh-acct'], A_SYSTEM['s3-url'], A_SYSTEM['vmaas-json'], A_SYSTEM['managed']) # delete the system with caplog.at_level(logging.INFO): process_delete(msg_dict, pg_db_conn) assert caplog.records[0].msg.startswith("Deleted system with inventory_id:") caplog.clear() # try to delete the system again with caplog.at_level(logging.INFO): process_delete(msg_dict, pg_db_conn) assert caplog.records[0].msg.startswith("Unable to delete system, inventory_id not found:") caplog.clear()
def test_update_system(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test updating a system.""" with DatabasePool(1): # make sure system is in DB db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) # now update the system rtrn = db_update_system(A_SYSTEM_UPDATE) assert rtrn['updated'] assert not rtrn['failed'] # try to update system with non-existing id rtrn = db_update_system( {'host': { 'id': '1-XXX', 'display_name': 'new.example.com' }}) assert not rtrn['updated'] assert not rtrn['failed'] caplog.clear()
def test_delete_system(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test deleting a system.""" with DatabasePool(1): # make sure system is in DB db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) # now delete the system rtrn = db_delete_system(A_SYSTEM_DELETE) assert rtrn['deleted'] assert not rtrn['failed'] # and again, same result, because the record in system_platform still exists rtrn = db_delete_system(A_SYSTEM_DELETE) assert rtrn['deleted'] assert not rtrn['failed'] # try to delete system with non-existing id rtrn = db_delete_system({'id': '0', 'account': 'NEW-ACCT'}) assert not rtrn['deleted'] assert not rtrn['failed'] caplog.clear()
def test_import_system(self, pg_db_conn, caplog): # pylint: disable=unused-argument """Test importing a system not-in-the-db, followed by same so it's-already-there""" # new system with DatabasePool(1): rtrn = db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) assert ImportStatus.INSERTED | ImportStatus.CHANGED == rtrn self._mark_evaluated(A_SYSTEM['host']['id']) # And now it's an rtrn['updated'], but same json rtrn = db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) assert ImportStatus.UPDATED == rtrn # And now it's another rtrn['updated'], same json rtrn = db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'], []) assert ImportStatus.UPDATED == rtrn # And now it's an rtrn['updated'], with diff json rtrn = db_import_system(A_SYSTEM, A_SYSTEM['vmaas-json'] + '-1', []) assert ImportStatus.UPDATED | ImportStatus.CHANGED == rtrn # And try to import system with invalid inventory id with caplog.at_level(logging.ERROR): system_copy = deepcopy(A_SYSTEM) system_copy['host']['id'] = None db_import_system(system_copy, A_SYSTEM['vmaas-json'], []) assert caplog.records[0].msg.startswith("Error importing system:") caplog.clear()