<s> """<STR_LIT>""" <EOL> import unittest <EOL> from cafe . drivers . unittest . decorators import tags <EOL> from cloudcafe . common . tools . datagen import rand_name <EOL> from cloudcafe . compute . common . clients . ping import PingClient <EOL> from cloudcafe . compute . common . exceptions import Forbidden <EOL> from cloudcafe . compute . common . types import NovaServerRebootTypes <EOL> from cloudcafe . compute . common . types import NovaServerStatusTypes as ServerStates <EOL> from cloudcafe . compute . composites import ComputeAdminComposite <EOL> from cloudroast . compute . fixtures import ServerFromImageFixture <EOL> class SuspendServerTests ( object ) : <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT:yes>' ) <EOL> def test_suspend_resume_server ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ping_ip = self . server . addresses . get_by_name ( <EOL> self . servers_config . network_for_ssh ) . ipv4 <EOL> response = self . admin_servers_client . suspend_server ( self . server . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . admin_server_behaviors . wait_for_server_status ( <EOL> self . server . id , ServerStates . SUSPENDED ) <EOL> PingClient . ping_until_unreachable ( <EOL> self . ping_ip , timeout = <NUM_LIT> , interval_time = <NUM_LIT:5> ) <EOL> response = self . admin_servers_client . resume_server ( self . server . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . admin_server_behaviors . wait_for_server_status ( <EOL> self . server . id , ServerStates . ACTIVE ) <EOL> PingClient . ping_until_reachable ( <EOL> self . ping_ip , timeout = <NUM_LIT> , interval_time = <NUM_LIT:5> ) <EOL> self . assertTrue ( self . server_behaviors . get_remote_instance_client ( <EOL> self . server , self . servers_config , key = self . key . private_key ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . server . id ) ) <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT:yes>' ) <EOL> def test_suspend_delete_server ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ping_ip = self . server . addresses . get_by_name ( <EOL> self . servers_config . network_for_ssh ) . ipv4 <EOL> response = self . admin_servers_client . suspend_server ( self . server . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . admin_server_behaviors . wait_for_server_status ( <EOL> self . server . id , ServerStates . SUSPENDED ) <EOL> PingClient . ping_until_unreachable ( <EOL> self . ping_ip , timeout = <NUM_LIT> , interval_time = <NUM_LIT:5> ) <EOL> delete_response = self . servers_client . delete_server ( self . server . id ) <EOL> self . assertEqual ( delete_response . status_code , <NUM_LIT> , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . server . id , delete_response . status_code ) ) <EOL> self . server_behaviors . wait_for_server_to_be_deleted ( self . server . id ) <EOL> class NegativeSuspendServerTests ( object ) : <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT:yes>' ) <EOL> def test_reboot_hard_suspended_server ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ping_ip = self . server . addresses . get_by_name ( <EOL> self . servers_config . network_for_ssh ) . ipv4 <EOL> response = self . admin_servers_client . suspend_server ( self . server . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . admin_server_behaviors . wait_for_server_status ( <EOL> self . server . id , ServerStates . SUSPENDED ) <EOL> PingClient . ping_until_unreachable ( <EOL> self . ping_ip , timeout = <NUM_LIT> , interval_time = <NUM_LIT:5> ) <EOL> with self . assertRaises ( Forbidden ) : <EOL> self . servers_client . reboot ( self . server . id , <EOL> NovaServerRebootTypes . HARD ) <EOL> PingClient . ping_until_unreachable ( <EOL> self . ping_ip , timeout = <NUM_LIT> , interval_time = <NUM_LIT:5> ) <EOL> class ServerFromImageSuspendTests ( ServerFromImageFixture , <EOL> SuspendServerTests ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( ServerFromImageSuspendTests , self ) . setUp ( ) <EOL> self . compute_admin = ComputeAdminComposite ( ) <EOL> self . admin_servers_client = self . compute_admin . servers . client <EOL> self . admin_server_behaviors = self . compute_admin . servers . behaviors <EOL> key_resp = self . keypairs_client . create_keypair ( rand_name ( "<STR_LIT:key>" ) ) <EOL> if key_resp . status_code != <NUM_LIT:200> : <EOL> raise Exception ( "<STR_LIT>" . format ( <EOL> key_resp . status_code ) ) <EOL> self . key = key_resp . entity <EOL> self . resources . add ( self . key . name , <EOL> self . keypairs_client . delete_keypair ) <EOL> self . server = self . server_behaviors . create_active_server ( <EOL> key_name = self . key . name ) . entity <EOL> self . resources . add ( self . server . id , self . servers_client . delete_server ) <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> class ServerFromImageNegativeSuspendTests ( ServerFromImageFixture , <EOL> NegativeSuspendServerTests ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> super ( ServerFromImageNegativeSuspendTests , cls ) . setUpClass ( ) <EOL> cls . compute_admin = ComputeAdminComposite ( ) <EOL> cls . admin_servers_client = cls . compute_admin . servers . client <EOL> cls . admin_server_behaviors = cls . compute_admin . servers . behaviors <EOL> cls . create_server ( ) </s>
