def create_one_client(self): """ Creates an XMLPRC client to OpenNebula. Returns: the new xmlrpc client. """ # context required for not validating SSL, old python versions won't validate anyway. if hasattr(ssl, '_create_unverified_context'): no_ssl_validation_context = ssl._create_unverified_context() else: no_ssl_validation_context = None # Check if the module can run if not HAS_PYONE: self.fail("pyone is required for this module") if 'api_url' in self.module.params: url = self.module.params.get("api_url", environ.get("ONE_URL", False)) else: self.fail( "Either api_url or the environment variable ONE_URL must be provided" ) if 'api_username' in self.module.params: username = self.module.params.get( "api_username", environ.get("ONE_USERNAME", False)) else: self.fail( "Either api_username or the environment vairable ONE_USERNAME must be provided" ) if 'api_password' in self.module.params: password = self.module.params.get( "api_password", environ.get("ONE_PASSWORD", False)) else: self.fail( "Either api_password or the environment vairable ONE_PASSWORD must be provided" ) session = "%s:%s" % (username, password) if not self.module.params.get( "validate_certs") and "PYTHONHTTPSVERIFY" not in environ: return OneServer(url, session=session, context=no_ssl_validation_context) else: return OneServer(url, session)
def test_auth_error(self): with self.assertRaises(OneAuthenticationException): afixture_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'auth.json.gz') # Disable SSL checks for TEST environment only, and deal with Centos, see issue #13 if "PYTHONHTTPSVERIFY" in os.environ: xone = OneServer(test_endpoint, fixture_file=afixture_file, session="oneadmin:invalidpass") else: xone = OneServer(test_endpoint, fixture_file=afixture_file, session="oneadmin:invalidpass", context=ssl._create_unverified_context()) xone.set_fixture_unit_test("test_auth_error") try: xone.hostpool.info() finally: xone.server_close()
'integration.json.gz') os.environ["PYONE_TEST_FIXTURE_REPLAY"] = "yes" # Note that we import a TesterServer that has extends with record/replay fixtures from pyone.server import OneServer # Deprecated utility, testing backward compatibility from pyone.util import one2dict # Capture OpenNebula Session parameters from environment or hardcoded... test_session = os.getenv("PYONE_SESSION", "oneadmin:onepass") test_endpoint = os.getenv("PYONE_ENDPOINT", 'https://192.168.121.78/RPC2') # Disable SSL checks for TEST environment only, and deal with Centos, see issue #13 if "PYTHONHTTPSVERIFY" in os.environ: one = OneServer(test_endpoint, session=test_session) else: one = OneServer(test_endpoint, session=test_session, context=ssl._create_unverified_context()) # Test Objects testHostAId = None testHostBId = None testVMAid = None class IntegrationTests(unittest.TestCase): @classmethod def setUpClass(cls): """