コード例 #1
0
ファイル: test_vultr.py プロジェクト: kevin-zhangsen/badam
class VultrTests(LibcloudTestCase):

    def setUp(self):
        VultrNodeDriver.connectionCls.conn_classes = \
            (VultrMockHttp, VultrMockHttp)
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_success(self):
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 22)

        size = sizes[0]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '512 MB RAM,160 GB SATA,1.00 TB BW')
        self.assertEqual(size.ram, 512)

        size = sizes[21]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '65536 MB RAM,800 GB SSD,9.00 TB BW')
        self.assertEqual(size.ram, 65536)

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].id, '1')
        self.assertEqual(nodes[0].public_ips, ['108.61.206.153'])

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)
コード例 #2
0
class VultrTests(LibcloudTestCase):
    def setUp(self):
        VultrNodeDriver.connectionCls.conn_classes = \
            (VultrMockHttp, VultrMockHttp)
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_success(self):
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 22)

        size = sizes[0]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '512 MB RAM,160 GB SATA,1.00 TB BW')
        self.assertEqual(size.ram, 512)

        size = sizes[21]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '65536 MB RAM,800 GB SSD,9.00 TB BW')
        self.assertEqual(size.ram, 65536)

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].id, '1')
        self.assertEqual(nodes[0].public_ips, ['108.61.206.153'])

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)
コード例 #3
0
class VultrTestsV2(unittest.TestCase):

    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttpV2
        VultrMockHttpV2.type = None
        self.driver = VultrNodeDriver('foo')

    def test_unknown_api_version(self):
        self.assertRaises(NotImplementedError, VultrNodeDriver,
                          'foo', api_version='3')

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

    def test_list_sizes(self):
        sizes = self.driver.list_sizes()
        self.assertEqual(len(sizes), 25)
        size = sizes[0]
        self.assertEqual(size.id, 'vc2-1c-1gb')
        self.assertEqual(size.name, 'vc2-1c-1gb')
        for size in sizes:
            self.assertIsInstance(size.price, int)
            self.assertIsInstance(size.ram, int)
            self.assertIsInstance(size.disk, int)

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images), 30)
        image = images[0]
        self.assertEqual(image.id, '124')
        self.assertEqual(image.name, 'Windows 2012 R2 x64')
        self.assertEqual(image.extra['arch'], 'x64')
        self.assertEqual(image.extra['family'], 'windows')

    def test_list_locations(self):
        locations = self.driver.list_locations()
        self.assertEqual(len(locations), 17)
        location = locations[0]
        self.assertEqual(location.country, 'NL')
        self.assertEqual(location.id, 'ams')
        self.assertEqual(location.name, 'Amsterdam')
        self.assertIsInstance(location.extra['option'], list)

    def test_list_nodes(self):
        nodes = self.driver.list_nodes(ex_list_bare_metals=False)
        self.assertEqual(len(nodes), 3)
        node = nodes[0]
        self.assertEqual(node.id, '123')
        self.assertEqual(node.name, 'test1')
        self.assertEqual(node.image, '477')
        self.assertEqual(node.size, 'vc2-1c-2gb')
        self.assertEqual(node.extra['location'], 'fra')
        self.assertIn('45.76.83.44', node.public_ips)
        for node in nodes:
            self.assertIsInstance(node.public_ips, list)
            self.assertIsInstance(node.private_ips, list)
            self.assertIsInstance(node.extra['vcpu_count'], int)
            self.assertIsInstance(node.extra['ram'], int)
            self.assertIsInstance(node.extra['disk'], int)
            self.assertIsInstance(node.extra['allowed_bandwidth'], int)

    def test_list_nodes_with_bare_metals(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 5)
        node = nodes[0]
        self.assertEqual(node.id, '123')
        self.assertEqual(node.name, 'test1')
        self.assertEqual(node.image, '477')
        self.assertEqual(node.size, 'vc2-1c-2gb')
        self.assertEqual(node.extra['vcpu_count'], 1)
        self.assertEqual(node.extra['location'], 'fra')
        self.assertFalse(node.extra['is_bare_metal'])
        self.assertIn('45.76.83.44', node.public_ips)
        node = nodes[-1]
        self.assertEqual(node.id, '234')
        self.assertEqual(node.size, 'vbm-8c-132gb')
        self.assertEqual(node.state, 'pending')
        self.assertEqual(node.extra['cpu_count'], 8)
        self.assertEqual(node.extra['location'], 'mia')
        self.assertTrue(node.extra['is_bare_metal'])
        self.assertEqual(node.extra['mac_address'], 189250955239968)

    def test_create_node(self):
        name = 'test123'
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]
        node = self.driver.create_node(name=name,
                                       image=image,
                                       size=size,
                                       location=location)
        self.assertEqual(node.id, '123')
        self.assertEqual(node.name, 'test123')
        self.assertEqual(node.image, '446')
        self.assertFalse(node.extra['is_bare_metal'])

    def test_destroy_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.destroy_node(node)
        self.assertTrue(response)

    def test_start_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.start_node(node)
        self.assertTrue(response)

    def test_reboot_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.reboot_node(node)
        self.assertTrue(response)

    def test_ex_stop_nodes(self):
        nodes = self.driver.list_nodes()
        response = self.driver.ex_stop_nodes(nodes)
        self.assertTrue(response)

    def test_stop_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.stop_node(node)
        self.assertTrue(response)

    def test_ex_get_node(self):
        node = self.driver.ex_get_node('123')
        self.assertEqual(node.name, 'test')
        self.assertEqual(node.id, '123')
        self.assertEqual(node.size, 'vc2-1c-1gb')
        self.assertEqual(node.image, '477')
        self.assertEqual(node.state, 'running')
        self.assertIn('45.76.36.72', node.public_ips)

    def test_ex_resize_node(self):
        node = self.driver.ex_get_node('123')
        size = self.driver.list_sizes()[1]
        node = self.driver.ex_resize_node(node, size)
        self.assertEqual(node.id, '123')
        self.assertEqual(node.size, 'vc2-1c-2gb')
        self.assertEqual(node.name, 'test4')
        self.assertIn('192.248.168.21', node.public_ips)

    def test_list_key_pairs(self):
        keys = self.driver.list_key_pairs()
        self.assertEqual(len(keys), 1)
        key = keys[0]
        self.assertEqual(key.name, 'tester')
        self.assertIsNone(key.private_key)
        self.assertEqual(key.extra['id'],
                         '123')

    def test_list_key_pairs_UNAUTHORIZED(self):
        VultrMockHttpV2.type = 'UNAUTHORIZED'
        with self.assertRaises(VultrException):
            self.driver.list_key_pairs()

    def test_get_key_pair(self):
        key_id = '123'
        key = self.driver.get_key_pair(key_id)
        self.assertEqual(key.name, 'tester')
        self.assertEqual(key.extra['id'], '123')
        self.assertIsNone(key.private_key)

    def test_import_key_pair_from_string(self):
        name = 'tester'
        key_material = 'material'
        key = self.driver.import_key_pair_from_string(name, key_material)
        self.assertEqual(key.name, 'tester')
        self.assertEqual(key.extra['id'], '123')
        self.assertIsNone(key.private_key)

    def test_delete_key_pair(self):
        keys = self.driver.list_key_pairs()
        key = keys[0]
        response = self.driver.delete_key_pair(key)
        self.assertTrue(response)

    def test_list_volumes(self):
        volumes = self.driver.list_volumes()
        self.assertEqual(len(volumes), 2)
        volume = volumes[0]
        self.assertEqual(volume.name, 'test1')
        self.assertEqual(volume.id, '123')
        self.assertEqual(volume.size, 10)
        self.assertEqual(volume.state, 'available')

    def test_create_volume(self):
        volume = self.driver.create_volume(size=15,
                                           name='test4',
                                           location='ewr')
        self.assertEqual(volume.name, 'test4')
        self.assertEqual(volume.id, 'ec6d1ecc-aa70-4f18-8edd-887a258b1b45')
        self.assertEqual(volume.size, 15)
        self.assertEqual(volume.state, 'creating')
        self.assertEqual(volume.extra['location'], 'ewr')

    def test_attach_volume(self):
        volume = self.driver.list_volumes()[0]
        node = self.driver.list_nodes()[0]
        response = self.driver.attach_volume(node, volume)
        self.assertTrue(response)

    def test_attach_volume_WRONG_LOCATION(self):
        volume = self.driver.list_volumes()[1]
        node = self.driver.list_nodes()[0]
        VultrMockHttpV2.type = 'WRONG_LOCATION'
        with self.assertRaises(VultrException):
            self.driver.attach_volume(node, volume)

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

    def test_destroy_volume(self):
        volume = self.driver.list_volumes()[0]
        response = self.driver.destroy_volume(volume)
        self.assertTrue(response)

    def test_ex_get_volume(self):
        volume = self.driver.ex_get_volume('123')
        self.assertEqual(volume.id, '123')
        self.assertEqual(volume.name, 'test2')
        self.assertEqual(volume.state, 'available')

    def test_ex_resize_volume(self):
        volume = self.driver.list_volumes()[0]
        response = self.driver.ex_resize_volume(volume, 20)
        self.assertTrue(response)

    def test_ex_list_available_sizes_for_location(self):
        location = self.driver.list_locations()[0]
        available_sizes = self.driver.ex_list_available_sizes_for_location(
            location
        )
        self.assertTrue(isinstance(available_sizes, list))

    def test_ex_list_networks(self):
        networks = self.driver.ex_list_networks()
        self.assertEqual(len(networks), 2)
        network = networks[0]
        self.assertEqual(network.id, '123')
        self.assertEqual(network.cidr_block, '10.7.96.0/20')
        self.assertEqual(network.location, 'ams')

    def test_ex_get_network(self):
        network = self.driver.ex_get_network('123')
        self.assertEqual(network.id, '123')
        self.assertEqual(network.cidr_block, '10.7.96.0/20')
        self.assertEqual(network.location, 'ams')

    def test_ex_create_network(self):
        network = self.driver.ex_create_network('10.0.0.0/24',
                                                'ams',
                                                'TestNetwork')
        self.assertEqual(network.id, '123')
        self.assertEqual(network.cidr_block, '10.0.0.0/24')
        self.assertEqual(network.location, 'ams')

    def test_ex_destroy_network(self):
        network = self.driver.ex_get_network('123')
        response = self.driver.ex_destroy_network(network)
        self.assertTrue(response)

    def ex_list_snapshots(self):
        snapshots = self.driver.ex_list_snapshots()
        self.assertEqual(len(snapshots), 2)
        snapshot = snapshots[0]
        self.assertEqual(snapshot.id, '123')
        self.assertEqual(snapshot.size, '25.0')
        self.assertEqual(snapshot.state, 'available')
        snapshot = snapshots[1]
        self.assertEqual(snapshot.id, '1234')
        self.assertEqual(snapshot.size, '25.0')
        self.assertEqual(snapshot.state, 'creating')

    def test_ex_get_snapshot(self):
        snapshot = self.driver.ex_get_snapshot('123')
        self.assertEqual(snapshot.id, '123')
        self.assertEqual(snapshot.size, 25.0)
        self.assertEqual(snapshot.state, 'available')

    def test_ex_create_snapshot(self):
        node = self.driver.list_nodes()[0]
        snapshot = self.driver.ex_create_snapshot(node)
        self.assertEqual(snapshot.id, '123')
        self.assertEqual(snapshot.size, 0)
        self.assertEqual(snapshot.state, 'creating')

    def test_ex_delete_snapshot(self):
        snapshot = self.driver.ex_get_snapshot('123')
        response = self.driver.ex_delete_snapshot(snapshot)
        self.assertTrue(response)

    def test_ex_list_bare_metal_sizes(self):
        sizes = self.driver.ex_list_bare_metal_sizes()
        self.assertEqual(len(sizes), 4)
        for size in sizes:
            self.assertIsInstance(size.extra['cpu_count'], int)
            self.assertIsInstance(size.extra['cpu_threads'], int)
            self.assertIsInstance(size.extra['cpu_model'], str)

    def test_create_bare_metal_node(self):
        image = self.driver.list_images()[0]
        location = self.driver.list_locations()[0]
        size = self.driver.list_sizes()[-1]
        node = self.driver.create_node(name='test1',
                                       image=image,
                                       location=location,
                                       size=size)
        self.assertEqual(node.name, 'test1')
        self.assertEqual(node.id, '234')
        self.assertTrue(node.extra['is_bare_metal'])
        self.assertEqual(node.extra['cpu_count'], 4)

    def test_reboot_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra['is_bare_metal'])
        response = self.driver.reboot_node(node)
        self.assertTrue(response)

    def test_start_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra['is_bare_metal'])
        response = self.driver.start_node(node)
        self.assertTrue(response)

    def test_stop_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra['is_bare_metal'])
        response = self.driver.stop_node(node)
        self.assertTrue(response)

    def test_destroy_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra['is_bare_metal'])
        response = self.driver.destroy_node(node)
        self.assertTrue(response)

    def test_pagination(self):
        images = self.driver.list_images()
        VultrMockHttpV2.type = 'PAGINATED'
        paginated_images = self.driver.list_images()
        self.assertEqual(len(images), len(paginated_images))
        for first, second in zip(images, paginated_images):
            self.assertEqual(first.id, second.id)
            self.assertEqual(first.name, second.name)
            self.assertDictEqual(first.extra, second.extra)
コード例 #4
0
class VultrTestsV2(unittest.TestCase):
    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttpV2
        VultrMockHttpV2.type = None
        self.driver = VultrNodeDriver("foo")

    def test_unknown_api_version(self):
        self.assertRaises(NotImplementedError, VultrNodeDriver, "foo", api_version="3")

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

    def test_list_sizes(self):
        sizes = self.driver.list_sizes()
        self.assertEqual(len(sizes), 25)
        size = sizes[0]
        self.assertEqual(size.id, "vc2-1c-1gb")
        self.assertEqual(size.name, "vc2-1c-1gb")
        for size in sizes:
            self.assertIsInstance(size.price, int)
            self.assertIsInstance(size.ram, int)
            self.assertIsInstance(size.disk, int)

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images), 30)
        image = images[0]
        self.assertEqual(image.id, "124")
        self.assertEqual(image.name, "Windows 2012 R2 x64")
        self.assertEqual(image.extra["arch"], "x64")
        self.assertEqual(image.extra["family"], "windows")

    def test_list_locations(self):
        locations = self.driver.list_locations()
        self.assertEqual(len(locations), 17)
        location = locations[0]
        self.assertEqual(location.country, "NL")
        self.assertEqual(location.id, "ams")
        self.assertEqual(location.name, "Amsterdam")
        self.assertIsInstance(location.extra["option"], list)

    def test_list_nodes(self):
        nodes = self.driver.list_nodes(ex_list_bare_metals=False)
        self.assertEqual(len(nodes), 3)
        node = nodes[0]
        self.assertEqual(node.id, "123")
        self.assertEqual(node.name, "test1")
        self.assertEqual(node.image, "477")
        self.assertEqual(node.size, "vc2-1c-2gb")
        self.assertEqual(node.extra["location"], "fra")
        self.assertIn("45.76.83.44", node.public_ips)
        for node in nodes:
            self.assertIsInstance(node.public_ips, list)
            self.assertIsInstance(node.private_ips, list)
            self.assertIsInstance(node.extra["vcpu_count"], int)
            self.assertIsInstance(node.extra["ram"], int)
            self.assertIsInstance(node.extra["disk"], int)
            self.assertIsInstance(node.extra["allowed_bandwidth"], int)

    def test_list_nodes_with_bare_metals(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 5)
        node = nodes[0]
        self.assertEqual(node.id, "123")
        self.assertEqual(node.name, "test1")
        self.assertEqual(node.image, "477")
        self.assertEqual(node.size, "vc2-1c-2gb")
        self.assertEqual(node.extra["vcpu_count"], 1)
        self.assertEqual(node.extra["location"], "fra")
        self.assertFalse(node.extra["is_bare_metal"])
        self.assertIn("45.76.83.44", node.public_ips)
        node = nodes[-1]
        self.assertEqual(node.id, "234")
        self.assertEqual(node.size, "vbm-8c-132gb")
        self.assertEqual(node.state, "pending")
        self.assertEqual(node.extra["cpu_count"], 8)
        self.assertEqual(node.extra["location"], "mia")
        self.assertTrue(node.extra["is_bare_metal"])
        self.assertEqual(node.extra["mac_address"], 189250955239968)

    def test_create_node(self):
        name = "test123"
        image = self.driver.list_images()[0]
        size = self.driver.list_sizes()[0]
        location = self.driver.list_locations()[0]
        node = self.driver.create_node(
            name=name, image=image, size=size, location=location
        )
        self.assertEqual(node.id, "123")
        self.assertEqual(node.name, "test123")
        self.assertEqual(node.image, "446")
        self.assertFalse(node.extra["is_bare_metal"])

    def test_destroy_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.destroy_node(node)
        self.assertTrue(response)

    def test_start_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.start_node(node)
        self.assertTrue(response)

    def test_reboot_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.reboot_node(node)
        self.assertTrue(response)

    def test_ex_stop_nodes(self):
        nodes = self.driver.list_nodes()
        response = self.driver.ex_stop_nodes(nodes)
        self.assertTrue(response)

    def test_stop_node(self):
        node = self.driver.list_nodes()[0]
        response = self.driver.stop_node(node)
        self.assertTrue(response)

    def test_ex_get_node(self):
        node = self.driver.ex_get_node("123")
        self.assertEqual(node.name, "test")
        self.assertEqual(node.id, "123")
        self.assertEqual(node.size, "vc2-1c-1gb")
        self.assertEqual(node.image, "477")
        self.assertEqual(node.state, "running")
        self.assertIn("45.76.36.72", node.public_ips)

    def test_ex_resize_node(self):
        node = self.driver.ex_get_node("123")
        size = self.driver.list_sizes()[1]
        node = self.driver.ex_resize_node(node, size)
        self.assertEqual(node.id, "123")
        self.assertEqual(node.size, "vc2-1c-2gb")
        self.assertEqual(node.name, "test4")
        self.assertIn("192.248.168.21", node.public_ips)

    def test_list_key_pairs(self):
        keys = self.driver.list_key_pairs()
        self.assertEqual(len(keys), 1)
        key = keys[0]
        self.assertEqual(key.name, "tester")
        self.assertIsNone(key.private_key)
        self.assertEqual(key.extra["id"], "123")

    def test_list_key_pairs_UNAUTHORIZED(self):
        VultrMockHttpV2.type = "UNAUTHORIZED"
        with self.assertRaises(VultrException):
            self.driver.list_key_pairs()

    def test_get_key_pair(self):
        key_id = "123"
        key = self.driver.get_key_pair(key_id)
        self.assertEqual(key.name, "tester")
        self.assertEqual(key.extra["id"], "123")
        self.assertIsNone(key.private_key)

    def test_import_key_pair_from_string(self):
        name = "tester"
        key_material = "material"
        key = self.driver.import_key_pair_from_string(name, key_material)
        self.assertEqual(key.name, "tester")
        self.assertEqual(key.extra["id"], "123")
        self.assertIsNone(key.private_key)

    def test_delete_key_pair(self):
        keys = self.driver.list_key_pairs()
        key = keys[0]
        response = self.driver.delete_key_pair(key)
        self.assertTrue(response)

    def test_list_volumes(self):
        volumes = self.driver.list_volumes()
        self.assertEqual(len(volumes), 2)
        volume = volumes[0]
        self.assertEqual(volume.name, "test1")
        self.assertEqual(volume.id, "123")
        self.assertEqual(volume.size, 10)
        self.assertEqual(volume.state, "available")

    def test_create_volume(self):
        volume = self.driver.create_volume(size=15, name="test4", location="ewr")
        self.assertEqual(volume.name, "test4")
        self.assertEqual(volume.id, "ec6d1ecc-aa70-4f18-8edd-887a258b1b45")
        self.assertEqual(volume.size, 15)
        self.assertEqual(volume.state, "creating")
        self.assertEqual(volume.extra["location"], "ewr")

    def test_attach_volume(self):
        volume = self.driver.list_volumes()[0]
        node = self.driver.list_nodes()[0]
        response = self.driver.attach_volume(node, volume)
        self.assertTrue(response)

    def test_attach_volume_WRONG_LOCATION(self):
        volume = self.driver.list_volumes()[1]
        node = self.driver.list_nodes()[0]
        VultrMockHttpV2.type = "WRONG_LOCATION"
        with self.assertRaises(VultrException):
            self.driver.attach_volume(node, volume)

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

    def test_destroy_volume(self):
        volume = self.driver.list_volumes()[0]
        response = self.driver.destroy_volume(volume)
        self.assertTrue(response)

    def test_ex_get_volume(self):
        volume = self.driver.ex_get_volume("123")
        self.assertEqual(volume.id, "123")
        self.assertEqual(volume.name, "test2")
        self.assertEqual(volume.state, "available")

    def test_ex_resize_volume(self):
        volume = self.driver.list_volumes()[0]
        response = self.driver.ex_resize_volume(volume, 20)
        self.assertTrue(response)

    def test_ex_list_available_sizes_for_location(self):
        location = self.driver.list_locations()[0]
        available_sizes = self.driver.ex_list_available_sizes_for_location(location)
        self.assertTrue(isinstance(available_sizes, list))

    def test_ex_list_networks(self):
        networks = self.driver.ex_list_networks()
        self.assertEqual(len(networks), 2)
        network = networks[0]
        self.assertEqual(network.id, "123")
        self.assertEqual(network.cidr_block, "10.7.96.0/20")
        self.assertEqual(network.location, "ams")

    def test_ex_get_network(self):
        network = self.driver.ex_get_network("123")
        self.assertEqual(network.id, "123")
        self.assertEqual(network.cidr_block, "10.7.96.0/20")
        self.assertEqual(network.location, "ams")

    def test_ex_create_network(self):
        network = self.driver.ex_create_network("10.0.0.0/24", "ams", "TestNetwork")
        self.assertEqual(network.id, "123")
        self.assertEqual(network.cidr_block, "10.0.0.0/24")
        self.assertEqual(network.location, "ams")

    def test_ex_destroy_network(self):
        network = self.driver.ex_get_network("123")
        response = self.driver.ex_destroy_network(network)
        self.assertTrue(response)

    def ex_list_snapshots(self):
        snapshots = self.driver.ex_list_snapshots()
        self.assertEqual(len(snapshots), 2)
        snapshot = snapshots[0]
        self.assertEqual(snapshot.id, "123")
        self.assertEqual(snapshot.size, "25.0")
        self.assertEqual(snapshot.state, "available")
        snapshot = snapshots[1]
        self.assertEqual(snapshot.id, "1234")
        self.assertEqual(snapshot.size, "25.0")
        self.assertEqual(snapshot.state, "creating")

    def test_ex_get_snapshot(self):
        snapshot = self.driver.ex_get_snapshot("123")
        self.assertEqual(snapshot.id, "123")
        self.assertEqual(snapshot.size, 25.0)
        self.assertEqual(snapshot.state, "available")

    def test_ex_create_snapshot(self):
        node = self.driver.list_nodes()[0]
        snapshot = self.driver.ex_create_snapshot(node)
        self.assertEqual(snapshot.id, "123")
        self.assertEqual(snapshot.size, 0)
        self.assertEqual(snapshot.state, "creating")

    def test_ex_delete_snapshot(self):
        snapshot = self.driver.ex_get_snapshot("123")
        response = self.driver.ex_delete_snapshot(snapshot)
        self.assertTrue(response)

    def test_ex_list_bare_metal_sizes(self):
        sizes = self.driver.ex_list_bare_metal_sizes()
        self.assertEqual(len(sizes), 4)
        for size in sizes:
            self.assertIsInstance(size.extra["cpu_count"], int)
            self.assertIsInstance(size.extra["cpu_threads"], int)
            self.assertIsInstance(size.extra["cpu_model"], str)

    def test_create_bare_metal_node(self):
        image = self.driver.list_images()[0]
        location = self.driver.list_locations()[0]
        size = self.driver.list_sizes()[-1]
        node = self.driver.create_node(
            name="test1", image=image, location=location, size=size
        )
        self.assertEqual(node.name, "test1")
        self.assertEqual(node.id, "234")
        self.assertTrue(node.extra["is_bare_metal"])
        self.assertEqual(node.extra["cpu_count"], 4)

    def test_reboot_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra["is_bare_metal"])
        response = self.driver.reboot_node(node)
        self.assertTrue(response)

    def test_start_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra["is_bare_metal"])
        response = self.driver.start_node(node)
        self.assertTrue(response)

    def test_stop_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra["is_bare_metal"])
        response = self.driver.stop_node(node)
        self.assertTrue(response)

    def test_destroy_bare_metal_node(self):
        nodes = self.driver.list_nodes()
        node = nodes[-1]
        self.assertTrue(node.extra["is_bare_metal"])
        response = self.driver.destroy_node(node)
        self.assertTrue(response)

    def test_pagination(self):
        images = self.driver.list_images()
        VultrMockHttpV2.type = "PAGINATED"
        paginated_images = self.driver.list_images()
        self.assertEqual(len(images), len(paginated_images))
        for first, second in zip(images, paginated_images):
            self.assertEqual(first.id, second.id)
            self.assertEqual(first.name, second.name)
            self.assertDictEqual(first.extra, second.extra)
コード例 #5
0
class VultrTests(LibcloudTestCase):
    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttp
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_dont_require_api_key(self):
        self.driver.list_images()
        self.assertFalse(self.driver.connection.require_api_key())

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_success(self):
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 17)

        size = sizes[0]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '8192 MB RAM,110 GB SSD,10.00 TB BW')
        self.assertEqual(size.ram, 8192)

        size = sizes[16]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '4096 MB RAM,1000 GB SATA,5.00 TB BW')
        self.assertEqual(size.ram, 4096)

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')

    def test_list_nodes_require_api_key(self):
        self.driver.list_nodes()
        self.assertTrue(self.driver.connection.require_api_key())

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].id, '1')
        self.assertEqual(nodes[0].public_ips, ['108.61.206.153'])

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_create_node_success(self):
        test_size = self.driver.list_sizes()[0]
        test_image = self.driver.list_images()[0]
        test_location = self.driver.list_locations()[0]
        created_node = self.driver.create_node('test-node', test_size,
                                               test_image, test_location)
        self.assertEqual(created_node.id, "1")

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)

    def test_list_key_pairs_success(self):
        key_pairs = self.driver.list_key_pairs()
        self.assertEqual(len(key_pairs), 1)
        key_pair = key_pairs[0]
        self.assertEqual(key_pair.id, '5806a8ef2a0c6')
        self.assertEqual(key_pair.name, 'test-key-pair')

    def test_create_key_pair_success(self):
        res = self.driver.create_key_pair('test-key-pair')
        self.assertTrue(res)

    def test_delete_key_pair_success(self):
        key_pairs = self.driver.list_key_pairs()
        key_pair = key_pairs[0]
        res = self.driver.delete_key_pair(key_pair)
        self.assertTrue(res)

    def test_rate_limit(self):
        VultrMockHttp.type = 'SERVICE_UNAVAILABLE'
        self.assertRaises(ServiceUnavailableError, self.driver.list_nodes)
コード例 #6
0
ファイル: test_vultr.py プロジェクト: subha4/libcloud
class VultrTests(LibcloudTestCase):
    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttp
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_dont_require_api_key(self):
        self.driver.list_images()
        self.assertFalse(self.driver.connection.require_api_key())

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_dont_require_api_key(self):
        self.driver.list_sizes()
        self.assertFalse(self.driver.connection.require_api_key())

    def test_list_sizes_success(self):
        """count of current plans"""
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 19)

        size = sizes[0]
        self.assertTrue(size.id.isdigit())
        self.assertEqual(size.name, '8192 MB RAM,110 GB SSD,10.00 TB BW')
        self.assertEqual(size.ram, 8192)

        size = sizes[16]
        self.assertTrue(size.id.isdigit())
        self.assertEqual(size.name, '16384 MB RAM,384 GB SSD,5.00 TB BW')
        self.assertEqual(size.ram, 16384)

    def test_list_locations_dont_require_api_key(self):
        self.driver.list_locations()
        self.assertFalse(self.driver.connection.require_api_key())

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')
        self.assertEqual(location.extra['continent'], 'North America')

    def test_list_locations_extra_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)
        extra_keys = [
            'continent', 'state', 'ddos_protection', 'block_storage',
            'regioncode'
        ]
        for location in locations:
            self.assertTrue(len(location.extra.keys()) >= 5)
            self.assertTrue(
                all(item in location.extra.keys() for item in extra_keys))

    def test_list_nodes_require_api_key(self):
        self.driver.list_nodes()
        self.assertTrue(self.driver.connection.require_api_key())

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 3)
        self.assertTrue(nodes[0].id.isdigit())
        self.assertEqual(nodes[0].id, '41306569')
        self.assertEqual(nodes[0].public_ips, ['45.76.43.87'])
        self.assertEqual(nodes[0].private_ips, ['10.7.96.85'])
        self.assertEqual(nodes[2].private_ips, [])

    def test_list_nodes_image_success(self):
        nodes = self.driver.list_nodes()
        node = nodes[0]
        self.assertTrue(isinstance(node.image, NodeImage))

    def test_list_nodes_size_success(self):
        nodes = self.driver.list_nodes()
        node = nodes[0]
        self.assertTrue(isinstance(node.size, NodeSize))

    def test_list_nodes_success_extra(self):
        extra_keys = [
            "default_password",
            "pending_charges",
            "cost_per_month",
        ]
        nodes = self.driver.list_nodes()
        for node in nodes:
            self.assertTrue(len(node.extra.keys()) > 5)
            self.assertTrue(
                all(item in node.extra.keys() for item in extra_keys))

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_create_node_success(self):
        test_size = self.driver.list_sizes()[0]
        test_image = self.driver.list_images()[0]
        test_location = self.driver.list_locations()[0]
        created_node = self.driver.create_node('test-node', test_size,
                                               test_image, test_location)
        self.assertEqual(created_node.id, "41326859")

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)

    def test_list_key_pairs_success(self):
        key_pairs = self.driver.list_key_pairs()
        self.assertEqual(len(key_pairs), 1)
        key_pair = key_pairs[0]
        self.assertEqual(key_pair.id, '5806a8ef2a0c6')
        self.assertEqual(key_pair.name, 'test-key-pair')

    def test_create_key_pair_success(self):
        res = self.driver.create_key_pair('test-key-pair')
        self.assertTrue(res)

    def test_delete_key_pair_success(self):
        key_pairs = self.driver.list_key_pairs()
        key_pair = key_pairs[0]
        res = self.driver.delete_key_pair(key_pair)
        self.assertTrue(res)

    def test_rate_limit(self):
        VultrMockHttp.type = 'SERVICE_UNAVAILABLE'
        self.assertRaises(ServiceUnavailableError, self.driver.list_nodes)
コード例 #7
0
class VultrTests(LibcloudTestCase):

    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttp
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_success(self):
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 22)

        size = sizes[0]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '512 MB RAM,160 GB SATA,1.00 TB BW')
        self.assertEqual(size.ram, 512)

        size = sizes[21]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '65536 MB RAM,800 GB SSD,9.00 TB BW')
        self.assertEqual(size.ram, 65536)

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].id, '1')
        self.assertEqual(nodes[0].public_ips, ['108.61.206.153'])

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_create_node_success(self):
        test_size = self.driver.list_sizes()[0]
        test_image = self.driver.list_images()[0]
        test_location = self.driver.list_locations()[0]
        created_node = self.driver.create_node('test-node', test_size,
                                               test_image, test_location)
        self.assertEqual(created_node.id, "1")

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)

    def test_list_key_pairs_success(self):
        key_pairs = self.driver.list_key_pairs()
        self.assertEqual(len(key_pairs), 1)
        key_pair = key_pairs[0]
        self.assertEqual(key_pair.id, '5806a8ef2a0c6')
        self.assertEqual(key_pair.name, 'test-key-pair')

    def test_create_key_pair_success(self):
        res = self.driver.create_key_pair('test-key-pair')
        self.assertTrue(res)

    def test_delete_key_pair_success(self):
        key_pairs = self.driver.list_key_pairs()
        key_pair = key_pairs[0]
        res = self.driver.delete_key_pair(key_pair)
        self.assertTrue(res)
コード例 #8
0
class VultrTests(LibcloudTestCase):
    def setUp(self):
        VultrNodeDriver.connectionCls.conn_class = VultrMockHttp
        VultrMockHttp.type = None
        self.driver = VultrNodeDriver(*VULTR_PARAMS)

    def test_list_images_success(self):
        images = self.driver.list_images()
        self.assertTrue(len(images) >= 1)

        image = images[0]
        self.assertTrue(image.id is not None)
        self.assertTrue(image.name is not None)

    def test_list_sizes_success(self):
        sizes = self.driver.list_sizes()
        self.assertTrue(len(sizes) == 22)

        size = sizes[0]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '512 MB RAM,160 GB SATA,1.00 TB BW')
        self.assertEqual(size.ram, 512)

        size = sizes[21]
        self.assertTrue(size.id is not None)
        self.assertEqual(size.name, '65536 MB RAM,800 GB SSD,9.00 TB BW')
        self.assertEqual(size.ram, 65536)

    def test_list_locations_success(self):
        locations = self.driver.list_locations()
        self.assertTrue(len(locations) >= 1)

        location = locations[0]
        self.assertEqual(location.id, '1')
        self.assertEqual(location.name, 'New Jersey')

    def test_list_nodes_success(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].id, '1')
        self.assertEqual(nodes[0].public_ips, ['108.61.206.153'])

    def test_reboot_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.reboot_node(node)
        self.assertTrue(result)

    def test_create_node_success(self):
        test_size = self.driver.list_sizes()[0]
        test_image = self.driver.list_images()[0]
        test_location = self.driver.list_locations()[0]
        created_node = self.driver.create_node('test-node', test_size,
                                               test_image, test_location)
        self.assertEqual(created_node.id, "1")

    def test_destroy_node_success(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.destroy_node(node)
        self.assertTrue(result)

    def test_list_key_pairs_success(self):
        key_pairs = self.driver.list_key_pairs()
        self.assertEqual(len(key_pairs), 1)
        key_pair = key_pairs[0]
        self.assertEqual(key_pair.id, '5806a8ef2a0c6')
        self.assertEqual(key_pair.name, 'test-key-pair')

    def test_create_key_pair_success(self):
        res = self.driver.create_key_pair('test-key-pair')
        self.assertTrue(res)

    def test_delete_key_pair_success(self):
        key_pairs = self.driver.list_key_pairs()
        key_pair = key_pairs[0]
        res = self.driver.delete_key_pair(key_pair)
        self.assertTrue(res)