def test_ioerror(self): try: auth = authinfo.load(provider="noip", config_location=self.test_dir) self.fail("An 'IOError' should be raised. auth=%s" + auth) except Exception as e: if not isinstance(e, IOError): self.fail("An 'IOError' should be raised. Got: %s" % e)
def execute_update(args): """Execute the update based on command line args and returns a dictionary with 'execution result, ''response code', 'response info' and 'process friendly message'. """ provider_class = getattr(dnsupdater, dnsupdater.AVAILABLE_PLUGINS.get(args.provider)) updater_options = {} process_message = None auth = None if args.store: # --store argument if provider_class.auth_type == 'T': user_arg = args.usertoken or utils.read_input( "Paste your auth token: ") auth = authinfo.ApiAuth(usertoken=user_arg) else: user_arg = args.usertoken or utils.read_input( "Type your username: "******"Type your password: "******"Auth info stored." else: update_ddns = True # informations arguments elif args.usertoken and args.hostname: if provider_class.auth_type == 'T': auth = authinfo.ApiAuth(args.usertoken) else: auth = authinfo.ApiAuth(args.usertoken, args.password) update_ddns = True exec_result = EXECUTION_RESULT_OK elif args.hostname: if authinfo.exists(args.provider, args.config): auth = authinfo.load(args.provider, args.config) update_ddns = True exec_result = EXECUTION_RESULT_OK else: update_ddns = False exec_result = EXECUTION_RESULT_NOK process_message = "No stored auth information found for " \ "provider: '%s'" % args.provider else: # no arguments update_ddns = False exec_result = EXECUTION_RESULT_NOK process_message = "Warning: The hostname to be updated must be " \ "provided.\nUsertoken and password can be either " \ "provided via command line or stored with --store " \ "option.\nExecute noipy --help for more details." if update_ddns and args.provider == 'generic': if args.url: if not URL_RE.match(args.url): process_message = "Malformed URL." exec_result = EXECUTION_RESULT_NOK update_ddns = False else: updater_options['url'] = args.url else: process_message = "Must use --url if --provider is 'generic' " \ "(default)" exec_result = EXECUTION_RESULT_NOK update_ddns = False response_code = None response_text = None if update_ddns: ip_address = args.ip if args.ip else utils.get_ip() if not ip_address: process_message = "Unable to get IP address. Check connection." exec_result = EXECUTION_RESULT_NOK elif ip_address == utils.get_dns_ip(args.hostname): process_message = "No update required." else: updater = provider_class(auth, args.hostname, updater_options) print("Updating hostname '%s' with IP address %s " "[provider: '%s']..." % (args.hostname, ip_address, args.provider)) response_code, response_text = updater.update_dns(ip_address) process_message = updater.status_message proc_result = { 'exec_result': exec_result, 'response_code': response_code, 'response_text': response_text, 'process_message': process_message, } return proc_result