<s> import unittest <EOL> import sys <EOL> import random <EOL> import string <EOL> from libcloud . utils . py3 import httplib <EOL> from libcloud . compute . drivers . gandi import GandiNodeDriver <EOL> from libcloud . common . gandi import GandiException <EOL> from libcloud . compute . types import NodeState <EOL> from libcloud . test . file_fixtures import ComputeFileFixtures <EOL> from libcloud . test . secrets import GANDI_PARAMS <EOL> from libcloud . test . common . test_gandi import BaseGandiMockHttp <EOL> class GandiTests ( unittest . TestCase ) : <EOL> node_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> GandiNodeDriver . connectionCls . conn_classes = ( <EOL> GandiMockHttp , GandiMockHttp ) <EOL> GandiMockHttp . type = None <EOL> self . driver = GandiNodeDriver ( * GANDI_PARAMS ) <EOL> def test_list_nodes ( self ) : <EOL> nodes = self . driver . list_nodes ( ) <EOL> self . assertTrue ( len ( nodes ) > <NUM_LIT:0> ) <EOL> self . assertTrue ( len ( nodes [ <NUM_LIT:0> ] . public_ips ) > <NUM_LIT:1> ) <EOL> def test_list_locations ( self ) : <EOL> loc = list ( filter ( lambda x : '<STR_LIT>' in x . country . lower ( ) , <EOL> self . driver . list_locations ( ) ) ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( loc . country , '<STR_LIT>' ) <EOL> def test_list_images ( self ) : <EOL> loc = list ( filter ( lambda x : '<STR_LIT>' in x . country . lower ( ) , <EOL> self . driver . list_locations ( ) ) ) [ <NUM_LIT:0> ] <EOL> images = self . driver . list_images ( loc ) <EOL> self . assertTrue ( len ( images ) > <NUM_LIT:2> ) <EOL> def test_list_sizes ( self ) : <EOL> sizes = self . driver . list_sizes ( ) <EOL> self . assertTrue ( len ( sizes ) >= <NUM_LIT:1> ) <EOL> def test_destroy_node_running ( self ) : <EOL> nodes = self . driver . list_nodes ( ) <EOL> test_node = list ( filter ( lambda x : x . state == NodeState . RUNNING , <EOL> nodes ) ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( self . driver . destroy_node ( test_node ) ) <EOL> def test_destroy_node_halted ( self ) : <EOL> nodes = self . driver . list_nodes ( ) <EOL> test_node = list ( filter ( lambda x : x . state == NodeState . TERMINATED , <EOL> nodes ) ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( self . driver . destroy_node ( test_node ) ) <EOL> def test_reboot_node ( self ) : <EOL> nodes = self . driver . list_nodes ( ) <EOL> test_node = list ( filter ( lambda x : x . state == NodeState . RUNNING , <EOL> nodes ) ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( self . driver . reboot_node ( test_node ) ) <EOL> def test_create_node ( self ) : <EOL> login = '<STR_LIT>' <EOL> passwd = '<STR_LIT>' . join ( random . choice ( string . ascii_letters ) <EOL> for i in range ( <NUM_LIT:10> ) ) <EOL> loc = list ( filter ( lambda x : '<STR_LIT>' in x . country . lower ( ) , <EOL> self . driver . list_locations ( ) ) ) [ <NUM_LIT:0> ] <EOL> images = self . driver . list_images ( loc ) <EOL> images = [ x for x in images if x . name . lower ( ) . startswith ( '<STR_LIT>' ) ] <EOL> img = list ( filter ( lambda x : '<STR_LIT:5>' in x . name , images ) ) [ <NUM_LIT:0> ] <EOL> size = self . driver . list_sizes ( ) [ <NUM_LIT:0> ] <EOL> node = self . driver . create_node ( name = self . node_name , login = login , <EOL> password = passwd , image = img , <EOL> location = loc , size = size ) <EOL> self . assertEqual ( node . name , self . node_name ) <EOL> def test_create_volume ( self ) : <EOL> loc = list ( filter ( lambda x : '<STR_LIT>' in x . country . lower ( ) , <EOL> self . driver . list_locations ( ) ) ) [ <NUM_LIT:0> ] <EOL> volume = self . driver . create_volume ( <EOL> size = <NUM_LIT> , name = '<STR_LIT>' , location = loc ) <EOL> self . assertEqual ( volume . name , '<STR_LIT>' ) <EOL> self . assertEqual ( volume . size , <NUM_LIT> ) <EOL> def test_list_volumes ( self ) : <EOL> disks = self . driver . list_volumes ( ) <EOL> self . assertTrue ( len ( disks ) > <NUM_LIT:0> ) <EOL> def test_destroy_volume ( self ) : <EOL> volumes = self . driver . list_volumes ( ) <EOL> test_vol = list ( filter ( lambda x : x . name == '<STR_LIT>' , <EOL> volumes ) ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( self . driver . destroy_volume ( test_vol ) ) <EOL> def test_attach_volume ( self ) : <EOL> disks = self . driver . list_volumes ( ) <EOL> nodes = self . driver . list_nodes ( ) <EOL> res = self . driver . attach_volume ( nodes [ <NUM_LIT:0> ] , disks [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( res ) <EOL> def test_detach_volume ( self ) : <EOL> disks = self . driver . list_volumes ( ) <EOL> nodes = self . driver . list_nodes ( ) <EOL> res = self . driver . detach_volume ( nodes [ <NUM_LIT:0> ] , disks [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( res ) <EOL> def test_ex_list_interfaces ( self ) : <EOL> ifaces = self . driver . ex_list_interfaces ( ) <EOL> self . assertTrue ( len ( ifaces ) > <NUM_LIT:0> ) <EOL> def test_ex_attach_interface ( self ) : <EOL> ifaces = self . driver . ex_list_interfaces ( ) <EOL> nodes = self . driver . list_nodes ( ) <EOL> res = self . driver . ex_node_attach_interface ( nodes [ <NUM_LIT:0> ] , ifaces [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( res ) <EOL> def test_ex_detach_interface ( self ) : <EOL> ifaces = self . driver . ex_list_interfaces ( ) <EOL> nodes = self . driver . list_nodes ( ) <EOL> res = self . driver . ex_node_detach_interface ( nodes [ <NUM_LIT:0> ] , ifaces [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( res ) <EOL> def test_ex_snapshot_disk ( self ) : <EOL> disks = self . driver . list_volumes ( ) <EOL> self . assertTrue ( self . driver . ex_snapshot_disk ( disks [ <NUM_LIT:2> ] ) ) <EOL> self . assertRaises ( GandiException , <EOL> self . driver . ex_snapshot_disk , disks [ <NUM_LIT:0> ] ) <EOL> def test_ex_update_disk ( self ) : <EOL> disks = self . driver . list_volumes ( ) <EOL> self . assertTrue ( self . driver . ex_update_disk ( disks [ <NUM_LIT:0> ] , new_size = <NUM_LIT> ) ) <EOL> def test_list_key_pairs ( self ) : <EOL> keys = self . driver . list_key_pairs ( ) <EOL> self . assertTrue ( len ( keys ) > <NUM_LIT:0> ) <EOL> def test_get_key_pair ( self ) : <EOL> key = self . driver . get_key_pair ( <NUM_LIT:10> ) <EOL> self . assertEqual ( key . name , '<STR_LIT>' ) <EOL> def test_import_key_pair_from_string ( self ) : <EOL> key = self . driver . import_key_pair_from_string ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( key . name , '<STR_LIT>' ) <EOL> self . assertEqual ( key . extra [ '<STR_LIT:id>' ] , <NUM_LIT:10> ) <EOL> def test_delete_key_pair ( self ) : <EOL> response = self . driver . delete_key_pair ( <NUM_LIT:10> ) <EOL> self . assertTrue ( response ) <EOL> def test_ex_get_node ( self ) : <EOL> node = self . driver . ex_get_node ( <NUM_LIT> ) <EOL> self . assertEqual ( node . name , "<STR_LIT>" ) <EOL> def test_ex_get_volume ( self ) : <EOL> volume = self . driver . ex_get_volume ( <NUM_LIT> ) <EOL> self . assertEqual ( volume . name , "<STR_LIT>" ) <EOL> class GandiRatingTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> node_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> GandiNodeDriver . connectionCls . conn_classes = ( <EOL> GandiMockRatingHttp , GandiMockRatingHttp ) <EOL> GandiMockRatingHttp . type = None <EOL> self . driver = GandiNodeDriver ( * GANDI_PARAMS ) <EOL> def test_list_sizes ( self ) : <EOL> sizes = self . driver . list_sizes ( ) <EOL> self . assertEqual ( len ( sizes ) , <NUM_LIT:4> ) <EOL> def test_create_node ( self ) : <EOL> login = '<STR_LIT>' <EOL> passwd = '<STR_LIT>' . join ( random . choice ( string . ascii_letters ) <EOL> for i in range ( <NUM_LIT:10> ) ) <EOL> loc = list ( filter ( lambda x : '<STR_LIT>' in x . country . lower ( ) , <EOL> self . driver . list_locations ( ) ) ) [ <NUM_LIT:0> ] <EOL> images = self . driver . list_images ( loc ) <EOL> images = [ x for x in images if x . name . lower ( ) . startswith ( '<STR_LIT>' ) ] <EOL> img = list ( filter ( lambda x : '<STR_LIT:5>' in x . name , images ) ) [ <NUM_LIT:0> ] <EOL> size = self . driver . list_sizes ( ) [ <NUM_LIT:0> ] <EOL> node = self . driver . create_node ( name = self . node_name , login = login , <EOL> password = passwd , image = img , <EOL> location = loc , size = size ) <EOL> self . assertEqual ( node . name , self . node_name ) <EOL> class GandiMockHttp ( BaseGandiMockHttp ) : <EOL> fixtures = ComputeFileFixtures ( '<STR_LIT>' ) <EOL> def _xmlrpc__hosting_datacenter_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_image_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_ip_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_account_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_delete ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__operation_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_create_from ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_reboot ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_stop ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_iface_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_iface_attach ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_iface_detach ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_disk_attach ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_disk_detach ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_create ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_create_from ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_update ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_disk_delete ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_ssh_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_ssh_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_ssh_create ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_ssh_delete ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> class GandiMockRatingHttp ( BaseGandiMockHttp ) : <EOL> """<STR_LIT>""" <EOL> fixtures = ComputeFileFixtures ( '<STR_LIT>' ) <EOL> def _xmlrpc__hosting_datacenter_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_image_list ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_create_from ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__operation_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_vm_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc__hosting_account_info ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( unittest . main ( ) ) </s>
