Esempio n. 1
0
class LinodeTestsV4(unittest.TestCase, TestCaseMixin):
    should_list_volumes = True

    def setUp(self):
        LinodeNodeDriver.connectionCls.conn_class = LinodeMockHttpV4
        LinodeMockHttpV4.type = None
        self.driver = LinodeNodeDriver('foo', api_version='4.0')

    def test_unknown_api_version(self):
        self.assertRaises(NotImplementedError,
                          LinodeNodeDriver,
                          'foo',
                          api_version='2.0')

    def test_correct_class_is_used(self):
        self.assertIsInstance(self.driver, LinodeNodeDriverV4)

    def test_list_sizes(self):
        sizes = self.driver.list_sizes()
        self.assertEqual(len(sizes), 28)
        size = sizes[0]
        self.assertEqual(size.id, 'g6-nanode-1')
        for size in sizes:
            self.assertIsInstance(size.price, float)
            if size.extra['class'] == 'gpu':
                self.assertGreater(size.extra['gpus'], 0)
            else:
                self.assertEqual(size.extra['gpus'], 0)

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images), 34)
        image = images[0]
        self.assertEqual(image.id, 'linode/alpine3.10')
        self.assertEqual(image.extra['type'], 'manual')
        self.assertEqual(image.extra['vendor'], 'Alpine')
        for image in images:
            self.assertIsInstance(image.extra['size'], int)
            self.assertTrue(image.extra['is_public'])

    def test_list_locations(self):
        locations = self.driver.list_locations()
        self.assertEqual(len(locations), 10)
        location = locations[0]
        self.assertEqual(location.country, 'IN')
        self.assertEqual(location.id, 'ap-west')
        self.assertEqual(location.extra['status'], 'ok')
        self.assertIsInstance(location.extra['capabilities'], list)

    def test_create_node_response(self):
        size = self.driver.list_sizes()[0]
        image = self.driver.list_images()[0]
        location = self.driver.list_locations()[0]
        node = self.driver.create_node(location=location,
                                       name='node-name',
                                       image=image,
                                       root_pass='******',
                                       size=size)
        self.assertTrue(isinstance(node, Node))

    def test_list_nodes(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        node = nodes[0]
        node_2 = nodes[1]
        self.assertEqual(node.id, '22344420')
        self.assertEqual(node.public_ips, ['138.89.34.81'])
        self.assertEqual(node.private_ips, ['192.168.1.230'])
        self.assertEqual(node.extra['hypervisor'], 'kvm')
        self.assertEqual(node_2.public_ips, ['156.12.197.243'])
        self.assertEqual(node_2.private_ips, [])

    def test_list_nodes_UNAUTHORIZED(self):
        LinodeMockHttpV4.type = 'UNAUTHORIZED'
        with self.assertRaises(InvalidCredsError):
            self.driver.list_nodes()

    def test_list_nodes_fills_datetime(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(nodes[0].created_at, datetime(2020, 10, 8, 18, 51,
                                                       29))

    def test_create_node(self):
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        node = self.driver.create_node(location,
                                       size,
                                       image=image,
                                       name='TestNode',
                                       root_pass='******',
                                       ex_backups_enabled=True,
                                       ex_tags=['testing123'],
                                       ex_private_ip=True)

        self.assertEqual(node.name, 'TestNode')
        self.assertEqual(len(node.private_ips), 1)
        self.assertTrue(node.extra['backups']['enabled'])
        self.assertEqual(node.extra['tags'], ['testing123'])

    def test_create_node_no_root_pass(self):
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location,
                                    size,
                                    image=image,
                                    name='TestNode')

    def test_create_node_no_image(self):
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]
        LinodeMockHttpV4.type = 'NO_IMAGE'
        node = self.driver.create_node(location,
                                       size,
                                       name='TestNode',
                                       ex_tags=['testing123'])

        self.assertIsNone(node.image)
        self.assertEqual(node.name, 'TestNode')
        self.assertFalse(node.extra['backups']['enabled'])
        self.assertEqual(node.extra['tags'], ['testing123'])
        self.assertEqual(len(node.private_ips), 0)

    def test_create_node_invalid_name(self):
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name='Test__Node')
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name='Test Node')
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name='Test--Node')
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name='Test..Node')

    def test_reboot_node(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_start_node(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        result = self.driver.start_node(node)
        self.assertTrue(result)

    def test_start_node_error(self):
        LinodeMockHttpV4.type = 'ALREADY_BOOTED'
        node = Node('22344420',
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        with self.assertRaises(LibcloudError):
            self.driver.start_node(node)

    def test_stop_node(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        result = self.driver.stop_node(node)
        self.assertTrue(result)

    def test_destroy_node(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        result = self.driver.stop_node(node)
        self.assertTrue(result)

    def test_ex_rename_node(self):
        node = Node('22344420', 'name1', None, None, None, driver=self.driver)
        renamed_node = self.driver.ex_rename_node(node, 'new_name')
        self.assertEqual(renamed_node.name, 'new_name')

    def test_ex_resize_node(self):
        node = Node('22344420',
                    None,
                    None,
                    None,
                    None,
                    driver=self.driver,
                    size='g6-nanode-1')
        size = self.driver.list_sizes()[0]
        result = self.driver.ex_resize_node(node, size=size)
        self.assertTrue(result)

    def test_ex_get_node(self):
        node_id = '22344420'
        node = self.driver.ex_get_node(node_id)
        self.assertEqual(node.name, 'test_2')
        self.assertEqual(node.image, 'linode/centos8')
        self.assertEqual(node.extra['tags'], ['testing'])
        self.assertEqual(node.public_ips, ['212.71.239.24'])
        self.assertEqual(node.extra['hypervisor'], 'kvm')

    def test_ex_list_disks(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        disks = self.driver.ex_list_disks(node)
        disk = disks[0]
        self.assertEqual(disk.name, 'CentOS 7 Disk')
        self.assertEqual(disk.size, 25088)
        for disk in disks:
            self.assertIsInstance(disk, LinodeDisk)

    def test_ex_create_disk(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        disk = self.driver.ex_create_disk(5000,
                                          'TestDisk',
                                          node,
                                          'ext4',
                                          image=image,
                                          ex_root_pass='******')
        self.assertIsInstance(disk, LinodeDisk)
        self.assertEqual(disk.size, 5000)
        self.assertEqual(disk.filesystem, 'ext4')
        self.assertEqual(disk.name, 'TestingDisk')

    def test_ex_create_disk_no_image(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        disk = self.driver.ex_create_disk(5000, 'TestDisk', node, 'ext4')
        self.assertIsInstance(disk, LinodeDisk)
        self.assertEqual(disk.size, 5000)
        self.assertEqual(disk.filesystem, 'ext4')
        self.assertEqual(disk.name, 'TestingDisk')

    def test_ex_create_disk_exception_no_root_pass(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_create_disk(5000,
                                       'TestDisk',
                                       node,
                                       'ext4',
                                       image=image)

    def test_ex_create_disk_exception_invalid_fs(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_create_disk(5000,
                                       'TestDisk',
                                       node,
                                       'random_fs',
                                       image=image,
                                       ex_root_pass='******')

    def test_ex_destroy_disk(self):
        node = Node('22344420',
                    None,
                    NodeState.STOPPED,
                    None,
                    None,
                    driver=self.driver)
        disk = LinodeDisk('23517413', None, None, None, self.driver, None)
        result = self.driver.ex_destroy_disk(node, disk)
        self.assertTrue(result)

    def test_ex_destroy_disk_exception(self):
        node = Node('22344420',
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        disk = LinodeDisk('23517413', None, None, None, self.driver, None)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_destroy_disk(node, disk)

    def test_list_volumes(self):
        volumes = self.driver.list_volumes()
        self.assertEqual(len(volumes), 2)
        volume = volumes[0]
        volume_2 = volumes[1]
        self.assertEqual(volume.id, '12345')
        self.assertEqual(volume.name, 'Testvolume1')
        self.assertEqual(volume.size, 100)
        self.assertEqual(volume.extra['linode_id'], 456353688)
        self.assertIsNone(volume_2.extra['linode_id'])

    def test_create_volume(self):
        node = Node('22344420',
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        volume = self.driver.create_volume('Volume1',
                                           50,
                                           node=node,
                                           tags=['test123', 'testing'])

        self.assertEqual(volume.extra['linode_id'], 22344420)
        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, 'Volume1')
        self.assertEqual(volume.extra['tags'], ['test123', 'testing'])

    def test_create_volume_unattached(self):
        location = self.driver.list_locations()[0]
        LinodeMockHttpV4.type = 'UNATTACHED'
        volume = self.driver.create_volume('Volume1',
                                           50,
                                           location=location,
                                           tags=['test123', 'testing'])

        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, 'Volume1')
        self.assertEqual(volume.extra['tags'], ['test123', 'testing'])

    def test_create_volume_invalid_name(self):
        location = self.driver.list_locations()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume('Volume__1', 50, location=location)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume('Volume 1', 50, location=location)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume('Volume--1', 50, location=location)

    def test_attach_volume_already_attached(self):
        volume = self.driver.list_volumes()[0]
        node = self.driver.list_nodes()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.attach_volume(node, volume)

    def test_attach_volume(self):
        volume = self.driver.list_volumes()[1]
        node = self.driver.list_nodes()[0]
        attached_volume = self.driver.attach_volume(node, volume)
        self.assertIsInstance(attached_volume, StorageVolume)
        self.assertEqual(str(attached_volume.extra['linode_id']), node.id)

    def test_detach_volume(self):
        volume = self.driver.list_volumes()[0]
        result = self.driver.detach_volume(volume)
        self.assertTrue(result)

    def test_detach_volume_already_detached(self):
        volume = self.driver.list_volumes()[1]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.detach_volume(volume)

    def test_destroy_volume(self):
        volume = self.driver.list_volumes()[1]
        result = self.driver.destroy_volume(volume)
        self.assertTrue(result)

    def test_destroy_volume_attached(self):
        volume = self.driver.list_volumes()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.destroy_volume(volume)

    def test_ex_resize_volume(self):
        volume = self.driver.list_volumes()[0]
        size = 200
        result = self.driver.ex_resize_volume(volume, size)
        self.assertTrue(result)

    def test_ex_resize_volume_resize_down(self):
        volume = self.driver.list_volumes()[0]
        size = 50
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_resize_volume(volume, size)

    def test_ex_clone_volume(self):
        volume = self.driver.list_volumes()[0]
        cloned_volume = self.driver.ex_clone_volume(volume, 'TestingClone')
        self.assertIsInstance(cloned_volume, StorageVolume)
        self.assertEqual(volume.size, cloned_volume.size)
        self.assertEqual(cloned_volume.name, 'TestingClone')

    def test_ex_get_volume(self):
        volume_id = '123456'
        volume = self.driver.ex_get_volume(volume_id)

        self.assertEqual(volume.name, 'Testvolume1')
        self.assertEqual(volume.size, 10)
        self.assertEqual(volume.extra['linode_id'], 456353688)

    def test_create_image(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        disk = self.driver.ex_list_disks(node)[0]
        image = self.driver.create_image(disk,
                                         name='Test',
                                         description='Test Image')
        self.assertIsInstance(image, NodeImage)
        self.assertEqual(image.name, 'Test')
        self.assertEqual(image.extra['description'], 'Test Image')

    def test_delete_image(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        disk = self.driver.ex_list_disks(node)[0]
        image = self.driver.create_image(disk,
                                         name='Test',
                                         description='Test Image')
        result = self.driver.delete_image(image)
        self.assertTrue(result)

    def test_ex_list_addresses(self):
        ips = self.driver.ex_list_addresses()
        self.assertEqual(len(ips), 3)
        ip = ips[0]
        self.assertEqual(ip.inet, '192.168.15.21')
        self.assertEqual(ip.version, 'ipv4')
        self.assertFalse(ip.public)
        for ip in ips:
            self.assertIsInstance(ip, LinodeIPAddress)

    def test_ex_list_node_addresses(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        ips = self.driver.ex_list_node_addresses(node)
        ip = ips[0]
        self.assertEqual(ip.inet, '176.58.100.100')
        self.assertEqual(ip.version, 'ipv4')
        self.assertTrue(ip.public)
        for ip in ips:
            self.assertIsInstance(ip, LinodeIPAddress)
            self.assertEqual(node.id, str(ip.extra['node_id']))

    def test_ex_allocate_private_address(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        ip = self.driver.ex_allocate_private_address(node)
        self.assertIsInstance(ip, LinodeIPAddress)
        self.assertEqual(ip.version, 'ipv4')
        self.assertEqual(ip.inet, '192.168.100.10')

    def test_ex_share_address(self):
        node = Node('22344420', None, None, None, None, driver=self.driver)
        ips = self.driver.ex_list_addresses()
        result = self.driver.ex_share_address(node, ips)
        self.assertTrue(result)

    def test__paginated_request_two_pages(self):
        LinodeMockHttpV4.type = 'PAGINATED'
        images = self.driver.list_images()
        self.assertEqual(len(images), 34)
Esempio n. 2
0
class LinodeTestsV4(unittest.TestCase, TestCaseMixin):
    should_list_volumes = True

    def setUp(self):
        LinodeNodeDriver.connectionCls.conn_class = LinodeMockHttpV4
        LinodeMockHttpV4.type = None
        self.driver = LinodeNodeDriver("foo", api_version="4.0")

    def test_unknown_api_version(self):
        self.assertRaises(NotImplementedError,
                          LinodeNodeDriver,
                          "foo",
                          api_version="2.0")

    def test_correct_class_is_used(self):
        self.assertIsInstance(self.driver, LinodeNodeDriverV4)

    def test_list_sizes(self):
        sizes = self.driver.list_sizes()
        self.assertEqual(len(sizes), 28)
        size = sizes[0]
        self.assertEqual(size.id, "g6-nanode-1")
        for size in sizes:
            self.assertIsInstance(size.price, float)
            if size.extra["class"] == "gpu":
                self.assertGreater(size.extra["gpus"], 0)
            else:
                self.assertEqual(size.extra["gpus"], 0)

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images), 34)
        image = images[0]
        self.assertEqual(image.id, "linode/alpine3.10")
        self.assertEqual(image.extra["type"], "manual")
        self.assertEqual(image.extra["vendor"], "Alpine")
        for image in images:
            self.assertIsInstance(image.extra["size"], int)
            self.assertTrue(image.extra["is_public"])

    def test_list_locations(self):
        locations = self.driver.list_locations()
        self.assertEqual(len(locations), 10)
        location = locations[0]
        self.assertEqual(location.country, "IN")
        self.assertEqual(location.id, "ap-west")
        self.assertEqual(location.extra["status"], "ok")
        self.assertIsInstance(location.extra["capabilities"], list)

    def test_create_node_response(self):
        size = self.driver.list_sizes()[0]
        image = self.driver.list_images()[0]
        location = self.driver.list_locations()[0]
        node = self.driver.create_node(
            location=location,
            name="node-name",
            image=image,
            root_pass="******",
            size=size,
        )
        self.assertTrue(isinstance(node, Node))

    def test_list_nodes(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        node = nodes[0]
        node_2 = nodes[1]
        self.assertEqual(node.id, "22344420")
        self.assertEqual(node.public_ips, ["138.89.34.81"])
        self.assertEqual(node.private_ips, ["192.168.1.230"])
        self.assertEqual(node.extra["hypervisor"], "kvm")
        self.assertEqual(node_2.public_ips, ["156.12.197.243"])
        self.assertEqual(node_2.private_ips, [])

    def test_list_nodes_UNAUTHORIZED(self):
        LinodeMockHttpV4.type = "UNAUTHORIZED"
        with self.assertRaises(InvalidCredsError):
            self.driver.list_nodes()

    def test_list_nodes_fills_datetime(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(nodes[0].created_at, datetime(2020, 10, 8, 18, 51,
                                                       29))

    def test_create_node(self):
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        node = self.driver.create_node(
            location,
            size,
            image=image,
            name="TestNode",
            root_pass="******",
            ex_backups_enabled=True,
            ex_tags=["testing123"],
            ex_private_ip=True,
        )

        self.assertEqual(node.name, "TestNode")
        self.assertEqual(len(node.private_ips), 1)
        self.assertTrue(node.extra["backups"]["enabled"])
        self.assertEqual(node.extra["tags"], ["testing123"])

    def test_create_node_no_root_pass(self):
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location,
                                    size,
                                    image=image,
                                    name="TestNode")

    def test_create_node_no_image(self):
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]
        LinodeMockHttpV4.type = "NO_IMAGE"
        node = self.driver.create_node(location,
                                       size,
                                       name="TestNode",
                                       ex_tags=["testing123"])

        self.assertIsNone(node.image)
        self.assertEqual(node.name, "TestNode")
        self.assertFalse(node.extra["backups"]["enabled"])
        self.assertEqual(node.extra["tags"], ["testing123"])
        self.assertEqual(len(node.private_ips), 0)

    def test_create_node_invalid_name(self):
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]

        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name="Test__Node")
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name="Test Node")
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name="Test--Node")
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_node(location, size, name="Test..Node")

    def test_reboot_node(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_start_node(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        result = self.driver.start_node(node)
        self.assertTrue(result)

    def test_start_node_error(self):
        LinodeMockHttpV4.type = "ALREADY_BOOTED"
        node = Node("22344420",
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        with self.assertRaises(LibcloudError):
            self.driver.start_node(node)

    def test_stop_node(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        result = self.driver.stop_node(node)
        self.assertTrue(result)

    def test_destroy_node(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        result = self.driver.stop_node(node)
        self.assertTrue(result)

    def test_ex_rename_node(self):
        node = Node("22344420", "name1", None, None, None, driver=self.driver)
        renamed_node = self.driver.ex_rename_node(node, "new_name")
        self.assertEqual(renamed_node.name, "new_name")

    def test_ex_resize_node(self):
        node = Node("22344420",
                    None,
                    None,
                    None,
                    None,
                    driver=self.driver,
                    size="g6-nanode-1")
        size = self.driver.list_sizes()[0]
        result = self.driver.ex_resize_node(node, size=size)
        self.assertTrue(result)

    def test_ex_get_node(self):
        node_id = "22344420"
        node = self.driver.ex_get_node(node_id)
        self.assertEqual(node.name, "test_2")
        self.assertEqual(node.image, "linode/centos8")
        self.assertEqual(node.extra["tags"], ["testing"])
        self.assertEqual(node.public_ips, ["212.71.239.24"])
        self.assertEqual(node.extra["hypervisor"], "kvm")

    def test_ex_list_disks(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        disks = self.driver.ex_list_disks(node)
        disk = disks[0]
        self.assertEqual(disk.name, "CentOS 7 Disk")
        self.assertEqual(disk.size, 25088)
        for disk in disks:
            self.assertIsInstance(disk, LinodeDisk)

    def test_ex_create_disk(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        disk = self.driver.ex_create_disk(5000,
                                          "TestDisk",
                                          node,
                                          "ext4",
                                          image=image,
                                          ex_root_pass="******")
        self.assertIsInstance(disk, LinodeDisk)
        self.assertEqual(disk.size, 5000)
        self.assertEqual(disk.filesystem, "ext4")
        self.assertEqual(disk.name, "TestingDisk")

    def test_ex_create_disk_no_image(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        disk = self.driver.ex_create_disk(5000, "TestDisk", node, "ext4")
        self.assertIsInstance(disk, LinodeDisk)
        self.assertEqual(disk.size, 5000)
        self.assertEqual(disk.filesystem, "ext4")
        self.assertEqual(disk.name, "TestingDisk")

    def test_ex_create_disk_exception_no_root_pass(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_create_disk(5000,
                                       "TestDisk",
                                       node,
                                       "ext4",
                                       image=image)

    def test_ex_create_disk_exception_invalid_fs(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        image = self.driver.list_images()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_create_disk(
                5000,
                "TestDisk",
                node,
                "random_fs",
                image=image,
                ex_root_pass="******",
            )

    def test_ex_destroy_disk(self):
        node = Node("22344420",
                    None,
                    NodeState.STOPPED,
                    None,
                    None,
                    driver=self.driver)
        disk = LinodeDisk("23517413", None, None, None, self.driver, None)
        result = self.driver.ex_destroy_disk(node, disk)
        self.assertTrue(result)

    def test_ex_destroy_disk_exception(self):
        node = Node("22344420",
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        disk = LinodeDisk("23517413", None, None, None, self.driver, None)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_destroy_disk(node, disk)

    def test_list_volumes(self):
        volumes = self.driver.list_volumes()
        self.assertEqual(len(volumes), 2)
        volume = volumes[0]
        volume_2 = volumes[1]
        self.assertEqual(volume.id, "12345")
        self.assertEqual(volume.name, "Testvolume1")
        self.assertEqual(volume.size, 100)
        self.assertEqual(volume.extra["linode_id"], 456353688)
        self.assertIsNone(volume_2.extra["linode_id"])

    def test_create_volume(self):
        node = Node("22344420",
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        volume = self.driver.create_volume("Volume1",
                                           50,
                                           node=node,
                                           tags=["test123", "testing"])

        self.assertEqual(volume.extra["linode_id"], 22344420)
        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, "Volume1")
        self.assertEqual(volume.extra["tags"], ["test123", "testing"])

    def test_create_volume_unattached(self):
        location = self.driver.list_locations()[0]
        LinodeMockHttpV4.type = "UNATTACHED"
        volume = self.driver.create_volume("Volume1",
                                           50,
                                           location=location,
                                           tags=["test123", "testing"])

        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, "Volume1")
        self.assertEqual(volume.extra["tags"], ["test123", "testing"])

    def test_create_volume_invalid_name(self):
        location = self.driver.list_locations()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume("Volume__1", 50, location=location)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume("Volume 1", 50, location=location)
        with self.assertRaises(LinodeExceptionV4):
            self.driver.create_volume("Volume--1", 50, location=location)

    def test_attach_volume_already_attached(self):
        volume = self.driver.list_volumes()[0]
        node = self.driver.list_nodes()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.attach_volume(node, volume)

    def test_attach_volume(self):
        volume = self.driver.list_volumes()[1]
        node = self.driver.list_nodes()[0]
        attached_volume = self.driver.attach_volume(node, volume)
        self.assertIsInstance(attached_volume, StorageVolume)
        self.assertEqual(str(attached_volume.extra["linode_id"]), node.id)

    def test_detach_volume(self):
        volume = self.driver.list_volumes()[0]
        result = self.driver.detach_volume(volume)
        self.assertTrue(result)

    def test_detach_volume_already_detached(self):
        volume = self.driver.list_volumes()[1]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.detach_volume(volume)

    def test_destroy_volume(self):
        volume = self.driver.list_volumes()[1]
        result = self.driver.destroy_volume(volume)
        self.assertTrue(result)

    def test_destroy_volume_attached(self):
        volume = self.driver.list_volumes()[0]
        with self.assertRaises(LinodeExceptionV4):
            self.driver.destroy_volume(volume)

    def test_ex_resize_volume(self):
        volume = self.driver.list_volumes()[0]
        size = 200
        result = self.driver.ex_resize_volume(volume, size)
        self.assertTrue(result)

    def test_ex_resize_volume_resize_down(self):
        volume = self.driver.list_volumes()[0]
        size = 50
        with self.assertRaises(LinodeExceptionV4):
            self.driver.ex_resize_volume(volume, size)

    def test_ex_clone_volume(self):
        volume = self.driver.list_volumes()[0]
        cloned_volume = self.driver.ex_clone_volume(volume, "TestingClone")
        self.assertIsInstance(cloned_volume, StorageVolume)
        self.assertEqual(volume.size, cloned_volume.size)
        self.assertEqual(cloned_volume.name, "TestingClone")

    def test_ex_get_volume(self):
        volume_id = "123456"
        volume = self.driver.ex_get_volume(volume_id)

        self.assertEqual(volume.name, "Testvolume1")
        self.assertEqual(volume.size, 10)
        self.assertEqual(volume.extra["linode_id"], 456353688)

    def test_create_image(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        disk = self.driver.ex_list_disks(node)[0]
        image = self.driver.create_image(disk,
                                         name="Test",
                                         description="Test Image")
        self.assertIsInstance(image, NodeImage)
        self.assertEqual(image.name, "Test")
        self.assertEqual(image.extra["description"], "Test Image")

    def test_delete_image(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        disk = self.driver.ex_list_disks(node)[0]
        image = self.driver.create_image(disk,
                                         name="Test",
                                         description="Test Image")
        result = self.driver.delete_image(image)
        self.assertTrue(result)

    def test_ex_list_addresses(self):
        ips = self.driver.ex_list_addresses()
        self.assertEqual(len(ips), 3)
        ip = ips[0]
        self.assertEqual(ip.inet, "192.168.15.21")
        self.assertEqual(ip.version, "ipv4")
        self.assertFalse(ip.public)
        for ip in ips:
            self.assertIsInstance(ip, LinodeIPAddress)

    def test_ex_list_node_addresses(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        ips = self.driver.ex_list_node_addresses(node)
        ip = ips[0]
        self.assertEqual(ip.inet, "176.58.100.100")
        self.assertEqual(ip.version, "ipv4")
        self.assertTrue(ip.public)
        for ip in ips:
            self.assertIsInstance(ip, LinodeIPAddress)
            self.assertEqual(node.id, str(ip.extra["node_id"]))

    def test_ex_allocate_private_address(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        ip = self.driver.ex_allocate_private_address(node)
        self.assertIsInstance(ip, LinodeIPAddress)
        self.assertEqual(ip.version, "ipv4")
        self.assertEqual(ip.inet, "192.168.100.10")

    def test_ex_share_address(self):
        node = Node("22344420", None, None, None, None, driver=self.driver)
        ips = self.driver.ex_list_addresses()
        result = self.driver.ex_share_address(node, ips)
        self.assertTrue(result)

    def test__paginated_request_two_pages(self):
        LinodeMockHttpV4.type = "PAGINATED"
        images = self.driver.list_images()
        self.assertEqual(len(images), 34)