def test_create_keypairs(self): """ Tests create agent and management keypairs, passing private key target path """ mgmt_key_name = "temp-unittest-mgmt-key" agent_key_name = "temp-unittest-agent-key" provider_config = _read_config(None) # setting special unit-test keynames. provider_config['compute']['management_server'][ 'management_keypair']['name'] = mgmt_key_name provider_config['compute']['agent_servers'][ 'agents_keypair']['name'] = agent_key_name cloud_driver = ExoscaleConnector(provider_config).create() keypair_creator = ExoscaleKeypairCreator(cloud_driver, provider_config) try: mgmt_pk_target_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), mgmt_key_name + ".pem") agent_pk_target_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), agent_key_name + ".pem") keypair_creator.create_key_pairs( mgmt_private_key_target_path=mgmt_pk_target_path, mgmt_keypair_name=mgmt_key_name, agent_private_key_target_path=agent_pk_target_path, agent_keypair_name=agent_key_name) if not keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair not created.') if not keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair not created.') keypair_creator.delete_keypairs() if keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair was not deleted.') if keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair was not deleted.') finally: try: cloud_driver.ex_delete_keypair(mgmt_key_name) cloud_driver.ex_delete_keypair(agent_key_name) except: pass
def test_create_keypairs(self): """ Tests create agent and management keypairs, passing private key target path """ mgmt_key_name = "temp-unittest-mgmt-key" agent_key_name = "temp-unittest-agent-key" provider_config = _read_config(None) #setting special unit-test keynames. provider_config['compute']['management_server'][ 'management_keypair']['name'] = mgmt_key_name provider_config['compute']['agent_servers'][ 'agents_keypair']['name'] = agent_key_name cloud_driver = ExoscaleConnector(provider_config).create() keypair_creator = ExoscaleKeypairCreator(cloud_driver, provider_config) try: mgmt_pk_target_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), mgmt_key_name + ".pem") agent_pk_target_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), agent_key_name + ".pem") keypair_creator.create_key_pairs( mgmt_private_key_target_path=mgmt_pk_target_path, mgmt_keypair_name=mgmt_key_name, agent_private_key_target_path=agent_pk_target_path, agent_keypair_name=agent_key_name) if not keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair not created.') if not keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair not created.') keypair_creator.delete_keypairs() if keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair was not deleted.') if keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair was not deleted.') finally: try: cloud_driver.ex_delete_keypair(mgmt_key_name) cloud_driver.ex_delete_keypair(agent_key_name) except: pass
def test_get_keypair(self): key_name = "temp_unittest_key" provider_config = _read_config(None) cloud_driver = ExoscaleConnector(provider_config).create() keypair_creator = ExoscaleKeypairCreator(cloud_driver, provider_config) key_pair = keypair_creator._get_keypair(key_name) if key_pair: raise AssertionError( 'the keypair {0} should not exist'.format(key_name)) cloud_driver.ex_create_keypair(key_name) key_pair = keypair_creator._get_keypair(key_name) if not key_pair: raise AssertionError( 'expecting to find an existing keypair with name {0}'.format( key_name)) cloud_driver.ex_delete_keypair(key_name)
def test_keypair_import(self): """ Tests public key import, passing public key path """ resource_folder_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), "test_resources") provider_config = _read_config(None) mgmt_key_name = 'temp-unittest-management-key' agent_key_name = 'temp-unittest-agent-key' # setting special unit-test keynames. provider_config['compute']['management_server'][ 'management_keypair']['name'] = mgmt_key_name provider_config['compute']['agent_servers'][ 'agents_keypair']['name'] = agent_key_name public_key_name = 'public_key.pub' public_key_path = os.path.join(resource_folder_path, public_key_name) try: cloud_driver = ExoscaleConnector(provider_config).create() keypair_creator = ExoscaleKeypairCreator(cloud_driver, provider_config) keypair_creator.create_key_pairs( mgmt_public_key_filepath=public_key_path, mgmt_keypair_name=mgmt_key_name, agent_public_key_filepath=public_key_path, agent_keypair_name=agent_key_name) keypair_creator.delete_keypairs() if keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair was not deleted.') if keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair was not deleted.') finally: try: cloud_driver.ex_delete_keypair(mgmt_key_name) cloud_driver.ex_delete_keypair(agent_key_name) except: pass
def test_keypair_import(self): """ Tests public key import, passing public key path """ resource_folder_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), "test_resources") provider_config = _read_config(None) mgmt_key_name = 'temp-unittest-management-key' agent_key_name = 'temp-unittest-agent-key' #setting special unit-test keynames. provider_config['compute']['management_server'][ 'management_keypair']['name'] = mgmt_key_name provider_config['compute']['agent_servers'][ 'agents_keypair']['name'] = agent_key_name public_key_name = 'public_key.pub' public_key_path = os.path.join(resource_folder_path, public_key_name) try: cloud_driver = ExoscaleConnector(provider_config).create() keypair_creator = ExoscaleKeypairCreator(cloud_driver, provider_config) keypair_creator.create_key_pairs( mgmt_public_key_filepath=public_key_path, mgmt_keypair_name=mgmt_key_name, agent_public_key_filepath=public_key_path, agent_keypair_name=agent_key_name) keypair_creator.delete_keypairs() if keypair_creator._get_keypair(mgmt_key_name): raise AssertionError('management keypair was not deleted.') if keypair_creator._get_keypair(agent_key_name): raise AssertionError('agent keypair was not deleted.') finally: try: cloud_driver.ex_delete_keypair(mgmt_key_name) cloud_driver.ex_delete_keypair(agent_key_name) except: pass