def test_setup_ds_minimal(topology): # Create the setupDs lc = LogCapture() # Give it the right types. sds = SetupDs(verbose=DEBUGGING, dryrun=False, log=lc.log) # Get the dicts from Type2Base, as though they were from _validate_ds_2_config # IE get the defaults back just from Slapd2Base.collect # Override instance name, root password, port and secure port. general_options = General2Base(lc.log) general_options.verify() general = general_options.collect() slapd_options = Slapd2Base(lc.log) slapd_options.set('instance_name', INSTANCE_SERVERID) slapd_options.set('port', INSTANCE_PORT) slapd_options.set('root_password', PW_DM) slapd_options.verify() slapd = slapd_options.collect() sds.create_from_args(general, slapd, {}, None) insts = topology.standalone.list(serverid=INSTANCE_SERVERID) # Assert we did change the system. assert (len(insts) == 1) # Make sure we can connect topology.standalone.open() # Make sure we can start stop. topology.standalone.stop() topology.standalone.start() # Okay, actually remove the instance remove_ds_instance(topology.standalone)
def instance_remove_all(log, args): """Remove all instances - clean sweep! """ inst_names = get_instance_list(args.remove_all) if len(inst_names) > 0: answer = input( "Are you sure you want to remove all the Directory Server instances? Enter \"Yes\" to continue: " ) if answer != 'Yes': print("Aborted removal of all instances") return # Do it! list_inst = DirSrv(verbose=args.verbose) insts = list_inst.list(all=True, serverid=inst_names[0]) for inst in insts: remove_inst = DirSrv(verbose=args.verbose) remove_inst.allocate(inst) try: log.info("Removing instance: slapd-" + str(remove_inst.serverid)) remove_ds_instance(remove_inst) except Exception as e: log.fatal('Failed to remove all instances: ' + str(e)) sys.exit(1) log.info('All instances have been successfully removed') else: print("No instances to remove")
def test_basic(topology_st, simple_allocate): """Check that all DS directories and systemd items were removed :id: 9e8bbcda-358d-4e9c-a38c-9b4c3b63308e :parametrized: yes """ inst = topology_st.standalone # FreeIPA uses local_simple_allocate for the removal process if simple_allocate: inst = DirSrv(verbose=inst.verbose) inst.local_simple_allocate(topology_st.standalone.serverid) remove_ds_instance(inst) paths = [ inst.ds_paths.backup_dir, inst.ds_paths.cert_dir, inst.ds_paths.config_dir, inst.ds_paths.db_dir, inst.get_changelog_dir(), inst.ds_paths.ldif_dir, inst.ds_paths.lock_dir, inst.ds_paths.log_dir ] for path in paths: assert not os.path.exists(path) try: subprocess.check_output( ['systemctl', 'is-enabled', 'dirsrv@{}'.format(inst.serverid)], encoding='utf-8') except subprocess.CalledProcessError as ex: assert "disabled" in ex.output
def instance_remove(inst, log, args): if not args.ack: # Some day do some type of dry-run validation? log.info("""Not removing: if you are sure, add --do-it""") return True else: log.info('Removing instance ...') try: remove_ds_instance(inst) log.info('Completed instance removal') except: log.fatal('Instance removal failed') return False
def _remove_failed_install(self, serverid): """The install failed, remove the scraps :param serverid - The server ID of the instance """ inst = DirSrv() # Allocate the instance based on name insts = [] insts = inst.list(serverid=serverid) if len(insts) != 1: self.log.error("No such instance to remove {}".format(serverid)) return inst.allocate(insts[0]) remove_ds_instance(inst, force=True)
def instance_remove(inst, log, args): if not args.ack: log.info("""Not removing: if you are sure, add --doit""") sys.exit(0) else: log.info(""" About to remove instance %s! If this is not what you want, press ctrl-c now ... """ % inst.serverid) for i in range(1, 6): log.info('%s ...' % (5 - int(i))) time.sleep(1) log.info('Removing instance ...') remove_ds_instance(inst) log.info('Completed instance removal')
def instance_remove(inst, log, args): if not args.ack: # Some day do some type of dry-run validation? log.info("""Not removing: if you are sure, add --do-it""") return True else: log.info(""" About to remove instance (%s)! If this is not what you want, press ctrl-c now ... """ % inst.serverid) for i in range(1, 6): log.info('%s ...' % (6 - int(i))) time.sleep(1) log.info('Removing instance ...') try: remove_ds_instance(inst) log.info('Completed instance removal') except: log.fatal('Instance removal failed') return False
def instance_remove_all(log, args): """Remove all instances - clean sweep! """ inst_names = get_instance_list() if len(inst_names) > 0: log.info(""" About to remove all Directory Server instances! If this is not what you want, press ctrl-c now ... """) for i in range(1, 6): log.info('%s ...' % (6 - int(i))) time.sleep(1) # Do it! list_inst = DirSrv(verbose=args.verbose) insts = list_inst.list(all=True, serverid=inst_names[0]) no_problems = True for inst in insts: remove_inst = DirSrv(verbose=args.verbose) remove_inst.allocate(inst) try: log.info("Removing instance: slapd-" + str(remove_inst.serverid)) remove_ds_instance(remove_inst) except Exception as e: log.error( f'Failed to remove slapd-{remove_inst.serverid} - Error: {str(e)}' ) no_problems = False if no_problems: log.info('All instances have been successfully removed') else: log.info('Some instances were not removed') else: print("No instances to remove")
def test_basic(topology_st): """Check that all DS directories and systemd items were removed""" inst = topology_st.standalone remove_ds_instance(inst) paths = [ inst.ds_paths.backup_dir, inst.ds_paths.cert_dir, inst.ds_paths.config_dir, inst.ds_paths.db_dir, inst.get_changelog_dir(), inst.ds_paths.ldif_dir, inst.ds_paths.lock_dir, inst.ds_paths.log_dir, "{}/sysconfig/dirsrv-{}".format(inst.ds_paths.sysconf_dir, inst.serverid) ] for path in paths: assert not os.path.exists(path) try: subprocess.check_output( ['systemctl', 'is-enabled', 'dirsrv@{}'.format(inst.serverid)], encoding='utf-8') except subprocess.CalledProcessError as ex: assert "disabled" in ex.output