def doRunDomainSynchronizer(self, *args, **kwargs): """ Action method. """ ds = domain_synchronizer.DomainSynchronizer( log_events=self.log_events, log_transitions=self.log_transitions, raise_errors=self.raise_errors, accept_code_2304=True, ) try: ds.event( 'run', self.target_domain, sync_contacts=False, sync_nameservers=False, renew_years=2, save_to_db=True, ) except Exception as exc: self.log(self.debug_level, 'Exception in DomainRefresher: %s' % exc) del ds self.event('refresh-failed', exc) else: self.outputs.extend(list(ds.outputs)) del ds self.event('refresh-ok')
def test_domain_another_registrar(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester_domain = testsupport.prepare_tester_domain( domain_name='owned-by-another-registar.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0], domain_epp_id='some_epp_id_123', ) scenario = [] ds = domain_synchronizer.DomainSynchronizer( log_events=True, log_transitions=True, raise_errors=True, ) ds.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append(( oldstate, newstate, event, )), ) ds.event('run', tester_domain, update_domain=True) outputs = list(ds.outputs) del ds assert scenario == [ ('AT_STARTUP', 'EXISTS?', 'run'), ('EXISTS?', 'OWNER?', 'response'), ('OWNER?', 'FAILED', 'response'), ] assert len(outputs) == 1 assert isinstance(outputs[0], zerrors.EPPRegistrarAuthFailed)
def test_domain_create(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable if os.environ.get('MANUAL', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester_domain = testsupport.prepare_tester_domain( domain_name='test-%s.%s' % (now().strftime('%Y%m%d%H%M%S'), settings.ZENAIDA_SUPPORTED_ZONES[0]), ) assert tester_domain.epp_id is None scenario = [] ds = domain_synchronizer.DomainSynchronizer( log_events=True, log_transitions=True, raise_errors=True, ) ds.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append( (oldstate, newstate, event, ) ), ) ds.event('run', tester_domain, renew_years=2, sync_contacts=True, sync_nameservers=True) outputs = list(ds.outputs) del ds assert scenario == [ ('AT_STARTUP', 'EXISTS?', 'run'), ('EXISTS?', 'CONTACTS', 'response'), ('CONTACTS', 'NAMESERVERS', 'contacts-ok'), ('NAMESERVERS', 'CREATE!', 'nameservers-ok'), ('CREATE!', 'READ', 'response'), ('READ', 'UPDATE!', 'response'), ('UPDATE!', 'DONE', 'no-updates'), ] assert tester_domain.epp_id is not None assert len(outputs) == 7 assert outputs[-1] is True
def test_domain_no_updates(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester_domain = testsupport.prepare_tester_domain( domain_name='test-write-0.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0], # TODO: take this from CoCCA server, need to prepare test data on the server domain_epp_id='86_zenaida', epp_id_dict={ 'registrant': 'TestWrite_0', 'admin': 'TestWrite_0', 'billing': 'TestWrite_0', 'tech': 'TestWrite_0', }, nameservers=[ 'ns1.google.com', 'ns2.google.com', ], ) scenario = [] ds = domain_synchronizer.DomainSynchronizer( log_events=True, log_transitions=True, raise_errors=True, ) ds.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append(( oldstate, newstate, event, )), ) ds.event('run', tester_domain, renew_years=None, sync_contacts=True, sync_nameservers=True) outputs = list(ds.outputs) del ds assert scenario == [ ('AT_STARTUP', 'EXISTS?', 'run'), ('EXISTS?', 'OWNER?', 'response'), ('OWNER?', 'CONTACTS', 'response'), ('CONTACTS', 'NAMESERVERS', 'contacts-ok'), ('NAMESERVERS', 'READ', 'nameservers-ok'), ('READ', 'UPDATE!', 'response'), ('UPDATE!', 'DONE', 'no-updates'), ] assert len(outputs) == 5 assert outputs[-1] is True
def domain_check_create_update_renew(domain_object, sync_contacts=True, sync_nameservers=True, renew_years=None, save_to_db=True, raise_errors=False, return_outputs=False, log_events=True, log_transitions=True): """ Check if domain exists first and then update it from `domain_object` info. If domain not exist create a new domain on back-end. If `renew_years` is positive integer it will also renew domain for that amount of years. If `renew_years=-1` it will use `domain_object.expiry_date` to decide how many days more needs to be added. """ ds = domain_synchronizer.DomainSynchronizer( log_events=log_events, log_transitions=log_transitions, raise_errors=raise_errors, accept_code_2304=True, ) ds.event( 'run', domain_object, sync_contacts=sync_contacts, sync_nameservers=sync_nameservers, renew_years=renew_years, save_to_db=save_to_db, ) outputs = list(ds.outputs) del ds logger.info('domain_synchronizer(%r) finished with %d outputs', domain_object.name, len(outputs)) if return_outputs: return outputs if not outputs or not outputs[-1] or isinstance(outputs[-1], Exception): if outputs and isinstance(outputs[-1], Exception): logger.error('domain_synchronizer(%r) failed with: %r', domain_object.name, outputs[-1]) return False logger.info('domain_synchronizer(%r) OK', domain_object.name) return True