def test_fails_if_app_isnt_running(self): # If the user wants to relocate their app to port X, but their app isn't # even running, this should fail. # Assume that the AppController is running but our app isn't. flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('get_app_info_map').with_args( 'the secret').and_return(json.dumps({})) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) argv = [ '--keyname', self.keyname, '--appname', self.appid, '--http_port', '80', '--https_port', '443' ] options = ParseArgs(argv, self.function).args self.assertRaises(AppScaleException, AppScaleTools.relocate_app, options)
def test_wait_for_machines_to_finish_loading(self): # mock out reading the secret key builtins = flexmock(sys.modules["__builtin__"]) builtins.should_call("open") # set the fall-through secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret" fake_secret = flexmock(name="fake_secret") fake_secret.should_receive("read").and_return("the secret") builtins.should_receive("open").with_args(secret_key_location, "r").and_return(fake_secret) # mock out getting all the ips in the deployment from the head node fake_soap = flexmock(name="fake_soap") fake_soap.should_receive("get_all_public_ips").with_args("the secret").and_return( json.dumps(["public1", "public2"]) ) role_info = [ {"public_ip": "public1", "private_ip": "private1", "jobs": ["shadow", "db_master"]}, {"public_ip": "public2", "private_ip": "private2", "jobs": ["appengine"]}, ] fake_soap.should_receive("get_role_info").with_args("the secret").and_return(json.dumps(role_info)) # also, let's say that our machines aren't running the first time we ask, # but that they are the second time fake_soap.should_receive("is_done_initializing").with_args("the secret").and_return(False).and_return(True) flexmock(SOAPpy) SOAPpy.should_receive("SOAPProxy").with_args("https://public1:17443").and_return(fake_soap) SOAPpy.should_receive("SOAPProxy").with_args("https://public2:17443").and_return(fake_soap) RemoteHelper.wait_for_machines_to_finish_loading("public1", "bookey")
def test_all_ok(self): # If the user wants to relocate their app to port X, and nothing else # runs on that port, this should succeed. # Assume that the AppController is running, so is our app, and that other # apps are not running on port 80. fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('get_app_info_map').with_args( 'the secret').and_return(json.dumps({ self.appid : { 'nginx' : 8080 }, 'a-different-app' : { 'nginx' : 81 } })) fake_appcontroller.should_receive('relocate_app').with_args(self.appid, 80, 443, 'the secret').and_return("OK") flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) argv = [ '--keyname', self.keyname, '--appname', self.appid, '--http_port', '80', '--https_port', '443' ] options = ParseArgs(argv, self.function).args AppScaleTools.relocate_app(options)
def setup_appcontroller_mocks(self, public_ip, private_ip): # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('set_parameters').with_args(str, list, ['none'], 'the secret').and_return('OK') fake_appcontroller.should_receive('get_all_public_ips').with_args('the secret') \ .and_return(json.dumps([public_ip])) role_info = [{ 'public_ip' : public_ip, 'private_ip' : private_ip, 'jobs' : ['shadow', 'login'] }] fake_appcontroller.should_receive('get_role_info').with_args('the secret') \ .and_return(json.dumps(role_info)) fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('nothing interesting here') \ .and_return('Database is at not-up-yet') \ .and_return('Database is at {0}'.format(public_ip)) fake_appcontroller.should_receive('is_done_initializing') \ .and_return(False) \ .and_return(True) fake_appcontroller.should_receive('is_initialized').and_return(True) fake_appcontroller.should_receive('does_user_exist').and_return(False) fake_appcontroller.should_receive('set_admin_role').and_return() fake_appcontroller.should_receive('create_user').with_args( '*****@*****.**', str, 'xmpp_user', 'the secret') \ .and_return('true') fake_appcontroller.should_receive('create_user').with_args( 'a@' + public_ip, str, 'xmpp_user', 'the secret') \ .and_return('true') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://{0}:17443'.format( public_ip)).and_return(fake_appcontroller)
def test_remove_app_and_app_is_running(self): # mock out reading from stdin, and assume the user says 'YES' builtins = flexmock(sys.modules['__builtin__']) builtins.should_receive('raw_input').and_return('YES') # mock out reading the secret key builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) app_stats_data = {'apps': {'blargapp': {'http': 8080, 'language': 'python27', 'total_reqs': 'no_change', 'appservers': 1, 'https': 4380, 'reqs_enqueued': None}}} # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') fake_appcontroller.should_receive('stop_app').with_args('blargapp', 'the secret').and_return('OK') fake_appcontroller.should_receive('is_app_running').with_args('blargapp', 'the secret').and_return(True).and_return(True).and_return(False) fake_appcontroller.should_receive('does_app_exist').with_args('blargapp', 'the secret').and_return(True) fake_appcontroller.should_receive('get_all_stats').with_args( 'the secret').and_return(json.dumps(app_stats_data)) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return( json.dumps({"node_info": [{ "public_ip": "public1", "private_ip": "private1", "jobs": ["shadow", "login"] }]})) fake_nodes_json.should_receive('write').and_return() builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) flexmock(RemoteHelper).should_receive('is_port_open').and_return(False) argv = [ "--appname", "blargapp", "--keyname", self.keyname ] options = ParseArgs(argv, self.function).args AppScaleTools.remove_app(options)
def _gotError(self, failure, request, methodName): e = failure.value if isinstance(e, SOAPpy.faultType): fault = e else: fault = SOAPpy.faultType("%s:Server" % SOAPpy.NS.ENV_T, "Method %s failed." % methodName) response = SOAPpy.buildSOAP(fault, encoding=self.encoding) self._sendResponse(request, response, status=500)
def test_appscale_in_two_node_virt_deployment(self): # pretend that the place we're going to put logs into doesn't exist flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args('/tmp/foobaz').and_return(False) # and mock out the mkdir operation flexmock(os) os.should_receive('mkdir').with_args('/tmp/foobaz').and_return() # next, mock out finding the login ip address os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return(json.dumps([{ "public_ip" : "public1", "private_ip" : "private1", "jobs" : ["shadow", "login"] }])) builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) # mock out writing the secret key to ~/.appscale, as well as reading it # later secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # and slip in a fake appcontroller to report on the two IP addrs fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('get_all_public_ips').with_args( 'the secret').and_return(json.dumps(['public1', 'public2'])) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) # fake the creation of the log directories locally os.should_receive('mkdir').with_args('/tmp/foobaz/public1').and_return() os.should_receive('mkdir').with_args('/tmp/foobaz/public2').and_return() # finally, fake the copying of the log files flexmock(subprocess) subprocess.should_receive('Popen').with_args(re.compile('/var/log/appscale'), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \ .and_return(self.success) argv = [ "--keyname", self.keyname, "--location", "/tmp/foobaz" ] options = ParseArgs(argv, self.function).args AppScaleTools.gather_logs(options)
def test_describe_instances_with_two_nodes(self): # mock out writing the secret key to ~/.appscale, as well as reading it # later builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') fake_secret.should_receive('write').and_return() builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('get_all_public_ips').with_args('the secret') \ .and_return(json.dumps(['public1', 'public2'])) fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('nothing interesting here') \ .and_return('Database is at not-up-yet') \ .and_return('Database is at 1.2.3.4') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) SOAPpy.should_receive('SOAPProxy').with_args('https://public2:17443') \ .and_return(fake_appcontroller) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return(json.dumps( {"node_info": [{ "public_ip": "public1", "private_ip": "private1", "jobs": ["shadow", "login"] }, { "public_ip": "public2", "private_ip": "private2", "jobs": ["appengine"] }, ]})) fake_nodes_json.should_receive('write').and_return() builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) # assume that there are two machines running in our deployment argv = [ "--keyname", self.keyname ] options = ParseArgs(argv, self.function).args AppScaleTools.describe_instances(options)
def test_remove_app_and_app_is_running(self): # mock out reading from stdin, and assume the user says 'YES' builtins = flexmock(sys.modules['__builtin__']) builtins.should_receive('raw_input').and_return('YES') # mock out reading the secret key builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') fake_appcontroller.should_receive('stop_app').with_args('blargapp', 'the secret').and_return('OK') fake_appcontroller.should_receive('is_app_running').with_args('blargapp', 'the secret').and_return(True).and_return(True).and_return(False) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return(json.dumps([{ "public_ip" : "public1", "private_ip" : "private1", "jobs" : ["shadow", "login"] }])) fake_nodes_json.should_receive('write').and_return() builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) # mock out calls to the UserAppServer and presume that the app does exist fake_userappserver = flexmock(name='fake_uaserver') fake_userappserver.should_receive('get_app_data').with_args( 'blargapp', 'the secret').and_return(json.dumps({ 'hosts' : { '192.168.1.1' : { 'http' : '80', 'https' : '443' }}})) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:4343') \ .and_return(fake_userappserver) argv = [ "--appname", "blargapp", "--keyname", self.keyname ] options = ParseArgs(argv, self.function).args AppScaleTools.remove_app(options)
def test_update_local_metadata(self): # mock out getting all the ips in the deployment from the head node fake_soap = flexmock(name='fake_soap') fake_soap.should_receive('get_all_public_ips').with_args('the secret') \ .and_return(json.dumps(['public1'])) role_info = [{ 'public_ip' : 'public1', 'private_ip' : 'private1', 'jobs' : ['shadow', 'db_master'] }] fake_soap.should_receive('get_role_info').with_args('the secret') \ .and_return(json.dumps(role_info)) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_soap) # mock out reading the secret key fake_secret = flexmock(name='fake_secret') fake_secret.should_receive('read').and_return('the secret') builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') builtins.should_receive('open').with_args( LocalState.get_secret_key_location('booscale'), 'r') \ .and_return(fake_secret) # mock out writing the yaml file fake_locations_yaml = flexmock(name='fake_locations_yaml') fake_locations_yaml.should_receive('write').with_args(yaml.dump({ 'load_balancer': 'public1', 'instance_id': 'i-ABCDEFG', 'secret': 'the secret', 'infrastructure': 'ec2', 'group': 'boogroup', 'ips': 'public1', 'table': 'cassandra', 'db_master': 'node-0', 'zone' : 'my-zone-1b' })).and_return() builtins.should_receive('open').with_args( LocalState.get_locations_yaml_location('booscale'), 'w') \ .and_return(fake_locations_yaml) # and mock out writing the json file fake_locations_json = flexmock(name='fake_locations_json') fake_locations_json.should_receive('write').with_args(json.dumps( role_info)).and_return() builtins.should_receive('open').with_args( LocalState.get_locations_json_location('booscale'), 'w') \ .and_return(fake_locations_json) options = flexmock(name='options', table='cassandra', infrastructure='ec2', keyname='booscale', group='boogroup', zone='my-zone-1b') node_layout = NodeLayout(options={ 'min' : 1, 'max' : 1, 'infrastructure' : 'ec2', 'table' : 'cassandra' }) host = 'public1' instance_id = 'i-ABCDEFG' LocalState.update_local_metadata(options, node_layout, host, instance_id)
def test_reset_password_for_user_that_exists(self): # put in a mock for reading the secret file builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out reading the username and new password from the user builtins.should_receive('raw_input').and_return('*****@*****.**') flexmock(getpass) getpass.should_receive('getpass').and_return('the password') # mock out finding the login node's IP address from the json file flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_secret") fake_nodes_json.should_receive('read').and_return(json.dumps([{ 'public_ip' : 'public1', 'private_ip' : 'private1', 'jobs' : ['login', 'db_master'] }])) builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) # mock out grabbing the userappserver ip from an appcontroller fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('nothing interesting here') \ .and_return('Database is at not-up-yet') \ .and_return('Database is at public1') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@foo.goo', str, 'the secret').and_return('true') SOAPpy.should_receive('SOAPProxy').with_args('https://public1:4343') \ .and_return(fake_userappserver) argv = [ "--keyname", self.keyname ] options = ParseArgs(argv, self.function).args AppScaleTools.reset_password(options)
def test_sensor_app_not_deployed_when_deployment_not_registered(self): # Test sensor app is not deployed when deployment is not registered. flexmock(helper).should_receive('get_deployment_id').and_return(None) flexmock(hermes).should_receive('create_appscale_user').and_return().\ times(0) flexmock(hermes).should_receive('create_xmpp_user').and_return().\ times(0) flexmock(AppControllerClient).should_receive('upload_app').and_return().\ times(0) deploy_sensor_app() # Test sensor app is not deployed when it is already running. flexmock(helper).should_receive('get_deployment_id').and_return( self.DEPLOYMENT_ID) flexmock(appscale_info).should_receive('get_secret').and_return( "fake_secret") flexmock(appscale_info).should_receive('get_db_master_ip').and_return() fake_uaserver = flexmock(name='fake_uaserver') # Assume appscalesensor app already running. fake_uaserver.should_receive('is_app_enabled').with_args( 'appscalesensor', 'fake_secret').and_return("true") flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').and_return(fake_uaserver) flexmock(AppControllerClient).should_receive('upload_app').and_return(). \ times(0) deploy_sensor_app() # Test sensor app is not deployed when the app is not currently running but # there was an error in creating a new user. fake_uaserver.should_receive('is_app_enabled').with_args( 'appscalesensor', 'fake_secret').and_return("false") # Assume error while creating a new user. fake_uaserver.should_receive('does_user_exist').and_return("false") fake_uaserver.should_receive('commit_new_user').and_return("false") flexmock(hermes).should_receive('create_appscale_user').and_return(). \ times(1) flexmock(AppControllerClient).should_receive('upload_app').and_return(). \ times(0) deploy_sensor_app() # Test sensor app is deployed after successfully creating a new user or # with an existing user. fake_uaserver.should_receive('commit_new_user').and_return("true") flexmock(tarfile).should_receive('open').and_return(tarfile.TarFile) flexmock(tarfile.TarFile).should_receive('add').and_return() flexmock(tarfile.TarFile).should_receive('close').and_return() flexmock(appscale_info).should_receive('get_appcontroller_client').and_return( AppControllerClient) flexmock(hermes).should_receive('create_appscale_user').and_return(True) flexmock(hermes).should_receive('create_xmpp_user').and_return(True) flexmock(AppControllerClient).should_receive('upload_app').and_return(). \ times(1) deploy_sensor_app()
def get_library(self, name): if not is_valid_identifier(name): raise SOAPpy.faultType(lib_name_error, _("Incorrect library name"), "") self.__sem.lock() try: library = None for child in self.libraries_element.children: if name == child.attributes["name"]: library = child break if not library: raise SOAPpy.faultType(lib_name_error, _("No such library '%s'" % name), "") return library.toxml(encode = False) finally: self.__sem.unlock()
def test_remove_app_but_app_isnt_running(self): # mock out reading from stdin, and assume the user says 'yes' builtins = flexmock(sys.modules['__builtin__']) builtins.should_receive('raw_input').and_return('yes') # mock out reading the secret key builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') fake_appcontroller.should_receive('is_app_running').with_args('blargapp', 'the secret').and_return(False) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return( json.dumps({"node_info": [{ "public_ip": "public1", "private_ip": "private1", "jobs": ["shadow", "login"] }]})) fake_nodes_json.should_receive('write').and_return() builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) argv = [ "--appname", "blargapp", "--keyname", self.keyname ] options = ParseArgs(argv, self.function).args self.assertRaises(AppScaleException, AppScaleTools.remove_app, options)
def test_get_property(self): # put in a mock for reading the secret file builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out finding the shadow node's IP address from the json file flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location(self.keyname)).and_return(True) fake_nodes_json = flexmock(name="fake_secret") fake_nodes_json.should_receive('read').and_return( json.dumps({"node_info": [{ 'public_ip': 'public1', 'private_ip': 'private1', 'roles': ['shadow'] }]})) builtins.should_receive('open').with_args( LocalState.get_locations_json_location(self.keyname), 'r') \ .and_return(fake_nodes_json) # mock out grabbing the userappserver ip from an appcontroller property_name = "name" property_value = "value" fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('set_property').with_args(property_name, property_value, 'the secret').and_return('OK') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_appcontroller) argv = [ "--keyname", self.keyname, "--property_name", property_name, "--property_value", property_value ] options = ParseArgs(argv, self.function).args result = AppScaleTools.set_property(options) self.assertEqual(None, result)
def handle_result(result): r = SOAPpy.parseSOAP(result) if r.DoDirectPaymentResponse.Ack == "Success": self.log.info(" - ") self.log.info("Received success from PayPal for %s" % (user_info['username']) ) self.log.info("%s" % result) payment_info = { 'transaction_id': r.DoDirectPaymentResponse.TransactionID, 'username': user_info['username'], 'amount': r.DoDirectPaymentResponse.Amount, 'avs_code': r.DoDirectPaymentResponse.AVSCode, 'cvv2_code': r.DoDirectPaymentResponse.CVV2Code, 'processing_node': self.app.host, } return (0, payment_info) else: self.log.info(" - ") if isinstance(r.DoDirectPaymentResponse.Errors, (list, tuple)): error_code = r.DoDirectPaymentResponse.Errors[0].ErrorCode long_message = r.DoDirectPaymentResponse.Errors[0].LongMessage else: error_code = r.DoDirectPaymentResponse.Errors.ErrorCode long_message = r.DoDirectPaymentResponse.Errors.LongMessage self.log.info("Did NOT receive success from PayPal: %s" % long_message) self.log.info("INFO: %s, %s" % (user_info['username'], self.app.host)) self.log.info("%s" % result) return (1, "%s: %s" % (error_code, long_message))
def call(self, method, **kwargs): """ Call the given remote method with the given arguments, as keywords. Returns a deferred, called with SOAPpy structure representing the soap response. @param method: The method name to call, eg. 'GetExternalIP' @param kwargs: The parameters of the call, as keywords @return: A deferred called with the external ip address of this host @rtype: L{twisted.internet.defer.Deferred} """ payload = SOAPpy.buildSOAP(method=method, config=Config, namespace=self._prefix, kw=kwargs) # Here begins the nasty hack payload = payload.replace( # Upnp wants s: instead of SOAP-ENV 'SOAP-ENV','s').replace( # Doesn't seem to like these encoding stuff 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"', '').replace( 'SOAP-ENC:root="1"', '').replace( # And it wants u: instead of ns1 namespace for arguments.. 'ns1','u') logging.debug("SOAP Payload:\n%s", payload) return client.getPage(self._url, postdata=payload, method="POST", headers={'content-type': 'text/xml', 'SOAPACTION': '%s#%s' % (self._prefix, method)} ).addCallbacks(self._got_page, self._got_error)
def _skeleton(self,*parameters,**kparameters): """ Dynamically generated method. Protocol: SOAP. Method name: METHOD_NAME. Documentation: DOCUMENTATION """ try: if SERIALIZE: parameters_instance = pickle.loads(parameters[0]) if SERIALIZE_MAPPING: parameters_instance = mapper.load_from_dto(parameters_instance) params, kparams = parameters_instance result = getattr(self._parent,'do_'+METHOD_NAME)( *params, **kparams ) if SERIALIZE_MAPPING: result = mapper.dto_generator(result) dumped_result = pickle.dumps(result) return dumped_result else: return getattr(self._parent,'do_'+METHOD_NAME)(*parameters,**kparameters) except Exception as e: # TODO: watch out, if server gets a Control + C, the exception is going to propagate tb = traceback.format_exc() if type(e) == types.InstanceType: class_name = str(e.__class__) else: class_name = type(e).__module__ + '.' + type(e).__name__ log.log(self,log.level.Info,"Exception : " + class_name + "; " + e.args[0] + "; " + tb) raise SOAPpy.faultType( faultcode=class_name, faultstring=e.args[0], detail=tb )
def set_library(self, name, data): if not is_valid_identifier(name): raise SOAPpy.faultType(lib_name_error, _("Incorrect library name"), "") self.__sem.lock() try: item = None for child in self.libraries_element.children: if name == child.attributes["name"]: item = child break if item: item.value = data else: x = xml_object(name="Library") x.attributes["Name"] = name self.libraries_element.children.append(x) x.value = data if "vscript" == self.scripting_language: try: x, y = vcompile(data, bytecode = 0) managers.file_manager.write_lib(self.id, name, x) self.libs[name] = y except: pass else: value="from scripting import server, application, log, session, request, response, VDOM_object, obsolete_request\n%s\n"%data managers.file_manager.write_lib(self.id, name, value) self.libs[name] = None self.invalidate_libraries() finally: self.__sem.unlock()
def render(self, request): """Handle a SOAP command.""" data = request.content.read() p, header, body, attrs = SOAPpy.parseSOAPRPC(data, 1, 1, 1) methodName, args, kwargs, ns = p._name, p._aslist, p._asdict, p._ns # deal with changes in SOAPpy 0.11 if callable(args): args = args() if callable(kwargs): kwargs = kwargs() function = self.lookupFunction(methodName) if not function: self._methodNotFound(request, methodName) return server.NOT_DONE_YET else: if hasattr(function, "useKeywords"): keywords = {} for k, v in kwargs.items(): keywords[str(k)] = v d = defer.maybeDeferred(function, **keywords) else: d = defer.maybeDeferred(function, *args) d.addCallback(self._gotResult, request, methodName) d.addErrback(self._gotError, request, methodName) return server.NOT_DONE_YET
def _gotResult(self, result, request, methodName): # hack twisted.web.soap here: # do not wrap result in a <Result> element response = SOAPpy.buildSOAP( kw={'%sResponse' % methodName: result}, encoding=self.encoding) self._sendResponse(request, response)
def callRemote(self, method, *args, **kwargs): payload = SOAPpy.buildSOAP(args=args, kw=kwargs, method=method, header=self.header, namespace=self.namespace) return client.getPage(self.url, postdata=payload, method="POST", headers={'content-type': 'text/xml', 'SOAPAction': method} ).addCallback(self._cbGotResult)
def _cbGotResult(self, result): result = SOAPpy.parseSOAPRPC(result) if hasattr(result, 'Result'): return result.Result elif len(result) == 1: return result[0] else: return result
def callRemote(self, method, *args, **kwargs): print "callRemote: " + str(args) kwargs.setdefault('headers', {})['Content-Type'] = 'text/xml' payload = SOAPpy.buildSOAP(args=args, kw=kwargs, method=method, header=None, namespace=None) return client.getPage(self.url, postdata=payload, method="POST", headers = kwargs['headers'] ).addCallback(self._cbGotResult)
def test_create_user_accounts(self): # mock out reading the secret key builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret" fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location('bookey')).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return( json.dumps({"node_info": [{ "public_ip": "public1", "private_ip": "private1", "roles": ["shadow"] }]})) builtins.should_receive('open').with_args( LocalState.get_locations_json_location('bookey'), 'r') \ .and_return(fake_nodes_json) # Mock out SOAP interactions with the AppController. fake_appcontroller = flexmock(name="fake_appcontroller") fake_appcontroller.should_receive('does_user_exist').with_args('*****@*****.**', 'the secret').and_return('false') fake_appcontroller.should_receive('create_user').with_args('*****@*****.**', str, 'xmpp_user', 'the secret').and_return('true') fake_appcontroller.should_receive('does_user_exist').with_args('boo@public1', 'the secret').and_return('false') fake_appcontroller.should_receive('create_user').with_args('boo@public1', str, 'xmpp_user', 'the secret').and_return('true') fake_appcontroller.should_receive('get_property').\ with_args('login', 'the secret').and_return('{"login":"******"}') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@foo.goo', 'password', 'public1', 'bookey')
def setup_appcontroller_mocks(self, public_ip, private_ip): # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name="fake_appcontroller") fake_appcontroller.should_receive("set_parameters").with_args(str, list, ["none"], "the secret").and_return( "OK" ) fake_appcontroller.should_receive("get_all_public_ips").with_args("the secret").and_return( json.dumps([public_ip]) ) role_info = [{"public_ip": public_ip, "private_ip": private_ip, "jobs": ["shadow", "login"]}] fake_appcontroller.should_receive("get_role_info").with_args("the secret").and_return(json.dumps(role_info)) fake_appcontroller.should_receive("status").with_args("the secret").and_return( "nothing interesting here" ).and_return("Database is at not-up-yet").and_return("Database is at {0}".format(public_ip)) fake_appcontroller.should_receive("is_done_initializing").and_return(False).and_return(True) flexmock(SOAPpy) SOAPpy.should_receive("SOAPProxy").with_args("https://{0}:17443".format(public_ip)).and_return( fake_appcontroller )
def test_create_user_accounts(self): # mock out reading the secret key builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret" fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out reading the locations.json file, and slip in our own json flexmock(os.path) os.path.should_call('exists') # set the fall-through os.path.should_receive('exists').with_args( LocalState.get_locations_json_location('bookey')).and_return(True) fake_nodes_json = flexmock(name="fake_nodes_json") fake_nodes_json.should_receive('read').and_return(json.dumps([{ "public_ip" : "public1", "private_ip" : "private1", "jobs" : ["shadow", "login"] }])) builtins.should_receive('open').with_args( LocalState.get_locations_json_location('bookey'), 'r') \ .and_return(fake_nodes_json) # mock out SOAP interactions with the UserAppServer fake_soap = flexmock(name='fake_soap') fake_soap.should_receive('does_user_exist').with_args('*****@*****.**', 'the secret').and_return('false') fake_soap.should_receive('commit_new_user').with_args('*****@*****.**', str, 'xmpp_user', 'the secret').and_return('true') fake_soap.should_receive('does_user_exist').with_args('boo@public1', 'the secret').and_return('false') fake_soap.should_receive('commit_new_user').with_args('boo@public1', str, 'xmpp_user', 'the secret').and_return('true') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@foo.goo', 'password', 'public1', 'bookey', False)
def test_wait_for_machines_to_finish_loading(self): # mock out reading the secret key builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret" fake_secret = flexmock(name="fake_secret") fake_secret.should_receive('read').and_return('the secret') builtins.should_receive('open').with_args(secret_key_location, 'r') \ .and_return(fake_secret) # mock out getting all the ips in the deployment from the head node fake_soap = flexmock(name='fake_soap') fake_soap.should_receive('get_all_public_ips').with_args('the secret') \ .and_return(json.dumps(['public1', 'public2'])) role_info = [ { 'public_ip' : 'public1', 'private_ip' : 'private1', 'jobs' : ['shadow', 'db_master'] }, { 'public_ip' : 'public2', 'private_ip' : 'private2', 'jobs' : ['appengine'] } ] fake_soap.should_receive('get_role_info').with_args('the secret') \ .and_return(json.dumps(role_info)) # also, let's say that our machines aren't running the first time we ask, # but that they are the second time fake_soap.should_receive('is_done_initializing').with_args('the secret') \ .and_return(False).and_return(True) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \ .and_return(fake_soap) SOAPpy.should_receive('SOAPProxy').with_args('https://public2:17443') \ .and_return(fake_soap) RemoteHelper.wait_for_machines_to_finish_loading('public1', 'bookey')
def setup_uaserver_mocks(self, public_uaserver_address): # mock out calls to the UserAppServer and presume that calls to create new # users succeed fake_userappserver = flexmock(name='fake_userappserver') fake_userappserver.should_receive('does_user_exist').with_args( '*****@*****.**', 'the secret').and_return('false') fake_userappserver.should_receive('does_user_exist').with_args( 'a@' + public_uaserver_address, 'the secret').and_return('false') fake_userappserver.should_receive('commit_new_user').with_args( '*****@*****.**', str, 'xmpp_user', 'the secret') \ .and_return('true') fake_userappserver.should_receive('commit_new_user').with_args( 'a@' + public_uaserver_address, str, 'xmpp_user', 'the secret') \ .and_return('true') fake_userappserver.should_receive('set_cloud_admin_status').with_args( '*****@*****.**', 'true', 'the secret').and_return() fake_userappserver.should_receive('set_capabilities').with_args( '*****@*****.**', UserAppClient.ADMIN_CAPABILITIES, 'the secret').and_return() SOAPpy.should_receive('SOAPProxy').with_args('https://{0}:4343'.format( public_uaserver_address)).and_return(fake_userappserver)
def test_get_property(self): # put in a mock for reading the secret file builtins = flexmock(sys.modules["__builtin__"]) builtins.should_call("open") # set the fall-through secret_key_location = LocalState.get_secret_key_location(self.keyname) fake_secret = flexmock(name="fake_secret") fake_secret.should_receive("read").and_return("the secret") builtins.should_receive("open").with_args(secret_key_location, "r").and_return(fake_secret) # mock out finding the shadow node's IP address from the json file flexmock(os.path) os.path.should_call("exists") # set the fall-through os.path.should_receive("exists").with_args(LocalState.get_locations_json_location(self.keyname)).and_return( True ) fake_nodes_json = flexmock(name="fake_secret") fake_nodes_json.should_receive("read").and_return( json.dumps({"node_info": [{"public_ip": "public1", "private_ip": "private1", "jobs": ["login", "shadow"]}]}) ) builtins.should_receive("open").with_args(LocalState.get_locations_json_location(self.keyname), "r").and_return( fake_nodes_json ) # mock out grabbing the userappserver ip from an appcontroller property_name = "name" property_value = "value" fake_appcontroller = flexmock(name="fake_appcontroller") fake_appcontroller.should_receive("set_property").with_args( property_name, property_value, "the secret" ).and_return("OK") flexmock(SOAPpy) SOAPpy.should_receive("SOAPProxy").with_args("https://public1:17443").and_return(fake_appcontroller) argv = ["--keyname", self.keyname, "--property_name", property_name, "--property_value", property_value] options = ParseArgs(argv, self.function).args result = AppScaleTools.set_property(options) self.assertEqual(None, result)
def main(): """ Main function for running the server. """ logging.basicConfig(format=LOG_FORMAT, level=logging.INFO) logging.info('Starting UAServer') global bindport global datastore_type global db global ERROR_CODES global user_schema for ii in range(1, len(sys.argv)): if sys.argv[ii] in ("-h", "--help"): usage() sys.exit() elif sys.argv[ii] in ('-t', "--type"): datastore_type = sys.argv[ii + 1] ii += 1 elif sys.argv[ii] in ('-p', "--port"): bindport = int(sys.argv[ii + 1]) ii += 1 else: pass db = appscale_datastore.DatastoreFactory.getDatastore(datastore_type) ERROR_CODES = appscale_datastore.DatastoreFactory.error_codes() valid_datastores = appscale_datastore.DatastoreFactory.valid_datastores() if datastore_type not in valid_datastores: raise Exception('{} not in valid datastores ({})'.format( datastore_type, valid_datastores)) # Keep trying until it gets the schema. timeout = 5 while 1: try: user_schema = db.get_schema(USER_TABLE) except AppScaleDBConnectionError as db_error: time.sleep(timeout) continue if user_schema[0] in ERROR_CODES: user_schema = user_schema[1:] Users.attributes_ = user_schema else: time.sleep(timeout) continue break ip = "0.0.0.0" server = SOAPpy.SOAPServer((ip, bindport)) logging.info('Serving on {}'.format(bindport)) # To debug this service, uncomment the 2 lines below. #server.config.dumpSOAPOut = 1 #server.config.dumpSOAPIn = 1 # Register soap functions. server.registerFunction(does_user_exist) server.registerFunction(get_all_users) server.registerFunction(get_user_data) server.registerFunction(add_admin_for_app) server.registerFunction(commit_new_user) server.registerFunction(commit_new_token) server.registerFunction(delete_user) server.registerFunction(change_password) server.registerFunction(disable_user) server.registerFunction(enable_user) server.registerFunction(is_user_enabled) server.registerFunction(is_user_cloud_admin) server.registerFunction(set_cloud_admin_status) server.registerFunction(get_capabilities) server.registerFunction(set_capabilities) while 1: server.serve_forever()
def __init__(self, ip="10.162.242.242", port="8000"): self.katana = SOAPpy.SOAPProxy("http://" + ip + ":" + port)
return True def usage(): """ Prints usage of this program """ print "args: --help or -h for this menu" ################################ # MAIN ################################ if __name__ == "__main__": for ii in range(1, len(sys.argv)): if sys.argv[ii] in ("-h", "--help"): usage() sys.exit() internal_ip = socket.gethostbyname(socket.gethostname()) server = SOAPpy.SOAPServer((internal_ip, constants.APP_MANAGER_PORT)) server.registerFunction(start_app) server.registerFunction(stop_app) server.registerFunction(stop_app_instance) server.registerFunction(restart_app_instances_for_app) file_io.set_logging_format() while 1: try: server.serve_forever() except SSL.SSLError: pass
# from DataCleaning import DataCleaning # from model import RegionData # #from datacollect import DataCollectionFromWebService """ data = {'region':"Padilla Bay, WA", 'stations':[ {'station':"Bayview Channel", 'code': "pdbbywq", 'lat':"48.496139",'lng':"122.502114"}, {'station':"Ploeg Channel", 'code': "pdbbpwq", 'lat':"48.556322",'lng':"122.530894"}, {'station':"Joe Leary Estuary", 'code': "pdbjewq", 'lat':"48.518264",'lng':"122.474189"}, ]} obj = RegionData() """ import SOAPpy server = SOAPpy.SOAPProxy( "http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl") #responsedata = server.exportAllParamsDateRangeXMLNew('niwolwq', '*', 'pH') responsedata = server.exportSingleParamXML('niwolwq', '2000', 'Turb') pythonObject = SOAPpy.Types.simplify(responsedata) print responsedata # dataArray = pythonObject # print(dataArray) """ obj = DataCleaning () obj.cleanJSONData(json.dumps(dataArray)) # client = pymongo.MongoClient() # #db and collection for testing purpose # #self.db = self.client.currentTest # db = client.test
def run(self): bend = SOAPpy.SOAPProxy("http://127.0.0.1:%s" % (str(self.port), )) while True: time.sleep(5) bend.test_internal()
import SOAPpy server = SOAPpy.SOAPProxy("http://192.168.0.3:8080/") print server.NuevaCamara("192.168.1.10","camara1","admin","", "123") print server.ObtenerCamaras() print server.video("camara1") print server.NuevoUsuario("user1","admin",["camara1"],"123") print server.ObtenerUsuarios() cam= server.ObtenerCamara("camara1","user1","admin") print server.video(cam.nombre)
application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.clientEmail = client_email headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # info_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' info_service = SOAPpy.SOAPProxy(namespace + '/InfoService', header=headers) info_service.config.debug = 0 # Get quota usage. total_limit = info_service.getUsageQuotaThisMonth() free_quota_limit = info_service.getFreeUsageQuotaThisMonth() start_date = datetime.datetime.now().strftime('%Y-%m-01T00:00:00') end_date = datetime.datetime.now().strftime('%Y-%m-%dT00:00:00') total_used = info_service.getUnitCount(SOAPpy.Types.untypedType(start_date), SOAPpy.Types.untypedType(end_date)) if long(total_used) > long(free_quota_limit): free_quota_used = free_quota_limit else: free_quota_used = total_used # Display quota usage info.
def __call__(self, *args, **kw): if self._name == "_": if self.__name in ["__repr__", "__str__"]: return self.__repr__() else: chain = [] parent = self._parent while parent._parent: chain = [parent._name] + chain parent = parent._parent url = parent._icontrol_url % parent.__dict__ ns = parent._icontrol_ns + ':' + '/'.join(chain) if parent._url_params: url = "%s?%s" % ( url, urllib.parse.urlencode(parent._url_params)) parent._cache.clear() p = parent if p._cache.get(ns) is not None: ic = p._cache[ns] else: if parent._session: headers = SOAPpy.Types.headerType() sess_t = SOAPpy.Types.integerType(parent._session) sess_t._setMustUnderstand(0) sess_t._setAttr('xmlns:myns1', parent._icontrol_ns) headers._addItem('myns1:session', sess_t) ic = SOAPpy.SOAPProxy(url, ns, header=headers, timeout=p.timeout) else: ic = SOAPpy.SOAPProxy(url, ns, timeout=p.timeout) p._cache[ns] = ic #ic.config.debug = p._debug ic.simplify_objects = 1 try: # An ugly way of setting the timeout per socket, but it # seems that SOAPpy is ignoring the timeout parameter set in # the SOAPProxy constructor. before = socket.getdefaulttimeout() socket.setdefaulttimeout(p.timeout) if p._debug: LOG.debug( "%s -> %s.%s(%s)", url, '.'.join(chain), self._name, ', '.join([ '%s=%s' % (x, y) for x, y in list(kw.items()) ])) ret = getattr(ic, self._name)(*args, **kw) if p._debug: LOG.debug(ret) return ret except SOAPpy.Types.faultType as e: if 'Unknown method' in e.faultstring: raise UnknownMethod(e) raise IControlFault(e) except SOAPpy.Errors.HTTPError as e: if 401 == e.code: raise AuthFailed(e) raise IControlTransportError(e) finally: socket.setdefaulttimeout(before)
application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.clientEmail = client_email headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # report_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' report_service = SOAPpy.SOAPProxy(namespace + '/ReportService', header=headers) report_service.config.debug = 0 # Create report job structure. report_job = """ <selectedReportType>%s</selectedReportType> <name>%s</name> <aggregationTypes>%s</aggregationTypes> <adWordsType>%s</adWordsType> <keywordType>%s</keywordType> <startDay>%s</startDay> <endDay>%s</endDay> <selectedColumns>%s</selectedColumns> <selectedColumns>%s</selectedColumns> <selectedColumns>%s</selectedColumns> <selectedColumns>%s</selectedColumns>
def soap_struct(self): return SOAPpy.structType({"a": "c"})
def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT, ssl=True): """ Initialize a new instance of the infrastructure manager service. Args: host Hostname to which the service should bind (Optional). Defaults to 0.0.0.0. port Port of the service (Optional). Default to 17444. ssl True if SSL should be engaged or False otherwise (Optional). Defaults to True. When engaged, this implementation expects to find the necessary SSL certificates in the /etc/appscale/certs directory. """ self.host = host self.port = port secret = None while True: try: secret = utils.get_secret(self.APPSCALE_DIR + 'secret.key') break except Exception: utils.log('Waiting for the secret key to become available') utils.sleep(5) utils.log('Found the secret set to: {0}'.format(secret)) SOAPpy.Config.simplify_objects = True if ssl: utils.log('Checking for the certificate and private key') cert = self.APPSCALE_DIR + 'certs/mycert.pem' key = self.APPSCALE_DIR + 'certs/mykey.pem' while True: if os.path.exists(cert) and os.path.exists(key): break else: utils.log('Waiting for certificates') utils.sleep(5) ssl_context = SSL.Context() ssl_context.load_cert(cert, key) self.server = SOAPpy.SOAPServer((host, port), ssl_context=ssl_context) else: self.server = SOAPpy.SOAPServer((host, port)) parent_dir = os.path.dirname(os.path.realpath(sys.argv[0])) config_file = os.path.join(parent_dir, self.CONFIG_FILE) if os.path.exists(config_file): file_handle = open(config_file, 'r') params = json.load(file_handle) file_handle.close() if params.has_key(PersistentStoreFactory.PARAM_STORE_TYPE): utils.log( 'Loading infrastructure manager configuration from ' + config_file) i = InfrastructureManager(params) else: i = InfrastructureManager() else: i = InfrastructureManager() self.server.registerFunction(i.describe_instances) self.server.registerFunction(i.run_instances) self.server.registerFunction(i.terminate_instances) self.server.registerFunction(i.attach_disk) self.started = False
def test_upload_tar_gz_app_successfully(self): app_dir = '/tmp/appscale-app-1234' # add in mocks so that the gzip'ed file gets extracted to /tmp # as well as for removing it later flexmock(os) os.should_receive('mkdir').with_args(app_dir) \ .and_return(True) flexmock(shutil) shutil.should_receive('rmtree').with_args(app_dir).and_return() local_state = flexmock(LocalState) local_state.should_receive('shell')\ .with_args(re.compile('tar zxvf'),False)\ .and_return() # add in mocks so that there is an app.yaml, but with no appid set flexmock(os.path) os.path.should_call('exists') app_yaml_location = AppEngineHelper.get_app_yaml_location(app_dir) os.path.should_receive('exists').with_args(app_yaml_location) \ .and_return(True) # mock out reading the app.yaml file builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through fake_app_yaml = flexmock(name="fake_app_yaml") fake_app_yaml.should_receive('read').and_return( yaml.dump({ 'application': 'baz', 'runtime': 'python' })) builtins.should_receive('open').with_args(app_yaml_location, 'r') \ .and_return(fake_app_yaml) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') fake_appcontroller.should_receive('done_uploading').with_args( 'baz', '/var/apps/baz/app/baz.tar.gz', 'the secret').and_return() fake_appcontroller.should_receive('update').with_args( ['baz'], 'the secret').and_return() fake_appcontroller.should_receive('is_app_running').with_args( 'baz', 'the secret').and_return(False).and_return(True) flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com', 'the secret').and_return('false') fake_userappserver.should_receive('commit_new_user').with_args( '*****@*****.**', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('commit_new_user').with_args( 'a@public1', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('get_app_data').with_args( 'baz', 'the secret').and_return('\n\nnum_ports:0\n') \ .and_return(app_data).and_return(app_data).and_return(app_data) fake_userappserver.should_receive('commit_new_app').with_args( 'baz', '*****@*****.**', 'python', 'the secret').and_return('true') SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com") flexmock(getpass) getpass.should_receive('getpass').and_return('aaaaaa') # mock out making the remote app directory local_state.should_receive('shell') \ .with_args(re.compile('^ssh'), False, 5, stdin=re.compile('^mkdir -p')) \ .and_return() # and mock out tarring and copying the app local_state.should_receive('shell') \ .with_args(re.compile('tar -czf'), False) \ .and_return() local_state.should_receive('shell') \ .with_args(re.compile('/tmp/appscale-app-baz.tar.gz'), False, 5) \ .and_return() # as well as removing the tar'ed app once we're done copying it flexmock(os) os.should_receive('remove').with_args('/tmp/appscale-app-baz-1234.tar.gz') \ .and_return() os.should_receive('listdir').and_return(['app.yaml', 'index.py']) # and slap in a mock that says the app comes up after waiting for it # three times fake_socket = flexmock(name='fake_socket') fake_socket.should_receive('connect').with_args(('public1', 8080)).and_raise(Exception).and_raise(Exception) \ .and_return(None) flexmock(socket) socket.should_receive('socket').and_return(fake_socket) argv = ["--keyname", self.keyname, "--file", self.app_dir + ".tar.gz"] options = ParseArgs(argv, self.function).args (host, port) = AppScaleTools.upload_app(options) self.assertEquals('public1', host) self.assertEquals(8080, port)
return True if __name__ == "__main__": for ii in range(1, len(sys.argv)): if sys.argv[ii] in ("-h", "--help"): usage() sys.exit() elif sys.argv[ii] in ('-t', "--type"): print "setting datastore type to ", sys.argv[ii + 1] datastore_type = sys.argv[ii + 1] ii += 1 setup_datastore(datastore_type) zk_locations = get_zk_locations() setup_zookeeper(zk_locations) ip = "0.0.0.0" server = SOAPpy.SOAPServer((ip, bindport)) server.registerFunction(start_migration) while 1: try: # Run Server server.serve_forever() except SSL.SSLError: pass
useragent = 'INSERT_COMPANY_NAME: AdWords API Python Sample Code' developer_token = 'INSERT_DEVELOPER_TOKEN_HERE' application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # account_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' account_service = SOAPpy.SOAPProxy(namespace + '/AccountService', header=headers) account_service.config.debug = 0 # Get client accounts. login_emails = account_service.getClientAccounts() # Convert to a list if we get back a single object. if len(login_emails) > 0 and not isinstance(login_emails, list): login_emails = [login_emails] # Display login emails. for login in login_emails: print 'Login email is "%s".' % (login)
import SOAPpy def hello(): return "Hello World" server = SOAPpy.SOAPServer(("localhost", 8080)) server.registerFunction(hello) server.serve_forever()
import SOAPpy from PIL import Image import glob import sys import pickle reload(sys) import base64 import cv2 server = SOAPpy.SOAPProxy("http://127.0.0.1:5000/") #server = SOAPpy.SOAPProxy("http://34.251.67.157:80/") CLASSES = ( '__background__', # always index 0 'carte', 'mrz', 'numero', 'date', 'nom', 'prenom', 'adresse', 'ville', 'marque', 'type_mine') def readFileImages(strFolderName): print strFolderName image_list = []
def main(): global outfile input_id = sys.argv[1] input_seq = sys.argv[2] output_file_name = sys.argv[3] server = SOAPpy.SOAPProxy("http://www.pdb.org/pdb/services/pdbws") this_cutoff = float(0.005) this_matrix = 'BLOSUM62' this_output_format = '1' # String blastPDB (String structureId, String chainId, double eCutOff, String matrix, String outputFormat) # soappy_output = server.blastPDB ( this_pdbid, this_chain, this_cutoff, this_matrix, this_output_format ); # String blastPDB (String sequence, double eCutOff, String matrix, String outputFormat) soappy_output = server.blastPDB(input_seq, this_cutoff, this_matrix, this_output_format) soappy_output_lines = soappy_output.rsplit("\n") i = 0 for inline in soappy_output_lines: #><a name = 5612></a>1E39:1:A|pdbid|entity|chain(s)|sequence if (inline.find('><a name = ') > -1): bits = inline.split('></a>') bit1 = bits[1] bits2 = bit1.split('|') bit2 = bits2[0] this_pdbid = bit2[0:4] this_pdbid = this_pdbid.lower() this_chain = bit2[7:8] # Identities = 108/411 (26%), Positives = 186/411 (45%), Gaps = 68/411 (16%) j = i + 4 inline2 = soappy_output_lines[j] if (inline2.find('Identities = ') == -1): print 'Did not find the identities line where expected for sequence', input_seq[ 0:10], '... :', inline else: bits3 = inline2.split(' ') identity_string = bits3[4] identity = identity_string identity = identity.replace(',', '') identity = identity.replace('(', '') identity = identity.replace(')', '') identity = identity.replace('%', '') identity = float(identity) if (identity >= 30): soappy_output2 = server.getReleaseDates(this_pdbid) bits1 = soappy_output2[0] bits2 = bits1.split("\t") this_date = bits2[1] if (this_date == 'N/A'): print 'PROBLEM :', this_pdbid, 'returned', this_date, 'when processing', input_id else: #print input_id, ':', this_pdbid, ':', this_date save_date.append(this_date) i = i + 1 return_date = '9999-99-99' if (len(save_date) > 0): for this_save_date in save_date: if (this_save_date < return_date): return_date = this_save_date outfile = open(output_file_name, "a") # open output file for writing in append mode output_line = input_id + ':::::' + return_date + ':::::' + "\r\n" outfile.write(output_line) outfile.close() return
#!/usr/bin/env python import SOAPpy URL = 'http://mcid.internal:1080/mcid' NS = 'http://www.medcommons.net/mcid' mcid_generator = SOAPpy.SOAPProxy(URL, namespace=NS) if __name__ == '__main__': print mcid_generator.next_mcid()
allapps = True elif sys.argv[ii] in ("--allusers"): allusers = True else: pass if not super_secret: with open(SECRET_LOCATION, 'r') as file_handle: super_secret = file_handle.read() print "address for server", app_location print "binding port:", bindport print "secret:", super_secret print "encrypt:", encrypt if encrypt: server = SOAPpy.SOAPProxy("https://" + app_location + ":" + str(bindport)) else: server = SOAPpy.SOAPProxy("http://" + app_location + ":" + str(bindport)) def createUser(): username = helper_functions.random_string(10) username += "@" username += helper_functions.random_string(5) username += "." username += helper_functions.random_string(3) password = helper_functions.random_string(10) return username, password def createApp():
def _gotResult(self, result, request, methodName): if not isinstance(result, SOAPpy.voidType): result = {"Result": result} response = SOAPpy.buildSOAP(kw={'%sResponse' % methodName: result}, encoding=self.encoding) self._sendResponse(request, response)
application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.clientEmail = client_email headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # keyword_tool_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' keyword_tool_service = SOAPpy.SOAPProxy(namespace + '/KeywordToolService', header=headers) keyword_tool_service.config.debug = 0 # Create seed keyword structure. seed_keyword = { 'negative': SOAPpy.Types.untypedType('false'), 'text': 'mars cruise', 'type': SOAPpy.Types.untypedType('Broad') } use_synonyms = SOAPpy.Types.untypedType('true') # Get keyword variations. variation_lists = keyword_tool_service.getKeywordVariations([seed_keyword], use_synonyms, ['en'], ['US'])
# socket.gethostbyname(socket.gethostname()) ip = "0.0.0.0" if super_secret == "": FILE = open(SECRET_LOCATION, 'r') super_secret = FILE.read() # Secure Socket Layer if encrypt == 1: ssl_context = SSL.Context() cert_location = CERT_LOCATION key_location = KEY_LOCATION ssl_context.load_cert(cert_location, key_location) server = SOAPpy.SOAPServer((ip, bindport), ssl_context = ssl_context) else: server = SOAPpy.SOAPServer((ip,bindport)) #Register Functions server.registerFunction(add_class) server.registerFunction(add_instance) server.registerFunction(does_user_exist) server.registerFunction(does_app_exist) server.registerFunction(get_key_block) server.registerFunction(get_all_apps) server.registerFunction(get_all_users) server.registerFunction(get_user_data) server.registerFunction(get_app_data) server.registerFunction(get_tar)
application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.clientEmail = client_email headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # criterion_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' criterion_service = SOAPpy.SOAPProxy(namespace + '/CriterionService', header=headers) criterion_service.config.debug = 0 # Create new keyword structure. ad_group_id = long('INSERT_AD_GROUP_ID_HERE') keyword = { 'adGroupId': ad_group_id, 'criterionType': SOAPpy.Types.untypedType('Keyword'), 'text': 'mars cruise', 'type': SOAPpy.Types.untypedType('Broad') } # Check new keyword for policy violations before adding it. language_target = {'languages': ['en']} geo_target = {'countryTargets': {'countries': ['US']}} errors = criterion_service.checkCriteria([keyword], language_target, geo_target)
def prepare(self, tenant_name="default", tenant_index=0, clear_shm=None): super(AuthManager, self).prepare(tenant_name, tenant_index, clear_shm) self.server = SOAPpy.ThreadingSOAPServer(("localhost", self.bend_port))
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import time import SOAPpy from datetime import date from debrfstats.RFSStats import RFS if __name__ == "__main__": url = 'http://bugs.debian.org/cgi-bin/soap.cgi' namespace = 'Debbugs/SOAP' server = SOAPpy.SOAPProxy(url, namespace) bugi = server.get_bugs("package", "sponsorship-requests", "status", "open") buglist = [RFS(b.value) for b in server.get_status(bugi).item] buglist_sorted_by_dust = sorted(buglist, key=lambda x: x.dust, reverse=False) print("Age Dust Number Title") for i in buglist_sorted_by_dust: print("{:<4} {:<4} {:<7} {}".format(i.age, i.dust, i.bug_number, i.subject))
def usage(): """ Prints usage of this program """ print "args: --help or -h for this menu" ################################ # MAIN ################################ if __name__ == "__main__": for args_index in range(1, len(sys.argv)): if sys.argv[args_index] in ("-h", "--help"): usage() sys.exit() INTERNAL_IP = appscale_info.get_private_ip() SERVER = SOAPpy.SOAPServer((INTERNAL_IP, constants.APP_MANAGER_PORT)) SERVER.registerFunction(start_app) SERVER.registerFunction(stop_app) SERVER.registerFunction(stop_app_instance) SERVER.registerFunction(restart_app_instances_for_app) file_io.set_logging_format() while 1: try: SERVER.serve_forever() except SSL.SSLError: pass
def test_upload_app_when_app_exists_on_virt_cluster(self): # we do let you upload an app if it's already running # add in mocks so that there is an app.yaml with an appid set flexmock(os.path) os.path.should_call('exists') app_yaml_location = AppEngineHelper.get_app_yaml_location(self.app_dir) os.path.should_receive('exists').with_args(app_yaml_location) \ .and_return(True) # mock out reading the app.yaml file builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through fake_app_yaml = flexmock(name="fake_app_yaml") fake_app_yaml.should_receive('read').and_return( yaml.dump({ 'application': 'baz', 'runtime': 'python' })) builtins.should_receive('open').with_args(app_yaml_location, 'r') \ .and_return(fake_app_yaml) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') fake_appcontroller.should_receive('done_uploading').with_args( 'baz', '/var/apps/baz/app/baz.tar.gz', 'the secret').and_return('OK') fake_appcontroller.should_receive('update').with_args( ['baz'], 'the secret').and_return('OK') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com', 'the secret').and_return('false') fake_userappserver.should_receive('commit_new_user').with_args( '*****@*****.**', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('commit_new_user').with_args( 'a@public1', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('get_app_data').with_args( 'baz', 'the secret').and_return(app_data) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com") flexmock(getpass) getpass.should_receive('getpass').and_return('aaaaaa') # mock out making the remote app directory flexmock(subprocess) subprocess.should_receive('Popen').with_args(re.compile('mkdir -p'), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \ .and_return(self.success) # and mock out tarring and copying the app subprocess.should_receive('Popen').with_args(re.compile('tar -czf'), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \ .and_return(self.success) subprocess.should_receive('Popen').with_args(re.compile( '/tmp/appscale-app-baz.tar.gz'), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \ .and_return(self.success) # as well as removing the tar'ed app once we're done copying it flexmock(os) os.should_receive('remove').with_args('/tmp/appscale-app-baz-1234.tar.gz') \ .and_return() # and slap in a mock that says the app comes up after waiting for it # three times fake_socket = flexmock(name='fake_socket') fake_socket.should_receive('connect').with_args(('public1', 8080)).and_raise(Exception).and_raise(Exception) \ .and_return(None) flexmock(socket) socket.should_receive('socket').and_return(fake_socket) argv = ["--keyname", self.keyname, "--file", self.app_dir] options = ParseArgs(argv, self.function).args (host, port) = AppScaleTools.upload_app(options) self.assertEquals('public1', host) self.assertEquals(8080, port)
def _methodNotFound(self, request, methodName): response = SOAPpy.buildSOAP(SOAPpy.faultType( "%s:Client" % SOAPpy.NS.ENV_T, "Method %s not found" % methodName), encoding=self.encoding) self._sendResponse(request, response, status=500)
def test_upload_app_when_app_admin_not_this_user(self): # we don't let you upload an app if the appid is registered to someone else, # so abort # add in mocks so that there is an app.yaml, but with no appid set flexmock(os.path) os.path.should_call('exists') app_yaml_location = AppEngineHelper.get_app_yaml_location(self.app_dir) os.path.should_receive('exists').with_args(app_yaml_location) \ .and_return(True) # mock out reading the app.yaml file builtins = flexmock(sys.modules['__builtin__']) builtins.should_call('open') # set the fall-through fake_app_yaml = flexmock(name="fake_app_yaml") fake_app_yaml.should_receive('read').and_return( yaml.dump({ 'application': 'baz', 'runtime': 'python' })) builtins.should_receive('open').with_args(app_yaml_location, 'r') \ .and_return(fake_app_yaml) # mock out the SOAP call to the AppController and assume it succeeded fake_appcontroller = flexmock(name='fake_appcontroller') fake_appcontroller.should_receive('status').with_args('the secret') \ .and_return('Database is at public1') flexmock(SOAPpy) SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com', 'the secret').and_return('false') fake_userappserver.should_receive('commit_new_user').with_args( '*****@*****.**', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('commit_new_user').with_args( 'a@public1', str, 'xmpp_user', 'the secret').and_return('true') fake_userappserver.should_receive('get_app_data').with_args( 'baz', 'the secret').and_return('\n\nnum_ports:0\n\napp_owner:[email protected]') SOAPpy.should_receive('SOAPProxy').with_args('https://*****:*****@a.com") flexmock(getpass) getpass.should_receive('getpass').and_return('aaaaaa') argv = ["--keyname", self.keyname, "--file", self.app_dir] options = ParseArgs(argv, self.function).args self.assertRaises(AppScaleException, AppScaleTools.upload_app, options)
application_token = 'INSERT_APPLICATION_TOKEN_HERE' # Define SOAP headers. headers = SOAPpy.Types.headerType() headers.email = email headers.password = password headers.clientEmail = client_email headers.useragent = useragent headers.developerToken = developer_token headers.applicationToken = application_token # Set up service connection. To view XML request/response, change value of # ad_service.config.debug to 1. To send requests to production # environment, replace "sandbox.google.com" with "adwords.google.com". namespace = 'https://sandbox.google.com/api/adwords/v12' ad_service = SOAPpy.SOAPProxy(namespace + '/AdService', header=headers) ad_service.config.debug = 0 # Get all ads. ad_group_ids = [long('INSERT_AD_GROUP_ID_HERE')] ads = ad_service.getAllAds(ad_group_ids) # Convert to a list if we get back a single object. if len(ads) > 0 and not isinstance(ads, list): ads = [ads] # Desplay ad info. for ad in ads: print 'Ad type is "%s" and id is "%s".' % (ad['adType'], ad['id'])