def setUp(self): from config.handlers import SiteCreator args = MyNamespace() args.name = '' args.subparser_name = 'create' args.skip_name = True args.quiet = True self.args = args self.handler = SiteCreator(args, {})
def setUp(self): from config.handlers import SiteCreator args = MyNamespace() args.name = '' args.subparser_name = 'create' args.skip_name = True args.quiet = True self.patcher = patch.dict('os.environ', {'UNIT_TESTING': 'True'}) self.mock_foo = self.patcher.start() self.args = args self.handler = SiteCreator(args, {}) self.addCleanup(self.patcher.stop) # add this line
def main(opts, parsername, need_names_dic, return_handler=False): """ return_handler is used while testing """ # default_handler = SiteCreator # if the name ends with /, cut it off if opts.name.endswith("/"): opts.name = opts.name[:-1] opts.subparser_name = parsername if parsername == "create": handler = SiteCreator(opts, SITES) elif parsername == "support": handler = SupportHandler(opts, SITES) elif parsername == "remote": handler = RemoteHandler(opts, SITES) elif parsername == "migrate": handler = MigrationHandler(opts, SITES) elif parsername == "docker": if opts.docker_use_bitnami: handler = KuberHandlerHelm(opts, SITES) else: handler = DockerHandler(opts, SITES) # elif parsername == 'mail': # handler = MailHandler(opts, SITES) else: handler = SiteCreator(opts, SITES) # _subparser_name = 'docker' # return handler to the test process if asked to if return_handler == 1: return handler # ckeck whether the used option needs a name to work handler.check_name(need_names_dic=need_names_dic) # ckeck wheter the path to the sites-list has to be adapted # if yes, flag it to the user. To do the actual update # the user has to use the support optin --fix-sites-list from config import sites_handler # ckeck wheter the the sites-list has to be autoloaded sites_handler.check_pull(opts=opts) did_run_a_command = False # ---------------------- # create commands # ---------------------- if parsername == "create": # create # ------ # builds or updates a server structure # to do so, it does a number of steps # - creates the needed folders in $ERP_SERVER_DATA # - creates a build structure in $PROJECT_HOME/$SITENAME/$SITENAME # where $PROJECT_HOME is read from the config file. # - copies and sets up all files from skeleton directory to the build structure # this is done executing create_new_project and do_copy # - builds a virtualenv environment in the build structure # - prepares to builds an erp server within the build structure by # execution bin/build_erp within the build structure. # Within this bild environment the erp's module path will be set # that it points to the usual erp-workbench directories within the build substructure # and also to the directories within erp_workbench as dictated by the # various modules installed from interpreting the site declaration # in sites.py # - add a "private" addons folder within the build structure called # $SITENAME_addons. This folder is also added to the erp-site's addon path. # - set the data_dir to point to $ERP_SERVER_DATA/$SITENAME/filestore # # modules_update # ------------- if opts.create or opts.modules_update or opts.module_update: info_dic = { "project_path": handler.default_values["inner"], "erp_version": handler.erp_version, "site_name": handler.site_name, "erp_provider": handler.erp_provider, } if opts.create: existed = handler.create_or_update_site() if existed: if not opts.quiet: print() print("%s site allredy existed" % handler.site_name) print(SITE_EXISTED % info_dic) else: if handler.site_name: if not opts.quiet: print() print("%s site created" % handler.site_name) print(SITE_NEW % info_dic) # create the folder structure within the datafoler defined in the config # this also creates the config file used by a docker server within the # newly created folders handler.create_folders(quiet=True) create_server_config(handler) did_run_a_command = True # make sure project was added to bash_aliases handler.add_aliases() # checkout repositories checkout_sa(opts, handler) # list_sites # ---------- # list_sites lists all existing sites both from global and local sites if opts.list_sites: list_sites(SITES, opts.quiet, opts.name) did_run_a_command = True return # listownmodules # -------------- # list the modules that are declared within the selected site # installown install all erp modules declared in the selected site # todo: why are the two following options combined here??? !!!!!!!!!!!! if opts.listownmodules or opts.install_erp_modules: handler.install_own_modules() did_run_a_command = True return # listapps # -------- # list odoo apps that are declared within the selected site if opts.listapps: handler.listapps() did_run_a_command = True return # delete_site_local # -------- # delete_site_local removes a site and all project files if opts.delete_site_local: handler.delete_site_local() did_run_a_command = True return # installown or updateown or removeown # ------------------------------------ # installown install all modules declared in the selected site # updateown updates one or all modules declared in the selected site # removeown removes one or all modules declared in the selected site # # to be able to execute do this, the target server has to be running. # this server is accessed uding odoo's rpc_api. # to do so, info on user, that should access the running server needs # to be collected. the following values # read from either the config data or can be set using command line options. # --- database --- # - db_user : the user to access the servers database # to check what modules are allready installed the servers database # has to be accessed. # option: "-dbu", "--dbuser". # default: logged in user # - db_password # option: "-p", "--dbpw". # default: admin # - dbhost: the host on which the database is running # option: "-dbh", "--dbhost" # default: localhost. # --- user accessing the running odoo server --- # - rpcuser: the login user to access the odoo server # option: "-rpcu", "--rpcuser" # default: admin. # - rpcpw: the login password to access the odoo server # option: "-P", "--rpcpw" # default: admin. # - rpcport: the the odoo server is running at # option: "-PO", "--port" # default: 8069. if opts.installown or opts.updateown or opts.removeown: handler.install_own_modules() did_run_a_command = True if opts.removeapps: handler.remove_apps() did_run_a_command = True # dataupdate # ---------- # these options are used to copy a running remote server to a lokal # odoo instance # # dataupdate: # ----------- # this copies both an odoo db and the related file data structure from # a remote server to a locally existing (buildout created) server. # the needed info is gathered from diverse sources: # local_data.py # ------------- # - DB_USER: the user name with which to access the local database # default: the logged in user. # - DB_PASSWORD: the password to access the local database server # default: odoo # If the option -p --password is used, the password in local_data is # overruled. # remote data: # ------------ # to collect data on the remote server the key remote_server is used # to get info from sites.py for $SITENAME # - remote_url : the servers url # - remote_data_path : COLLECT it from ODOO_SERVER_DATA ?? # local_data.REMOTE_SERVERS: # --------------------------- # from this dictonary information on the remote server is collected # this is done looking up 'remote_url' in local_data.REMOTE_SERVERS. # - remote_user: user to acces the remote server with # - remote_pw : password to access the remote user with. should normaly the empty # as it is best only to use a public key. # - remote_data_path: how the odoo erverdata can be access on the remote server # ??? should be created automatically # sites_pw.py: # ------------ # the several password used for the services to be acces on the odoo instance, # the remote server or on the mail server can be mixed in from # sites_pw.py. # !!!! sites_pw.py should be kept separate, and should not be version controlled with the rest !!! # # it executes these steps: # - it executes a a command in a remote remote server in a remote shell # this command starts a temporary docker container and dumps the # database of the source server to its dump folder which is: # $REMOTE_URL:$ODOO_SERVER_DATA/$SITENAME/dump/$SITENAME.dmp # - rsync this file to: # localhost:$ODOO_SERVER_DATA/$SITENAME/dump/$SITENAME.dmp # - drop the local database $SITENAME # - create the local database $SITENAME # - restore the local datbase $SITENAME from localhost:$ODOO_SERVER_DATA/$SITENAME/dump/$SITENAME.dmp # - rsync the remote filestore to the local filestore: # which is done with a command similar to: # rsync -av $REMOTEUSER@$REMOTE_URL:$ODOO_SERVER_DATA/$SITENAME/filestore/ localhost:$ODOO_SERVER_DATA/$SITENAME/filestore/ # # run_local_docker # ---------------- # when the option -L --local_docker is used, data is copied from a docker container # running on localhost if opts.dataupdate or opts.dataupdate_close_connections: # def __init__(self, opts, default_values, site_name, foldernames=FOLDERNAMES) set_local = opts.startafterupdate handler.doUpdate( db_update=not opts.noupdatedb, norefresh=opts.norefresh, set_local=set_local, ) did_run_a_command = True if opts.dump_local: # def __init__(self, opts, default_values, site_name, foldernames=FOLDERNAMES) handler.dump_instance() did_run_a_command = True # set_erp_settings # ---------------- # set local settings from the site description if opts.set_erp_settings: handler.set_erp_settings(use_docker=False, local=False) did_run_a_command = True # set_local_data # -------------- # set local settings from the site description if opts.set_local_data: handler.set_local_data(use_remote_setting=False) did_run_a_command = True # set_null_smtp # -------------- # set null smtp handler from the site description if opts.set_null_smtp: handler.set_null_mail_server() did_run_a_command = True # ---------------------- # docker commands # ---------------------- if parsername == "docker": # docker_create_container # ----------------------- # it creates and starts a docker container # or a docker compose file # the created container collects info from sites.py for $SITENAME # it uses the data found with the key "docker" # it collects these data: # - container_name: name of the container to create. # must be unique for each remote server # - odoo_image_version: name of the docker image used to build # the container # - odoo_port: port on which to the running odoo server within the # container can be reached. must be unique for each remote server if opts.docker_create_container or opts.create_compose_file: # "docker -dc", "--create_container", if opts.docker_use_bitnami: handler.create_binami_container() else: handler.check_and_create_container() did_run_a_command = True if opts.docker_create_update_container: # "docker -dcu", "--create_update_container", # create a container that runs etc/odoorunner.sh as entrypoint handler.check_and_create_container(update_container=True) did_run_a_command = True if opts.docker_delete_container: if opts.docker_use_bitnami: handler.delete_bitnami_container() else: handler.check_and_create_container(delete_container=True) did_run_a_command = True if opts.docker_create_db_container: # "docker -dcdb", "--create_db_container", handler.check_and_create_container(container_name="db") did_run_a_command = True # set_erp_settings # ---------------- # set local settings from the site description if opts.set_erp_settings_docker: handler.set_erp_settings(use_docker=True, local=False) did_run_a_command = True # recreate container # ------------------ # recreate a conainer if opts.docker_recreate_container: handler.check_and_create_container(recreate_container=True) did_run_a_command = True return # rename container # ---------------- # recreate a conainer if opts.docker_rename_container: handler.check_and_create_container(rename_container=True) did_run_a_command = True return # # build image # # ---------- # # build docker image according to bitnami # if opts.build_image_bitnami: # handler.build_image_bitnami() # did_run_a_command = True # return # build image # ---------- # build docker image used by a site if opts.docker_build_image or opts.__dict__.get( 'docker_build_image_use_sites'): handler.build_image() did_run_a_command = True return if opts.build_dumper_image: handler.build_dumper_image() did_run_a_command = True return # pull image # ---------- # pull an actual docker image used by a site if opts.docker_pull_image: handler.check_and_create_container(pull_image=True) did_run_a_command = True return # push image # ---------- # push docker image used by a site if opts.docker_push_image: handler.push_image() did_run_a_command = True return # push retag image # ---------------- # push docker image used by a site if opts.docker_images_retag: handler.retag_image() did_run_a_command = True return # installown or updateown or removeown # ------------------------------------ # installown install all modules declared in the selected site # updateown updates one or all modules declared in the selected site # removeown removes one or all modules declared in the selected site # ----------> see create commands if (opts.dinstallown or opts.dupdateown or opts.dremoveown or opts.dinstall_erp_modules): # handler = dockerHandler(opts, default_values, site_name) handler.docker_install_own_modules() did_run_a_command = True # dataupdate_docker # ------------------------------- # these options are used to copy a running remote server to a lokal # odoo instance # # see explanation create->dataupdate # run_local_docker # ---------------- # when the option -L --local_docker is used, data is copied from a docker container # running on localhost if opts.dataupdate_docker: # def __init__(self, opts, default_values, site_name, foldernames=FOLDERNAMES) set_local = True handler.doUpdate( db_update=not opts.noupdatedb, norefresh=opts.norefresh, set_local=set_local, ) did_run_a_command = True if opts.dump_local_docker: # def __init__(self, opts, default_values, site_name, foldernames=FOLDERNAMES) handler.dump_instance() did_run_a_command = True # start or restart docker if (opts.docker_restart_container or opts.docker_start_container or opts.docker_stop_container): if opts.docker_start_container: handler.start_container() elif opts.docker_restart_container: handler.restart_container() else: handler.stop_container() did_run_a_command = True # docker_show # -------------- # show some info about a containe if opts.docker_show or opts.docker_show_all: if opts.docker_show_all: handler.docker_show("all") else: handler.docker_show() did_run_a_command = True # set_local_data # -------------- # set local settings from the site description if opts.set_local_data_docker: handler.set_local_data(use_remote_setting=True) did_run_a_command = True if not did_run_a_command: print(bcolors.WARNING) print("*" * 80) print( "The selected docker option is either invalid or not yet implemented" ) print(bcolors.ENDC) return # ---------------------- # migration commands # ---------------------- if parsername == "migrate": if opts.migrate_remove_apps: handler.migrate_remove_apps() did_run_a_command = True return if opts.migrate_dump_site: handler.migrate_dump_site() did_run_a_command = True return # ---------------------- # support commands # ---------------------- if parsername == "support": # add_site # -------- # add_site adds a site description to the sites.py file # add_site_local adds a site description to the sites_local.py file if opts.add_site or opts.add_site_local: handler.add_site_to_sitelist() did_run_a_command = True return # drop_site # -------- # drop_site removes a site description from the sites.py file if opts.drop_site: handler.drop_site() did_run_a_command = True return # edit_site, edit_server # ---------------------- # Lets the user edit the content of config/localdat.py to edit a server # description, or change the server description in LOCALDATA['sitesinfo_path'] if opts.edit_site or opts.edit_server: if opts.edit_site: handler.check_name() handler.edit_site_or_server() did_run_a_command = True return # ------------------------------------- # editing yam files # ------------------------------------- if opts.edit_config: handler.edit_yaml_file("config.yaml") did_run_a_command = True return if opts.edit_docker: handler.edit_yaml_file("docker.yaml") did_run_a_command = True return if opts.edit_project: handler.edit_yaml_file("project.yaml") did_run_a_command = True return if opts.edit_servers: handler.edit_yaml_file("servers.yaml") did_run_a_command = True return # add_server # ---------- # add_server_to_server_list # add new server info to localdat # ---------------------------------- if opts.add_server: handler.add_server_to_server_list() did_run_a_command = True return # upgrade # ---------- # migrate to new odoo version # ---------------------------------- if opts.upgrade: handler.upgrade(target_site=opts.upgrade) did_run_a_command = True return if not did_run_a_command: print(bcolors.WARNING) print("*" * 80) print( "The selected support option is either invalid or not yet implemented" ) print(bcolors.ENDC) return # ---------------------- # remote commands # ---------------------- if parsername == "remote": if opts.add_apache: handler.add_site_to_apache() did_run_a_command = True return if opts.add_nginx: handler.add_site_to_nginx() did_run_a_command = True return if not did_run_a_command: print(bcolors.WARNING) print("*" * 80) print( "The selected remote option is either invalid or not yet implemented" ) print(bcolors.ENDC) return
def main(opts, parsername, need_names_dic): """ """ # default_handler = SiteCreator try: import wingdbstub except: pass opts.subparser_name = parsername if parsername == 'create': handler = SiteCreator(opts, SITES) elif parsername == 'support': handler = SupportHandler(opts, SITES) elif parsername == 'remote': handler = RemoteHandler(opts, SITES) elif parsername == 'docker': handler = DockerHandler(opts, SITES) elif parsername == 'mail': handler = MailHandler(opts, SITES) else: handler = SiteCreator(opts, SITES) # ckeck whether the used option needs a name to work handler.check_name(need_names_dic=need_names_dic) # ---------------------- # create commands # ---------------------- if parsername == 'create': # create # ------ # builds or updates a server structure # to do so, it does a number of steps # - creates the needed folders in $ERP_SERVER_DATA # - creates a build structure in $PROJECT_HOME/$SITENAME/$SITENAME # where $PROJECT_HOME is read from the config file. # - copies and sets up all files from skeleton directory to the build structure # this is done executing create_new_project and do_copy # - builds a virtualenv environment in the build structure # - prepares to builds an erp server within the build structure by # execution bin/build_erp within the build structure. # Within this bild environment the erp's module path will be set # that it points to the usual erp-workbench directories within the build substructure # and also to the directories within erp_workbench as dictated by the # various modules installed from interpreting the site declaration # in sites.py # - add a "private" addons folder within the build structure called # $SITENAME_addons. This folder is also added to the erp-site's addon path. # - set the data_dir to point to $ERP_SERVER_DATA/$SITENAME/filestore # # modules_update # ------------- if opts.create or opts.modules_update or opts.module_update: info_dic = { 'project_path': handler.default_values['inner'], 'erp_version': BASE_INFO.get('erp_version'), 'site_name': handler.site_name } if opts.create: existed = handler.create_or_update_site() if existed: if not opts.quiet: print() print('%s site allredy existed' % handler.site_name) print(SITE_EXISTED % info_dic) else: if handler.site_name: if not opts.quiet: print() print('%s site created' % handler.site_name) print(SITE_NEW % info_dic) # create the folder structure within the datafoler defined in the config # this also creates the config file used by a docker server within the # newly created folders handler.create_folders(quiet=True) create_server_config(handler) did_run_a_command = True # make sure project was added to bash_aliases handler.add_aliases() # checkout repositories checkout_sa(opts) # list_sites # ---------- # list_sites lists all existing sites both from global and local sites if opts.list_sites: list_sites(SITES, opts.quiet) did_run_a_command = True return # listownmodules # -------------- # list the modules that are declared within the selected site # installown install all erp modules declared in the selected site # todo: why are the two following options combined here??? !!!!!!!!!!!! if opts.listownmodules or opts.install_erp_modules: handler.install_own_modules() did_run_a_command = True return # delete_site_local # -------- # delete_site_local removes a site and all project files if opts.delete_site_local: handler.delete_site_local() did_run_a_command = True return # installown or updateown or removeown # ------------------------------------ # installown install all modules declared in the selected site # updateown updates one or all modules declared in the selected site # removeown removes one or all modules declared in the selected site # # to be able to execute do this, the target server has to be running. # this server is accessed uding odoo's rpc_api. # to do so, info on user, that should access the running server needs # to be collected. the following values # read from either the config data or can be set using command line options. # --- database --- # - db_user : the user to access the servers database # to check what modules are allready installed the servers database # has to be accessed. # option: "-dbu", "--dbuser". # default: logged in user # - db_password # option: "-p", "--dbpw". # default: admin # - dbhost: the host on which the database is running # option: "-dbh", "--dbhost" # default: localhost. # --- user accessing the running odoo server --- # - rpcuser: the login user to access the odoo server # option: "-rpcu", "--rpcuser" # default: admin. # - rpcpw: the login password to access the odoo server # option: "-P", "--rpcpw" # default: admin. # - rpcport: the the odoo server is running at # option: "-PO", "--port" # default: 8069. if opts.installown or opts.updateown or opts.removeown: handler.install_own_modules() did_run_a_command = True # ---------------------- # docker commands # ---------------------- if parsername == 'docker': # docker_create_container # ----------------------- # it creates and starts a docker container # the created container collects info from sites.py for $SITENAME # it uses the data found with the key "docker" # it collects these data: # - container_name: name of the container to create. # must be unique for each remote server # - odoo_image_version: name of the docker image used to build # the container # - odoo_port: port on which to the running odoo server within the # container can be reached. must be unique for each remote server if opts.docker_create_container: # "docker -dc", "--create_container", handler.check_and_create_container() did_run_a_command = True if opts.docker_create_update_container: # "docker -dcu", "--create_update_container", handler.check_and_create_container(update_container=True) did_run_a_command = True if opts.docker_create_db_container: # "docker -dcdb", "--create_db_container", handler.check_and_create_container(container_name='db') did_run_a_command = True # build image # ---------- # build docker image used by a site if opts.docker_build_image: handler.build_image() did_run_a_command = True return # installown or updateown or removeown # ------------------------------------ # installown install all modules declared in the selected site # updateown updates one or all modules declared in the selected site # removeown removes one or all modules declared in the selected site # ----------> see create commands if opts.dinstallown or opts.dupdateown or opts.dremoveown or opts.dinstallodoomodules: #handler = dockerHandler(opts, default_values, site_name) handler.docker_install_own_modules() did_run_a_command = True # ---------------------- # support commands # ---------------------- if parsername == 'support': # add_site # -------- # add_site adds a site description to the sites.py file # add_site_local adds a site description to the sites_local.py file if opts.add_site or opts.add_site_local: handler.add_site_to_sitelist() did_run_a_command = True return # drop_site # -------- # drop_site removes a site description from the sites.py file if opts.drop_site: handler.drop_site() did_run_a_command = True return # edit_site, edit_server # ---------------------- # Lets the user edit the content of config/localdat.py to edit a server # description, or change the server description in LOCALDATA['sitesinfo_path'] if opts.edit_site or opts.edit_server: if opts.edit_site: handler.check_name() handler.edit_site_or_server() did_run_a_command = True return