def test_node_gpu_relation(self): """ Unit test that verifies that the correct relation between the GPU class and the node class is built """ # We create a node node = Node() node.name = "node1" node.information_retrieved = True # We add several CPUs to it node.gpus = [ GPU("Nvidia", "GeForce"), GPU("AMD", "Raedon") ] # We save everything to the db db.session.add(node) db.session.commit() # We retrived and verify that the gpus are there node = db.session.query(Node).filter_by(name='node1').first() self.assertEquals(2, len(node.gpus)) self.assertEquals("Nvidia", node.gpus[0].vendor_id) self.assertEquals("AMD", node.gpus[1].vendor_id) # Lets delete a gpu directly from the session db.session.delete(node.gpus[1]) db.session.commit() node = db.session.query(Node).filter_by(name='node1').first() self.assertEquals(1, len(node.gpus)) self.assertEquals("Nvidia", node.gpus[0].vendor_id)
def test_crud_gpu(self): """ It tests the basic CRUD operations of an GPU class """ # We erify the object is not in the db after creating it gpu = GPU("NVIDIA", "GF110GL") self.assertIsNone(gpu.id) # We store the object in the db db.session.add(gpu) # We recover the GPU from the db gpu = db.session.query(GPU).filter_by(vendor_id='NVIDIA').first() self.assertIsNotNone(gpu.id) self.assertEquals("NVIDIA", gpu.vendor_id) self.assertEquals("GF110GL", gpu.model_name) # We update the gpu gpu.vendor_id = "AMD" db.session.commit() gpu = db.session.query(GPU).filter_by(vendor_id='AMD').first() self.assertEquals("AMD", gpu.vendor_id) # We check the deletion db.session.delete(gpu) count = db.session.query(GPU).filter_by(vendor_id='AMD').count() self.assertEquals(0, count)
def test_init_methods(self): """Checks that the variables are correctly set""" # Processor class processor = Processor("x1", "x2") self.assertEquals("x1", processor.vendor_id) self.assertEquals("x2", processor.model_name) # CPU class cpu = CPU("Intel", "Xeon", "x86_64", "e6333", "2600Mhz", "yes", 2, "cache", "111") self.assertEquals("Intel", cpu.vendor_id) self.assertEquals("Xeon", cpu.model_name) self.assertEquals("x86_64", cpu.arch) self.assertEquals("2600Mhz", cpu.speed) self.assertEquals("yes", cpu.fpu) self.assertEquals(2, cpu.cores) self.assertEquals("cache", cpu.cache) self.assertEquals("111", cpu.flags) # GPU gpu = GPU("AMD", "Raedon") self.assertEquals("AMD", gpu.vendor_id) self.assertEquals("Raedon", gpu.model_name) self.assertEquals([], gpu.memory) # MCP mcp = MCP("Intel", "Phi") self.assertEquals("Intel", mcp.vendor_id) self.assertEquals("Phi", mcp.model_name) self.assertEquals([], mcp.memory)
def add_gpu(self): """ Just adds a gpu object for add gpu and remove gpu tests""" # We add one element to the node gpu = GPU("NVIDIA", "Maxwell") self.node.add_gpu(gpu) return gpu
def find_gpu_slurm(model_code_slurm): """ This function will look at the internal json gpu inventory and look for the GPU that has the same "model_code_slurm" field and return a GPU object """ with open(GPU_FILE) as data_file: gpus = json.load(data_file) gpu = next((gpu for gpu in gpus if gpu['model_code_slurm'] == model_code_slurm), None) if gpu: return GPU(vendor_id=gpu['vendor_id'], model_name=gpu['model_name']) else: return None
def find_gpu(model_code: str, field): """ This function will look at the internal json gpu inventory and look for the GPU that has the same value of the given field as model_code and return a GPU object """ with open(GPU_FILE) as data_file: gpus = json.load(data_file) gpu = next((gpu for gpu in gpus if gpu[field] == model_code), None) if gpu: return GPU(vendor_id=gpu['vendor_id'], model_name=gpu['model_name']) else: return None
def test_remove_memory(self): """We verify it is possible to delete a memory element""" # We create an initial GPU gpu = GPU("NVIDIA", "GF110GL") print(len(gpu.memory)) self.assertEquals(0, len(gpu.memory)) # We add a Memory element memory = Memory(1111, "kilobytes") gpu.add_memory(memory) self.assertEquals(1, len(gpu.memory)) # We remove it gpu.remove_memory(memory) self.assertEquals(0, len(gpu.memory)) # We verify that removing an inexistent elements gives no error gpu.remove_memory("xxx") self.assertEquals(0, len(gpu.memory))
def test_add_memory_gpu(self): """Test that we can correctly add memory to a GPU moemory array""" # We create an initial GPU gpu = GPU("NVIDIA", "GF110GL") self.assertEquals(0, len(gpu.memory)) # We add a Memory element memory = Memory(1111, "kilobytes") gpu.add_memory(memory) self.assertEquals(1, len(gpu.memory)) self.assertEquals(memory, gpu.memory[0]) # We verify that we can not add memory of the wrong type gpu.add_memory("xxx") self.assertEquals(1, len(gpu.memory)) self.assertEquals(memory, gpu.memory[0])