'Test list_nodes functionality.'

def test_list_nodes(self):

    nodes = self.driver.list_nodes()
    self.assertEqual(len(nodes), 3)
    node = nodes[0]
    self.assertEqual(node.id, '5')
    self.assertEqual(node.name, 'Compute    5')
    self.assertEqual(node.state, OpenNebulaNodeDriver.NODE_STATE_MAP['ACTIVE'])
    self.assertEqual(node.public_ips[0].id, '5')
    self.assertEqual(node.public_ips[0].name, 'Network    5')
    self.assertEqual(node.public_ips[0].address, '192.168.0.1')
    self.assertEqual(node.public_ips[0].size, 1)
    self.assertEqual(node.public_ips[0].extra['mac'], '02:00:c0:a8:00:01')
    self.assertEqual(node.public_ips[1].id, '15')
    self.assertEqual(node.public_ips[1].name, 'Network    15')
    self.assertEqual(node.public_ips[1].address, '192.168.1.1')
    self.assertEqual(node.public_ips[1].size, 1)
    self.assertEqual(node.public_ips[1].extra['mac'], '02:00:c0:a8:01:01')
    self.assertEqual(node.private_ips, [])
    self.assertTrue((len([size for size in self.driver.list_sizes() if (size.id == node.size.id)]) == 1))
    self.assertEqual(node.size.id, '1')
    self.assertEqual(node.size.name, 'small')
    self.assertEqual(node.size.ram, 1024)
    self.assertTrue(((node.size.cpu is None) or isinstance(node.size.cpu, int)))
    self.assertTrue(((node.size.vcpu is None) or isinstance(node.size.vcpu, int)))
    self.assertEqual(node.size.cpu, 1)
    self.assertEqual(node.size.vcpu, None)
    self.assertEqual(node.size.disk, None)
    self.assertEqual(node.size.bandwidth, None)
    self.assertEqual(node.size.price, None)
    self.assertTrue((len([image for image in self.driver.list_images() if (image.id == node.image.id)]) == 1))
    self.assertEqual(node.image.id, '5')
    self.assertEqual(node.image.name, 'Ubuntu    9.04    LAMP')
    self.assertEqual(node.image.extra['type'], 'DISK')
    self.assertEqual(node.image.extra['target'], 'hda')
    context = node.extra['context']
    self.assertEqual(context['hostname'], 'compute-5')
    node = nodes[1]
    self.assertEqual(node.id, '15')
    self.assertEqual(node.name, 'Compute    15')
    self.assertEqual(node.state, OpenNebulaNodeDriver.NODE_STATE_MAP['ACTIVE'])
    self.assertEqual(node.public_ips[0].id, '5')
    self.assertEqual(node.public_ips[0].name, 'Network    5')
    self.assertEqual(node.public_ips[0].address, '192.168.0.2')
    self.assertEqual(node.public_ips[0].size, 1)
    self.assertEqual(node.public_ips[0].extra['mac'], '02:00:c0:a8:00:02')
    self.assertEqual(node.public_ips[1].id, '15')
    self.assertEqual(node.public_ips[1].name, 'Network    15')
    self.assertEqual(node.public_ips[1].address, '192.168.1.2')
    self.assertEqual(node.public_ips[1].size, 1)
    self.assertEqual(node.public_ips[1].extra['mac'], '02:00:c0:a8:01:02')
    self.assertEqual(node.private_ips, [])
    self.assertTrue((len([size for size in self.driver.list_sizes() if (size.id == node.size.id)]) == 1))
    self.assertEqual(node.size.id, '1')
    self.assertEqual(node.size.name, 'small')
    self.assertEqual(node.size.ram, 1024)
    self.assertTrue(((node.size.cpu is None) or isinstance(node.size.cpu, int)))
    self.assertTrue(((node.size.vcpu is None) or isinstance(node.size.vcpu, int)))
    self.assertEqual(node.size.cpu, 1)
    self.assertEqual(node.size.vcpu, None)
    self.assertEqual(node.size.disk, None)
    self.assertEqual(node.size.bandwidth, None)
    self.assertEqual(node.size.price, None)
    self.assertTrue((len([image for image in self.driver.list_images() if (image.id == node.image.id)]) == 1))
    self.assertEqual(node.image.id, '15')
    self.assertEqual(node.image.name, 'Ubuntu    9.04    LAMP')
    self.assertEqual(node.image.extra['type'], 'DISK')
    self.assertEqual(node.image.extra['target'], 'hda')
    context = node.extra['context']
    self.assertEqual(context['hostname'], 'compute-15')
    node = nodes[2]
    self.assertEqual(node.id, '25')
    self.assertEqual(node.name, 'Compute    25')
    self.assertEqual(node.state, NodeState.UNKNOWN)
    self.assertEqual(node.public_ips[0].id, '5')
    self.assertEqual(node.public_ips[0].name, 'Network    5')
    self.assertEqual(node.public_ips[0].address, '192.168.0.3')
    self.assertEqual(node.public_ips[0].size, 1)
    self.assertEqual(node.public_ips[0].extra['mac'], '02:00:c0:a8:00:03')
    self.assertEqual(node.public_ips[1].id, '15')
    self.assertEqual(node.public_ips[1].name, 'Network    15')
    self.assertEqual(node.public_ips[1].address, '192.168.1.3')
    self.assertEqual(node.public_ips[1].size, 1)
    self.assertEqual(node.public_ips[1].extra['mac'], '02:00:c0:a8:01:03')
    self.assertEqual(node.private_ips, [])
    self.assertEqual(node.size, None)
    self.assertEqual(node.image, None)
    context = node.extra['context']
    self.assertEqual(context, {})
